c - Why does ptrace not recognize the function? -


i can't figure out why function returns "no such process" error message every time run it, using same instructions inline produces required output.

#include <sys/ptrace.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/user.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h>  void getregs(pid_t proc, struct user_regs_struct *regs);  int main() {         pid_t proc = fork();          if(proc == 0) {                 if(ptrace(ptrace_traceme, 0, null, null) == -1) {                        perror("traceme");                        exit(0);                 }                  if(execl("child", "child", null) == -1) {                        perror("execl");                        exit(0);                 }         } else {                 wait(&proc);                 struct user_regs_struct regs;                 ptrace(ptrace_getregs, proc, null, &regs);                 printf("eax: %08x\n", (unsigned int)regs.eax);                 getregs(proc, &regs);                 ptrace(ptrace_cont, proc, null, null);         }          return 0; }  void getregs(pid_t proc, struct user_regs_struct *regs) {         if(ptrace(ptrace_getregs, proc, null, &regs) == -1) {                 perror("getregs");                 exit(1);         }          printf("eax: %08x\n", (unsigned int)regs->eax); } 

when run get

~$ ./tracer  eax: 0000002f  getregs: no such process 

i don't why getregs() returns error. it's outside scope of something?

also, little unrelated: eax set 0000002f no matter process try execl(). natural? don't know if i'm forking child process or not. need make new question on this?

you hit error because modifying value of process identifier (pid) contained in variable proc passing address wait(2) syscall.

the wait syscall change value of proc return status of child process upon termination. when reference child process in ptrace using proc, value invalid , referencing no existing processes.

and @lornix noticed, make sure pass right pointer ptrace in getregs function.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -