Skip to content
This repository was archived by the owner on Nov 21, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ dummy := $(call unnest-vars,.., \
# Now restore obj-y
obj-y := $(obj-y-save)

common-obj-$(HAS_TRACEWRAP) += tracewrap.o

all-obj-y = $(obj-y) $(common-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)

Expand Down
3 changes: 3 additions & 0 deletions include/gtracewrap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void do_qemu_set_trace(const char *tracefilename);
2 changes: 1 addition & 1 deletion include/tracewrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "cpu.h"
#include "gtracewrap.h"

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

Expand All @@ -13,7 +14,6 @@ struct toc_entry {
};

extern FILE *qemu_tracefile;
void do_qemu_set_trace(const char *tracefilename);
void qemu_trace(Frame frame);
void qemu_trace_newframe(uint64_t addr, int tread_id);
void qemu_trace_add_operand(OperandInfo *oi, int inout);
Expand Down
1 change: 0 additions & 1 deletion linux-user/Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ obj-$(TARGET_HAS_BFLT) += flatload.o
obj-$(TARGET_I386) += vm86.o
obj-$(TARGET_ARM) += arm/nwfpe/
obj-$(TARGET_M68K) += m68k-sim.o
obj-$(HAS_TRACEWRAP) += tracewrap.o
30 changes: 26 additions & 4 deletions python/printProto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
import getopt
import sys
import IPython
import pickle
from collections import defaultdict
import google

FMT_TXT=0x1
FMT_PKL_HIGHLIGHT=0x2
FMT_UNIQ_INSNS=0x3

def getFrameLength(f):
return struct.unpack("Q", f.read(8))[0]
Expand Down Expand Up @@ -55,7 +62,7 @@ def printFrame(f):
print "PRE: %s" % printOperandList(f.std_frame.operand_pre_list.elem)
print "POST: %s" % printOperandList(f.std_frame.operand_post_list.elem)

def process(infileName, outfileName=None, maxCnt=0):
def process(infileName, outfileName=None, maxCnt=0, outFormat=FMT_TXT):
out = sys.stdout
if outfileName:
out = open(outfileName, 'w')
Expand All @@ -70,15 +77,24 @@ def process(infileName, outfileName=None, maxCnt=0):

print "maxCnt: %i" % maxCnt

insns = defaultdict(lambda : 0)
while (cnt <= maxCnt):
cnt += 1
try:
fr = getFrame(infile)
insns[fr.std_frame.address]+=1
except google.protobuf.message.DecodeError, e:
print "maxCnt: %i, cnt: %i\n" % (maxCnt, cnt)
print e
break
out.write("0x%x, %r\n" % (fr.std_frame.address, fr.std_frame.rawbytes))
if outFormat == FMT_TXT:
out.write("0x%x, %r\n" % (fr.std_frame.address, fr.std_frame.rawbytes))

if outFormat == FMT_PKL_HIGHLIGHT:
highlight_data = {1:set(insns.keys())}
pickle.dump(highlight_data, out)
elif outFormat == FMT_UNIQ_INSNS:
out.write("\n".join(["0x%x" % i for i in set(insns.keys())]))

def getMetaData(f):
f.seek(0x20)
Expand All @@ -91,7 +107,8 @@ def main():
maxCnt = 0
infile = None
outfile = None
opts,argv = getopt.getopt(sys.argv[1:], "f:c:o:d")
outFormat = FMT_TXT
opts,argv = getopt.getopt(sys.argv[1:], "f:c:o:F:d")
for k,v in opts:
if k == '-d':
debug += 1
Expand All @@ -101,9 +118,14 @@ def main():
outfile = v
if k == '-c':
maxCnt = int(v)
if k == '-F':
if v == 'pkl':
outFormat = FMT_PKL_HIGHLIGHT
elif v == 'uniq':
outFormat = FMT_UNIQ_INSNS

if infile:
process(infile, outfile, maxCnt)
process(infile, outfile, maxCnt, outFormat)

if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions qemu-options.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,16 @@ STEXI
Like -monitor but opens in 'control' mode.
ETEXI

DEF("tracefile", HAS_ARG, QEMU_OPTION_tracefile, \
"-tracefile file write BAP traces to file\n",
QEMU_ARCH_ARM)
STEXI
@item -tracefile @var{file}
@findex -tracefile
Write BAP traces into file @var{file}.
Default: /dev/shm/proto
ETEXI

DEF("mon", HAS_ARG, QEMU_OPTION_mon, \
"-mon [chardev=]name[,mode=readline|control][,default]\n", QEMU_ARCH_ALL)
STEXI
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion target-arm/trace_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ OperandInfo * load_store_mem(uint32_t addr, uint32_t val, int ls, int len)
}
OperandInfo *oi = (OperandInfo *)malloc(sizeof(OperandInfo));
operand_info__init(oi);
oi->bit_length = 0;
oi->bit_length = len * 8;
oi->operand_info_specific = ois;
oi->operand_usage = ou;
oi->value.len = len;
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions target-arm/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -10910,15 +10910,16 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
} else {
disas_arm_insn(env, dc);
}
#ifdef HAS_TRACEWRAP
gen_trace_endframe(dc);
#endif //HAS_TRACEWRAP

if (dc->condjmp && !dc->is_jmp) {
gen_set_label(dc->condlabel);
dc->condjmp = 0;
}

#ifdef HAS_TRACEWRAP
gen_trace_endframe(dc);
#endif //HAS_TRACEWRAP

if (tcg_check_temp_count()) {
fprintf(stderr, "TCG temporary leak before "TARGET_FMT_lx"\n",
dc->pc);
Expand Down
12 changes: 8 additions & 4 deletions linux-user/tracewrap.c → tracewrap.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "tracewrap.h"
#include "trace_consts.h"
#include <string.h>

Frame * g_frame;
struct toc_entry *toc;
Expand All @@ -13,6 +12,9 @@ FILE *qemu_tracefile;

void do_qemu_set_trace(const char *tracefilename)
{
if (tracefilename == NULL) {
tracefilename = "/dev/shm/proto";
}
printf("Setting qemu_tracefile at %s\n", tracefilename);
qemu_tracefile = fopen(tracefilename, "wb");
if (qemu_tracefile == NULL) {
Expand All @@ -28,7 +30,8 @@ void qemu_trace_newframe(uint64_t addr, int thread_id)
{
if (open_frame)
{
fprintf(stderr, "frame still open! 0x%08lx\n", (long unsigned int)addr);
fprintf(stderr, "frame still open! 0x%08lx\n",
(long unsigned int)g_frame->std_frame->address);
qemu_trace_endframe(NULL, 0, 0);
}
open_frame = 1;
Expand Down Expand Up @@ -112,8 +115,9 @@ void qemu_trace_endframe(CPUArchState *env, target_ulong pc, size_t size)
StdFrame *sframe = g_frame->std_frame;
sframe->rawbytes.len = size;
sframe->rawbytes.data = (uint8_t *)malloc(size);
for (i = 0; i < size; i++)
sframe->rawbytes.data[i] = cpu_ldub_code(env, pc+i);
for (i = 0; i < size; i++) {
sframe->rawbytes.data[i] = cpu_ldub_code(env, pc+i);
}

size_t msg_size = frame__get_packed_size(g_frame);
uint8_t *packed_buffer = (uint8_t *)malloc(msg_size);
Expand Down
17 changes: 17 additions & 0 deletions vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "config-host.h"

#ifdef HAS_TRACEWRAP
#include "gtracewrap.h"
#endif

#ifdef CONFIG_SECCOMP
#include "sysemu/seccomp.h"
#endif
Expand Down Expand Up @@ -2957,6 +2961,9 @@ int main(int argc, char **argv, char **envp)
bool userconfig = true;
const char *log_mask = NULL;
const char *log_file = NULL;
#ifdef HAS_TRACEWRAP
const char *tracefile = NULL;
#endif
GMemVTable mem_trace = {
.malloc = malloc_and_trace,
.realloc = realloc_and_trace,
Expand Down Expand Up @@ -3412,6 +3419,11 @@ int main(int argc, char **argv, char **envp)
monitor_parse(optarg, "readline");
}
break;
#ifdef HAS_TRACEWRAP
case QEMU_OPTION_tracefile:
tracefile = optarg;
break;
#endif
case QEMU_OPTION_qmp:
monitor_parse(optarg, "control");
default_monitor = 0;
Expand Down Expand Up @@ -3907,6 +3919,11 @@ int main(int argc, char **argv, char **envp)
}
}
}

#ifdef HAS_TRACEWRAP
do_qemu_set_trace(tracefile);
#endif

loc_set_none();

if (qemu_init_main_loop()) {
Expand Down