Skip to content

Commit d2a28a2

Browse files
committed
More logging
1 parent e5b3a24 commit d2a28a2

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

cpu-exec.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "qemu/rcu.h"
3030

3131
/* -icount align implementation. */
32+
uint64_t tracer_code_start,
33+
tracer_code_end;
3234

3335
typedef struct SyncClocks {
3436
int64_t diff_clk;
@@ -493,16 +495,23 @@ int cpu_exec(CPUArchState *env)
493495
tcg_ctx.tb_ctx.tb_invalidated_flag = 0;
494496
}
495497
if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
496-
qemu_log("Trace %p [" TARGET_FMT_lx "] %s\n",
497-
tb->tc_ptr, tb->pc, lookup_symbol(tb->pc));
498+
/* tracer only cares about transitions in .text */
499+
if (tb->pc >= tracer_code_start && tb->pc <= tracer_code_end)
500+
qemu_log("Trace %p [" TARGET_FMT_lx "] %s\n",
501+
tb->tc_ptr, tb->pc, lookup_symbol(tb->pc));
498502
}
499503
/* see if we can patch the calling TB. When the TB
500504
spans two pages, we cannot safely do a direct
501505
jump. */
506+
507+
/* tracer needs to see every basic block transition */
508+
/*
502509
if (next_tb != 0 && tb->page_addr[1] == -1) {
503510
tb_add_jump((TranslationBlock *)(next_tb & ~TB_EXIT_MASK),
504511
next_tb & TB_EXIT_MASK, tb);
505512
}
513+
*/
514+
506515
have_tb_lock = false;
507516
spin_unlock(&tcg_ctx.tb_ctx.tb_lock);
508517

linux-user/elfload.c

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#define ELF_OSABI ELFOSABI_SYSV
3030

31+
extern uint64_t tracer_code_start, tracer_code_end;
32+
3133
/* from personality.h */
3234

3335
/*
@@ -1785,6 +1787,7 @@ static void load_elf_image(const char *image_name, int image_fd,
17851787
struct image_info *info, char **pinterp_name,
17861788
char bprm_buf[BPRM_BUF_SIZE])
17871789
{
1790+
printf("[tracer-debug] Loading image %s\n", image_name);
17881791
struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
17891792
struct elf_phdr *phdr;
17901793
abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
@@ -1922,9 +1925,12 @@ static void load_elf_image(const char *image_name, int image_fd,
19221925
if (elf_prot & PROT_EXEC) {
19231926
if (vaddr < info->start_code) {
19241927
info->start_code = vaddr;
1928+
if (!tracer_code_start) tracer_code_start = vaddr;
19251929
}
19261930
if (vaddr_ef > info->end_code) {
19271931
info->end_code = vaddr_ef;
1932+
printf("[tracer-debug] highest address of mapped code: 0x%lx\n", (unsigned long)vaddr_ef);
1933+
if (!tracer_code_end) tracer_code_end = vaddr_ef;
19281934
}
19291935
}
19301936
if (elf_prot & PROT_WRITE) {

linux-user/flatload.c

+4
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
683683
/* Create the file name */
684684
sprintf(buf, "/lib/lib%d.so", id);
685685

686+
printf("[tracer-debug] Load_flat_so %s\n", buf);
687+
686688
/* Open the file up */
687689
bprm.filename = buf;
688690
bprm.file = open_exec(bprm.filename);
@@ -714,6 +716,8 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info)
714716
int res;
715717
int i, j;
716718

719+
printf("[tracer-debug] Load_flat %s\n", bprm->filename);
720+
717721
memset(libinfo, 0, sizeof(libinfo));
718722
/*
719723
* We have to add the size of our arguments to our stack size

linux-user/mmap.c

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
//#define DEBUG_MMAP
3535

36+
extern uint64_t tracer_code_end;
37+
3638
static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
3739
static __thread int mmap_lock_count;
3840

@@ -372,6 +374,12 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
372374
{
373375
abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;
374376

377+
if (len+start > tracer_code_end)
378+
{
379+
printf("[tracer-debug] mmap: tracer_code_end updated: 0x%lx\n", (unsigned long)len+start);
380+
tracer_code_end = len+start;
381+
}
382+
375383
mmap_lock();
376384
#ifdef DEBUG_MMAP
377385
{

linux-user/syscall.c

+13
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
204204
#define TARGET_NR__llseek TARGET_NR_llseek
205205
#endif
206206

207+
static bool last_read_empty = false;
208+
207209
#ifdef __NR_gettid
208210
_syscall0(int, gettid)
209211
#else
@@ -671,6 +673,7 @@ abi_long do_brk(abi_ulong new_brk)
671673
}
672674
target_brk = new_brk;
673675
DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk <= brk_page)\n", target_brk);
676+
printf("[tracer-debug] New BRK: 0x%lx\n", (unsigned long) target_brk);
674677
return target_brk;
675678
}
676679

@@ -699,6 +702,7 @@ abi_long do_brk(abi_ulong new_brk)
699702
brk_page = HOST_PAGE_ALIGN(target_brk);
700703
DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr == brk_page)\n",
701704
target_brk);
705+
printf("[tracer-debug] New BRK: 0x%lx\n", (unsigned long) target_brk);
702706
return target_brk;
703707
} else if (mapped_addr != -1) {
704708
/* Mapped but at wrong address, meaning there wasn't actually
@@ -718,6 +722,7 @@ abi_long do_brk(abi_ulong new_brk)
718722
return -TARGET_ENOMEM;
719723
#endif
720724
/* For everything else, return the previous break. */
725+
printf("[tracer-debug] BRK unchanged (0x%lx\n)", (unsigned long) target_brk);
721726
return target_brk;
722727
}
723728

@@ -5572,6 +5577,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
55725577
if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
55735578
goto efault;
55745579
ret = get_errno(read(arg1, p, arg3));
5580+
if (ret == 0) {
5581+
if (last_read_empty) {
5582+
exit_group(1);
5583+
}
5584+
last_read_empty = true;
5585+
} else {
5586+
last_read_empty = false;
5587+
}
55755588
unlock_user(p, arg2, ret);
55765589
}
55775590
break;

0 commit comments

Comments
 (0)