简体   繁体   English

调试MSP430时在GDB中打印变量的值

[英]Print value of variable in GDB while debugging msp430

I am using GDB to debug my msp430. 我正在使用GDB调试我的msp430。 I connect the target and then load the binary of program and then "continue". 我连接目标,然后加载程序的二进制文件,然后“继续”。

My program is working fine however I want to see certain values of variables in real time. 我的程序运行正常,但是我想实时查看变量的某些值。 Actually I want to check the time stamp of my start of code and end of code which will give me total duration. 实际上,我想检查我的代码开始和代码结束的时间戳,这将给我总的持续时间。

As I am totally new to GDB, currently I have placed this line in my code 由于我是GDB的新手,因此目前我已将此行放入代码中

printf("Hello World\n");

However nothing is printed but my code is working fine which is actually blinking LEDs. 但是什么也没打印,但是我的代码工作正常,实际上是LED闪烁。

Please guide me how to view values of variables in GDB in debug mode. 请指导我如何在调试模式下查看GDB中的变量值。

Thanks 谢谢

To print a variable in gdb you can use the print command 要在gdb中打印变量,可以使用print命令

(gdb) print counter

You can set a breakpoint on line 10 with break 10 . 您可以在第10行的break 10设置一个断点。 And then attach a sequence of commands to be run every time the program stops at breakpoint 1 with commands 1 . 然后,每次程序在断点1处停止时,都附加要运行的命令序列,并带有commands 1 An example is below: 下面是一个示例:

(gdb) break 10
Breakpoint 1 at 0x1c4d: file example.c, line 10.
(gdb) commands 1
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>print counter
>continue
>end
(gdb) continue

So this will break at line 10, print the value of counter and then continue the program. 因此,这将在第10行中断,打印counter的值,然后继续执行程序。

For timestamps, what you probably want to do is set two breakpoints, one at the start of the code, and one at the end. 对于时间戳记,您可能想要做的是设置两个断点,一个在代码开头,一个在结尾。 Have each breakpoint record the time, say by calling the appropriate function. 让每个断点记录时间,例如通过调用适当的函数。 You can make a breakpoint do things by using the commands feature. 您可以使用commands功能使断点执行操作。

However, if this is something you want to do frequently, you might consider just adding code to your program to do it. 但是,如果您想经常这样做,则可以考虑将代码添加到程序中来完成。

For real-time (-ish) access to variables when debugging remotely, you might be interested in the gdb "tracepoint" feature. 为了在远程调试时实时(-ish)访问变量,您可能对gdb的“跟踪点”功能感兴趣。 Currently this feature only works when debugging remotely, and it relies on the remote debug server having the needed features. 当前,此功能仅在远程调试时有效,它依赖于具有所需功能的远程调试服务器。 Tracepoints let you record some selected variables at selected points, and then examine them later. 跟踪点使您可以在选定的点记录一些选定的变量,然后稍后进行检查。 The recording is done with reasonably minimal overhead. 以合理的最小开销完成记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM