简体   繁体   中英

Print value of variable in GDB while debugging msp430

I am using GDB to debug my 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

printf("Hello World\n");

However nothing is printed but my code is working fine which is actually blinking LEDs.

Please guide me how to view values of variables in GDB in debug mode.

Thanks

To print a variable in gdb you can use the print command

(gdb) print counter

You can set a breakpoint on line 10 with break 10 . And then attach a sequence of commands to be run every time the program stops at breakpoint 1 with 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.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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