DEV Community

mahesh_attarde
mahesh_attarde

Posted on • Edited on

[GDB-Quick] BreakPoints - Log/Source

For debugging, most obvious way to start is adding print. Second obvious is putting breakpoints and printing. While as simple as it sounds, it may not useful with large scale software variety of architecture.

While each debugging can take several runs, we need efficient setup, hence following post.

Save Your Breakpoints for future.

Save breakpoints in file with command.

(gdb) save breakpoints bpt_file
Enter fullscreen mode Exit fullscreen mode

Rookie stuff!
Here is more, What is right time to save breakpoint? :P
For System level debug, create local breakpoints files is efficient, at times multiple ones, depending on debugging flow.

This save is similar as gdb commands, so edit bpt_file in text editor is required.

Load Breakpoints from history

bpt_file is gdb commands, source it with command line or in gdb, it works!

(gdb) source bpt_file
Enter fullscreen mode Exit fullscreen mode

For VIM users

You can avoid writing breakpoint descriptions like file:line or class::function with few key strokes. Assign KeyMap from VIM to log current file:line_num in bpt_file

break file:line
Enter fullscreen mode Exit fullscreen mode

Now VimScript to do that is

function! Brkpt(message, file)
  new
  setlocal buftype=nofile bufhidden=hide noswapfile nobuflisted
  put=a:message
  execute 'w ' a:file
  q
endfun

function! BrkLog(fileName,lineNum)
  let msg = 'break' .a:fileName . ':' . a:lineNum
  echo msg
  call Brkpt(msg,'~/gdb.txt')
endfun
Enter fullscreen mode Exit fullscreen mode

copy content into say brk.vim file and source in vim. call this function on keystroke.

:nomap <C-G> :call BrkLog(expand('%:t'),line('.'))
Enter fullscreen mode Exit fullscreen mode

Last While sourcing breakpoints, libraries that are not loaded will default error then just

(gdb) set breakpoint pending on
Enter fullscreen mode Exit fullscreen mode

Happy Hacking!

Top comments (0)