Can you only redirect stderr to GDB with tcsh as wrapper?
I am debugging some code and when I go through one thread I get a ton of timeout error messages printed to STDERR from another thread. I would like to hide everything that was printed to stderr. I tried using redirection on application startup:
(gdb) run 2> /dev/null
but this seems to redirect stdout as well, and I need that to call pretty print functions on my objects as you step through the code.
PS I am using GDB 7.2 and no, I cannot update :(
PPS I would not think it depends on the shell, but I am running tcsh 6.17
source to share
In my case, the main reason was using tcsh. It has no way of redirecting just stderr, and gdb seems to pipe those redirection lines to the shell interpreter. There are hacks to get around this on the command line , but I couldn't get them to work inside GDB. If you are using a sane wrapper then an invalid input approach will work . I never had a chance to test paul's suggestion as I was on this project by then, but it might work with tcsh. I'll change the selected answer in case someone checks it works.
source to share
[Edit: @ wrong input answer is correct. At least with a suitable latest gdb, you can do f-fd redirection in command set args
or run
. I'm not sure exactly when gdb figured out how to do this. If it doesn't work for you, the solution below might be helpful.]
I don't think there is a way to do this with simple shell reallocations recognized by the command However, you can use gdb to manually redirect the bottom stderr stream to a file.run
.
Something like
# get the program started
break __libc_start_main
run
# open a new filehandle to /dev/null. the 1 is the value of the
# O_WRONLY constant, cause we want to open /dev/null in write mode.
set $nullfd = open("/dev/null", 1)
# make fd 2 (stderr) be a copy of that new handle
call dup2($nullfd, 2)
# we can close the new handle now (optional)
call close($nullfd)
# let the program carry on
cont
will do the job by overriding whatever was open in fd 2 (the thing that was there before was probably your terminal handle). After that, any writing to stderr will go to /dev/null
.
Obviously this may require customization depending on your platform. You may not have a symbol __libc_start_main
in your executable; main
might work instead.
source to share