如何在gdb中不显示反斜杠转义而使用换行符打印以null结尾的字符串?

时间:2022-03-26 19:33:06

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?

我想用新行打印出来而不是反斜杠n,可能吗?

2 个解决方案

#1


77  

Update: Why not just use the gdb printf command?

更新:为什么不使用gdb printf命令?

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

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

旧的回答:在调试器中可以执行命令。就叫printf

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

#2


17  

Use the string specifier:

使用字符串说明符:

print /s x

#1


77  

Update: Why not just use the gdb printf command?

更新:为什么不使用gdb printf命令?

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

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

旧的回答:在调试器中可以执行命令。就叫printf

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

#2


17  

Use the string specifier:

使用字符串说明符:

print /s x