GDB Permissions

Viewed 2128

I'm attempting to run gdb on an executable file within Ubuntu. However, when I attempt to run within gdb, I get the following error.

/vagrant/unit_test: cannot execute: Permission denied
During startup program exited with code 126.

I've ensured that the file ./unit_test has the proper execute permissions. I've also tried running gdb with sudo in front of it, sudo gdb ./unit_test.
It might be important to know that I'm using a Vagrantfile to boot up a virtual environment. Has anyone run into this problem before?

2 Answers

It appears that virtual file systems may not be friendly to certain executables (e.g. Qt-built ones) when used with gdb.

In my case, the problem was VirtualBox Shared Folders. When an executable was in the shared folder for the Windows Host, the Linux Guest gave the "cannot execute: permission denied" under GDB (even though the file could be executed normally). But when I moved the executable into the Linux Guest's extfs filesystem, it worked.

What's strange is that a simple stdio-based "Hello, World" built from the command line can be debugged fine, while a Qt-built app cannot. For the sake of argument, here's a dump of what ldd shows for the hello world without Qt:

linux-vdso.so.1 (0x00007ffc8bd07000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fda83d71000)
/lib64/ld-linux-x86-64.so.2 (0x00007fda83f7d000)

And here's what it shows for the Qt mandelbrot sample:

linux-vdso.so.1 (0x00007ffd48441000)
libQt5Widgets.so.5 => /home/hostilefork/Qt/5.13.1/gcc_64/lib/libQt5Widgets.so.5 (0x00007f09fa7b4000)
libQt5Gui.so.5 => /home/hostilefork/Qt/5.13.1/gcc_64/lib/libQt5Gui.so.5 (0x00007f09f9f68000)
libQt5Core.so.5 => /home/hostilefork/Qt/5.13.1/gcc_64/lib/libQt5Core.so.5 (0x00007f09f97b9000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f09f9613000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f09f9486000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f09f946c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f09f9280000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f09f925f000)
libGL.so.1 => /usr/lib/x86_64-linux-gnu/libGL.so.1 (0x00007f09f91cb000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f09f8fae000)
libicui18n.so.56 => /home/hostilefork/Qt/5.13.1/gcc_64/lib/libicui18n.so.56 (0x00007f09f8b15000)
libicuuc.so.56 => /home/hostilefork/Qt/5.13.1/gcc_64/lib/libicuuc.so.56 (0x00007f09f875d000)
libicudata.so.56 => /home/hostilefork/Qt/5.13.1/gcc_64/lib/libicudata.so.56 (0x00007f09f6d78000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f09f6d72000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f09f6d6d000)
libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f09f6c50000)
/lib64/ld-linux-x86-64.so.2 (0x00007f09fb034000)
libGLX.so.0 => /usr/lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f09f6c1c000)
libGLdispatch.so.0 => /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f09f6b5d000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f09f6ae9000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f09f69af000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f09f6986000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f09f6782000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f09f657a000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f09f6363000)

Presumably it's something about that which makes a difference.

If you encounter this error while using vagrant, try to add mount_options: ["dmode=0770", "fmode=0770"] to config.vm.synced_folder method call inside your Vagrantfile, e.g.:

config.vm.synced_folder "C:\\Projects", "/projects", mount_options: ["dmode=0770", "fmode=0770"]
Related