I really don’t get this, I have the following C++ program:
#include <cstring>
#include <stdexcept>
#include <fcntl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main()
{
int fd;
if ((fd = ::open("/dev/net/tun", O_RDWR|O_CLOEXEC)) == -1)
throw std::runtime_error("failed to open /dev/net/tun");
ifreq ifr {};
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
std::strncpy(ifr.ifr_name, "tunnel", IFNAMSIZ);
if (::ioctl(fd, TUNSETIFF, &ifr) == -1)
throw std::runtime_error("failed to create TUN interface");
}
The program is built as follows:
g++ -g -O0 main.cc -o main
sudo setcap cap_net_admin=ep main
I want to now use gdb to inspect the arguments passed to the TUNSETIFF
ioctl
(in this case I know that they are of course but really I want to figure this out for another program where I don’t):
gdb ./main
(gdb) b ioctl
Breakpoint 1 at 0x1130|
(gdb) r
Starting program: ./main
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, __GI___ioctl (fd=3, request=1074025674) at ../sysdeps/unix/sysv/linux/ioctl.c:26
26 ../sysdeps/unix/sysv/linux/ioctl.c: No such file or directory.
(gdb) p *request
Cannot access memory at address 0x400454ca
So that’s not very helpful, how to I break on the libc ::ioctl
call instead of whatever __GI___ioctl
is?