Re: [PATCH] perf annotate: Fix instruction association and parsing for LoongArch

From: Namhyung Kim
Date: Wed Jun 21 2023 - 00:54:21 EST


On Tue, Jun 20, 2023 at 9:37 PM WANG Rui <wangrui@xxxxxxxxxxx> wrote:
>
> Hello Namhyung,
>
> On Wed, Jun 21, 2023 at 2:42 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > > +static int loongarch_call__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms)
> > > +{
> > > + char *c, *endptr, *tok, *name;
> > > + struct map *map = ms->map;
> > > + struct addr_map_symbol target = {
> > > + .ms = { .map = map, },
> >
> > Looking here...
> >
> > > + };
> > > +
> > > + c = strchr(ops->raw, '#');
> > > + if (c++ == NULL)
> > > + return -1;
> > > +
> > > + ops->target.addr = strtoull(c, &endptr, 16);
> > > +
> > > + name = strchr(endptr, '<');
> > > + name++;
> > > +
> > > + if (arch->objdump.skip_functions_char &&
> > > + strchr(name, arch->objdump.skip_functions_char))
> > > + return -1;
> > > +
> > > + tok = strchr(name, '>');
> > > + if (tok == NULL)
> > > + return -1;
> > > +
> > > + *tok = '\0';
> > > + ops->target.name = strdup(name);
> > > + *tok = '>';
> > > +
> > > + if (ops->target.name == NULL)
> > > + return -1;
> > > +
> > > + target.addr = map__objdump_2mem(map, ops->target.addr);
> > > +
> > > + if (maps__find_ams(ms->maps, &target) == 0 &&
> > > + map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
> >
> > So the target.ms.map is 'map', right? Then we can reduce the line.
>
> toos/perf/util/maps.c:
>
> > int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
> > {
> > if (ams->addr < map__start(ams->ms.map) || ams->addr >= map__end(ams->ms.map)) {
> > if (maps == NULL)
> > return -1;
> > ams->ms.map = maps__find(maps, ams->addr);
>
> Is it possible that `target.ms.map` might be reassigned within the
> `maps_find_ams` function in this case?

Ah, ok. Missed that part. It can change if the target is from a
different library.

Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>

Thanks,
Namhyung

>
> > if (ams->ms.map == NULL)
> > return -1;
> > }
> >
> > ams->al_addr = map__map_ip(ams->ms.map, ams->addr);
> > ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
> >
> > return ams->ms.sym ? 0 : -1;
> > }

>