GDB and SystemTap probes -- part 1
After a long time, here we are again :-).
With this post I will start to talk about the integration between GDB and SystemTap. This is something that Tom Tromey and I did during the last year. The patch is being reviewed as I write this post, and I expect to see it checked-in in the next few days/weeks. But let’s get our hands dirty…
SystemTap Userspace Probes
You probably use (or have at least heard of) SystemTap, and maybe you think the tool is only useful for kernel inspections. If that’s your case, I have a good news: you’re wrong! You can actually use SystemTap to inspect userspace applications too, by using what we call SDT probes, or Static Defined Tracing probes. This is a very cheap and easy way to include probes in your application, and you can even specify arguments to those probes.
In order to use the probes (see an example below), you must include the
<sys/sdt.h> header file in your source code. If you are using Fedora
systems, you can obtain this header file by installing the package
systemtap-sdt-devel, version equal or greater than
Here’s a simple example of an application with a one-argument probe:
As you can see, this is a very simple program with one probe, which contains one argument. You can now compile the program:
Now you must be thinking: “Wait, wait… Didn’t you just forget to link
this program against some SystemTap-specific library or something?” And
my answer is no. One of the spetacular things about this
<sys/sdt.h> header is that it does not have any dependencies at all!
As Tom said in his blog post, this is
“a virtuoso display of ELF and GCC asm wizardy”.
If you want to make sure your probe was inserted in the binary, you can
(I will think about writing an explanation on how the probes are laid
out on the binary, but for now you just have to care if you actually
see an output from this
You can also use SystemTap to perform this verification:
So far, so good. If you see an output like the one above, it means your probe is correctly inserted. You could obviously use SystemTap to inspect this probe, but I won’t do this right now because this is not the purpose of this post.
For now, we have learned how to:
- Include an
SDT probein our source code, and compile it;
- Verify if the probe was correctly inserted.
In the next post, I will talk about the GDB support that allows you to
inspect, print arguments, and gather other information about
SDT probes. I hope you like it!