Skip to content

Commit cd45969

Browse files
committed
Write trace header (without machine details yet).
1 parent f690488 commit cd45969

File tree

4 files changed

+160
-17
lines changed

4 files changed

+160
-17
lines changed

contrib/plugins/bap-tracing/meson.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ piqi_src = custom_target('piqi',
1010
output: 'frame.piqi.proto',
1111
command: [piqi, 'to-proto', '@INPUT@', '-o', '@OUTPUT@'])
1212

13+
frame_arch_h = fs.copyfile('bap-frames/libtrace/src/frame_arch.h',
14+
'frame_arch.h')
15+
1316
# protobuf file -> C code
1417
frame_proto_src_raw = custom_target('proto',
1518
input: piqi_src,
@@ -30,7 +33,7 @@ frame_proto_src = custom_target(
3033
libprotobuf = dependency('libprotobuf-c')
3134
frame_protobuf = static_library('protobuf', [frame_proto_src], pic: true)
3235
dep_libprotobuf = declare_dependency(
33-
sources : frame_proto_src,
36+
sources : [frame_proto_src, frame_arch_h],
3437
link_with : [frame_protobuf],
3538
dependencies: [libprotobuf]
3639
)
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
#pragma once
2-
3-
// #include "trace_info.h"
4-
5-
const uint64_t magic_number = 7456879624156307493LL;
6-
const uint64_t magic_number_offset = 0LL;
7-
const uint64_t trace_version_offset = 8LL;
8-
const uint64_t bfd_arch_offset = 16LL;
9-
const uint64_t bfd_machine_offset = 24LL;
10-
const uint64_t num_trace_frames_offset = 32LL;
11-
const uint64_t toc_offset_offset = 40LL;
12-
const uint64_t first_frame_offset = 48LL;
13-
const uint64_t out_trace_version = 2LL;
1+
#ifndef BAP_TRACE_CONSTS_H
2+
#define BAP_TRACE_CONSTS_H
3+
4+
#include <stdint.h>
5+
6+
// Trace header constants
7+
8+
static const uint64_t magic_number = 7456879624156307493LL;
9+
static const uint64_t magic_number_offset = 0LL;
10+
static const uint64_t trace_version_offset = 8LL;
11+
static const uint64_t bfd_arch_offset = 16LL;
12+
static const uint64_t bfd_machine_offset = 24LL;
13+
static const uint64_t num_trace_frames_offset = 32LL;
14+
static const uint64_t toc_offset_offset = 40LL;
15+
static const uint64_t first_frame_offset = 48LL;
16+
static const uint64_t out_trace_version = 2LL;
17+
18+
// Arch specific
19+
20+
#endif

contrib/plugins/bap-tracing/tracing.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <glib.h>
55

6+
#include "frame_arch.h"
67
#include "frame_buffer.h"
78
#include "qemu-plugin.h"
89
#include "tracing.h"
@@ -185,9 +186,46 @@ static void plugin_exit(qemu_plugin_id_t id, void *udata) {
185186
// Dump rest of frames to file.
186187
}
187188

189+
static bool get_frame_arch_mach(const char *target_name, uint64_t *arch,
190+
uint64_t *mach) {
191+
*arch = 0;
192+
*arch = frame_arch_last;
193+
const char *aname = arch_map[0].name;
194+
for (size_t i = 0; arch_map[i].name; ++i) {
195+
aname = arch_map[i].name;
196+
if (!strncmp(aname, target_name, strlen(aname))) {
197+
*arch = arch_map[i].val;
198+
break;
199+
}
200+
}
201+
return *arch != frame_arch_last;
202+
}
203+
204+
static bool write_header(FILE *file, const char *target_name) {
205+
uint64_t frame_arch = 0;
206+
uint64_t frame_mach = 0;
207+
if (!get_frame_arch_mach(target_name, &frame_arch, &frame_mach)) {
208+
qemu_plugin_outs("Failed to get arch/mach.\n");
209+
return false;
210+
}
211+
uint64_t num_frames = 0ULL;
212+
uint64_t toc_off = 0ULL;
213+
WRITE(magic_number);
214+
WRITE(out_trace_version);
215+
WRITE(frame_arch);
216+
WRITE(frame_mach);
217+
WRITE(num_frames);
218+
WRITE(toc_off);
219+
return true;
220+
}
221+
188222
QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
189223
const qemu_info_t *info, int argc,
190224
char **argv) {
225+
qemu_plugin_outs("Target name: ");
226+
qemu_plugin_outs(info->target_name);
227+
qemu_plugin_outs("\n");
228+
191229
const char *target_path = "/tmp/test.trace";
192230
state.frame_buffer = g_ptr_array_new();
193231
state.vcpus = g_ptr_array_new();
@@ -198,7 +236,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
198236
for (size_t i = 0; i < argc; ++i) {
199237
qemu_plugin_outs(argv[i]);
200238
}
201-
// write_header();
239+
if (!write_header(state.file, info->target_name)) {
240+
qemu_plugin_outs("Failed to header.\n");
241+
return 1;
242+
}
202243
// write_meta(argv, envp, target_argv, target_envp);
203244

204245
qemu_plugin_register_vcpu_init_cb(id, vcpu_init);

contrib/plugins/bap-tracing/tracing.h

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,105 @@
44
#ifndef BAP_TRACING_H
55
#define BAP_TRACING_H
66

7+
#include <glib.h>
78
#include <qemu-plugin.h>
89
#include <stdio.h>
9-
#include <glib.h>
1010

1111
#include "frame.piqi.pb-c-patched.h"
12-
#include "tracewrap.h"
12+
#include "frame_arch.h"
1313
#include "frame_buffer.h"
14+
#include "trace_consts.h"
15+
16+
struct arch_enum_entry {
17+
const char *name;
18+
enum frame_architecture val;
19+
};
20+
21+
static struct arch_enum_entry arch_map[] = {
22+
{.name = "unknown", .val = frame_arch_unknown},
23+
{.name = "obscure", .val = frame_arch_obscure},
24+
{.name = "m68k", .val = frame_arch_m68k},
25+
{.name = "vax", .val = frame_arch_vax},
26+
{.name = "i960", .val = frame_arch_i960},
27+
{.name = "or32", .val = frame_arch_or32},
28+
{.name = "sparc", .val = frame_arch_sparc},
29+
{.name = "spu", .val = frame_arch_spu},
30+
{.name = "mips", .val = frame_arch_mips},
31+
{.name = "i386", .val = frame_arch_i386},
32+
{.name = "l1om", .val = frame_arch_l1om},
33+
{.name = "we32k", .val = frame_arch_we32k},
34+
{.name = "tahoe", .val = frame_arch_tahoe},
35+
{.name = "i860", .val = frame_arch_i860},
36+
{.name = "i370", .val = frame_arch_i370},
37+
{.name = "romp", .val = frame_arch_romp},
38+
{.name = "convex", .val = frame_arch_convex},
39+
{.name = "m88k", .val = frame_arch_m88k},
40+
{.name = "m98k", .val = frame_arch_m98k},
41+
{.name = "pyramid", .val = frame_arch_pyramid},
42+
{.name = "h8300", .val = frame_arch_h8300},
43+
{.name = "pdp11", .val = frame_arch_pdp11},
44+
{.name = "plugin", .val = frame_arch_plugin},
45+
{.name = "powerpc", .val = frame_arch_powerpc},
46+
{.name = "rs6000", .val = frame_arch_rs6000},
47+
{.name = "hppa", .val = frame_arch_hppa},
48+
{.name = "d10v", .val = frame_arch_d10v},
49+
{.name = "d30v", .val = frame_arch_d30v},
50+
{.name = "dlx", .val = frame_arch_dlx},
51+
{.name = "m68hc11", .val = frame_arch_m68hc11},
52+
{.name = "m68hc12", .val = frame_arch_m68hc12},
53+
{.name = "z8k", .val = frame_arch_z8k},
54+
{.name = "h8500", .val = frame_arch_h8500},
55+
{.name = "sh", .val = frame_arch_sh},
56+
{.name = "alpha", .val = frame_arch_alpha},
57+
{.name = "arm", .val = frame_arch_arm},
58+
{.name = "ns32k", .val = frame_arch_ns32k},
59+
{.name = "w65", .val = frame_arch_w65},
60+
{.name = "tic30", .val = frame_arch_tic30},
61+
{.name = "tic4x", .val = frame_arch_tic4x},
62+
{.name = "tic54x", .val = frame_arch_tic54x},
63+
{.name = "tic6x", .val = frame_arch_tic6x},
64+
{.name = "tic80", .val = frame_arch_tic80},
65+
{.name = "v850", .val = frame_arch_v850},
66+
{.name = "arc", .val = frame_arch_arc},
67+
{.name = "m32c", .val = frame_arch_m32c},
68+
{.name = "m32r", .val = frame_arch_m32r},
69+
{.name = "mn10200", .val = frame_arch_mn10200},
70+
{.name = "mn10300", .val = frame_arch_mn10300},
71+
{.name = "fr30", .val = frame_arch_fr30},
72+
{.name = "frv", .val = frame_arch_frv},
73+
{.name = "moxie", .val = frame_arch_moxie},
74+
{.name = "mcore", .val = frame_arch_mcore},
75+
{.name = "mep", .val = frame_arch_mep},
76+
{.name = "ia64", .val = frame_arch_ia64},
77+
{.name = "ip2k", .val = frame_arch_ip2k},
78+
{.name = "iq2000", .val = frame_arch_iq2000},
79+
{.name = "mt", .val = frame_arch_mt},
80+
{.name = "pj", .val = frame_arch_pj},
81+
{.name = "avr", .val = frame_arch_avr},
82+
{.name = "bfin", .val = frame_arch_bfin},
83+
{.name = "cr16", .val = frame_arch_cr16},
84+
{.name = "cr16c", .val = frame_arch_cr16c},
85+
{.name = "crx", .val = frame_arch_crx},
86+
{.name = "cris", .val = frame_arch_cris},
87+
{.name = "rx", .val = frame_arch_rx},
88+
{.name = "s390", .val = frame_arch_s390},
89+
{.name = "score", .val = frame_arch_score},
90+
{.name = "openrisc", .val = frame_arch_openrisc},
91+
{.name = "mmix", .val = frame_arch_mmix},
92+
{.name = "xstormy16", .val = frame_arch_xstormy16},
93+
{.name = "msp430", .val = frame_arch_msp430},
94+
{.name = "xc16x", .val = frame_arch_xc16x},
95+
{.name = "xtensa", .val = frame_arch_xtensa},
96+
{.name = "z80", .val = frame_arch_z80},
97+
{.name = "lm32", .val = frame_arch_lm32},
98+
{.name = "microblaze", .val = frame_arch_microblaze},
99+
{.name = "6502", .val = frame_arch_6502},
100+
{.name = "aarch64", .val = frame_arch_aarch64},
101+
{.name = "8051", .val = frame_arch_8051},
102+
{.name = "sm83", .val = frame_arch_sm83},
103+
{.name = "hexagon", .val = frame_arch_hexagon},
104+
{.name = NULL, .val = frame_arch_last},
105+
};
14106

15107
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
16108

0 commit comments

Comments
 (0)