|
From: Philippe W. <phi...@sk...> - 2015-05-14 20:27:53
|
The patch below aims at allowing a backtrace when Valgrind does
client syscalls.
Doing a test on x86 (running sleep 100 under valgrind),
I see that backtraces are already working on x86 with GDB 7.7.
(gdb) bt
#0 vgModuleLocal_do_syscall_for_client_WRK () at m_syswrap/syscall-x86-linux.S:117
#1 0x3807f5fe in do_syscall_for_client (syscall_mask=<optimized out>, tst=<optimized out>, syscallno=<optimized out>)
at m_syswrap/syswrap-main.c:313
#2 vgPlain_client_syscall (tid=0, trc=77) at m_syswrap/syswrap-main.c:1743
#3 0x3807c351 in handle_syscall (tid=4294966780, tid@entry=1, trc=134538532) at m_scheduler/scheduler.c:1099
#4 0x3807da27 in vgPlain_scheduler (tid=1) at m_scheduler/scheduler.c:1413
#5 0x3808b6d2 in thread_wrapper (tidW=<optimized out>) at m_syswrap/syswrap-linux.c:102
#6 run_a_thread_NORETURN (tidW=1) at m_syswrap/syswrap-linux.c:155
#7 0x00000000 in ?? ()
(gdb)
On amd64, GDB 7.7 also succeeds to make a backtrace (but containing
strange program counters) :
(gdb) bt
#0 vgModuleLocal_do_syscall_for_client_WRK () at m_syswrap/syscall-amd64-linux.S:147
#1 0x0000000000000008 in ?? ()
#2 0x000000080308bdd0 in ?? ()
#3 0x000000080308bd90 in ?? ()
#4 0x00000008020083a0 in ?? ()
#5 0x0000000000000023 in ?? ()
#6 0x00000008023844a8 in ?? ()
#7 0x00000008023844f0 in ?? ()
#8 0x0000000000000023 in ?? ()
#9 0x0000000000000001 in ?? ()
#10 0x0000000802008390 in ?? ()
#11 0x0000000802384460 in ?? ()
#12 0x0000000038090f72 in do_syscall_for_client (syscall_mask=0x80308bd90, tst=0x802008390, syscallno=35) at m_syswrap/syswrap-main.c:313
#13 vgPlain_client_syscall (tid=tid@entry=1, trc=trc@entry=73) at m_syswrap/syswrap-main.c:1743
#14 0x000000003808d943 in handle_syscall (tid=tid@entry=1, trc=73) at m_scheduler/scheduler.c:1099
....
Is the patch improving the above (for x86 and/or amd64) ?
Or is the backtrace not working at all in your environment ?
Which GDB version are you using ?
Thanks
Philippe
On Thu, 2015-05-14 at 21:20 +0200, Matthias Schwarzott wrote:
> These allow to attach gdb and see the backtrace while valgrind is doing a syscall.
> ---
> coregrind/m_syswrap/syscall-amd64-linux.S | 59 ++++++++++++++++++++++++-------
> coregrind/m_syswrap/syscall-x86-linux.S | 15 ++++++++
> 2 files changed, 61 insertions(+), 13 deletions(-)
>
> diff --git a/coregrind/m_syswrap/syscall-amd64-linux.S b/coregrind/m_syswrap/syscall-amd64-linux.S
> index 0810b54..9498b98 100644
> --- a/coregrind/m_syswrap/syscall-amd64-linux.S
> +++ b/coregrind/m_syswrap/syscall-amd64-linux.S
> @@ -77,29 +77,46 @@
>
> .globl ML_(do_syscall_for_client_WRK)
> ML_(do_syscall_for_client_WRK):
> + .cfi_startproc
> /* save callee-saved regs */
> pushq %rbx
> + .cfi_adjust_cfa_offset 8
> pushq %rbp
> + .cfi_adjust_cfa_offset 8
> pushq %r12
> + .cfi_adjust_cfa_offset 8
> pushq %r13
> + .cfi_adjust_cfa_offset 8
> pushq %r14
> + .cfi_adjust_cfa_offset 8
> pushq %r15
> + .cfi_adjust_cfa_offset 8
>
> #define FSZ ((4+1)*4) /* 4 args + ret addr */
>
> -#define PUSH_di_si_dx_cx_8 \
> - pushq %rdi ; \
> - pushq %rsi ; \
> - pushq %rdx ; \
> - pushq %rcx ; \
> - pushq %r8
> -
> -#define POP_di_si_dx_cx_8 \
> - popq %r8 ; \
> - popq %rcx ; \
> - popq %rdx ; \
> - popq %rsi ; \
> - popq %rdi
> +#define PUSH_di_si_dx_cx_8 \
> + pushq %rdi ; \
> + .cfi_adjust_cfa_offset 8 ; \
> + pushq %rsi ; \
> + .cfi_adjust_cfa_offset 8 ; \
> + pushq %rdx ; \
> + .cfi_adjust_cfa_offset 8 ; \
> + pushq %rcx ; \
> + .cfi_adjust_cfa_offset 8 ; \
> + pushq %r8 ; \
> + .cfi_adjust_cfa_offset 8
> +
> +#define POP_di_si_dx_cx_8 \
> + popq %r8 ; \
> + .cfi_adjust_cfa_offset -8 ; \
> + popq %rcx ; \
> + .cfi_adjust_cfa_offset -8 ; \
> + popq %rdx ; \
> + .cfi_adjust_cfa_offset -8 ; \
> + popq %rsi ; \
> + .cfi_adjust_cfa_offset -8 ; \
> + popq %rdi ; \
> + .cfi_adjust_cfa_offset -8
>
> 1: /* Even though we can't take a signal until the sigprocmask completes,
> start the range early.
> @@ -129,6 +146,7 @@ ML_(do_syscall_for_client_WRK):
>
> movq %rsi, %rax /* rax --> VexGuestAMD64State * */
> pushq %rdi /* syscallno -> stack */
> + .cfi_adjust_cfa_offset 8
> movq OFFSET_amd64_RDI(%rax), %rdi
> movq OFFSET_amd64_RSI(%rax), %rsi
> movq OFFSET_amd64_RDX(%rax), %rdx
> @@ -136,6 +154,7 @@ ML_(do_syscall_for_client_WRK):
> movq OFFSET_amd64_R8(%rax), %r8
> movq OFFSET_amd64_R9(%rax), %r9
> popq %rax /* syscallno -> %rax */
> + .cfi_adjust_cfa_offset -8
>
> /* If rip==2, then the syscall was either just about
> to start, or was interrupted and the kernel was
> @@ -168,24 +187,38 @@ ML_(do_syscall_for_client_WRK):
> 5: /* now safe from signals */
> movq $0, %rax /* SUCCESS */
> popq %r15
> + .cfi_adjust_cfa_offset -8
> popq %r14
> + .cfi_adjust_cfa_offset -8
> popq %r13
> + .cfi_adjust_cfa_offset -8
> popq %r12
> + .cfi_adjust_cfa_offset -8
> popq %rbp
> + .cfi_adjust_cfa_offset -8
> popq %rbx
> + .cfi_adjust_cfa_offset -8
> ret
> + .cfi_adjust_cfa_offset 6*8
>
> 7: /* failure: return 0x8000 | error code */
> negq %rax
> andq $0x7FFF, %rax
> orq $0x8000, %rax
> popq %r15
> + .cfi_adjust_cfa_offset -8
> popq %r14
> + .cfi_adjust_cfa_offset -8
> popq %r13
> + .cfi_adjust_cfa_offset -8
> popq %r12
> + .cfi_adjust_cfa_offset -8
> popq %rbp
> + .cfi_adjust_cfa_offset -8
> popq %rbx
> + .cfi_adjust_cfa_offset -8
> ret
> + .cfi_endproc
> #undef FSZ
>
> .section .rodata
> diff --git a/coregrind/m_syswrap/syscall-x86-linux.S b/coregrind/m_syswrap/syscall-x86-linux.S
> index 78b3df4..fc8d792 100644
> --- a/coregrind/m_syswrap/syscall-x86-linux.S
> +++ b/coregrind/m_syswrap/syscall-x86-linux.S
> @@ -78,11 +78,16 @@
>
> .globl ML_(do_syscall_for_client_WRK)
> ML_(do_syscall_for_client_WRK):
> + .cfi_startproc
> /* save callee-saved regs */
> push %esi
> + .cfi_adjust_cfa_offset 4
> push %edi
> + .cfi_adjust_cfa_offset 4
> push %ebx
> + .cfi_adjust_cfa_offset 4
> push %ebp
> + .cfi_adjust_cfa_offset 4
> #define FSZ ((4+1)*4) /* 4 args + ret addr */
>
> 1: /* Even though we can't take a signal until the sigprocmask completes,
> @@ -131,20 +136,30 @@ ML_(do_syscall_for_client_WRK):
> 5: /* now safe from signals */
> movl $0, %eax /* SUCCESS */
> popl %ebp
> + .cfi_adjust_cfa_offset -4
> popl %ebx
> + .cfi_adjust_cfa_offset -4
> popl %edi
> + .cfi_adjust_cfa_offset -4
> popl %esi
> + .cfi_adjust_cfa_offset -4
> ret
> + .cfi_adjust_cfa_offset 4*4
>
> 7: /* failure: return 0x8000 | error code */
> negl %eax
> andl $0x7FFF, %eax
> orl $0x8000, %eax
> popl %ebp
> + .cfi_adjust_cfa_offset -4
> popl %ebx
> + .cfi_adjust_cfa_offset -4
> popl %edi
> + .cfi_adjust_cfa_offset -4
> popl %esi
> + .cfi_adjust_cfa_offset -4
> ret
> + .cfi_endproc
> #undef FSZ
>
>
|