Skip to content

Commit

Permalink
Merge pull request #5 from BinaryAnalysisPlatform/frames-2.0
Browse files Browse the repository at this point in the history
This PR introduces Frames-2.0 protocol
  • Loading branch information
ivg committed Apr 20, 2016
2 parents 91a9513 + 491b7db commit 3b4aaa5
Show file tree
Hide file tree
Showing 14 changed files with 637 additions and 610 deletions.
108 changes: 0 additions & 108 deletions include/arch.h

This file was deleted.

3 changes: 0 additions & 3 deletions include/gtracewrap.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/trace_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const uint64_t bfd_machine_offset = 24LL;
const uint64_t num_trace_frames_offset = 32LL;
const uint64_t toc_offset_offset = 40LL;
const uint64_t first_frame_offset = 48LL;
const uint64_t out_trace_version = 1LL;
const uint64_t out_trace_version = 2LL;
40 changes: 30 additions & 10 deletions include/tracewrap.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
#pragma once
#pragma once

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "cpu.h"
#include "gtracewrap.h"

#include "frame.piqi.pb-c.h"

struct toc_entry {
uint64_t offset;
struct toc_entry * next;
};

extern FILE *qemu_tracefile;
void qemu_trace(Frame frame);
/** initializes trace subsystem.
All pointers are owned by the caller.
@param filename a name of filesystem entry where trace will be dumpled,
if NULL then the name is basename(argv[0]).frames
@param targetname a path to the executable, must be non NULL
@param argv a full list of arguments passed to the tracer, NULL terminated.
Can be NULL or empty (i.e., contain only a NULL element).
The list may include target arguments.
@param envp a null terminated list of environment parameters,
can be NULL or empty.
@param target_argv a null terminated list of target arguments,
can be NULL or empty.
@param target_envp a null terminated list of target environment,
can be NULL or empty.
*/
void qemu_trace_init(const char *filename, const char *targetname,
char **argv, char **envp,
char **target_argv,
char **target_envp);
void qemu_trace_newframe(target_ulong addr, int tread_id);
void qemu_trace_add_operand(OperandInfo *oi, int inout);
void qemu_trace_endframe(CPUArchState *env, target_ulong pc, target_ulong size);
Expand All @@ -23,12 +43,12 @@ void qemu_trace_finish(uint32_t exit_code);
OperandInfo * load_store_reg(target_ulong reg, target_ulong val, int ls);
OperandInfo * load_store_mem(target_ulong addr, target_ulong val, int ls, int len);

#define REG_CPSR 64
#define REG_APSR 65
#define REG_EFLAGS 66
#define REG_LO 33
#define REG_HI 34

#define REG_CPSR 64
#define REG_APSR 65
#define REG_SP 13
#define REG_LR 14
#define REG_PC 15
Expand Down
4 changes: 2 additions & 2 deletions linux-user/i386/trace_info.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "arch.h"
#include "disas/bfd.h"

const uint64_t bfd_arch = bfd_arch_i386;
const uint64_t bfd_machine = mach_i386_i386;
const uint64_t bfd_machine = bfd_mach_i386_i386;
84 changes: 43 additions & 41 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "elf.h"
#ifdef HAS_TRACEWRAP
#include "tracewrap.h"
const char * qemu_tracefilename = "/dev/shm/proto";
const char * qemu_tracefilename = NULL;
#endif //HAS_TRACEWRAP

char *exec_path;
Expand Down Expand Up @@ -2808,7 +2808,7 @@ void cpu_loop(CPUCRISState *env)
CPUState *cs = CPU(cris_env_get_cpu(env));
int trapnr, ret;
target_siginfo_t info;

while (1) {
trapnr = cpu_cris_exec (env);
switch (trapnr) {
Expand All @@ -2826,13 +2826,13 @@ void cpu_loop(CPUCRISState *env)
/* just indicate that signals should be handled asap */
break;
case EXCP_BREAK:
ret = do_syscall(env,
env->regs[9],
env->regs[10],
env->regs[11],
env->regs[12],
env->regs[13],
env->pregs[7],
ret = do_syscall(env,
env->regs[9],
env->regs[10],
env->regs[11],
env->regs[12],
env->regs[13],
env->pregs[7],
env->pregs[11],
0, 0);
env->regs[10] = ret;
Expand Down Expand Up @@ -2867,7 +2867,7 @@ void cpu_loop(CPUMBState *env)
CPUState *cs = CPU(mb_env_get_cpu(env));
int trapnr, ret;
target_siginfo_t info;

while (1) {
trapnr = cpu_mb_exec (env);
switch (trapnr) {
Expand All @@ -2888,13 +2888,13 @@ void cpu_loop(CPUMBState *env)
/* Return address is 4 bytes after the call. */
env->regs[14] += 4;
env->sregs[SR_PC] = env->regs[14];
ret = do_syscall(env,
env->regs[12],
env->regs[5],
env->regs[6],
env->regs[7],
env->regs[8],
env->regs[9],
ret = do_syscall(env,
env->regs[12],
env->regs[5],
env->regs[6],
env->regs[7],
env->regs[8],
env->regs[9],
env->regs[10],
0, 0);
env->regs[3] = ret;
Expand Down Expand Up @@ -3428,7 +3428,7 @@ void stop_all_tasks(void)
void init_task_state(TaskState *ts)
{
int i;

ts->used = 1;
ts->first_free = ts->sigqueue_table;
for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) {
Expand Down Expand Up @@ -3690,7 +3690,7 @@ static const struct qemu_argument arg_table[] = {
"", "display version information and exit"},
#ifdef HAS_TRACEWRAP
{"tracefile", "", true, handle_trace_filename,
"", "path to trace file (default: /dev/shm/proto)"},
"file", "path to trace file (defaults to <target>.frames)"},
#endif //HAS_TRACEWRAP
{NULL, NULL, false, NULL, NULL, NULL}
};
Expand Down Expand Up @@ -3877,10 +3877,6 @@ int main(int argc, char **argv, char **envp)

optind = parse_args(argc, argv);

#ifdef HAS_TRACEWRAP
//do_qemu_set_trace("/dev/shm/proto");
do_qemu_set_trace(qemu_tracefilename);
#endif //HAS_TRACEWRAP

/* Zero out regs */
memset(regs, 0, sizeof(struct target_pt_regs));
Expand Down Expand Up @@ -4018,6 +4014,12 @@ int main(int argc, char **argv, char **envp)
}
target_argv[target_argc] = NULL;


#ifdef HAS_TRACEWRAP
qemu_trace_init(qemu_tracefilename, filename,
argv, environ, target_argv, target_environ);
#endif //HAS_TRACEWRAP

ts = g_malloc0 (sizeof(TaskState));
init_task_state(ts);
/* build Task State */
Expand Down Expand Up @@ -4297,23 +4299,23 @@ int main(int argc, char **argv, char **envp)
env->regs[12] = regs->r12;
env->regs[13] = regs->r13;
env->regs[14] = regs->r14;
env->regs[15] = regs->r15;
env->regs[16] = regs->r16;
env->regs[17] = regs->r17;
env->regs[18] = regs->r18;
env->regs[19] = regs->r19;
env->regs[20] = regs->r20;
env->regs[21] = regs->r21;
env->regs[22] = regs->r22;
env->regs[23] = regs->r23;
env->regs[24] = regs->r24;
env->regs[25] = regs->r25;
env->regs[26] = regs->r26;
env->regs[27] = regs->r27;
env->regs[28] = regs->r28;
env->regs[29] = regs->r29;
env->regs[30] = regs->r30;
env->regs[31] = regs->r31;
env->regs[15] = regs->r15;
env->regs[16] = regs->r16;
env->regs[17] = regs->r17;
env->regs[18] = regs->r18;
env->regs[19] = regs->r19;
env->regs[20] = regs->r20;
env->regs[21] = regs->r21;
env->regs[22] = regs->r22;
env->regs[23] = regs->r23;
env->regs[24] = regs->r24;
env->regs[25] = regs->r25;
env->regs[26] = regs->r26;
env->regs[27] = regs->r27;
env->regs[28] = regs->r28;
env->regs[29] = regs->r29;
env->regs[30] = regs->r30;
env->regs[31] = regs->r31;
env->sregs[SR_PC] = regs->pc;
}
#elif defined(TARGET_MIPS)
Expand Down Expand Up @@ -4375,7 +4377,7 @@ int main(int argc, char **argv, char **envp)
env->regs[12] = regs->r12;
env->regs[13] = regs->r13;
env->regs[14] = info->start_stack;
env->regs[15] = regs->acr;
env->regs[15] = regs->acr;
env->pc = regs->erp;
}
#elif defined(TARGET_S390X)
Expand Down
5 changes: 3 additions & 2 deletions linux-user/mips/trace_info.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "arch.h"
#include "disas/bfd.h"

const uint64_t bfd_arch = bfd_arch_mips;
const uint64_t bfd_machine = mach_i386_i386;
const uint64_t bfd_machine = 32 ; /* bfd_mach_mipsisa32 */
/* our bfd.h is so outdated, that it doesn't include it.*/
4 changes: 2 additions & 2 deletions linux-user/x86_64/trace_info.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "arch.h"
#include "disas/bfd.h"

const uint64_t bfd_arch = bfd_arch_i386;
const uint64_t bfd_machine = mach_x86_64;
const uint64_t bfd_machine = bfd_mach_x86_64;
Loading

0 comments on commit 3b4aaa5

Please sign in to comment.