From: Andi Kleen <ak@linux.intel.com>
To: Changbin Du <changbin.du@huawei.com>
Cc: linux-perf-users@vger.kernel.org, adrian.hunter@intel.com
Subject: Re: [PATCH 1/2] perf, capstone: Support 32bit code under 64bit OS
Date: Wed, 28 Feb 2024 15:29:16 -0800 [thread overview]
Message-ID: <Zd_BzC4gHONl0VL7@tassilo> (raw)
In-Reply-To: <20240228110006.piqtuyhvrjq2lulq@M910t>
On Wed, Feb 28, 2024 at 07:00:06PM +0800, Changbin Du wrote:
> On Tue, Feb 27, 2024 at 03:48:04PM -0800, Andi Kleen wrote:
> > Use the DSO to resolve whether an IP is 32bit or 64bit and use that to
> > configure capstone to the correct mode. This allows to correctly
> > disassemble 32bit code under a 64bit OS.
> >
> > % cat > loop.c
> > volatile int var;
> > int main(void)
> > {
> > int i;
> > for (i = 0; i < 100000; i++)
> > var++;
> > }
> > % gcc -m32 -o loop loop.c
> > % perf record -e cycles:u ./loop
> > % perf script -F +disasm
> > loop 82665 1833176.618023: 1 cycles:u: f7eed500 _start+0x0 (/usr/lib/ld-linux.so.2) movl %esp, %eax
> > loop 82665 1833176.618029: 1 cycles:u: f7eed500 _start+0x0 (/usr/lib/ld-linux.so.2) movl %esp, %eax
> > loop 82665 1833176.618031: 7 cycles:u: f7eed500 _start+0x0 (/usr/lib/ld-linux.so.2) movl %esp, %eax
> > loop 82665 1833176.618034: 91 cycles:u: f7eed500 _start+0x0 (/usr/lib/ld-linux.so.2) movl %esp, %eax
> > loop 82665 1833176.618036: 1242 cycles:u: f7eed500 _start+0x0 (/usr/lib/ld-linux.so.2) movl %esp, %eax
> >
> > Signed-off-by: Andi Kleen <ak@linux.intel.com>
> > ---
> > tools/perf/util/print_insn.c | 20 +++++++++++++++++---
> > 1 file changed, 17 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/perf/util/print_insn.c b/tools/perf/util/print_insn.c
> > index 459e0e93d7b1..bd7a95e64ce5 100644
> > --- a/tools/perf/util/print_insn.c
> > +++ b/tools/perf/util/print_insn.c
> > @@ -12,6 +12,8 @@
> > #include "machine.h"
> > #include "thread.h"
> > #include "print_insn.h"
> > +#include "map.h"
> > +#include "dso.h"
> >
> > size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp)
> > {
> > @@ -28,12 +30,12 @@ size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp)
> > #ifdef HAVE_LIBCAPSTONE_SUPPORT
> > #include <capstone/capstone.h>
> >
> > -static int capstone_init(struct machine *machine, csh *cs_handle)
> > +static int capstone_init(struct machine *machine, csh *cs_handle, bool is64)
> > {
> > cs_arch arch;
> > cs_mode mode;
> >
> > - if (machine__is(machine, "x86_64")) {
> > + if (machine__is(machine, "x86_64") && is64) {
> > arch = CS_ARCH_X86;
> > mode = CS_MODE_64;
> > } else if (machine__normalized_is(machine, "x86")) {
> > @@ -101,9 +103,21 @@ size_t sample__fprintf_insn_asm(struct perf_sample *sample, struct thread *threa
> > size_t count;
> > size_t printed = 0;
> > int ret;
> > + struct addr_location al;
> > + bool is64bit = machine__is(machine, "x86_64");
> > + struct dso *dso;
> > +
> > + addr_location__init(&al);
> > + if (thread__find_map(thread, sample->cpumode, sample->ip, &al) &&
> > + (dso = map__dso(al.map)) != NULL &&
> > + (dso->data.status != DSO_DATA_STATUS_ERROR)) {
> > + map__load(al.map);
> > + is64bit = dso->is_64_bit;
> > + }
> > + addr_location__exit(&al);
> >
> This could be extracted as a standalone function. And this should apply to arm64
> also.
It should work for ARM64 too, at least for the sample case which it
supports. I haven't tested it however because I don't have such a
system.
-Andi
next prev parent reply other threads:[~2024-02-28 23:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 23:48 [PATCH 1/2] perf, capstone: Support 32bit code under 64bit OS Andi Kleen
2024-02-27 23:48 ` [PATCH 2/2] perf, capstone: Support capstone for -F +brstackinsn Andi Kleen
2024-02-28 11:05 ` Changbin Du
2024-02-28 23:26 ` Andi Kleen
2024-02-28 11:00 ` [PATCH 1/2] perf, capstone: Support 32bit code under 64bit OS Changbin Du
2024-02-28 23:29 ` Andi Kleen [this message]
2024-02-28 11:42 ` Adrian Hunter
2024-02-28 23:30 ` Andi Kleen
2024-02-29 7:02 ` Adrian Hunter
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=Zd_BzC4gHONl0VL7@tassilo \
--to=ak@linux.intel.com \
--cc=adrian.hunter@intel.com \
--cc=changbin.du@huawei.com \
--cc=linux-perf-users@vger.kernel.org \
/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.