8

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

Hassan
  • 113
  • 1
  • 1
  • 8
  • did you google for `gdb print variables`? look at this: http://stackoverflow.com/q/6261392/3684343 – mch May 19 '15 at 08:19
  • Hi. Yes I googled. However my question is getting the variable value from the code running on hardware and not on software. – Hassan May 19 '15 at 09:13
  • Maybe what you want are *watchpoints*. Does this help: https://sourceware.org/gdb/onlinedocs/gdb/Set-Watchpoints.html – Mark Plotnick May 19 '15 at 15:43

2 Answers2

17

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.

Jeremy
  • 695
  • 5
  • 7
0

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.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63