title: fetching file name using ptrace
body: <p>I'm trying to fetch the filename which gets opened when the <code>sys_open</code> system call is invoked, but I am hitting a Segmentation Fault. The system call <code>sys_open</code> opens only the first file used and then hits the segmentation fault. How do I resolve this?</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>    while(1) {
       wait(&amp;status);
       if(WIFEXITED(status))
           break;
       orig_eax = ptrace(PTRACE_PEEKUSER,
                         sb-&gt;child, 8 * ORIG_RAX,
                         NULL);
       printf("%l\n", orig_eax);
       if(orig_eax == SYS_open) {
          if(toggle == 0) {
             toggle = 1;
             rdi = ptrace(PTRACE_PEEKUSER,
                                sb-&gt;child, 8 * RDI,
                                NULL);
             rsi = ptrace(PTRACE_PEEKUSER,
                                sb-&gt;child, 8 * RSI,
                                NULL);
             rdx = ptrace(PTRACE_PEEKUSER,
                                sb-&gt;child, 8 * RDX,
                                NULL);
             str = (char *)calloc((rdx+1)
                               , sizeof(char));
  
             getdata(sb-&gt;child, rdi, str, 100);
          }
          else {
             toggle = 0;
          }
       }
    ptrace(PTRACE_SYSCALL, sb-&gt;child, NULL, NULL);
    }
  </code></pre>