I am not able to debug anything with gdb (various versions, 6.0, 6.1 and 6.2.1-r1). Everytime I try (does not depend on the executable), I get an error like "Cannot insert breakpoint 1. Error accessing memory address 0x8048264: Input/output error." (for details please see the sample session below). I noticed this behavious on 3 different gentoo machines (2 hardened, 1 non-hardened). I usually use hardened-sources (2x 2.4.x and 1x 2.6.x) but I have this problem also after booting a gentoo-sources kernel. I dont experience the problem on a Debian machine, but of course, gcc, glibc, binutils are different there. Reproducible: Always Steps to Reproduce: Using gdb 6.1 and the following source code as test: # cat test.c #include <stdio.h> int main(int argc, char *argv[]) { printf("%d\n", argc); return 0; } #gcc -v -static -ggdb -O0 -o test test.c Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/specs Configured with: /var/tmp/portage/gcc-3.3.4-r1/work/gcc-3.3.4/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3 --includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/info --enable-shared --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib --enable-languages=c,c++ --enable-threads=posix --enable-long-long --disable-checking --disable-libunwind-exceptions --enable-cstdio=stdio --enable-version-specific-runtime-libs --with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include/g++-v3 --with-local-prefix=/usr/local --enable-shared --enable-nls --without-included-gettext --disable-multilib --enable-__cxa_atexit --enable-clocale=generic Thread model: posix gcc version 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6) /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/cc1 -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=4 test.c -quiet -dumpbase test.c -auxbase test -ggdb -O0 -version -o /tmp/ccAbZEWf.s GNU C version 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6) (i686-pc-linux-gnu) compiled by GNU C version 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6). GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32088 ignoring nonexistent directory "/usr/i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include /usr/include End of search list. /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../../../i686-pc-linux-gnu/bin/as -V -Qy -o /tmp/ccYJHp9l.o /tmp/ccAbZEWf.s GNU assembler version 2.15.90.0.1.1 (i686-pc-linux-gnu) using BFD version 2.15.90.0.1.1 20040303 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/collect2 -m elf_i386 -static -o test /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../../crt1.o /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../../crti.o /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/crtbeginT.o -L/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4 -L/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../../../i686-pc-linux-gnu/lib -L/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../.. /tmp/ccYJHp9l.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/crtend.o /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../../crtn.o # ./test arg 2 # gdb test GNU gdb 6.1 Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". (gdb) list 1 #include <stdio.h> 2 3 int main(int argc, char *argv[]) 4 { 5 printf("%d\n", argc); 6 return 0; 7 } (gdb) break 3 Breakpoint 1 at 0x8048254: file test.c, line 3. (gdb) run Starting program: /root/testkit/test Warning: Cannot insert breakpoint 1. Error accessing memory address 0x8048254: Input/output error. Cannot insert breakpoint -5. Error accessing memory address 0x8048140: Input/output error. (gdb) next Single stepping until exit from function _start, which has no line number information. Warning: Cannot insert breakpoint -1. Error accessing memory address 0x8079c00: Input/output error. Cannot insert breakpoint 1. Error accessing memory address 0x8048254: Input/output error. Cannot insert breakpoint -5. Error accessing memory address 0x8048140: Input/output error. (gdb) q The program is running. Exit anyway? (y or n) y # emerge info Portage 2.0.51-r3 (default-linux/x86/2004.3, gcc-3.3.4, glibc-2.3.4.20040808-r1, 2.4.27-hardened-r2 i686) ================================================================= System uname: 2.4.27-hardened-r2 i686 AMD Athlon(tm) XP 1800+ Gentoo Base System version 1.4.16 Autoconf: sys-devel/autoconf-2.59-r5 Automake: sys-devel/automake-1.8.5-r1 Binutils: sys-devel/binutils-2.15.90.0.1.1-r3 Headers: sys-kernel/linux-headers-2.4.19-r1,sys-kernel/linux-headers-2.4.21-r1 Libtools: sys-devel/libtool-1.5.2-r7 ACCEPT_KEYWORDS="x86" AUTOCLEAN="yes" CFLAGS="-mcpu=athlon-xp -O2 -pipe" CHOST="i686-pc-linux-gnu" COMPILER="" CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config /usr/share/config /usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/config/ /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/bind /var/qmail/control" CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d" CXXFLAGS="-mcpu=athlon-xp -O2 -pipe" DISTDIR="/usr/portage/distfiles" FEATURES="autoaddcvs autoconfig ccache distlocks sandbox sfperms strict" GENTOO_MIRRORS="http://linux.rz.rub.de/download/gentoo-mirror" MAKEOPTS="-j2" PKGDIR="/usr/portage/packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage" PORTDIR_OVERLAY="/usr/local/portage" SYNC="rsync://linux.rz.rub.de/gentoo-portage" USE="x86 3dnow acl apache2 apm berkdb bitmap-fonts crypt fbcon fortran gdbm gif gtk2 imap innodb ipv6 jpeg libwww mad mbox md5sum mysql ncurses nls odbc oggvorbis pam pdflib perl png python readline sasl sftplogging skey slang spell sqlite ssl tcpd tetex xml2 zlib" I hope that someone can help me with this, I have run out of ideas now.
Please show the output of: chpax -v a.out paxctl -v a.out Thanks
Sorry, s/a.out/test/
Actually, can you just try recompiling with: gcc -v -static -ggdb -O0 -fno-pie -o test test.c Then try gdb
Actually, I tried this on a non-hardened system, so gcc should not use PIE by default. I also remember trying -fno-pie on the hardened systems before. I checked it again, but no effect. But your first comment gave me a clue: disabling MPROTECT with paxctl seems to work. In fact, I tried to disable the PaX stuff before (with paxctl -pemxsr) and I even booted a non-hardened kernel (gentoo-sources) on that machine (so PaX is not even there) and it did not work. Therefore I was really sure that PaX was not the source of the problem... Unfortunately I tried that with a different executable on a different machine and despite of the same error message it was apparently a different problem... OK, now I checked again with my original program: It did not work with "paxctl -m ..." and I got my original error message as yesterday. Because I was convinced that my problem originated in the building/linking process I inspected my makefiles again. At the end I found out that they had the -fno-pie during compilation but were missing -fno-pie during the linking step. :-( After I corrected that, gdb works now. :-) So I had 2 problems, one related to PIE and one to PaX and trying to disable PIE or PaX of course didnt help me. ;-) (I stupidly thought that adding -fno-pie while compiling was sufficient, obviously it was not. I will now keep in mind to compile _and_ link everything I want to debug with -fno-pie and to disable MPROTECT for the executables. And waiting for a pie-aware gdb of course. *g*) Thank you very much for your help Rob! :-) (And please accept my apology for consuming your time!)
glad its sorted.