diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-10-02 15:38:51 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-10-15 20:12:25 +0100 |
commit | ae6400219c19f165692254740531b2a7ad74945e (patch) | |
tree | 1253f1c6520169ee796ff32581920f44ea70cec8 /gdb/dwarf2read.h | |
parent | 55dfc88f7edeeb926dd6e2cae54b3666f8df596e (diff) | |
download | binutils-ae6400219c19f165692254740531b2a7ad74945e.zip binutils-ae6400219c19f165692254740531b2a7ad74945e.tar.gz binutils-ae6400219c19f165692254740531b2a7ad74945e.tar.bz2 |
gdb: Remove use of VEC from dwarf2read.c
This removes a use of VEC from GDB, from dwarf2read.c. This removal
is not very clean, and would probably benefit from additional
refactoring in the future.
The problem here is that the VEC is contained within struct
dwarf2_per_cu_data, which is treated as POD in dwarf2read.c. As such
it is actually a VEC pointer. When converting this to a std::vector
in an ideal world we would not use a std::vector pointer, and use the
std::vector directly. Sadly, to do that would require some rewriting
in dwarf2read.c - my concern would be introducing bugs during this
rewrite.
If we move to a std::vector pointer then we need to take care to
handle the case where the pointer is null. The old VEC library would
handle null for us, making the VEC interface very clean. With
std::vector we need to handle the null pointer case ourselves.
The achieve this then I've added a small number of function that wrap
up access to the std::vector, hopefully hiding the null pointer
management.
The final ugliness with this conversion is that, ideally, when
wrapping a data member behind an interface I would make the data
member private, however, treating the structure as POD once again
prevents this, so we are left with the data member being public, but
access (ideally) being through the published interface functions.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* gdb/dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile):
Update for new std::vector based implementation.
(process_psymtab_comp_unit_reader): Likewise.
(scan_partial_symbols): Likewise.
(recursively_compute_inclusions): Likewise.
(compute_compunit_symtab_includes): Likewise.
(process_imported_unit_die): Likewise.
(queue_and_load_dwo_tu): Likewise.
(follow_die_sig_1): Likewise.
* gdb/dwarf2read.h: Remove DEF_VEC_P.
(typedef dwarf2_per_cu_ptr): Remove.
(struct dwarf2_per_cu_data) <imported_symtabs_empty>: New
function.
(struct dwarf2_per_cu_data) <imported_symtabs_push>: New function.
(struct dwarf2_per_cu_data) <imported_symtabs_size>: New function.
(struct dwarf2_per_cu_data) <imported_symtabs_free>: New function.
(struct dwarf2_per_cu_data) <imported_symtabs>: Change to
std::vector.
Change-Id: Id0f4bda977c9dd83b0ba3d7fb42f7e5e2b6869c8
Diffstat (limited to 'gdb/dwarf2read.h')
-rw-r--r-- | gdb/dwarf2read.h | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index a737168..53fc7f4 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -30,9 +30,6 @@ extern struct cmd_list_element *set_dwarf_cmdlist; extern struct cmd_list_element *show_dwarf_cmdlist; -typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr; -DEF_VEC_P (dwarf2_per_cu_ptr); - extern bool dwarf_always_disassemble; /* A descriptor for dwarf sections. @@ -347,6 +344,37 @@ struct dwarf2_per_cu_data struct dwarf2_per_cu_quick_data *quick; } v; + /* Return true of IMPORTED_SYMTABS is empty or not yet allocated. */ + bool imported_symtabs_empty () const + { + return (imported_symtabs == nullptr || imported_symtabs->empty ()); + } + + /* Push P to the back of IMPORTED_SYMTABS, allocated IMPORTED_SYMTABS + first if required. */ + void imported_symtabs_push (dwarf2_per_cu_data *p) + { + if (imported_symtabs == nullptr) + imported_symtabs = new std::vector <dwarf2_per_cu_data *>; + imported_symtabs->push_back (p); + } + + /* Return the size of IMPORTED_SYMTABS if it is allocated, otherwise + return 0. */ + size_t imported_symtabs_size () const + { + if (imported_symtabs == nullptr) + return 0; + return imported_symtabs->size (); + } + + /* Delete IMPORTED_SYMTABS and set the pointer back to nullptr. */ + void imported_symtabs_free () + { + delete imported_symtabs; + imported_symtabs = nullptr; + } + /* The CUs we import using DW_TAG_imported_unit. This is filled in while reading psymtabs, used to compute the psymtab dependencies, and then cleared. Then it is filled in again while reading full @@ -364,8 +392,14 @@ struct dwarf2_per_cu_data .gdb_index version <=7 this also records the TUs that the CU referred to. Concurrently with this change gdb was modified to emit version 8 indices so we only pay a price for gold generated indices. - http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */ - VEC (dwarf2_per_cu_ptr) *imported_symtabs; + http://sourceware.org/bugzilla/show_bug.cgi?id=15021. + + This currently needs to be a public member due to how + dwarf2_per_cu_data is allocated and used. Ideally in future things + could be refactored to make this private. Until then please try to + avoid direct access to this member, and instead use the helper + functions above. */ + std::vector <dwarf2_per_cu_data *> *imported_symtabs; }; /* Entry in the signatured_types hash table. */ |