Re: [PATCH 03/12] dwarf_loader: Separate creating the cu/dcu pair from processing it

Jiri Olsa
2024-04-04T09:42:36Z

On Tue, Apr 02, 2024 at 04:39:36PM -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> We will need it so that we add the dcu to a list in the same order as
> the CUs are in the DWARF file (vmlinux mostly).
>
> Cc: Alan Maguire <alan.maguire@oracle.com>
> Cc: Kui-Feng Lee <kuifeng@fb.com>
> Cc: Thomas Weißschuh <linux@weissschuh.net>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> dwarf_loader.c | 24 +++++++++++++++++++-----
> 1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/dwarf_loader.c b/dwarf_loader.c
> index 1dffb3f433cb7c8e..125e361ef2bf3f7b 100644
> --- a/dwarf_loader.c
> +++ b/dwarf_loader.c
> @@ -3207,8 +3207,7 @@ struct dwarf_thread {
> void *data;
> };
>
> -static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die,
> - uint8_t pointer_size, void *thr_data)
> +static struct dwarf_cu *dwarf_cus__create_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die, uint8_t pointer_size)
> {
> /*
> * DW_AT_name in DW_TAG_compile_unit can be NULL, first seen in:
> @@ -3218,17 +3217,32 @@ static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *c
> const char *name = attr_string(cu_die, DW_AT_name, dcus->conf);
> struct cu *cu = cu__new(name ?: "", pointer_size, dcus->build_id, dcus->build_id_len, dcus->filename, dcus->conf->use_obstack);
> if (cu == NULL || cu__set_common(cu, dcus->conf, dcus->mod, dcus->elf) != 0)
> - return DWARF_CB_ABORT;
> + return NULL;
>
> struct dwarf_cu *dcu = dwarf_cu__new(cu);
>
> - if (dcu == NULL)
> - return DWARF_CB_ABORT;
> + if (dcu == NULL) {
> + cu__delete(cu);

hm, I dont see cu__delete being called before, why do we need that?

jirka

> + return NULL;
> + }
>
> dcu->type_unit = dcus->type_dcu;
> cu->priv = dcu;
> cu->dfops = &dwarf__ops;
>
> + return dcu;
> +}
> +
> +static int dwarf_cus__create_and_process_cu(struct dwarf_cus *dcus, Dwarf_Die *cu_die,
> + uint8_t pointer_size, void *thr_data)
> +{
> + struct dwarf_cu *dcu = dwarf_cus__create_cu(dcus, cu_die, pointer_size);
> +
> + if (dcu == NULL)
> + return DWARF_CB_ABORT;
> +
> + struct cu *cu = dcu->cu;
> +
> if (die__process_and_recode(cu_die, cu, dcus->conf) != 0 ||
> cus__finalize(dcus->cus, cu, dcus->conf, thr_data) == LSK__STOP_LOADING)
> return DWARF_CB_ABORT;
> --
> 2.44.0
>