29.11.2016 Views

Hacker Bits, Issue 11

HACKER BITS is the monthly magazine that gives you the hottest technology stories crowdsourced by the readers of Hacker News. We select from the top voted stories and publish them in an easy-to-read magazine format. Get HACKER BITS delivered to your inbox every month! For more, visit https://hackerbits.com/issue11.

HACKER BITS is the monthly magazine that gives you the hottest technology stories crowdsourced by the readers of Hacker News. We select from the top voted stories and publish them in an easy-to-read magazine format.

Get HACKER BITS delivered to your inbox every month! For more, visit https://hackerbits.com/issue11.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

I<br />

am fascinated by the debuggers. I love them so much that I wrote a small and very basic debugger as<br />

one of my projects recently. In this post I am going to write down what I’ve learned about how can a<br />

debugger set a breakpoint.. This post can be divided into these following sections.<br />

1. What’s a breakpoint?<br />

2. What’s a debugger?<br />

3. What does the debugger need to do to set a breakpoint?<br />

4. How can the debugger make the debuggee process halt?<br />

What’s a breakpoint?<br />

A breakpoint makes your program stop whenever a certain point in the program is reached.<br />

What’s a debugger?<br />

You can consider your debugger to be a program which forks() to create a child process and then calls<br />

execl() to load the process we want to debug. I used execl() in my code, but any of the system calls<br />

from the exec family of functions can be used.<br />

The debugger process<br />

And here’s the run_child() function which calls the execl() with the debuggee process’s executable<br />

name and path.<br />

We see a call to ptrace() in run_child() function before calling execl(). Let’s, for the moment, not go into<br />

what ptrace() is, even though it’s very important to understand how does a debugger work. We will<br />

eventually come to it.<br />

Now we have two processes running:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!