Search code examples
c++cgdbgdbserver

Debugging with gdb - (gdb) "x/s pointer" output


I am trying to debug using gdb. I got that if you want output in string you have to use "x/s Ptr". It works fine some time. But many times I am getting either Null value i.e. " " or some random numeric values. My file has 10000 lines of codes. :-p Please find some gdb output. For e.g.

krb5_get_credentials_for_user (context=0x59c00eb0, options=4, ccache=0x5a001d40, in_creds=0x5ab022a8, subject_cert=0x0, 
out_creds=0x5ab02378) at test_abc.c:696
(gdb) x/s 0x59c00eb0
0x59c00eb0:  "$\247\016\227"
(gdb) x/s 0x5ab022a8
0x5ab022a8:  ""

Could someone please tell me how I can solve this prob? Thanks in advance!


Solution

  • ... fine some times. But many times I am getting either Null value i.e. " " or some random numeric...

    Been there, done that. Allow me to encourage you to be creative.

    I sometimes create a function (call it foo? bar? show? dump?), that is not used by the program being debugged. The function is often c-style (because gdb seems to understand that better, and simpler to invoke), global scope, simple. The temporary install of this function close (in the same file?) to what you want to improve the visibility of sometimes helps.

    I can then invoke this function using the gdb p command, such as

     gdb> p foo
    

    it is possible to pass parameters to foo, but if I'm touching the code to debug something, I usually make foo more capable ... when no parameters it does one thing. Or perhaps use an int parameter (bar(7)) that switches to show more or differently.

    Experiment.

    This is not typical, and I suspect better knowledge of gdb might be worth the effort, if I could remember it to the next time I need it. Sometimes gdb just doesn't understand, and I can't figure out why. Other times, I get away with adding a pointer and trying to print that:

    gdb> p *foobar