title: View/Print function code from within GDB
body: <p>I am trying to develop a simple text based user interface which runs some gdb commands.
  I want to user to be able to set and break/trace point at a certain area of the code and run some debug commands.</p>
  
  <p>I want to user to enter the function which needs to be debugged. I then take this function name and print out the source code of the function, then ask the user to select which line of code at which to set the break/trace point. At the moment, using the disassemble command I can print out the memory addresses for the user, but i want to print the actual source code instead.</p>
  
  <p>Can this be done in gdb?</p>
  
  <p>Currently:</p>
  
  <pre><code>Dump of assembler code for function test_function:
     0x03800f70 &lt;test_function+0&gt;:  push   %ebp
     0x03800f71 &lt;test_function+1&gt;:  mov    %esp,%ebp
     0x03800f73 &lt;test_function+3&gt;:  sub    $0x48,%esp
  </code></pre>
  
  <p>What I want:</p>
  
  <pre><code>void main()
  {
    printf("Hello World\n");
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>EDIT:
  I'm getting this:</p>
  
  <pre><code>(gdb) list myFunction
  941     directory/directory_etc/sourcefile.c: No such file or directory.
          in directory/directory_etc/sourcefile.c
  </code></pre>
  
  <p>then i tried specifying linenum:</p>
  
  <pre><code>(gdb) list directory/directory_etc/sourcefile.c:941
  936     in directory/directory_etc/sourcefile.c
  </code></pre>
  
  <p>So the behaviour is similar to what you are describing, but "list filename:linenum" still isnt working</p>
  
  <p>Thank you!</p>