在GDB中将多个行值设置为变量

时间:2014-04-08 09:41:29

标签: c debugging testing gdb

我有一个char数组x,我需要给它一个跨越多行的输入。

GDB接受类似x:="value"的输入,但我如何使其获取像

这样的值
x := "this is a multiple lines
     input. We are now in second line"

这里的问题不是让GDB识别\ n而是在我提供非常长的字符串输入时使我的脚本可读。

ex:而不是x =“这是一个非常长的文本输入。很长的输入。非常长的输入”     我需要给x =“这是非常的                             长文本输入。                             很长的输入。                             非常长的输入“

2 个答案:

答案 0 :(得分:0)

我希望嵌入式换行符能够正常工作:

gdb$ set var x = "this is a long\nstring with\nmultiple lines\in it!"

但我现在无法访问gdb来尝试它。

答案 1 :(得分:0)

用反斜杠结束该行,然后继续下一行。

$ gdb s
(gdb) list
1   #include <stdio.h>
2   
3   char buf[512];
4   
5   main()
6   {
7       printf("%s\n", buf);
8   }
(gdb) break main
Breakpoint 1 at 0x80483bd: file s.c, line 7.
(gdb) run
Starting program: s 

Breakpoint 1, main () at s.c:7
7       printf("%s\n", buf);
(gdb) set buf="I have always wished for my computer to be as easy to use \
as my telephone; my wish has come true because I can no longer figure out \
how to use my telephone. --Bjarne Stroustrup."
(gdb) cont
Continuing.
I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone. --Bjarne Stroustrup.

Program exited with code 0262.
(gdb)