CLION中的GDB Monitor命令

bad*_*fee 6 debugging jlink gdbserver cortex-m clion

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

  • 目标:ARM Cortex M0.
  • SEGGER J-Link GDB服务器V6.10命令行版本
  • arm-none-eabi-gdb 7.10.1.20160616-cvs
  • CLion 2016.2.2,Build#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
Run Code Online (Sandbox Code Playgroud)

几天来困扰我的事情是,如果我直接从终端调试gdb,这可以正常工作,但是当我在CLion中使用调试器时却没有.在CLion我收到错误:

此目标不支持"monitor"命令.

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

CLion是否阻止了监视器命令?如果是这样,那么为什么并且有解决方法?

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

Eld*_*mov 8

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
    
    Run Code Online (Sandbox Code Playgroud)
  • 以下是使用相同.gdbinit文件从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)
    
    Run Code Online (Sandbox Code Playgroud)
  • 这是从CLion执行GDB并删除attach命令时发生的事情:

    # 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
    
    Run Code Online (Sandbox Code Playgroud)

您链接的问题完全是正确的,请随时投票(免责声明:我是CLION开发人员之一).我害怕,我现在无法想出一个合理的解决方法来建议你.

更新:

实际上有针对两个克利翁和终端调试会话的工作原理您的使用情况下的解决方法.您可以使用GDB挂钩来实现这一目标.

在您的.gdbinit文件中,使用以下行替换相关命令:

define target hookpost-remote
file "/path_to_output_file/blinky.elf"
monitor reset
break main
end
Run Code Online (Sandbox Code Playgroud)

这样,每次连接远程目标时,GDB都将执行定义的钩子中指定的命令,无论您是从CLion还是从终端启动调试器.