【问题标题】:Setting multiple line values to a variable in GDB将多行值设置为 GDB 中的变量
【发布时间】:2014-04-08 09:41:29
【问题描述】:

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

GDB 接受像 x:="value" 这样的输入,但我如何让它接受像这样的值

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

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

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

【问题讨论】:

    标签: c debugging testing gdb


    【解决方案1】:

    我希望嵌入式换行符转义可以工作:

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

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

    【讨论】:

      【解决方案2】:

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

      $ 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)
      

      【讨论】:

        猜你喜欢
        • 2011-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-28
        • 2021-12-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多