代码之家  ›  专栏  ›  技术社区  ›  bad_coffee

CLion中的GDB监视器命令

  •  7
  • bad_coffee  · 技术社区  · 8 年前

    我正在尝试使用远程GDB调试嵌入式项目。我的系统:

    • 目标:ARM Cortex M0。
    • SEGGER J-Link GDB Server V6.10命令行版本
    • 无臂eabi gdb 7.10.1.20160616-cvs
    • CLion 2016.2.2,版本号CL-162.1967.7
    • Ubuntu 16.04版

    我的.gdbinit文件中有以下内容:

    target remote localhost:2331 #(I remove this line when debugging with CLion)
    set verbose on
    file "/path_to_output_file/blinky.elf"
    monitor reset
    break main
    

    现在困扰我几天的问题是,如果我直接从终端使用gdb进行调试,而不是在CLion中使用调试器,那么这会很好。在CLion中,我得到错误:

    此目标不支持“monitor”命令。

    我的理论是终端接受“监视器重置”命令(至少它没有抱怨)。另一方面,CLion会打印一个错误,但随后似乎会继续,而不会执行重置。结果似乎是,当我在CLion中启动一个新的调试会话时,我不会从main()的开头开始。

    CLion是否阻塞监视器命令?如果是这样,那么为什么会这样,是否有解决办法?

    我觉得我的问题可能与 CPP-7322 CPP-7256 .

    2 回复  |  直到 5 年前
        1
  •  10
  •   Rolf    7 年前

    CLion不会阻止来自 .gdbinit 故意地问题是,这些命令在连接到目标之前在调试器启动时执行。这意味着 monitor reset 命令在未运行远程会话的情况下执行,因此失败。

    只是为了澄清:

    • 以下是手动执行GDB时发生的情况:

      # commands from .gdbinit
      target remote localhost:2331
      set verbose on
      file "/path_to_output_file/blinky.elf"
      monitor reset
      break main
      
    • 下面是当您使用相同的命令从CLion执行GDB时发生的情况 文件:

      # commands from .gdbinit
      target remote localhost:2331
      set verbose on
      file "/path_to_output_file/blinky.elf"
      monitor reset
      break main
      
      # commands executed by CLion to attach
      target remote localhost:2331  # <- ERROR (A program is being debugged already)
      
    • # commands from .gdbinit
      set verbose on
      file "/path_to_output_file/blinky.elf"
      monitor reset  # <- ERROR not attached to remote gdbserver => unknown command
      
      # ... not executed due to the error above
      break main
      # commands executed by CLion to attach
      target remote localhost:2331
      

    您链接的问题完全正确,请自由投票(免责声明:我是CLion开发者之一)。 恐怕我现在无法想出一个合理的变通办法来建议你。

    更新:

    实际上那里 您的用例的一个变通方法,适用于CLion和终端调试会话。你可以使用 GDB hooks

    在你 .gdbinit文件 文件将有问题的命令替换为以下行:

    define target hookpost-remote
    file "/path_to_output_file/blinky.elf"
    monitor reset
    break main
    end
    

    这样,每次连接远程目标时,GDB都将执行在定义的钩子中指定的命令,而不管您如何从CLion或终端启动调试器。

        2
  •  1
  •   jfmorin    6 年前

    GitHub project 这有一个关于在CLion上设置JLink调试器的很好的分步指南。真正帮助我的是生成 .gdbinit 在用户主目录中。

    无需添加 file /firmware.elf 命令,因为这是由CLion在启动调试会话时处理的。另一方面 load

    推荐文章