在CLion中的GDB监视器命令 [英] GDB Monitor commands in 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#(我删除这行$ CL
$ pre>
目前困扰我的事情是,如果我直接从终端调试gdb,而不是在CLion中使用调试器。在CLION中,我得到错误:
此目标不支持监视命令。
我的理论是终端接受监视复位命令(至少不会抱怨)。另一方面,CLION打印错误,但是似乎在不进行重置的情况下继续移动。结果似乎是当我在CLion中启动一个新的调试会话时,我不会在main()的开头开始。
CLion是否阻止监视器命令?如果是这样,那么为什么和有解决方法?
我有这样的感觉,我的问题可能与 CPP-7322 和 CPP -7256 。
解决方案 CLion不会阻止任何特定的命令从 .gdbinit
。事实是,这些命令在调试器启动之前执行,然后再附加到目标。这意味着监视器重置
命令在没有运行远程会话的情况下被执行,因此它失败。
只需澄清:
-
这里是手动执行GDB时会发生什么:
#命令from .gdbinit
target remote localhost:2331
set verbose on
file/ path_to_output_file / blinky.elf
显示器重置
break main
-
当您使用相同的 .gdbinit
文件从CLion执行GDB时,会发生什么:
break main
由CLion执行的#命令附加
target remote localhost:2331#< - ERROR(正在调试一个程序)
<$
$ b /未知命令
#...由于
以上的错误而未执行
由CLion执行附加
目标远程本地主机:2331
您链接的问题是完全正确的,请感觉免费投票(免责声明:我是CLion开发者之一)。
UPD。
实际上是您的用例的解决方法,适用于CLion和终端调试会话。您可以使用 GDB挂钩来实现。
在您的 .gdbinit
文件中,使用以下行替换有问题的命令:
定义目标hookpost-remote
文件/path_to_output_file/blinky.elf
monitor reset
break main
结束
这样,每次远程目标连接时,GDB将执行指定的命令无论您是从CLION还是从终端启动调试器,您都可以定义钩子。
I'm trying to debug an embedded project using remote GDB. My system:
- Target: ARM Cortex M0.
- SEGGER J-Link GDB Server V6.10 Command Line Version
- arm-none-eabi-gdb 7.10.1.20160616-cvs
- CLion 2016.2.2, Build #CL-162.1967.7
- Ubuntu 16.04
I have the following in my .gdbinit file:
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
The thing that has troubled me for days now, is that this works fine if I debug with gdb directly from a terminal, but not when I use the debugger in CLion. In CLion I get the error:
"monitor" command not supported by this target.
My theory is that the terminal accepts the "monitor reset" command (at least it doesn't complain). CLion on the other hand, prints an error, but appears to move on afterwards without doing the reset. The consequence seems to be that when I start a new debugging session in CLion I don't start at the beginning of main().
Is CLion blocking the monitor commands? If so, then why and is there a workaround?
I have the feeling that my questions might be related to CPP-7322 and CPP-7256.
CLion doesn't block any particular command from .gdbinit
on purpose. The thing is, these commands are executed on the debugger startup, before attaching to the target. That means that the monitor reset
command gets executed without a remote session being run yet, hence it fails.
Just to clarify:
here's what happens when you execute GDB manually:
# commands from .gdbinit target remote localhost:2331 set verbose on file "/path_to_output_file/blinky.elf" monitor reset break main
here's what happens when you execute GDB from CLion with the same
.gdbinit
file:# 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)
and here's what's going on when you execute GDB from CLion with the attach command removed:
# 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
The issues you linked are totally the right ones, please feel free to vote (disclaimer: I'm one of CLion developers). I couldn't come up with a reasonable workaround to suggest you for now, I'm afraid.
UPD.
There actually is a workaround for your use case that works for both CLion and terminal debug sessions. You can use GDB hooks to achieve that.
In your .gdbinit
file replace the commands in question with the following lines:
define target hookpost-remote
file "/path_to_output_file/blinky.elf"
monitor reset
break main
end
This way, every time the remote target is connected, the GDB will execute the commands specified in the defined hook, regardless the way you start the debugger, either from CLion or from a terminal.
这篇关于在CLion中的GDB监视器命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!