Bug 504101

Summary: Add a "vgstack" script
Product: [Developer tools] valgrind Reporter: Paul Floyd <pjfloyd>
Component: generalAssignee: Paul Floyd <pjfloyd>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 3.25 GIT   
Target Milestone: ---   
Platform: Other   
OS: Other   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: initial patch

Description Paul Floyd 2025-05-12 13:57:03 UTC
I think that it would be useful to add a "vgstack" script. This would work like pstack/gstack but rather than print the host stack it would print the guest stack.

gstack does this

$GDB --quiet -nx $GDBARGS /proc/$1/exe $1 <<EOF 2>&1 | 
set width 0
set height 0
set pagination no
$backtrace
EOF
/bin/sed -n \
    -e 's/^\((gdb) \)*//' \
    -e '/^#/p' \
    -e '/^Thread/p'

If I move the exe and pid and put in a vgdb command like this

$GDB --quiet -nx $GDBARGS <<EOF 2>&1 |
set width 0
set height 0
set pagination no
target remote | vgdb --pid=$1
$backtrace
EOF
/bin/sed -n \
    -e 's/^\((gdb) \)*//' \
    -e '/^#/p' \
    -e '/^Thread/p'

then it seems to work reasonably well.

I'll need to adapt it so that it works on FreeBSD (and maybe illumos).
Comment 1 Paul Floyd 2025-05-13 18:44:36 UTC
Created attachment 181250 [details]
initial patch

Just tested on FreeBSD so far.
Comment 2 Paul Floyd 2025-05-14 06:28:10 UTC
This doesn't work on illumos. The Valgrind process core dumps and vgstack gets no output.

Possibly the same issue as

https://bugs.kde.org/show_bug.cgi?id=503130
Comment 3 Paul Floyd 2025-05-14 06:49:59 UTC
Seems OK on Linux.
Comment 4 Paul Floyd 2025-05-14 19:44:38 UTC
commit 568ce38ac76e1cefc20b006c7da8cf7bf2209596 (HEAD -> master, origin/master, origin/HEAD, bug504101)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Tue May 13 20:34:48 2025 +0200

    Bug 504101 - Add a "vgstack" script
    
    This works just like pstack/gstack (and bstack on FreeBSD).
    
    Run "vgstack [valgrind pid]" and you will get the guest backtraces.