title: gdb can't insert a breakpoint when attach to a process
body: <p>I'm trying to attach <code>gdb</code> to a program started by <code>socat</code> like this:</p>
  
  <pre><code>socat TCP-LISTEN:5678,reuseaddr,fork EXEC:./test
  </code></pre>
  
  <p>In another terminal,</p>
  
  <pre><code>sudo gdb 
  attach `pidof socat`
  br *0x080487D4
  </code></pre>
  
  <p>when execute <code>continue</code> command in gdb, it shows error like this:</p>
  
  <pre><code>Warning:
  Cannot insert breakpoint 1.
  Cannot access memory at address 0x80487d4
  
  Command aborted.
  </code></pre>
  
  <p>0x080487D4 is in <code>.text</code> of <code>test</code> program. The <code>follow-fork-mode</code> of gdb is <code>child</code>, I have searched online but still can't solve it.</p>
  
  <p>I debugged program successfully like this way a month ago, and don't know why it doesn't work now. But it's ok if debug the program directly using gdb like this:</p>
  
  <pre><code>gdb -q ./test
  </code></pre>
  
  <p>However, the way above doesn't meet my needs.</p>
  
  <p>Through debugging, I think <code>gdb</code> expects that address is a valid address in the <code>socat</code> rather then <code>test</code> program. So how can I set breakpoints in <code>test</code> program? Without breakpoints in <code>test</code> program, it will run directly to the end when execute <code>continue</code> command. Setting breakpoints in <code>socat</code> program is useless.</p>
  
  <p>Any advice? Thanks in advance.</p>