From face536c391e1b61a315deb0ab48f0001555d06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 26 Apr 2022 09:12:29 +0200 Subject: [PATCH 1/2] launch gdb with -nx (ignore all .gdbinit) Otherwise the test may fail simply because .gdbinit setup does something strange (I happen to have 'set auto-solib-add off', which disables loading debug info by default). --- test/elf/gdb-index-compress-output.sh | 2 +- test/elf/gdb-index-dwarf2.sh | 2 +- test/elf/gdb-index-dwarf3.sh | 2 +- test/elf/gdb-index-dwarf4.sh | 2 +- test/elf/gdb-index-dwarf5.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/elf/gdb-index-compress-output.sh b/test/elf/gdb-index-compress-output.sh index eb82655a..05bfabd2 100755 --- a/test/elf/gdb-index-compress-output.sh +++ b/test/elf/gdb-index-compress-output.sh @@ -49,7 +49,7 @@ readelf -WS $t/exe 2> /dev/null | fgrep -q .gdb_index $QEMU $t/exe | grep -q 'Hello world' -DEBUGINFOD_URLS= gdb $t/exe -batch -ex 'b main' -ex r -ex 'b trap' \ +DEBUGINFOD_URLS= gdb $t/exe -nx -batch -ex 'b main' -ex r -ex 'b trap' \ -ex c -ex bt -ex quit >& $t/log grep -Pq 'hello \(\) at .*:7' $t/log diff --git a/test/elf/gdb-index-dwarf2.sh b/test/elf/gdb-index-dwarf2.sh index 96eee077..8e15c8e8 100755 --- a/test/elf/gdb-index-dwarf2.sh +++ b/test/elf/gdb-index-dwarf2.sh @@ -60,7 +60,7 @@ readelf -WS $t/exe 2> /dev/null | fgrep -q .gdb_index $QEMU $t/exe | grep -q 'Hello world' -DEBUGINFOD_URLS= gdb $t/exe -batch -ex 'b main' -ex r -ex 'b trap' \ +DEBUGINFOD_URLS= gdb $t/exe -nx -batch -ex 'b main' -ex r -ex 'b trap' \ -ex c -ex bt -ex quit >& $t/log grep -Pq 'hello2 \(\) at .*:7' $t/log diff --git a/test/elf/gdb-index-dwarf3.sh b/test/elf/gdb-index-dwarf3.sh index 84207e2f..727dfcbe 100755 --- a/test/elf/gdb-index-dwarf3.sh +++ b/test/elf/gdb-index-dwarf3.sh @@ -60,7 +60,7 @@ readelf -WS $t/exe 2> /dev/null | fgrep -q .gdb_index $QEMU $t/exe | grep -q 'Hello world' -DEBUGINFOD_URLS= gdb $t/exe -batch -ex 'b main' -ex r -ex 'b trap' \ +DEBUGINFOD_URLS= gdb $t/exe -nx -batch -ex 'b main' -ex r -ex 'b trap' \ -ex c -ex bt -ex quit >& $t/log grep -Pq 'hello2 \(\) at .*:7' $t/log diff --git a/test/elf/gdb-index-dwarf4.sh b/test/elf/gdb-index-dwarf4.sh index c2f5336c..79ae5d1a 100755 --- a/test/elf/gdb-index-dwarf4.sh +++ b/test/elf/gdb-index-dwarf4.sh @@ -60,7 +60,7 @@ readelf -WS $t/exe 2> /dev/null | fgrep -q .gdb_index $QEMU $t/exe | grep -q 'Hello world' -DEBUGINFOD_URLS= gdb $t/exe -batch -ex 'b main' -ex r -ex 'b trap' \ +DEBUGINFOD_URLS= gdb $t/exe -nx -batch -ex 'b main' -ex r -ex 'b trap' \ -ex c -ex bt -ex quit >& $t/log grep -Pq 'hello2 \(\) at .*:7' $t/log diff --git a/test/elf/gdb-index-dwarf5.sh b/test/elf/gdb-index-dwarf5.sh index dbd625ea..02c0249d 100755 --- a/test/elf/gdb-index-dwarf5.sh +++ b/test/elf/gdb-index-dwarf5.sh @@ -92,7 +92,7 @@ readelf -WS $t/exe 2> /dev/null | fgrep -q .gdb_index $QEMU $t/exe | grep -q 'Hello world' -DEBUGINFOD_URLS= gdb $t/exe -batch -ex 'b main' -ex r -ex 'b trap' \ +DEBUGINFOD_URLS= gdb $t/exe -nx -batch -ex 'b main' -ex r -ex 'b trap' \ -ex c -ex bt -ex quit >& $t/log grep -Pq 'fn8 \(\) at .*/d.c:6' $t/log From 886695d914942732ab5a5dfe6e9ad81a2697fbce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 26 Apr 2022 10:42:03 +0200 Subject: [PATCH 2/2] [ELF] check DWARF address size The current code assumes the debuginfo address size is equal to the native address size, which should be the case, but check that just in case it isn't. --- elf/dwarf.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/elf/dwarf.cc b/elf/dwarf.cc index 74e62266..f9e477bf 100644 --- a/elf/dwarf.cc +++ b/elf/dwarf.cc @@ -119,10 +119,16 @@ find_compunit(Context &ctx, ObjectFile &file, i64 offset) { case 3: case 4: abbrev_offset = *(u32 *)(cu + 6); + if (u32 address_size = cu[10]; address_size != E::word_size) + Fatal(ctx) << file << ": --gdb-index: unsupported address size " + << address_size; cu += 11; break; case 5: { abbrev_offset = *(u32 *)(cu + 8); + if (u32 address_size = cu[7]; address_size != E::word_size) + Fatal(ctx) << file << ": --gdb-index: unsupported address size " + << address_size; switch (u32 unit_type = cu[6]; unit_type) { case DW_UT_compile: