Re: [PATCH 1/3] perf scripts python: arm-cs-trace-disasm.py: print dso base address

From: Leo Yan
Date: Sun Dec 24 2023 - 03:33:49 EST


Hi Ruidong,

On Fri, Dec 22, 2023 at 03:29:18PM +0800, Ruidong Tian wrote:

[...]

> > Although it's also not that clear what this is useful for, given that
> > all the other output is relative too? Maybe you could add an example to
> > the commit message, even if it's just for debugging. Would an option
> > that turned _all_ the output into virtual addresses not be more useful?
>
> I want to use arm-cs-trace-disasm.py output associate with PMU and SPE data
> to explore more CPU performance info, all the PMU/SPE/Coresight informations
> generated by `perf report` and `perf script` include virtual address, so i
> want this script do the same thing.

I think James' suggestion is valid for replacing all offsets with
virtual addresses, in addition to introducing a new option.

Below change works well at my side. Hope this is helpful.

diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
index de58991c78bb..6c94ff2287cd 100755
--- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
+++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
@@ -36,7 +36,10 @@ option_list = [
help="Set path to objdump executable file"),
make_option("-v", "--verbose", dest="verbose",
action="store_true", default=False,
- help="Enable debugging log")
+ help="Enable debugging log"),
+ make_option("-a", "--vaddr", dest="vaddr",
+ action="store_true", default=False,
+ help="Enable virtual address")
]

parser = OptionParser(option_list=option_list)
@@ -108,6 +111,14 @@ def print_disam(dso_fname, dso_start, start_addr, stop_addr):
m = disasm_re.search(line)
if m is None:
continue
+
+ # Replace offset with virtual address
+ if (options.vaddr == True):
+ offset = re.search(r"^\s*([0-9a-fA-F]+)", line).group()
+ if offset:
+ virt_addr = dso_start + int(offset, 16)
+ line = line.replace(offset.lstrip(), "0x%016x" % virt_addr)
+
print("\t" + line)

def print_sample(sample):

Thanks,
Leo