From 76547ab31b16b521e29892cab5a29b60b52291a5 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Wed, 14 Oct 2020 12:24:42 +0200 Subject: [PATCH] [gdb] Fix segfault in solib_contains_address_p Starting commit bb2a67773c "Use a std::vector in target_section_table" we run into: ... ERROR: GDB process no longer exists GDB process exited with wait status 22239 exp12 0 0 CHILDKILLED SIGABRT UNRESOLVED: gdb.base/exec-invalid-sysroot.exp: continue to exec catchpoint ... which reproduces as: ... Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. solib_contains_address_p (address=4196111, solib=0x1dd9970) at /home/vries/gdb_versions/devel/src/gdb/solib.c:1120 1120 for (target_section &p : solib->sections->sections) (gdb) p solib->sections->sections Cannot access memory at address 0x0 ... Fix this by handling solib->sections == nullptr in solib_contains_address_p. Build and reg-tested on x86_64-linux. gdb/ChangeLog: 2020-10-14 Tom de Vries PR gdb/26733 * solib.c (solib_contains_address_p): Handle 'solib->sections == nullptr'. --- gdb/ChangeLog | 6 ++++++ gdb/solib.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 954eaa35d4d..70e1e81a167 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-10-14 Tom de Vries + + PR gdb/26733 + * solib.c (solib_contains_address_p): Handle + 'solib->sections == nullptr'. + 2020-10-13 Simon Marchi PR gdb/26642 diff --git a/gdb/solib.c b/gdb/solib.c index b4864429e9a..28f6a4ecbfb 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1113,6 +1113,9 @@ bool solib_contains_address_p (const struct so_list *const solib, CORE_ADDR address) { + if (solib->sections == nullptr) + return false; + for (target_section &p : *solib->sections) if (p.addr <= address && address < p.endaddr) return true; -- 2.30.2