title: How to set breakpoint in gdb when attach to another process
body: <p>I have a C program which a really complicated script is written to run it. I need to debug this program using <code>gdb</code>. I have tried to run the script and attach gdb to it's process, but then I'm not able to set breakpoints that I need:</p>
  
  <pre><code>$ gdb median.o 27944
  GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
  Copyright (C) 2014 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  and "show warranty" for details.
  This GDB was configured as "x86_64-linux-gnu".
  Type "show configuration" for configuration details.
  For bug reporting instructions, please see:
  &lt;http://www.gnu.org/software/gdb/bugs/&gt;.
  Find the GDB manual and other documentation resources online at:
  &lt;http://www.gnu.org/software/gdb/documentation/&gt;.
  For help, type "help".
  Type "apropos word" to search for commands related to "word"...
  Reading symbols from median.o...done.
  Attaching to program: median.o, process 27944
  Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.19.so...done.
  done.
  Loaded symbols for /lib64/ld-linux-x86-64.so.2
  0x00007fc376e9cbfa in ?? ()
  (gdb) break median.c:10
  Cannot access memory at address 0x40059d
  </code></pre>
  
  <p>I also tried this:</p>
  
  <pre><code>$gdb -p 28303
  GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
  Copyright (C) 2014 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  and "show warranty" for details.
  This GDB was configured as "x86_64-linux-gnu".
  Type "show configuration" for configuration details.
  For bug reporting instructions, please see:
  &lt;http://www.gnu.org/software/gdb/bugs/&gt;.
  Find the GDB manual and other documentation resources online at:
  &lt;http://www.gnu.org/software/gdb/documentation/&gt;.
  For help, type "help".
  Type "apropos word" to search for commands related to "word".
  Attaching to process 28303
  Reading symbols from /bin/dash...(no debugging symbols found)...done.
  Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.19.so...done.
  done.
  Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
  Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.19.so...done.
  done.
  Loaded symbols for /lib64/ld-linux-x86-64.so.2
  0x00007fe918e50bfa in wait4 () at ../sysdeps/unix/syscall-template.S:81
  81  ../sysdeps/unix/syscall-template.S: No such file or directory.
  (gdb) break median.c:10
  No source file named median.c.
  Make breakpoint pending on future shared library load? (y or [n]) y
  Breakpoint 1 (median.c:10) pending.
  (gdb) continue
  Continuing.
  Please enter 3 numbers separated by spaces &gt; 6 is the median
  [Inferior 1 (process 28303) exited normally]
  </code></pre>
  
  <p>So it continues without stopping at the breakpoint. It is worth mentioning that if I call <code>run median.o &lt; input</code> from gdb itself, it works.</p>
  
  <p>How can I set breakpoints on a C program which is being run by a script?</p>