diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2020-06-04 15:25:32 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2020-07-22 18:02:17 +0100 |
commit | c6e9a1e576ce4d948393b29e77b37e4ad934ee8f (patch) | |
tree | 9d1aa02a06b41c5c2cf446d5006152805f8b4c31 /libctf/ctf-types.c | |
parent | 8b37e7b63ed77fa66e08c7dd08147db6a263d0fb (diff) | |
download | gdb-c6e9a1e576ce4d948393b29e77b37e4ad934ee8f.zip gdb-c6e9a1e576ce4d948393b29e77b37e4ad934ee8f.tar.gz gdb-c6e9a1e576ce4d948393b29e77b37e4ad934ee8f.tar.bz2 |
libctf, types: enhance ctf_type_aname to print function arg types
Somehow this never got implemented, which makes debugging any kind of
bug that has to do with argument types fantastically confusing, because
it *looks* like the func type takes no arguments though in fact it does.
This also lets us simplify the dumper slightly (and introduces our first
uses of ctf_assert and ctf_err_warn: there will be many more).
ctf_type_aname dumps function types without including the function
pointer name itself: ctf_dump search-and-replaces it in. This seems to
give the nicest-looking results for existing users of both, even if it
is a bit fiddly.
libctf/
* ctf-types.c (ctf_type_aname): Print arg types here...
* ctf-dump.c (ctf_dump_funcs): ... not here: but do substitute
in the type name here.
Diffstat (limited to 'libctf/ctf-types.c')
-rw-r--r-- | libctf/ctf-types.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index 5500682..ddcca66 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -745,7 +745,51 @@ ctf_type_aname (ctf_file_t *fp, ctf_id_t type) ctf_decl_sprintf (&cd, "[%u]", cdp->cd_n); break; case CTF_K_FUNCTION: - ctf_decl_sprintf (&cd, "()"); + { + size_t i; + ctf_funcinfo_t fi; + ctf_id_t *argv = NULL; + + if (ctf_func_type_info (rfp, cdp->cd_type, &fi) < 0) + goto err; /* errno is set for us. */ + + if ((argv = calloc (fi.ctc_argc, sizeof (ctf_id_t *))) == NULL) + { + ctf_set_errno (rfp, errno); + goto err; + } + + if (ctf_func_type_args (rfp, cdp->cd_type, + fi.ctc_argc, argv) < 0) + goto err; /* errno is set for us. */ + + ctf_decl_sprintf (&cd, "(*) ("); + for (i = 0; i < fi.ctc_argc; i++) + { + char *arg = ctf_type_aname (rfp, argv[i]); + + if (arg == NULL) + goto err; /* errno is set for us. */ + ctf_decl_sprintf (&cd, "%s", arg); + free (arg); + + if ((i < fi.ctc_argc - 1) + || (fi.ctc_flags & CTF_FUNC_VARARG)) + ctf_decl_sprintf (&cd, ", "); + } + + if (fi.ctc_flags & CTF_FUNC_VARARG) + ctf_decl_sprintf (&cd, "..."); + ctf_decl_sprintf (&cd, ")"); + + free (argv); + break; + + err: + free (argv); + ctf_decl_fini (&cd); + return NULL; + } break; case CTF_K_STRUCT: case CTF_K_FORWARD: |