gdb useful tidbits/bookmarks

Some of these are hard to google for and I’ve used more than once now, so to save time I’m bookmarking them here.

  1. Setting watch points in gdb
  2. Displaying the whole string in gdb
  3. Setting gdb to break at a particular file/line
  4. Setting the coredump limit of a running process to catch a core

None of this is rocket science, but still useful.

1) Watchpoints

Setting a watchpoint;

(gdb) watch mm_dictionary.mmdict_head->index 
Hardware watchpoint 3: mm_dictionary.mmdict_head->index
(gdb) cont
Continuing.
[Switching to Thread 0x7ffff565c700 (LWP 15147)]
Hardware watchpoint 3: mm_dictionary.mmdict_head->index

Old value = 20
New value = 0
reporter_thread () at x_reporter.c:148

watch -l didn’t seem to work on my gdb, so I had to set the watch on the global scope variable.

Listing and removing watchpoints

(gdb) info watchpoints
Num     Type           Disp Enb Address            What
2       hw watchpoint  keep y                      *current->index
(gdb) clear
No breakpoint at this line.
(gdb) clear 2
No breakpoint at 2.
(gdb) delete 2
(gdb) info watchpoints
No watchpoints

reference:

https://sourceware.org/gdb/onlinedocs/gdb/Delete-Breaks.html#Delete-Breaks

https://sourceware.org/gdb/onlinedocs/gdb/Set-Watchpoints.html#Set-Watchpoints

2) Viewing the whole string

(gdb) set print elements 0

3) Setting GDB to break at a file:line number

This is obvious, in hindsight;

(gdb) break x_symdict.c:149
Breakpoint 5 at 0x402038: file x_symdict.c, line 149.
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
3       hw watchpoint  keep y                      mm_dictionary.mmdict_head->index
    breakpoint already hit 1 time
5       breakpoint     keep y   0x0000000000402038 in add_mmdict at x_symdict.c:149
(gdb) delete 5
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
3       hw watchpoint  keep y                      mm_dictionary.mmdict_head->index
    breakpoint already hit 1 time

4) Setting a core limit on a running process dynamically

echo -n "Max core file size=unlimited:unlimited" >/proc/12345/limits 

 Thank you; http://blogs.kent.ac.uk/unseenit/2013/06/06/changing-ulimit-for-running-processes/

 You were hard to find, so I’m putting you here for safe keeping.

Any opinions, news, research, analyses, prices or other information ("information") contained on this Blog, constitutes marketing communication and it has not been prepared in accordance with legal requirements designed to promote the independence of investment research. Further, the information contained within this Blog does not contain (and should not be construed as containing) investment advice or an investment recommendation, or an offer of, or solicitation for, a transaction in any financial instrument. LMAX Group has not verified the accuracy or basis-in-fact of any claim or statement made by any third parties as comments for every Blog entry.

LMAX Group will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information. No representation or warranty is given as to the accuracy or completeness of the above information. While the produced information was obtained from sources deemed to be reliable, LMAX Group does not provide any guarantees about the reliability of such sources. Consequently any person acting on it does so entirely at his or her own risk. It is not a place to slander, use unacceptable language or to promote LMAX Group or any other FX and CFD provider and any such postings, excessive or unjust comments and attacks will not be allowed and will be removed from the site immediately.