On 3/2/24 21:05, Mark Wielaard wrote:
Hi Martin,

[...]

It would be interesting to see the perf tool patch. I don't understand
the use case. So I assume perf currently does something which is wrong
and with your patch calling this new dwfl_set_offline_next_addres it
will do the right thing. That is what I was thinking of when asking
for an example or testcase. I agree that on itself such a simple
setter doesn't need a dedicated testcase. But maybe we can come up
with a testcase given the right context.

Erm, I think I have a more clear example. When I use libdw to do
something like addr2line with an ELF file I fail to get the address
source line. Then I saw that eu-addr2line sets offline_next_address to
zero. The following is the program I've used to see the source info of
an address.

    int main(int argc, const char **argv)
    {
      if (argc != 3)
        return 1;

      Dwfl *dwfl = dwfl_begin(&offline_callbacks);
      if (!dwfl)
        return 1;
      dwfl_set_offline_next_address(dwfl, 0);

      if (!dwfl_report_offline(dwfl, "", argv[1], -1)) {
        dwfl_end(dwfl);
        return 1;
      }
      if (dwfl_report_end(dwfl, NULL, NULL)) {
        dwfl_end(dwfl);
        return 1;
      }

      char *endp = NULL;
      GElf_Addr addr = strtoumax(argv[2], &endp, 16);

      Dwfl_Module *mod = dwfl_addrmodule(dwfl, addr);

      int width = get_addr_width(mod);
      printf("0x%.*" PRIx64 "\n", width, addr);

      GElf_Sym s;
      GElf_Off off = 0;
      const char *name =
        dwfl_module_addrinfo(mod, addr, &off, &s, NULL, NULL, NULL);

      Dwfl_Line *line = dwfl_module_getsrc(mod, addr);
      if (!line)
        line = dwfl_getsrc(dwfl, addr);
      if (line) {
        int nline, column;
        const char *filename =
          dwfl_lineinfo(line, &addr, &nline, &column, NULL, NULL);
        printf("%s:%i,%i\n", filename, nline, column);
      } else {
        printf("??:0\n");
      }

      dwfl_end(dwfl);

      return 0;
    }

It could print the symbol name but that would've made the program
much longer but I think that this should be clear now.


Cheers,

Mark

Reply via email to