tags:

views:

313

answers:

2

i have a char buffer[100] and i'm trying to use gdb to read the contents out of it at various stages of runtime.

i use p buffer and i get

"/*\000\000\000\000\000\000????X?o\000\025\202\004\b", '\0' <repeats 12 times>, ".N=?", '\0' <repeats 24 times>, "`\203\004\b\000\000\000\000L\227\004\bX????\202\004\b?\017\204\000\f?\203\000\210???i\205\004\b??r"

how do i get p to convert it into a readable format???

+4  A: 

If you want to get rid of the junk after the terminating null (so you'll just see "/*" for this string) you can use:

p (char*)buffer

At the moment gdb is printing your variable as an array, so it's showing all 100 characters; casting it to char* makes it print it as a C string.

Mike Dinsdale
+6  A: 

x/s buffer should display the contents of the array as a null terminated string (which is what I assume you'd like).

Michael Burr
Yeah, that's better than my way - less typing :)
Mike Dinsdale