public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Segfault in dwfl_module_getsrc
@ 2023-05-10  0:35 Wei Wu
  2023-05-10  1:18 ` Frank Ch. Eigler
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Wu @ 2023-05-10  0:35 UTC (permalink / raw)
  To: elfutils-devel

[-- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Segfault in dwfl_module_getsrc
  2023-05-10  0:35 Segfault in dwfl_module_getsrc Wei Wu
@ 2023-05-10  1:18 ` Frank Ch. Eigler
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2023-05-10  1:18 UTC (permalink / raw)
  To: Wei Wu; +Cc: elfutils-devel

Hi -

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

A red flag is "within a signal handler".  The kinds of code that one
may safely invoke in a signal handler are highly limited.  Most
elfutils functions are not safe this way.  See

% man signal-safety

- FChE


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-10  1:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-10  0:35 Segfault in dwfl_module_getsrc Wei Wu
2023-05-10  1:18 ` Frank Ch. Eigler

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).