gdb: Any way to debug a segfault in a ROS node?
Hi,
After a refactoring of my code, my node segfaults, so I would like to debug it with gdb. I used roslaunch with gdb prefix as indicated in this tutorial.
Nevertheless it seems that I'm able to see the error output. I have removed the "run" parameter to see if I can run it manually, add a breakpoint and so on. It works, but I cannot see neither what I type nor the standard output. For instance if I try typing the unexisting gdb command "hello", I see successfully:
Undefined command: "hello". Try "help".
But if I run a gdb command that is successfully executed (breakpoint main
, print argc
, or whatever....), the prompt does not display anything.
I tried gdb --tty /dev/pts/4
but it redirects only my program, so gdb standard input and output are still invisible.
Moreover I get the error warning: GDB: Failed to set controlling terminal: Operation not permitted
and also [tcsetpgrp failed in terminal_inferior: Inappropriate ioctl for device]
. The last error seems to be a bug of gdb, so I've installed the last version 7.7, it's now solved but I still get the first error and no display except stderr.
What program do you use to debug your nodes? Any tip or trick to redirect the standard input/output in some terminal?
Many thanks
Usually if an application does not crash/segfault's on GDB, it's some sort of race condition. Here some tiny [manual](http://blogs.adobe.com/flascc/2012/11/30/finding-multi-threading-bugs-with-gdb/) from Adobe, how to debug multi-threaded applications with GDB. Also, [Valgrind](http://valgrind.org/) should be useful. One more thing, why the hell there are no automatic tests written, huh? You're going to burn in hell forever for missing that. Oh, one more thing. Usually system logs (`dmesg | tail 100`) contains some handy information about segfaults. Oh, another thing - instead of redirecting IO from Your program, You could attach to working process from another terminal with GDB as described here: http://stackoverflow.com/a/11965416/1150918 . `gdb -p <pid_of_the_proccess>`, for short.
Are you using the xterm variant from the linked tutorial?