public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Wei Wu <eddy16112@gmail.com>
To: elfutils-devel@sourceware.org
Subject: Segfault in dwfl_module_getsrc
Date: Tue, 9 May 2023 18:35:21 -0600	[thread overview]
Message-ID: <CABu-HV5YKefnQwhzYWCz9_gMwame=ApYMoxBtjDmRWVUV8JCig@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2808 bytes --]

Hello elfutils developers,

I tried to use elfutils to retrieve the backtrace within a signal handle,
but I am having a segfault inside `dwfl_module_getsrc`.

*Here is my code:*
Dwfl_Callbacks proc_callbacks;
proc_callbacks.find_debuginfo = dwfl_standard_find_debuginfo,
proc_callbacks.debuginfo_path = NULL,
proc_callbacks.find_elf = dwfl_linux_proc_find_elf;
Dwfl *dwfl_handle = dwfl_begin(&proc_callbacks);
assert(dwfl_handle != NULL);

//from the current process.
dwfl_report_begin(dwfl_handle);
int r = dwfl_linux_proc_report(dwfl_handle, getpid());
dwfl_report_end(dwfl_handle, NULL, NULL);
assert(r >= 0);

for(size_t i = 0; i < pcs.size(); i++) {
  printf("trace %p\n", (void*)(pcs[i]));
  Dwarf_Addr trace_addr = reinterpret_cast<Dwarf_Addr>(pcs[i]);
  Dwfl_Module* mod = dwfl_addrmodule(dwfl_handle, trace_addr);
  char const* file;
  int line = -1;
  if (mod) {
    const char *sym_name = dwfl_module_addrname(mod, trace_addr);
    Dwfl_Line* dwfl_line = dwfl_module_getsrc(mod, trace_addr);
    if(dwfl_line) {
      Dwarf_Addr addr;
      file = dwfl_lineinfo(dwfl_line, &addr, &line, nullptr, nullptr,
nullptr);
      printf("sym_name %s, file %s, line %d\n", sym_name, file, line);
    }
  }
}
dwfl_end(dwfl_handle);

*Here is the information from gdb:*
Thread 5 "partitioning" received signal SIGSEGV, Segmentation fault.
0x00007ffff7f57a09 in __libdw_alloc_tail (dbg=0x7fffc401ca40) at
libdw_alloc.c:53
53  if (thread_id == THREAD_ID_UNSET)
(gdb) p thread_id
Cannot access memory at address 0x0
(gdb) bt
#0  0x00007ffff7f57a09 in __libdw_alloc_tail (dbg=0x7fffc401ca40) at
libdw_alloc.c:53
#1  0x00007ffff7f4b1d0 in read_srclines (dbg=0x7fffc401ca40,
linep=0x7fffbb3508c7
"_ZNSt6vectorIN6Legion17PointerConstraintESaIS1_EE16_M_shrink_to_fitEv",
lineendp=0x7fffbb3508c7
"_ZNSt6vectorIN6Legion17PointerConstraintESaIS1_EE16_M_shrink_to_fitEv",
    comp_dir=0x7fffbb3e404b
"/scratch2/wwu/legion_python/tutorial/07_partitioning", address_size=8,
linesp=0x7fffcb56d330, filesp=0x7fffcb56d328) at dwarf_getsrclines.c:1025
#2  0x00007ffff7f4bade in __libdw_getsrclines (dbg=0x7fffc401ca40,
debug_line_offset=14426912, comp_dir=0x7fffbb3e404b
"/scratch2/wwu/legion_python/tutorial/07_partitioning", address_size=8,
linesp=0x7fffc4e320e8, filesp=0x7fffc4e320f0) at dwarf_getsrclines.c:1157
#3  0x00007ffff7f4be62 in dwarf_getsrclines (cudie=0x7fffc4dafdd0,
lines=0x5555584fe8b8, nlines=0x5555584fe8c0) at dwarf_getsrclines.c:1247
#4  0x00007ffff7f77ed8 in __libdwfl_cu_getsrclines (cu=0x7fffc4dafdd0) at
lines.c:44
#5  0x00007ffff7f78551 in dwfl_module_getsrc (mod=0x7fffc4018b90,
addr=93825030279034) at dwfl_module_getsrc.c:46
#6  0x00005555571aa81d in Realm::Backtrace::lookup_symbols
(this=0x5555584fea30) at
/scratch2/wwu/legion_python/runtime/realm/faults.cc:335

Any suggestions?

Thanks,
Wei

             reply	other threads:[~2023-05-10  0:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10  0:35 Wei Wu [this message]
2023-05-10  1:18 ` Frank Ch. Eigler

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='CABu-HV5YKefnQwhzYWCz9_gMwame=ApYMoxBtjDmRWVUV8JCig@mail.gmail.com' \
    --to=eddy16112@gmail.com \
    --cc=elfutils-devel@sourceware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).