Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

debugging

gdb

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?

like image 684
Łukasz Lew Avatar asked Oct 07 '09 10:10

Łukasz Lew


2 Answers

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) 
like image 111
ezpz Avatar answered Oct 08 '22 07:10

ezpz


Use the string specifier:

print /s x 
like image 42
netskink Avatar answered Oct 08 '22 07:10

netskink