André Rösti

libtracer

A lightweight idiomatic C++ wrapper around Linux ptrace

libtracer library is a by-product of my research into MVEEs. It reduces the number of lines of boilerplate code required to use ptrace, abstracts away architecture-specific idiosyncracies, provides a clean C++ object-based interface with exceptions for error handling, and adds some commonly used functionality not native to ptrace (such as identifying system call numbers and names).

libtracer makes using ptrace as simple as this:

#include <iostream>
#include "tracer.hpp"

tracer the_tracer;

int main(int argc, char **argv) {
	if(the_tracer.fork() == 0) {
		std::cout << "Hello, World!";
	} else {
		while(the_tracer.resume_and_wait(stop_reason::SYSCALL_ENTRY)) {
			std::cout << the_tracer.get_syscall_name() << "\n";
		}
	}
}

This will print the name of all the system calls executed in the child process, something like:

fstat
write
Hello, World!
exit_group

The library, as well as its documentation and installation instructions can be found here:

GitHub repository