At a very high level gdb works as below. Check for the actual implementation for more details.
ptrace system call will be used for tracing the program. It has 4 arguments
1) operation
2) target pid
3) address in the target process memory
4) data pointer
The last arguments depends on operation.
For example, to attach debugger
ptrace(PTRACE_ATTACH, pid, 0, 0) ;
ptrace(PTRACE_DETAACH, pid, 0, 0) ;
single step execution
ptrace(PTRACE_ATTACH, pid, 0, 0) ;
int status ;
waitpid(pid, &status, WSTOPPED) ;
while (...) {
ptrace(PTRACE_SINGLESTEP, pid, 0, 0) ;
// give the user a chance to do something
}
ptrace(PTRACE_DETACH, pid, 0, 0) ;
I dont know who will write new debuggers, where we have freely the best GDB available. :-).
ptrace system call will be used for tracing the program. It has 4 arguments
1) operation
2) target pid
3) address in the target process memory
4) data pointer
The last arguments depends on operation.
For example, to attach debugger
ptrace(PTRACE_ATTACH, pid, 0, 0) ;
ptrace(PTRACE_DETAACH, pid, 0, 0) ;
single step execution
ptrace(PTRACE_ATTACH, pid, 0, 0) ;
int status ;
waitpid(pid, &status, WSTOPPED) ;
while (...) {
ptrace(PTRACE_SINGLESTEP, pid, 0, 0) ;
// give the user a chance to do something
}
ptrace(PTRACE_DETACH, pid, 0, 0) ;
I dont know who will write new debuggers, where we have freely the best GDB available. :-).
No comments:
Post a Comment