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 d321419811

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.
This commit is contained in:
Weimin Pan 2021-03-05 19:17:00 -05:00
parent 844be3f240
commit dd99cf0c58
2 changed files with 32 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2021-03-06 Weimin Pan <weimin.pan@oracle.com>
* ctfread.c (ctf_psymtab_add_enums): New function.
(ctf_psymtab_type_cb): call ctf_psymtab_add_enums.
2021-03-06 Weimin Pan <weimin.pan@oracle.com>
* ctfread.c (read_func_kind_type): Set up function arguments.

View File

@ -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<char> 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,