Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make GDB print a string literally (without escaping)?

Tags:

gdb

I have a big, long string that I want to capture to a file. I can use logging to get most of the way there:

set logging on
set logging file gdb.log

…but if I use p or x/s to print the string, quotes and junk are all escaped. How can I get the string as-is?

like image 490
s4y Avatar asked Dec 21 '12 23:12

s4y


2 Answers

For a really large string you can also use:

(gdb) set variable $s = MY_STRING
(gdb) dump binary memory FILE $s $s + (size_t)strlen($s)

which can be easily adapted to handle buffers with null bytes. Also the content of FILE would never contain anything other than the string.

like image 192
scottt Avatar answered Oct 21 '22 12:10

scottt


Ah, I totally forgot about printf:

printf "%s\n", some_string
like image 39
s4y Avatar answered Oct 21 '22 12:10

s4y