public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "fabian_kessler at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/110196] stacktrace_entry does not print which library the function was from
Date: Sat, 10 Jun 2023 12:57:19 +0000	[thread overview]
Message-ID: <bug-110196-4-evKqPkBoHO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110196-4@http.gcc.gnu.org/bugzilla/>

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

      parent reply	other threads:[~2023-06-10 12:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09 15:42 [Bug libstdc++/110196] New: stacktrace_entry does not print origin binary filename fabian_kessler at gmx dot de
2023-06-09 15:56 ` [Bug libstdc++/110196] " pinskia at gcc dot gnu.org
2023-06-09 15:58 ` fabian_kessler at gmx dot de
2023-06-09 16:07 ` fabian_kessler at gmx dot de
2023-06-09 16:09 ` [Bug libstdc++/110196] stacktrace_entry does not print which library the function was from pinskia at gcc dot gnu.org
2023-06-09 16:16 ` fabian_kessler at gmx dot de
2023-06-09 16:17 ` fabian_kessler at gmx dot de
2023-06-09 16:18 ` fabian_kessler at gmx dot de
2023-06-09 16:47 ` fabian_kessler at gmx dot de
2023-06-09 20:56 ` redi at gcc dot gnu.org
2023-06-09 21:38 ` redi at gcc dot gnu.org
2023-06-10 10:21 ` fabian_kessler at gmx dot de
2023-06-10 12:57 ` fabian_kessler at gmx dot de [this message]

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=bug-110196-4-evKqPkBoHO@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).