From: Namhyung Kim <namhyung@kernel.org>
To: Zecheng Li <zecheng@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
"Liang, Kan" <kan.liang@linux.intel.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Zecheng Li <zli94@ncsu.edu>, Xu Liu <xliuprof@google.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/6] perf dwarf-aux: More accurate variable type match for breg
Date: Sat, 26 Jul 2025 17:14:21 -0700 [thread overview]
Message-ID: <aIVvXUMKjDBR3kxs@google.com> (raw)
In-Reply-To: <20250725202809.1230085-3-zecheng@google.com>
On Fri, Jul 25, 2025 at 08:28:05PM +0000, Zecheng Li wrote:
> Introduces the function is_breg_access_indirect to determine whether a
> memory access involving a DW_OP_breg* operation refers to the variable's
> value directly or requires dereferencing the variable's type as a
> pointer based on the DWARF expression. Previously, all breg based
> accesses were assumed to directly access the variable's value
> (is_pointer = false).
>
> The is_breg_access_indirect function handles three main cases:
>
> 1. Base register + offset only: (e.g., DW_OP_breg7 RSP+88) The
> calculated address is the location of the variable. The access is
> direct, so no type dereference is needed. Returns false.
This is the common case. Either basic type is store in the stack or
pointer type is spilled into the stack.
>
> 2. Base register + offset, followed by other operations ending in
> DW_OP_stack_value, including DW_OP_deref: (e.g., DW_OP_breg7 RSP+96,
> DW_OP_deref, DW_OP_plus_uconst 0x64, DW_OP_stack_value) The DWARF
> expression computes the variable's value, but that value requires a
> dereference. The memory access is fetching that value, so no type
> dereference is needed. Returns false.
This is a complex case: the variable needs a pointer calculation. We
don't support those (complex) expressions for now.
>
> 3. Base register + offset, followed only by DW_OP_stack_value: (e.g.,
> DW_OP_breg7 RSP+176, DW_OP_stack_value) This indicates the value at
> the base + offset is the variable's value. Since this value is being
> used as an address in the memory access, the variable's type is
> treated as a pointer and requires a type dereference. Returns true.
The value has a value. But I guess the type dereference is only
required if the base register points to the stack.
>
> The is_pointer argument passed to match_var_offset is now set by
> is_breg_access_indirect for breg accesses.
>
> Signed-off-by: Zecheng Li <zecheng@google.com>
> ---
> tools/perf/util/dwarf-aux.c | 42 ++++++++++++++++++++++++++++++++-----
> 1 file changed, 37 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index bf906dff9ef0..814c96ea509f 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -1424,6 +1424,38 @@ static bool match_var_offset(Dwarf_Die *die_mem, struct find_var_data *data,
> return true;
> }
>
> +/**
> + * is_breg_access_indirect - Check if breg based access implies type dereference
> + * @ops: DWARF operations array
> + * @nops: Number of operations in @ops
> + *
> + * Returns true if the DWARF expression indicates the variable's value is
> + * a pointer that the memory access dereferences.
> + * Returns false if the expression evaluates to the variable's value directly.
> + * This is called after check_allowed_ops.
> + */
> +static bool is_breg_access_indirect(Dwarf_Op *ops, size_t nops)
> +{
> + ops++;
> + nops--;
> +
> + /* only the base register */
> + if (nops == 0)
> + return false;
> +
> + switch (ops->atom) {
> + case DW_OP_stack_value:
> + return true;
As I said, I think it also need to check if the base is the stack.
> + case DW_OP_deref_size:
> + case DW_OP_deref:
> + case DW_OP_piece:
> + return false;
I'm not sure if it's always false. I sometimes see this pattern
DW_OP_bregN, DW_OP_deref*, DW_OP_stack_value
which I believe it's almost same as just
DW_OP_bregN
No?
> + default:
> + /* unreachable, OP not supported */
> + return false;
> + }
> +}
> +
> /* Only checks direct child DIEs in the given scope. */
> static int __die_find_var_reg_cb(Dwarf_Die *die_mem, void *arg)
> {
> @@ -1452,7 +1484,7 @@ static int __die_find_var_reg_cb(Dwarf_Die *die_mem, void *arg)
> if (data->is_fbreg && ops->atom == DW_OP_fbreg &&
> check_allowed_ops(ops, nops) &&
> match_var_offset(die_mem, data, data->offset, ops->number,
> - /*is_pointer=*/false))
> + /*is_pointer=*/is_breg_access_indirect(ops, nops)))
The annotate like /*is_pointer=*/ is used for constant arguments.
You can delete here and below.
Thanks,
Namhyung
> return DIE_FIND_CB_END;
>
> /* Only match with a simple case */
> @@ -1464,11 +1496,11 @@ static int __die_find_var_reg_cb(Dwarf_Die *die_mem, void *arg)
> /*is_pointer=*/true))
> return DIE_FIND_CB_END;
>
> - /* Local variables accessed by a register + offset */
> + /* variables accessed by a register + offset */
> if (ops->atom == (DW_OP_breg0 + data->reg) &&
> check_allowed_ops(ops, nops) &&
> match_var_offset(die_mem, data, data->offset, ops->number,
> - /*is_pointer=*/false))
> + /*is_pointer=*/is_breg_access_indirect(ops, nops)))
> return DIE_FIND_CB_END;
> } else {
> /* pointer variables saved in a register 32 or above */
> @@ -1478,11 +1510,11 @@ static int __die_find_var_reg_cb(Dwarf_Die *die_mem, void *arg)
> /*is_pointer=*/true))
> return DIE_FIND_CB_END;
>
> - /* Local variables accessed by a register + offset */
> + /* variables accessed by a register + offset */
> if (ops->atom == DW_OP_bregx && data->reg == ops->number &&
> check_allowed_ops(ops, nops) &&
> match_var_offset(die_mem, data, data->offset, ops->number2,
> - /*is_poitner=*/false))
> + /*is_pointer=*/is_breg_access_indirect(ops, nops)))
> return DIE_FIND_CB_END;
> }
> }
> --
> 2.50.1.470.g6ba607880d-goog
>
next prev parent reply other threads:[~2025-07-27 0:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-25 20:28 [PATCH v1 0/6] perf tools: Some improvements on data type profiler Zecheng Li
2025-07-25 20:28 ` [PATCH v1 1/6] perf dwarf-aux: Use signed comparison in match_var_offset Zecheng Li
2025-07-26 0:58 ` Ian Rogers
2025-07-26 23:56 ` Namhyung Kim
2025-07-25 20:28 ` [PATCH v1 2/6] perf dwarf-aux: More accurate variable type match for breg Zecheng Li
2025-07-27 0:14 ` Namhyung Kim [this message]
2025-07-25 20:28 ` [PATCH v1 3/6] perf dwarf-aux: Better type matching for stack variables Zecheng Li
2025-07-26 1:17 ` Ian Rogers
2025-07-27 0:22 ` Namhyung Kim
2025-07-25 20:28 ` [PATCH v1 4/6] perf annotate: Skip annotating data types to lea instructions Zecheng Li
2025-07-26 1:19 ` Ian Rogers
2025-07-25 20:28 ` [PATCH v1 5/6] perf dwarf-aux: Find pointer type to a type Zecheng Li
2025-07-27 0:24 ` Namhyung Kim
2025-07-25 20:28 ` [PATCH v1 6/6] perf annotate: Track arithmetic instructions on pointers Zecheng Li
2025-07-27 0:32 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aIVvXUMKjDBR3kxs@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=xliuprof@google.com \
--cc=zecheng@google.com \
--cc=zli94@ncsu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.