From dd99cf0c580ac7b989a991283fa9f3eab07aec99 Mon Sep 17 00:00:00 2001 From: Weimin Pan Date: Fri, 5 Mar 2021 19:17:00 -0500 Subject: CTF: add all members of an enum type to psymtab With the following change which was made last April: [gdb] Use partial symbol table to find language for main commit d3214198119c1a2f9a6a2b8fcc56d8c324e1a245 The ctf reader was modified to enter all members of an enum type, similar to what the dwarf2 reader did, into the psymtab or gdb won't be able to find them. In addition, the empty name checking needed to be moved down so members of a unnamed enum were not left out. gdb/ChangeLog: * ctfread.c (ctf_psymtab_add_enums): New function. (ctf_psymtab_type_cb): call ctf_psymtab_add_enums. --- gdb/ctfread.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'gdb/ctfread.c') diff --git a/gdb/ctfread.c b/gdb/ctfread.c index dfd543a..4ff475f 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -1245,6 +1245,27 @@ ctf_end_symtab (ctf_psymtab *pst, return result; } +/* Add all members of an enum with type TID to partial symbol table. */ + +static void +ctf_psymtab_add_enums (struct ctf_context *ccp, ctf_id_t tid) +{ + int val; + const char *ename; + ctf_next_t *i = nullptr; + + while ((ename = ctf_enum_next (ccp->fp, tid, &i, &val)) != nullptr) + { + ccp->pst->add_psymbol (ename, true, + VAR_DOMAIN, LOC_CONST, -1, + psymbol_placement::GLOBAL, + 0, language_c, ccp->of); + } + if (ctf_errno (ccp->fp) != ECTF_NEXT_END) + complaint (_("ctf_enum_next ctf_psymtab_add_enums failed - %s"), + ctf_errmsg (ctf_errno (ccp->fp))); +} + /* Read in full symbols for PST, and anything it depends on. */ void @@ -1366,17 +1387,17 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg) ccp = (struct ctf_context *) arg; gdb::unique_xmalloc_ptr name (ctf_type_aname_raw (ccp->fp, tid)); - if (name == nullptr || strlen (name.get ()) == 0) - return 0; domain_enum domain = UNDEF_DOMAIN; enum address_class aclass = LOC_UNDEF; kind = ctf_type_kind (ccp->fp, tid); switch (kind) { + case CTF_K_ENUM: + ctf_psymtab_add_enums (ccp, tid); + /* FALL THROUGH */ case CTF_K_STRUCT: case CTF_K_UNION: - case CTF_K_ENUM: domain = STRUCT_DOMAIN; aclass = LOC_TYPEDEF; break; @@ -1407,6 +1428,9 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg) return 0; } + if (name == nullptr || strlen (name.get ()) == 0) + return 0; + ccp->pst->add_psymbol (name.get (), true, domain, aclass, section, psymbol_placement::GLOBAL, -- cgit v1.1