debugging strategies

Jan Dvořák mordae at thirdcms.org
Fri Mar 23 16:48:07 PDT 2007


Robert Connolly wrote:
> GDB doesn't build, or doesn't work?
For me it does build, but fails like this:

$ cat >>gdb-test.c <<EOF
int main()
{
	return 42;
}
EOF

---------------------------------

$ gcc -ggdb -v -o gdb-test gdb-test.c
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../butterfly-toolchain/configure --prefix=/usr 
--libexecdir=/usr/lib --enable-shared --enable-threads=posix 
--enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++ 
--enable-checking --enable-bootstrap
Thread model: posix
gcc version 4.1.1
  /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/cc1 -quiet -v -D_FORTIFY_SOURCE=2 
gdb-test.c -fPIE -fstack-protector-all -O -quiet -dumpbase gdb-test.c 
-mtune=pentiumpro -auxbase gdb-test -ggdb -version -o /tmp/cc42vwe1.s
ignoring nonexistent directory 
"/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
  /usr/local/include
  /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include
  /usr/include
End of search list.
GNU C version 4.1.1 (i686-pc-linux-gnu)
	compiled by GNU C version 4.1.1.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 7dab25506487cc63d4fe4f4a489fe76a
 
/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/as 
-V -Qy -o /tmp/ccq06cYU.o /tmp/cc42vwe1.s
GNU assembler version 2.17 (i686-pc-linux-gnu) using BFD version 2.17
  /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/collect2 --eh-frame-hdr -m 
elf_i386 -dynamic-linker /lib/ld-linux.so.2 -z now -z relro -z combreloc 
-pie -o gdb-test /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../Scrt1.o 
/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../crti.o 
/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/crtbeginS.o 
-L/usr/lib/gcc/i686-pc-linux-gnu/4.1.1 
-L/usr/lib/gcc/i686-pc-linux-gnu/4.1.1 
-L/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/lib 
-L/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../.. /tmp/ccq06cYU.o -lgcc 
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s 
--no-as-needed /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/crtendS.o 
/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../crtn.o

---------------------------------

$ gdb ./gdb-test
GNU gdb 6.6
[snip warranty]
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at 0x656
(gdb) r
Starting program: /home/mordae/w/gdb-test
Failed to read a valid object file image from memory.
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x656: Input/output error.
(gdb) quit
The program is running.  Exit anyway? (y or n) y

---------------------------------

$ gdb /lib/ld-linux.so.2
GNU gdb 6.6
[snip warranty]
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) b main
Function "main" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y

Breakpoint 1 (main) pending.
(gdb) run ./gdb-test
Starting program: /lib/ld-linux.so.2 ./gdb-test
Failed to read a valid object file image from memory.

Program exited with code 052.
(gdb) quit

---------------------------------

$ /sbin/paxctl -permsx ./gdb-test
$ /sbin/paxctl -v ./gdb-test
PaX control v0.4
Copyright 2004,2005,2006 PaX Team <pageexec at freemail.hu>

- PaX flags: -p-s-m-x-e-r [./gdb-test]
	PAGEEXEC is disabled
	SEGMEXEC is disabled
	MPROTECT is disabled
	RANDEXEC is disabled
	EMUTRAMP is disabled
	RANDMMAP is disabled

---------------------------------

$ # Repeated both `gdb ./gdb-test` and `gdb /lib/ld-linux.so.2` (run 
./gdb-test) with exactly same results...

---------------------------------

$ cp /lib/ld-linux.so.2 ./
$ cp /lib/libc.so.6 ./
$ export LD_LIBRARY_PATH=.
$ /sbin/paxctl -permsx ./ld-linux.so.2
$ /sbin/paxctl -v ./ld-linux.so.2
PaX control v0.4
Copyright 2004,2005,2006 PaX Team <pageexec at freemail.hu>

- PaX flags: -p-s-m-x-e-r [./ld-linux.so.2]
	PAGEEXEC is disabled
	SEGMEXEC is disabled
	MPROTECT is disabled
	RANDEXEC is disabled
	EMUTRAMP is disabled
	RANDMMAP is disabled
$ /sbin/paxctl -permsx ./libc.so.6
$ /sbin/paxctl -v ./libc.so.6
PaX control v0.4
Copyright 2004,2005,2006 PaX Team <pageexec at freemail.hu>

- PaX flags: -p-s-m-x-e-r [./libc.so.6]
	PAGEEXEC is disabled
	SEGMEXEC is disabled
	MPROTECT is disabled
	RANDEXEC is disabled
	EMUTRAMP is disabled
	RANDMMAP is disabled
$ ./ld-linux.so.2 --list ./gdb-test
	linux-gate.so.1 =>  (0xffffe000)
	libc.so.6 => ./libc.so.6 (0xb7e70000)
	/lib/ld-linux.so.2 => ./ld-linux.so.2 (0x80000000)


---------------------------------

# Both gdb runs failed once again -- now with paxctl'ed libc and once 
again even with paxctl'ed dynamic loader. Same errors...


---------------------------------

And second prob... How to compile without hardening?

- Mordae



More information about the hlfs-dev mailing list