How to print a null-terminated string with newlines without showing backslash escapes in gdb?

CDebuggingGdb

C Problem Overview


I have a variable

char* x = "asd\nqwe\n ... "

and I want to print it with newlines printed as newlines not backslash n. Is it possible?

C Solutions


Solution 1 - C

Update: Why not just use the gdb printf command?

(gdb) printf "%s", x
asd
qwe
...
(gdb)

Old answer: From within the debugger you can execute commands. Just call printf

(gdb) call printf("%s", x)
asd
qwe
...
(gdb)

Solution 2 - C

Use the string specifier:

print /s x

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionŁukasz LewView Question on Stackoverflow
Solution 1 - CezpzView Answer on Stackoverflow
Solution 2 - CnetskinkView Answer on Stackoverflow