https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110196

--- Comment #11 from fabian_kessler at gmx dot de <fabian_kessler at gmx dot 
de> ---
With the following code extension, I get what I want, but this may also be
platform dependent:

class stacktrace_entry{
// ...  
  std::string _symbol(uintptr_t const pc) const {
    Dl_info info;
    int status;
    link_map *map;
    status = dladdr1((void const *)(pc), &info, reinterpret_cast<void
**>(&map),
                     RTLD_DL_LINKMAP);
    return std::string(info.dli_fname ?: "");
  }
// ...
}

// ...

inline std::ostream &operator<<(std::ostream &__os,
                                const stacktrace_entry &__f) {
  std::string __desc, __file;
  int __line;
  if (__f._M_get_info(&__desc, &__file, &__line)) {
    __os.width(4);
    __os << __f._symbol(__f._M_pc) << "(" << __desc << ") at " << __file << ':'
         << __line;
  }
  return __os;
}

Outputs:

   0# /mnt/c/Users/Febbe/workspace/test/build/test_stacktrace_20(main) at
/mnt/c/Users/Febbe/workspace/test/test/main.cpp:7
   1# /lib/x86_64-linux-gnu/libc.so.6(__libc_start_call_main) at
../sysdeps/nptl/libc_start_call_main.h:58
   2# /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main_impl) at
../csu/libc-start.c:360
   3# /mnt/c/Users/Febbe/workspace/test/build/test_stacktrace_20(_start) at :0

Reply via email to