paulfloyd / freebsd_valgrind

Git repo used to Upstream the FreeBSD Port of Valgrind
GNU General Public License v2.0
15 stars 4 forks source link

vgdb target remote without pid doesn't pick up only valgrind instance #152

Closed paulfloyd closed 2 years ago

paulfloyd commented 3 years ago

(gdb) target remote | /usr/home/paulf/tools/valgrind/bin/vgdb
Remote debugging using | /usr/home/paulf/tools/valgrind/bin/vgdb no --pid= arg given and multiple valgrind pids found: use --pid=28987 for ./tools/valgrind/bin/valgrind --vgdb-error=0 ./small_g.exe use --pid=1547 for /usr/local/bin/akonadi_birthdays_resource --identifier akonadi_birthdays_resource

akonadi_birthdays is not exactly the same thing as valgrind.

paulfloyd commented 2 years ago

And again

no --pid= arg given and multiple valgrind pids found: use --pid=1462 for /usr/local/bin/gmenudbusmenuproxy use --pid=13613 for /home/paulf/scratch/vg_examples/445032/../../valgrind/coregrind/valgrind --vgdb-error=0 ./pthread_signal_clang

paulfloyd commented 2 years ago

The code for this is in vgdb.c, search_arg_pid()

This does a dirent() and loops over FIFOs, then it does a strncmp with the vgdb prefix (default /tmp/vgdb-pipe but can be changed via command line argument). Then there is an strtol to get the pid.

It does a kil(pid, 0). I can see that is prone to failure if there a loads of dead pipes hanging about (like on my system) and a the pid has been recycled. It then reads /proc/pid/cmdline.

I don't think that this is a FreeBSD specific problem. Perhaps /proc/pid/file ought to be read to ensure that the exe is the right one (memcheck or whatever).