Skip to content

Commit 03edaf3

Browse files
committed
core: Add internal __cu__new() that allows passing a tag_tables instance
And make cu__new() have the same interface as before, but allocate the tags table, hand it to __cu__new() and ask it to delete it at cu__delete() time. Next patches will introduce cu__new_with_tables() for using the tags table from a base CU, so that we can add more types from an alternate DWARF file, like with .dwz. Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e3e79ee commit 03edaf3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

dwarves.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,9 @@ static void tag_tables__delete(struct tag_tables *tables)
673673
free(tables);
674674
}
675675

676-
struct cu *cu__new(const char *name, uint8_t addr_size,
677-
const unsigned char *build_id, int build_id_len,
678-
const char *filename, bool use_obstack)
676+
static struct cu *__cu__new(const char *name, uint8_t addr_size,
677+
const unsigned char *build_id, int build_id_len,
678+
const char *filename, bool use_obstack, struct tag_tables *tables, bool delete_tables)
679679
{
680680
struct cu *cu = zalloc(sizeof(*cu) + build_id_len);
681681

@@ -694,14 +694,16 @@ struct cu *cu__new(const char *name, uint8_t addr_size,
694694
if (cu->filename == NULL)
695695
goto out_free_name;
696696

697-
cu->tables = tag_tables__new();
698-
if (cu->tables == NULL)
699-
goto out_free_filename;
697+
cu->tables = tables;
698+
cu->delete_tables = delete_tables;
700699
/*
701700
* the first entry is historically associated with void,
702-
* so make sure we don't use it
701+
* so make sure we don't use it.
702+
*
703+
* But only if we are the creator of the tables, otherwise
704+
* we end up with two (or more) void entries.
703705
*/
704-
if (ptr_table__add(&cu->tables->types, NULL, &void_id) < 0)
706+
if (delete_tables && ptr_table__add(&cu->tables->types, NULL, &void_id) < 0)
705707
goto out_free_tables;
706708

707709
cu->functions = RB_ROOT;
@@ -729,9 +731,10 @@ struct cu *cu__new(const char *name, uint8_t addr_size,
729731
return cu;
730732

731733
out_free_tables:
732-
tag_tables__delete(cu->tables);
734+
if (delete_tables)
735+
tag_tables__delete(cu->tables);
736+
733737
cu->tables = NULL;
734-
out_free_filename:
735738
zfree(&cu->filename);
736739
out_free_name:
737740
zfree(&cu->name);
@@ -740,12 +743,23 @@ struct cu *cu__new(const char *name, uint8_t addr_size,
740743
return NULL;
741744
}
742745

746+
struct cu *cu__new(const char *name, uint8_t addr_size,
747+
const unsigned char *build_id, int build_id_len,
748+
const char *filename, bool use_obstack)
749+
{
750+
struct tag_tables *tables = tag_tables__new();
751+
752+
return tables != NULL ? __cu__new(name, addr_size, build_id, build_id_len, filename, use_obstack, tables, /*delete_tables:*/ true) : NULL;
753+
}
754+
743755
void cu__delete(struct cu *cu)
744756
{
745757
if (cu == NULL)
746758
return;
747759

748-
tag_tables__delete(cu->tables);
760+
if (cu->delete_tables)
761+
tag_tables__delete(cu->tables);
762+
749763
cu->tables = NULL;
750764

751765
if (cu->dfops && cu->dfops->cu__delete)

dwarves.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ struct cu {
261261
struct obstack obstack;
262262
uint32_t cached_symtab_nr_entries;
263263
bool use_obstack;
264+
bool delete_tables;
264265
uint8_t addr_size;
265266
uint8_t extra_dbg_info:1;
266267
uint8_t has_addr_info:1;

0 commit comments

Comments
 (0)