On Mon, Oct 13, 2025 at 06:16:04PM +0000, Zecheng Li wrote:
> Since we are skipping the check_variable, we need to preserve typedefs
> in match_var_offset to match the results by __die_get_real_type. Also
> move the (offset == 0) branch after the is_pointer check to ensure the
> correct type is used, fixing cases where an incorrect pointer type was
> chosen when the access offset was 0.
>
> Signed-off-by: Zecheng Li <zecheng@google.com>
> ---
> tools/perf/util/dwarf-aux.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index b57cdc8860f0..b2189de07daf 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -1395,24 +1395,24 @@ static bool match_var_offset(Dwarf_Die *die_mem, struct find_var_data *data,
> Dwarf_Word size;
> s64 offset = addr_offset - addr_type;
>
> - if (offset == 0) {
> - /* Update offset relative to the start of the variable */
> - data->offset = 0;
> - return true;
> - }
> -
> if (offset < 0)
> return false;
>
> - if (die_get_real_type(die_mem, &data->type) == NULL)
> + if (__die_get_real_type(die_mem, &data->type) == NULL)
> return false;
If the type was a typedef of a pointer, then the following check for a
pointer cannot detect the target type.
Thanks,
Namhyung
>
> if (is_pointer && dwarf_tag(&data->type) == DW_TAG_pointer_type) {
> /* Get the target type of the pointer */
> - if (die_get_real_type(&data->type, &data->type) == NULL)
> + if (__die_get_real_type(&data->type, &data->type) == NULL)
> return false;
> }
>
> + if (offset == 0) {
> + /* Update offset relative to the start of the variable */
> + data->offset = 0;
> + return true;
> + }
> +
> if (dwarf_aggregate_size(&data->type, &size) < 0)
> return false;
>
> --
> 2.51.0.788.g6d19910ace-goog
>