Skip to content

Commit 11cb20e

Browse files
committed
[gdb/symtab] Note errors in process_skeletonless_type_units
With a hello world a.out, and using the compiler flags from target board dwarf5-fission-debug-types: ... $ gcc -gdwarf-5 -fdebug-types-section -gsplit-dwarf ~/data/hello.c ... I run into: ... $ gdb -q -batch a.out terminate called after throwing an instance of 'gdb_exception_error' ... What happens is that an error is thrown due to invalid dwarf, but the error is not caught, causing gdb to terminate. In a way, this is a duplicate of PR32861, in the sense that we no longer run into this after: - applying the proposed patch (work around compiler bug), or - using gcc 9 or newer (compiler bug fixed). But in this case, the failure mode is worse than in PR32861. Fix this by catching the error in cooked_index_worker_debug_info::process_skeletonless_type_units. With the patch, we get instead: ... $ gdb -q -batch a.out Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing outside of \ .debug_str.dwo section in CU at offset 0x0 [in module a.out] ... While we're at it, absorb the common use of cooked_index_worker_result::note_error: ... try { ... } catch (gdb_exception &exc) { (...).note_error (std::move (exc)); } ... into the method and rename it to catch_error, resulting in more compact code for the fix: ... (...).catch_error ([&] () { ... }); ... While we're at it, also use it in cooked_index_worker_debug_info::process_units which looks like it needs the same fix. Tested on x86_64-linux. PR symtab/32979 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32979
1 parent f217207 commit 11cb20e

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

gdb/dwarf2/cooked-index-worker.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,20 @@ class cooked_index_worker_result
107107
return &m_parent_map;
108108
}
109109

110-
/* Add an exception to the list of exceptions caught while reading.
111-
These are passed forward and printed by the main thread. */
112-
void note_error (gdb_exception &&except)
110+
/* Catch exceptions from calling F (), and add them to the list of caught
111+
exceptions. These are passed forward and printed by the main thread. */
112+
template <typename F>
113+
void
114+
catch_error (F &&f)
113115
{
114-
m_exceptions.push_back (std::move (except));
116+
try
117+
{
118+
f ();
119+
}
120+
catch (gdb_exception &ex)
121+
{
122+
m_exceptions.push_back (std::move (ex));
123+
}
115124
}
116125

117126
/* Called when the thread using this object is done with its work.

gdb/dwarf2/read-debug-names.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,11 @@ cooked_index_worker_debug_names::do_reading ()
416416
{
417417
complaint_interceptor complaint_handler;
418418

419-
try
419+
/* Arbitrarily put all exceptions into the first result. */
420+
m_map.indices[0].catch_error ([&] ()
420421
{
421422
m_map.scan_all_names ();
422-
}
423-
catch (gdb_exception &exc)
424-
{
425-
/* Arbitrarily put all exceptions into the first result. */
426-
m_map.indices[0].note_error (std::move (exc));
427-
}
423+
});
428424

429425
bool first = true;
430426
for (auto &iter : m_map.indices)

gdb/dwarf2/read.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,7 +3425,10 @@ cooked_index_worker_debug_info::process_type_units
34253425
abbrev_table.get (), nullptr, false,
34263426
language_minimal);
34273427
if (!reader.is_dummy ())
3428-
process_type_unit (&reader, storage);
3428+
storage->catch_error ([&] ()
3429+
{
3430+
process_type_unit (&reader, storage);
3431+
});
34293432
}
34303433
}
34313434

@@ -3467,7 +3470,10 @@ cooked_index_worker_debug_info::process_skeletonless_type_units
34673470
if (per_objfile->per_bfd->dwp_file == nullptr)
34683471
for (const dwo_file_up &file : per_objfile->per_bfd->dwo_files)
34693472
for (const dwo_unit_up &unit : file->tus)
3470-
process_skeletonless_type_unit (unit.get (), per_objfile, storage);
3473+
storage->catch_error ([&] ()
3474+
{
3475+
process_skeletonless_type_unit (unit.get (), per_objfile, storage);
3476+
});
34713477
}
34723478

34733479
void
@@ -3486,14 +3492,10 @@ cooked_index_worker_debug_info::process_units (size_t task_number,
34863492
{
34873493
dwarf2_per_cu *per_cu = inner->get ();
34883494

3489-
try
3495+
thread_storage.catch_error ([&] ()
34903496
{
34913497
process_unit (per_cu, m_per_objfile, &thread_storage);
3492-
}
3493-
catch (gdb_exception &except)
3494-
{
3495-
thread_storage.note_error (std::move (except));
3496-
}
3498+
});
34973499
}
34983500

34993501
thread_storage.done_reading (complaint_handler.release ());

0 commit comments

Comments
 (0)