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?
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)
printf() function call may succeed and return the number of characters in the string, but not actually output those characters on the screen; the same holds true for puts() function call and perhaps others of that kind. In contrast, the built-in printf command works as expected.Use the string specifier:
print /s x
printf, but may only work on relatively new versions of GDB: mine yields “Format letter "s" is meaningless in "print" command”, for example.x is a variable other than address, in that case, need use x command, e.g x/s x, or need a type convert, e.g p (char *) &x.
\nin gdb output\n, use:x/s x