Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Sep 2023 10:26:21 +0000
From:      bugzilla-noreply@freebsd.org
To:        ports-bugs@FreeBSD.org
Subject:   [Bug 273688] sysutils/pstack: does not work with Valgrind
Message-ID:  <bug-273688-7788-dbyAv9ZRRn@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-273688-7788@https.bugs.freebsd.org/bugzilla/>
References:  <bug-273688-7788@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D273688

--- Comment #2 from Paul Floyd <pjfloyd@wanadoo.fr> ---
Some more analysis

In first window,=20

./vg-in-place sleep 100000

Tthat's my dev build of Valgrind, just 'valgrind' from pkd devel/valgrind-d=
evel
should be fine as well.

In the second window, GDB test



(gdb) attach 48907
Attaching to process 48907
Reading symbols from
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd...
[Switching to LWP 104670 of process 48907]
vgModuleLocal_do_syscall_for_client_WRK () at
m_syswrap/syscall-amd64-freebsd.S:144
144        setc  0(%rsp)         /* stash returned carry flag */
(gdb) bt
#0  vgModuleLocal_do_syscall_for_client_WRK () at
m_syswrap/syscall-amd64-freebsd.S:144
#1  0x000000003819f27a in do_syscall_for_client (syscallno=3D240,
tst=3D0x1002024f10, syscall_mask=3D0x1002ca9e20) at m_syswrap/syswrap-main.=
c:368
#2  vgPlain_client_syscall (tid=3Dtid@entry=3D1, trc=3Dtrc@entry=3D73) at
m_syswrap/syswrap-main.c:2341
#3  0x000000003819b150 in handle_syscall (tid=3Dtid@entry=3D1, trc=3Dtrc@en=
try=3D73) at
m_scheduler/scheduler.c:1206
#4  0x0000000038199223 in vgPlain_scheduler (tid=3Dtid@entry=3D1) at
m_scheduler/scheduler.c:1552
#5  0x00000000381ab33c in thread_wrapper (tidW=3D1) at
m_syswrap/syswrap-freebsd.c:112
#6  run_a_thread_NORETURN (tidW=3D1) at m_syswrap/syswrap-freebsd.c:166
#7  0x0000000000000000 in ?? ()

That's what I'd expect.

And lldb:
(lldb) attach 48907
This version of LLDB has no plugin for the language "assembler". Inspection=
 of
frame variables will be limited.
Process 48907 stopped
* thread #1, name =3D 'memcheck-amd64-f', stop reason =3D signal SIGSTOP
    frame #0: 0x00000000381a03a6
memcheck-amd64-freebsd`vgModuleLocal_do_syscall_for_client_WRK at
syscall-amd64-freebsd.S:144
   141        but hasn't been committed to RAX. */
   142=20
   143     /* stack contents: 3 words for syscall above, plus our prologue =
*/
-> 144     setc  0(%rsp)         /* stash returned carry flag */
   145=20
   146     movq  -16(%rbp), %r11 /* r11 =3D VexGuestAMD64State * */
   147     movq  %rax, OFFSET_amd64_RAX(%r11)    /* save back to RAX */
Executable module set to
"/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd".
Architecture set to: x86_64-unknown-freebsd13.2.
(lldb) bt
* thread #1, name =3D 'memcheck-amd64-f', stop reason =3D signal SIGSTOP
  * frame #0: 0x00000000381a03a6
memcheck-amd64-freebsd`vgModuleLocal_do_syscall_for_client_WRK at
syscall-amd64-freebsd.S:144
    frame #1: 0x000000003819f27a memcheck-amd64-freebsd`vgPlain_client_sysc=
all
[inlined] do_syscall_for_client(syscallno=3D240, tst=3D0x0000001002024f10,
syscall_mask=3D0x0000001002ca9e20) at syswrap-main.c:368:10
    frame #2: 0x000000003819f232
memcheck-amd64-freebsd`vgPlain_client_syscall(tid=3D1, trc=3D73) at
syswrap-main.c:2341:10
    frame #3: 0x000000003819b150 memcheck-amd64-freebsd`handle_syscall(tid=
=3D1,
trc=3D73) at scheduler.c:1206:4
    frame #4: 0x0000000038199223
memcheck-amd64-freebsd`vgPlain_scheduler(tid=3D1) at scheduler.c:1552:3
    frame #5: 0x00000000381ab33c memcheck-amd64-freebsd`run_a_thread_NORETU=
RN
[inlined] thread_wrapper(tidW=3D1) at syswrap-freebsd.c:112:10
    frame #6: 0x00000000381ab2c6
memcheck-amd64-freebsd`run_a_thread_NORETURN(tidW=3D1) at
syswrap-freebsd.c:166:10

Again, that's OK.

I've dowloaded the pstack source from github and built it.

In gdb, looking at elfFindSymbolByAddress I see that the address that pstac=
k is
using is the same as the address I see when attaching gdb. Namely 0x381a03a=
6.

There is no .dynsym so elfFindSectionByName finds .symtab.

symStrings looks OK to me. The frst entry is nil, and after that there is

(gdb) x /s obj->fileData + shdrs[symSection->sh_link]->sh_offset+1
0x8027e5829:    "mc_leakcheck.c"

That matches what I see with objdump -t:

paulf> objdump -t
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd | less=20=
=20=20=20=20=20=20=20=20

/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd:     file
format elf64-x86-64-freebsd

SYMBOL TABLE:
0000000000000000 l    df *ABS*  0000000000000000 mc_leakcheck.c

And the function where it is sleeping is

00000000381a034c g       .text  0000000000000000
vgModuleLocal_do_syscall_for_client_WRK

I've done some more debugging and I've seen one error.

@ -196,11 +198,23 @@ elfFindSymbolByAddress(struct ElfObject *obj, Elf_Addr
addr,
                    symSection->sh_offset + symSection->sh_size);

                for (; sym < endSym; sym++) {
-                       if ((type =3D=3D STT_NOTYPE ||
+                       if ((ELF_ST_TYPE(sym->st_info) =3D=3D STT_NOTYPE ||

elfFindSymbolByAddress is only ever called with type =3D=3D STT_FUNC and so
STT_FUNC =3D=3D STT_NOTYPE is always false and any function with type
STT_NOTYPE aren't processed. I suppose STT_NOTYPE also means a size of 0.

With the above change I get

  0x381a03a6 vgModuleLocal_do_syscall_for_client_WRK (3819f27a, 0, 1301, 0,
3812ddf8, 0) + 5a

but only the one line.

I need to so some more debugging of elfFindSymbolByAddress() to see why it's
not getting the full callstack.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-273688-7788-dbyAv9ZRRn>