14

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

3
  • did you google for gdb print variables? look at this: stackoverflow.com/q/6261392/3684343 Commented May 19, 2015 at 8:19
  • Hi. Yes I googled. However my question is getting the variable value from the code running on hardware and not on software. Commented May 19, 2015 at 9:13
  • Maybe what you want are watchpoints. Does this help: sourceware.org/gdb/onlinedocs/gdb/Set-Watchpoints.html Commented May 19, 2015 at 15:43

2 Answers 2

27

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.

Sign up to request clarification or add additional context in comments.

3 Comments

It says "The program is not being run" after typing continue at the end
It says No symbol "VAR" in current context.
@minseong you can type start and press enter to start the program under gdb. Then proceed line by line by typing n followed by enter (n for next), or just continue the execution by typing c followed by enter (c for continue).
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.