+2021-04-07 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * dwarf2/section.c (dwarf2_section_info::get_bfd_owner): Add an
+ assert.
+ (dwarf2_section_info::get_file_name): Add an assert.
+ (dwarf2_section_info::read_string): Display a minimal, sane error
+ when the dwarf2_section_info is not associated with a bfd section.
+
2021-04-07 Andrew Burgess <andrew.burgess@embecosm.com>
* top.c (staged_gdb_datadir): Update comment.
section = get_containing_section ();
gdb_assert (!section->is_virtual);
}
+ gdb_assert (section->s.section != nullptr);
return section->s.section->owner;
}
{
bfd *abfd = get_bfd_owner ();
+ gdb_assert (abfd != nullptr);
return bfd_get_filename (abfd);
}
{
read (objfile);
if (buffer == NULL)
- error (_("%s used without %s section [in module %s]"),
- form_name, get_name (), get_file_name ());
+ {
+ if (get_bfd_section () == nullptr)
+ error (_("Dwarf Error: %s used without required section"),
+ form_name);
+ else
+ error (_("Dwarf Error: %s used without %s section [in module %s]"),
+ form_name, get_name (), get_file_name ());
+ }
if (str_offset >= size)
error (_("%s pointing outside of %s section [in module %s]"),
form_name, get_name (), get_file_name ());
+2021-04-07 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.dwarf2/dw2-using-debug-str.exp: Add an additional test.
+
2021-04-07 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.python/py-parameter.exp: Add test for reading data-directory
# fictional, it only exists in the DWARF, but it contains lots of nice
# field names, all of which are stored in the .debug_str section.
gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
+
+# Now copy the executable, and remove the .debug_str section. This
+# creates an executable with an invalid DWARF configuration. GDB
+# should give an error when trying to read the debug information from
+# this executable.
+set binfile_no_debug_str "${binfile}-no-debug-str"
+set args "--remove-section .debug_str $binfile ${binfile_no_debug_str}"
+if {[run_on_host "objcopy" [gdb_find_objcopy] "$args"]} {
+ perror "failed to run objcopy"
+ return -1
+}
+
+# Restart GDB, but don't load an executable. When we do load the
+# executable we're going to get an error, which we check for below.
+clean_restart
+
+# This pattern is hit when GDB does not use -readnow (i.e. the default
+# behaviour).
+set pattern1 \
+ [multi_line \
+ "Reading symbols from \[^\r\n\]+" \
+ "Dwarf Error: DW_FORM_strp used without required section" \
+ "\\(No debugging symbols \[^\r\n\]+\\)"]
+
+# This pattern is hit when GDB does use -readnow (e.g. running with
+# --target_board=readnow).
+set pattern2 \
+ [multi_line \
+ "Reading symbols from \[^\r\n\]+" \
+ "Expanding full symbols from \[^\r\n\]+" \
+ "Dwarf Error: DW_FORM_strp used without required section"]
+
+# Load the executable, we expect an error from the DWARF parser.
+gdb_test_multiple "file $binfile_no_debug_str" "file $testfile" {
+ -wrap -re $pattern1 {
+ pass $gdb_test_name
+ }
+ -re -wrap "$pattern2" {
+ pass $gdb_test_name
+ }
+}