aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/python.exp
diff options
context:
space:
mode:
authorGuinevere Larsen <guinevere@redhat.com>2024-10-21 15:57:55 -0300
committerGuinevere Larsen <guinevere@redhat.com>2024-12-03 11:31:22 -0300
commit32e3f1a0aa0aec359d944da029ea7b7262d259cd (patch)
treeafe69ef2eb6ab7365fa51bb39f7d3e37814e4257 /gdb/testsuite/gdb.python/python.exp
parent2639ca087dfcae63c91a692cdf74d6476baaf719 (diff)
downloadbinutils-32e3f1a0aa0aec359d944da029ea7b7262d259cd.zip
binutils-32e3f1a0aa0aec359d944da029ea7b7262d259cd.tar.gz
binutils-32e3f1a0aa0aec359d944da029ea7b7262d259cd.tar.bz2
gdb: fix crash when GDB can't read an objfile
If a user starts an inferior composed of objfiles that GDB is unable to read, there is an error thrown in find_sym_fns, printing the famous "I'm sorry, Dave, I can't do that" and the objfile stops being read. However, the objfile will already have been linked to the program space, and future interactions with the objfile will assume that it is readable. Relevant to this commit, if GDB tries to find out the section that contains a PC, and this section happens to land in the unreadable objfile, GDB will try to create a section mapping, eventually calling update_section_map. Since that function uses bfd to calculate the sections, it'll think there are sections to be ordered, but when trying to access the objfile::section_offsets, it'll be indexing a size 0 std::vector, which will end up segfaulting. Currently, it isn't easy to trigger this crash, but the upcoming possibility to disable support for some file formats would make the crash very easy to reproduce, by attempting to debug an unsupported inferior and using "break *<instruction>" command, or simply connecting to a gdbserver loaded with an unsupported inferior. The struct objfile_up seems to have been created to catch these kinds of errors and unlink the partially-read objfile from the program space, as the objfile isn't useful to GDB anymore, but it seems to have been added before find_sym_fns would throw errors for unreadable objfiles, as the instance in syms_from_objfile_1 (that could save GDB from this crash) is declared well after find_sym_fns, too late to guard us. This commit moves the declaration up to the top of the function, so it works as intended. Further discussion on the mailing list also agreed that the name "objfile_up" implies some level of ownership of the pointer, which this struct doesn't have. So this commit renames the struct to scoped_objfile_unlinker, which is more descriptive of what the struct is actually meant to do. The final change this commit does is add an assertion to objfile::section_offset and objfile::set_section_offset, which ensures that the section_offsets vector is large enough to return the desired offset. This ensures that we won't misteriously segfault or worse, continue going with garbage data. Reported-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/testsuite/gdb.python/python.exp')
0 files changed, 0 insertions, 0 deletions