Reputation: 8087
Windows provides a set of Debug API's so that the program can stop at certain positions and dump corresponding information, to write our own debugger, etc, like Using DebugActiveProcess and WaitForDebugEvent seems to hang
My question is, does linux also provide such a series of debug api so that we can easily write our own debugger, or extend gdb, not having to gain knowledge about linux kernel, etc?
Upvotes: 4
Views: 1805
Reputation: 213897
does linux also provide such a series of debug api so that we can easily write our own debugger, or extend gdb, not having to gain knowledge about linux kernel, etc?
It is an illusion that one can easily write a Windows debugger without understanding the Windows kernel.
On Linux, the APIs provided are even harder to use and using ptrace
to write a debugger almost certainly requires deep understanding of the kernel process management.
Upvotes: 0
Reputation: 94445
There is ptrace()
user-space API in Linux (and some Unix) to implement debuggers (gdb
) or tracers (strace
):
* Man page of ptrace()
in Linux http://man7.org/linux/man-pages/man2/ptrace.2.html
* Wikipedia page on ptrace
with history and overview in other UNIX https://en.wikipedia.org/wiki/Ptrace
ptrace()
can be used to stop/start process, get/set its registers, read and write its memory, doing single stepping or stop at every syscall.
Some basic information, memory maps and access to memory may be also exported to /proc
special filesystem (procfs as /proc/self/
directory for current process and /proc/PID
for process with pid of PID
.
To extend gdb you may use gdb commands or gdb python API interface and python commands, which are much easier (and sometimes more portable) than reimplementing basic parts of gdb.
Upvotes: 6