Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make gdb print unprintable characters of a string in hex instead of octal while preserving the ascii characters in ascii form?

Tags:

Suppose I have a buffer buf whose c string representation is

 char* buf = "Hello World \x1c" 

When I print this buf in gdb using the command p buf, I get the following

 $1 = "Hello World \034" 

Is there a print command or a gdb setting that will print the following instead?

$1 = "Hello World \x1c" 

I have tried various format parameters such as /c and /x, but none of them get the effect that I am looking for. I have also played with printf but was unable to achieve the desired effect.

Update: I am using "GNU gdb (GDB) 7.0.1-debian".

Update: I have played with x as well.

If I do x/c it prints octal and decimal for nonprintable characters, and then prints printable characters with the ascii and decimal.

If I do x/s it outputs exactly the same as the p command.

If I do x/x it just outputs hex but then we lose the ascii characters for the printable part.

Update: This reference, unless incomplete, suggests that what I desire is not available, but can anyone confirm?

like image 664
merlin2011 Avatar asked Apr 16 '13 07:04

merlin2011


1 Answers

You might use the x command to dump the memory your char-pointer points to:

(gdb) x/32xb buf 

shows the first 32 bytes.

See

(gdb) help x 

for details.

like image 154
alk Avatar answered Oct 30 '22 10:10

alk