diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2019-10-21 11:27:43 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2020-06-26 15:56:39 +0100 |
commit | fe4c2d55634c700ba527ac4183e05c66e9f93c62 (patch) | |
tree | 67eeb7d1fa76d860f2d2473eddc9c7f4533cc6c9 /libctf/ctf-create.c | |
parent | 094e34f22146ad53eb93da22e480cab428bd23b5 (diff) | |
download | gdb-fe4c2d55634c700ba527ac4183e05c66e9f93c62.zip gdb-fe4c2d55634c700ba527ac4183e05c66e9f93c62.tar.gz gdb-fe4c2d55634c700ba527ac4183e05c66e9f93c62.tar.bz2 |
libctf: create: non-root-visible types should not appear in name tables
We were accidentally interning newly-added and newly-opened
non-root-visible types into name tables, and removing names from name
tables when such types were removed. This is very wrong: the whole
point of non-root-visible types is they do not go in name tables and
cannot be looked up by name. This bug made non-root-visible types
basically identical to root-visible types, right back to the earliest
days of libctf in the Solaris era.
libctf/
* ctf-open.c (init_types): Only intern root-visible types.
* ctf-create.c (ctf_dtd_insert): Likewise.
(ctf_dtd_delete): Only remove root-visible types.
(ctf_rollback): Likewise.
(ctf_add_generic): Adjust.
(ctf_add_struct_sized): Adjust comment.
(ctf_add_union_sized): Likewise.
(ctf_add_enum): Likewise.
* ctf-impl.h (ctf_dtd_insert): Adjust prototype.
Diffstat (limited to 'libctf/ctf-create.c')
-rw-r--r-- | libctf/ctf-create.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index ed9bfc5..e8e8028 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -597,13 +597,13 @@ ctf_name_table (ctf_file_t *fp, int kind) } int -ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd, int kind) +ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd, int flag, int kind) { const char *name; if (ctf_dynhash_insert (fp->ctf_dthash, (void *) dtd->dtd_type, dtd) < 0) return -1; - if (dtd->dtd_data.ctt_name + if (flag == CTF_ADD_ROOT && dtd->dtd_data.ctt_name && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL) { if (ctf_dynhash_insert (ctf_name_table (fp, kind)->ctn_writable, @@ -646,7 +646,8 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd) } if (dtd->dtd_data.ctt_name - && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL) + && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL + && LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info)) { ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable, name); @@ -762,7 +763,8 @@ ctf_rollback (ctf_file_t *fp, ctf_snapshot_id_t id) kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info); if (dtd->dtd_data.ctt_name - && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL) + && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL + && LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info)) { ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable, name); @@ -831,7 +833,7 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name, int kind, return (ctf_set_errno (fp, EAGAIN)); } - if (ctf_dtd_insert (fp, dtd, kind) < 0) + if (ctf_dtd_insert (fp, dtd, flag, kind) < 0) { free (dtd); return CTF_ERR; /* errno is set for us. */ @@ -1094,8 +1096,7 @@ ctf_add_struct_sized (ctf_file_t *fp, uint32_t flag, const char *name, ctf_dtdef_t *dtd; ctf_id_t type = 0; - /* Promote forwards to structs. */ - + /* Promote root-visible forwards to structs. */ if (name != NULL) type = ctf_lookup_by_rawname (fp, CTF_K_STRUCT, name); @@ -1132,7 +1133,7 @@ ctf_add_union_sized (ctf_file_t *fp, uint32_t flag, const char *name, ctf_dtdef_t *dtd; ctf_id_t type = 0; - /* Promote forwards to unions. */ + /* Promote root-visible forwards to unions. */ if (name != NULL) type = ctf_lookup_by_rawname (fp, CTF_K_UNION, name); @@ -1168,7 +1169,7 @@ ctf_add_enum (ctf_file_t *fp, uint32_t flag, const char *name) ctf_dtdef_t *dtd; ctf_id_t type = 0; - /* Promote forwards to enums. */ + /* Promote root-visible forwards to enums. */ if (name != NULL) type = ctf_lookup_by_rawname (fp, CTF_K_ENUM, name); |