Skip to content

Commit 491b7db

Browse files
committed
This PR introduces Frames-2.0 protocol
The protocol supports meta information. The new protocol also renders TOC optional, allowing to work with streams. In particular it can dump trace into named pipe, thus allowing to trace programs interactive or non-terminating programs. The PR also fixes an allotment of bugs and issues 1. use glib memory management tools 2. check return values 3. rewrote trace writer 4. removed outdated and incorrect arch.h, use disas/bfd.h 5. removed dead and unused code
1 parent 9bc683d commit 491b7db

File tree

14 files changed

+637
-610
lines changed

14 files changed

+637
-610
lines changed

include/arch.h

Lines changed: 0 additions & 108 deletions
This file was deleted.

include/gtracewrap.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

include/trace_consts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const uint64_t bfd_machine_offset = 24LL;
1010
const uint64_t num_trace_frames_offset = 32LL;
1111
const uint64_t toc_offset_offset = 40LL;
1212
const uint64_t first_frame_offset = 48LL;
13-
const uint64_t out_trace_version = 1LL;
13+
const uint64_t out_trace_version = 2LL;

include/tracewrap.h

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1-
#pragma once
1+
#pragma once
22

33
#include <stdint.h>
44
#include <stdio.h>
55
#include <stdlib.h>
66
#include "cpu.h"
7-
#include "gtracewrap.h"
87

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

11-
struct toc_entry {
12-
uint64_t offset;
13-
struct toc_entry * next;
14-
};
1510

16-
extern FILE *qemu_tracefile;
17-
void qemu_trace(Frame frame);
11+
/** initializes trace subsystem.
12+
13+
All pointers are owned by the caller.
14+
15+
@param filename a name of filesystem entry where trace will be dumpled,
16+
if NULL then the name is basename(argv[0]).frames
17+
18+
@param targetname a path to the executable, must be non NULL
19+
20+
21+
@param argv a full list of arguments passed to the tracer, NULL terminated.
22+
Can be NULL or empty (i.e., contain only a NULL element).
23+
The list may include target arguments.
24+
25+
@param envp a null terminated list of environment parameters,
26+
can be NULL or empty.
27+
28+
@param target_argv a null terminated list of target arguments,
29+
can be NULL or empty.
30+
31+
@param target_envp a null terminated list of target environment,
32+
can be NULL or empty.
33+
*/
34+
void qemu_trace_init(const char *filename, const char *targetname,
35+
char **argv, char **envp,
36+
char **target_argv,
37+
char **target_envp);
1838
void qemu_trace_newframe(target_ulong addr, int tread_id);
1939
void qemu_trace_add_operand(OperandInfo *oi, int inout);
2040
void qemu_trace_endframe(CPUArchState *env, target_ulong pc, target_ulong size);
@@ -23,12 +43,12 @@ void qemu_trace_finish(uint32_t exit_code);
2343
OperandInfo * load_store_reg(target_ulong reg, target_ulong val, int ls);
2444
OperandInfo * load_store_mem(target_ulong addr, target_ulong val, int ls, int len);
2545

26-
#define REG_CPSR 64
27-
#define REG_APSR 65
2846
#define REG_EFLAGS 66
2947
#define REG_LO 33
3048
#define REG_HI 34
3149

50+
#define REG_CPSR 64
51+
#define REG_APSR 65
3252
#define REG_SP 13
3353
#define REG_LR 14
3454
#define REG_PC 15

linux-user/i386/trace_info.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "arch.h"
3+
#include "disas/bfd.h"
44

55
const uint64_t bfd_arch = bfd_arch_i386;
6-
const uint64_t bfd_machine = mach_i386_i386;
6+
const uint64_t bfd_machine = bfd_mach_i386_i386;

linux-user/main.c

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "elf.h"
3737
#ifdef HAS_TRACEWRAP
3838
#include "tracewrap.h"
39-
const char * qemu_tracefilename = "/dev/shm/proto";
39+
const char * qemu_tracefilename = NULL;
4040
#endif //HAS_TRACEWRAP
4141

4242
char *exec_path;
@@ -2808,7 +2808,7 @@ void cpu_loop(CPUCRISState *env)
28082808
CPUState *cs = CPU(cris_env_get_cpu(env));
28092809
int trapnr, ret;
28102810
target_siginfo_t info;
2811-
2811+
28122812
while (1) {
28132813
trapnr = cpu_cris_exec (env);
28142814
switch (trapnr) {
@@ -2826,13 +2826,13 @@ void cpu_loop(CPUCRISState *env)
28262826
/* just indicate that signals should be handled asap */
28272827
break;
28282828
case EXCP_BREAK:
2829-
ret = do_syscall(env,
2830-
env->regs[9],
2831-
env->regs[10],
2832-
env->regs[11],
2833-
env->regs[12],
2834-
env->regs[13],
2835-
env->pregs[7],
2829+
ret = do_syscall(env,
2830+
env->regs[9],
2831+
env->regs[10],
2832+
env->regs[11],
2833+
env->regs[12],
2834+
env->regs[13],
2835+
env->pregs[7],
28362836
env->pregs[11],
28372837
0, 0);
28382838
env->regs[10] = ret;
@@ -2867,7 +2867,7 @@ void cpu_loop(CPUMBState *env)
28672867
CPUState *cs = CPU(mb_env_get_cpu(env));
28682868
int trapnr, ret;
28692869
target_siginfo_t info;
2870-
2870+
28712871
while (1) {
28722872
trapnr = cpu_mb_exec (env);
28732873
switch (trapnr) {
@@ -2888,13 +2888,13 @@ void cpu_loop(CPUMBState *env)
28882888
/* Return address is 4 bytes after the call. */
28892889
env->regs[14] += 4;
28902890
env->sregs[SR_PC] = env->regs[14];
2891-
ret = do_syscall(env,
2892-
env->regs[12],
2893-
env->regs[5],
2894-
env->regs[6],
2895-
env->regs[7],
2896-
env->regs[8],
2897-
env->regs[9],
2891+
ret = do_syscall(env,
2892+
env->regs[12],
2893+
env->regs[5],
2894+
env->regs[6],
2895+
env->regs[7],
2896+
env->regs[8],
2897+
env->regs[9],
28982898
env->regs[10],
28992899
0, 0);
29002900
env->regs[3] = ret;
@@ -3428,7 +3428,7 @@ void stop_all_tasks(void)
34283428
void init_task_state(TaskState *ts)
34293429
{
34303430
int i;
3431-
3431+
34323432
ts->used = 1;
34333433
ts->first_free = ts->sigqueue_table;
34343434
for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) {
@@ -3690,7 +3690,7 @@ static const struct qemu_argument arg_table[] = {
36903690
"", "display version information and exit"},
36913691
#ifdef HAS_TRACEWRAP
36923692
{"tracefile", "", true, handle_trace_filename,
3693-
"", "path to trace file (default: /dev/shm/proto)"},
3693+
"file", "path to trace file (defaults to <target>.frames)"},
36943694
#endif //HAS_TRACEWRAP
36953695
{NULL, NULL, false, NULL, NULL, NULL}
36963696
};
@@ -3877,10 +3877,6 @@ int main(int argc, char **argv, char **envp)
38773877

38783878
optind = parse_args(argc, argv);
38793879

3880-
#ifdef HAS_TRACEWRAP
3881-
//do_qemu_set_trace("/dev/shm/proto");
3882-
do_qemu_set_trace(qemu_tracefilename);
3883-
#endif //HAS_TRACEWRAP
38843880

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

4017+
4018+
#ifdef HAS_TRACEWRAP
4019+
qemu_trace_init(qemu_tracefilename, filename,
4020+
argv, environ, target_argv, target_environ);
4021+
#endif //HAS_TRACEWRAP
4022+
40214023
ts = g_malloc0 (sizeof(TaskState));
40224024
init_task_state(ts);
40234025
/* build Task State */
@@ -4297,23 +4299,23 @@ int main(int argc, char **argv, char **envp)
42974299
env->regs[12] = regs->r12;
42984300
env->regs[13] = regs->r13;
42994301
env->regs[14] = regs->r14;
4300-
env->regs[15] = regs->r15;
4301-
env->regs[16] = regs->r16;
4302-
env->regs[17] = regs->r17;
4303-
env->regs[18] = regs->r18;
4304-
env->regs[19] = regs->r19;
4305-
env->regs[20] = regs->r20;
4306-
env->regs[21] = regs->r21;
4307-
env->regs[22] = regs->r22;
4308-
env->regs[23] = regs->r23;
4309-
env->regs[24] = regs->r24;
4310-
env->regs[25] = regs->r25;
4311-
env->regs[26] = regs->r26;
4312-
env->regs[27] = regs->r27;
4313-
env->regs[28] = regs->r28;
4314-
env->regs[29] = regs->r29;
4315-
env->regs[30] = regs->r30;
4316-
env->regs[31] = regs->r31;
4302+
env->regs[15] = regs->r15;
4303+
env->regs[16] = regs->r16;
4304+
env->regs[17] = regs->r17;
4305+
env->regs[18] = regs->r18;
4306+
env->regs[19] = regs->r19;
4307+
env->regs[20] = regs->r20;
4308+
env->regs[21] = regs->r21;
4309+
env->regs[22] = regs->r22;
4310+
env->regs[23] = regs->r23;
4311+
env->regs[24] = regs->r24;
4312+
env->regs[25] = regs->r25;
4313+
env->regs[26] = regs->r26;
4314+
env->regs[27] = regs->r27;
4315+
env->regs[28] = regs->r28;
4316+
env->regs[29] = regs->r29;
4317+
env->regs[30] = regs->r30;
4318+
env->regs[31] = regs->r31;
43174319
env->sregs[SR_PC] = regs->pc;
43184320
}
43194321
#elif defined(TARGET_MIPS)
@@ -4375,7 +4377,7 @@ int main(int argc, char **argv, char **envp)
43754377
env->regs[12] = regs->r12;
43764378
env->regs[13] = regs->r13;
43774379
env->regs[14] = info->start_stack;
4378-
env->regs[15] = regs->acr;
4380+
env->regs[15] = regs->acr;
43794381
env->pc = regs->erp;
43804382
}
43814383
#elif defined(TARGET_S390X)

linux-user/mips/trace_info.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

3-
#include "arch.h"
3+
#include "disas/bfd.h"
44

55
const uint64_t bfd_arch = bfd_arch_mips;
6-
const uint64_t bfd_machine = mach_i386_i386;
6+
const uint64_t bfd_machine = 32 ; /* bfd_mach_mipsisa32 */
7+
/* our bfd.h is so outdated, that it doesn't include it.*/

linux-user/x86_64/trace_info.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "arch.h"
3+
#include "disas/bfd.h"
44

55
const uint64_t bfd_arch = bfd_arch_i386;
6-
const uint64_t bfd_machine = mach_x86_64;
6+
const uint64_t bfd_machine = bfd_mach_x86_64;

0 commit comments

Comments
 (0)