diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2025-03-19 22:44:29 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2025-03-20 12:11:51 +0000 |
commit | a3b1d33bf67a44a9f7677ecfe8d897038c77e9a9 (patch) | |
tree | c3046505068e475e32235fae64c629d8a4712972 | |
parent | fcd8fe52223ed4d35edde2a786a06013a5c09368 (diff) | |
download | binutils-a3b1d33bf67a44a9f7677ecfe8d897038c77e9a9.zip binutils-a3b1d33bf67a44a9f7677ecfe8d897038c77e9a9.tar.gz binutils-a3b1d33bf67a44a9f7677ecfe8d897038c77e9a9.tar.bz2 |
libctf: add proper CTF_K_FUNCTION support in ctf_add_type
No CTF_K_FUNC_LINKAGE yet, but at least we emit the function args
and arg names.
-rw-r--r-- | libctf/ctf-create.c | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index aee4add..68e6cd2 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -2566,19 +2566,68 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type dst_type = ctf_add_array (dst_fp, flag, &src_ar); break; - /* UPTODO: FUNC_LINKAGE, FUNCTION, DATASEC, VAR, *TAG */ + /* UPTODO: FUNC_LINKAGE, DATASEC, VAR, *TAG */ case CTF_K_FUNCTION: - ctc.ctc_return = ctf_add_type_internal (dst_fp, src_fp, - src_tp->ctt_type, - proc_tracking_fp); - ctc.ctc_argc = 0; - ctc.ctc_flags = 0; + { + ctf_funcinfo_t fi; + ctf_id_t *argv; + const char **arg_names; + size_t i; - if (ctc.ctc_return == CTF_ERR) - return CTF_ERR; /* errno is set for us. */ + if (ctf_func_type_info (src_fp, src_type, &fi) < 0) + return CTF_ERR; /* errno is set for us. */ - dst_type = ctf_add_function (dst_fp, flag, &ctc, NULL); - break; + fi.ctc_return = ctf_add_type_internal (dst_fp, src_fp, + src_tp->ctt_type, + proc_tracking_fp); + + if (fi.ctc_return == CTF_ERR) + return CTF_ERR; /* errno is set for us. */ + + if ((argv = calloc (fi.ctc_argc, sizeof (ctf_id_t *))) == NULL) + { + ctf_set_errno (src_fp, errno); + return CTF_ERR; + } + + if (ctf_func_type_args (src_fp, src_type, fi.ctc_argc, argv) < 0) + { + free (argv); + return CTF_ERR; /* errno is set for us. */ + } + + for (i = 0; i < fi.ctc_argc; i++) + { + argv[i] = ctf_add_type_internal (dst_fp, src_fp, + argv[i], + proc_tracking_fp); + if (argv[i] == CTF_ERR) + { + free (argv); + return CTF_ERR; /* errno is set for us. */ + } + } + + if ((arg_names = calloc (fi.ctc_argc, sizeof (const char **))) == NULL) + { + free (argv); + free (arg_names); + return CTF_ERR; /* errno is set for us. */ + } + + if (ctf_func_type_arg_names (src_fp, src_type, fi.ctc_argc, + arg_names) < 0) + { + free (argv); + free (arg_names); + return CTF_ERR; /* errno is set for us. */ + } + + dst_type = ctf_add_function (dst_fp, flag, &fi, argv, arg_names); + free (argv); + free (arg_names); + break; + } case CTF_K_STRUCT: case CTF_K_UNION: |