Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert a time string into a GDB log?

I recently discovered that you can set breakpoints in Xcode that will print to the console and auto-continue -- meaning you can insert log statements without having to write NSLog() calls and recompile (on-the-fly logging, woot).

Only problem is that it seems to be a little limited in what you can display when doing a log. It shows some tokens you can insert, like %B to print out some info about the current breakpoint or %H for the hit count.

I'd like to know if there's any way I can insert a time stamp in a particular format into the log line?

I tried playing with the "shell script" breakpoint action, but it told me that the date command didn't exist.... strange...

Any help would be awesome, Thanks guys!

like image 319
Jasarien Avatar asked Nov 05 '22 20:11

Jasarien


1 Answers

Read the GDB manual about Breakpoint Command Lists

You can give any breakpoint (or watchpoint or catchpoint) a series of commands to execute when your program stops due to that breakpoint. For example, you might want to print the values of certain expressions, or enable other breakpoints.

And in particular:

for example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.

break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end

Does this answer your question?

like image 134
lothar Avatar answered Nov 14 '22 02:11

lothar