11

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?

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

7

Ah, I totally forgot about printf:

printf "%s\n", some_string

2 Comments

Neat idea, but I can't figure out how to redirect this into a file.
@mehaase, simple: set logging file str_dump.txt set logging on set logging redirect on The first two lines instruct gdb to write output to the file (in addition to writing to the terminal), the last line disables output to the terminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.