Change how dwarf2_per_cu_data is deleted
authorTom Tromey <tromey@adacore.com>
Mon, 17 May 2021 18:55:18 +0000 (12:55 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 17 May 2021 19:01:42 +0000 (13:01 -0600)
commit473ab96443eaf08f1a56c116c82410de2022c29b
tree99609fd2b1cd5f3103f2a4303537d87aecd1cf1a
parent16e0020bfc845d87f2f3584414c4efa2454f8d05
Change how dwarf2_per_cu_data is deleted

Address sanitizer pointed out that the patch to use 'delete' for
dwarf2_per_cu_data introduced a bug -- now it is possible to delete a
signatured_type using a pointer to its base class.

This patch fixes the problem by introducing a deleter and a unique_ptr
specialization.  A virtual destructor would be more ordinary here, but
it seemed wasteful to add a vtable just for this purpose.  If virtual
methods are ever needed here, we can revisit this.

2021-05-17  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.h (struct dwarf2_per_cu_data_deleter: New.
(dwarf2_per_cu_data_up): New typedef.
(struct dwarf2_per_bfd) <allocate_per_cu>: Change return type.
<all_comp_units>: Use dwarf2_per_cu_data_up.
* dwarf2/read.c (dwarf2_per_cu_data::operator()): New function.
(dwarf2_per_bfd::allocate_per_cu): Return dwarf2_per_cu_data_up.
(create_cu_from_index_list): Likewise.
(create_signatured_type_table_from_index)
(create_cus_from_debug_names_list, add_type_unit)
(read_comp_units_from_section): Update.
(dwarf2_find_containing_comp_unit): Change type of all_comp_units.
(run_test): Update.
gdb/ChangeLog
gdb/dwarf2/read.c
gdb/dwarf2/read.h