title: How to reload a recompiled binary in gdb without exiting and losing breakpoints?
body: <p>According to <a href="http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/Debug.html#tth_sEc4.5" rel="noreferrer">this excellent guide</a> one should be able to recompile a source file and simply use 'r' to have gdb begin debugging the new, changed binary.</p>
  
  <p>This also seemed implied <a href="https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_17.html#SEC18" rel="noreferrer">in the gdb manual</a> by "If the modification time of your symbol file has changed since the last time GDB read its symbols, GDB discards its symbol table, and reads it again."</p>
  
  <p>I am trying to debug a simple, single .cpp file on Ubuntu 16.10. After compiling via <code>g++ -ggdb -std=c++11 589.cpp</code>, I can debug as usual.</p>
  
  <pre><code>GNU gdb (Ubuntu 7.11.90.20161005-0ubuntu2) 7.11.90.20161005-git
  [...]
  (gdb) break main
  Breakpoint 1 at 0x2754: file 589.cpp, line 204.
  (gdb) r
  Starting program: /home/code/589
  
  Breakpoint 1, main () at 589.cpp:204
  (gdb) n
  (gdb) k
  Kill the program being debugged? (y or n) y
  </code></pre>
  
  <p>Here, I make a minor change to source file and then recompile. When trying to run the file again:</p>
  
  <pre><code>(gdb) r
  /home/code/589' has changed; re-reading symbols.
  Error in re-setting breakpoint 1: Cannot access memory at address 0x55555555674b
  Starting program: /home/code/598
  warning: Probes-based dynamic linker interface failed.
  Reverting to original interface.
  
  [Inferior 1 (process 20898) exited normally]
  </code></pre>
  
  <p>Is there a way to successfully reload the binary while keeping my breakpoints intact?</p>
  
  <p>EDIT: <a href="https://stackoverflow.com/a/37131295/5294170">This post</a> had the answer I was looking for. You reload the executable with the <code>file binaryname</code> command.</p>
  
  <pre><code>(gdb) file 589
  A program is being debugged already.
  Are you sure you want to change the file? (y or n) y
  A program is being debugged already.
  Load new symbol table from "589"? (y or n) y
  Reading symbols from 589...done.
  Error in re-setting breakpoint 1: Cannot access memory at address 0x274b
  Error in re-setting breakpoint 2: Cannot access memory at address 0x274b
  </code></pre>
  
  <p>We see the breakpoints are still there, just disabled:</p>
  
  <pre><code>(gdb) i b
  Num     Type           Disp Enb Address            What
  1       breakpoint     keep n   0x0000555555556754
          breakpoint already hit 1 time
  2       breakpoint     keep n   0x000055555555677b 
  </code></pre>
  
  <p>And so we just enable them:</p>
  
  <pre><code>(gdb) enable
  (gdb) i b
  Num     Type           Disp Enb Address            What
  1       breakpoint     keep y   0x0000555555556754 
          breakpoint already hit 1 time
  2       breakpoint     keep y   0x000055555555677b
  (gdb) 
  </code></pre>
  
  <p>This works, but I would love to hear if anyone has further advice or input on whether simply using <code>run</code> should indeed work.</p>