From: Jan Vrany <jan.vrany@fit.cvut.cz>
To: Simon Sobisch <simonsobisch@gnu.org>, gdb@sourceware.org
Subject: Re: How to get the full source location of a frame via python
Date: Wed, 03 Nov 2021 20:07:42 +0000 [thread overview]
Message-ID: <6c506574eb7c0464d70421e4ec23c499b5c6a41e.camel@fit.cvut.cz> (raw)
In-Reply-To: <d0b69495-7953-1f5b-da25-2124eebb6e07@gnu.org>
On Wed, 2021-11-03 at 17:31 +0100, Simon Sobisch via Gdb wrote:
> With the Python API we can do nearly everything necessary related to
> frames and
> st = frame.find_sal().symtab
> if st:
> filename = st.filename
>
> provides the filename as noted in the debug info.
>
> If we now need to get the full filename as used in GDB (with source
> path
> and similar applied) the only version I've found so far involves GDB
> text parsing:
>
> # Get the full path for the source file
> old_frame = gdb.selected_frame()
> frame.select()
> info_source = gdb.execute("info source", False, True)
> pattern = re.compile(r"Located in (.*)\n")
> match = re.search(pattern, info_source)
> if match:
> self.current_full_path = match.group(1)
> else:
> self.current_full_path = filename_frame
> old_frame.select()
>
> Which seems not very robust as it parses text which may have a
> different
> format in other GDB versions and likely a different text when
> localized;
> additional it needs a regex which is not that fast.
>
> Questions:
> Is there a direct way to get the full source location for a frame?
By glancing at the code, it seems to me that using
st.fullname() # instead of st.filename
should return the path printed by `info source`. Both return
fullname member from struct symtab* IIUC.
Did you try `fullname()`?
Jan
next prev parent reply other threads:[~2021-11-03 20:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-02 16:40 How to create new mi commands via python / get current interpreter in python Simon Sobisch
2021-11-02 16:56 ` Jan Vrany
2021-11-02 19:11 ` Simon Sobisch
2021-11-03 9:06 ` Jan Vrany
2021-11-05 18:51 ` Jan Vrany
2021-11-05 21:18 ` feature branch for creating MI commands with python (was: How to create new mi commands via python / get current interpreter in python) Simon Sobisch
2021-11-23 12:29 ` Jan Vrany
2021-11-23 12:48 ` Lancelot SIX
2021-11-23 16:28 ` Jan Vrany
2021-11-03 16:31 ` How to get the full source location of a frame via python Simon Sobisch
2021-11-03 20:07 ` Jan Vrany [this message]
2021-11-03 20:35 ` Simon Sobisch
2021-11-03 20:50 ` UnicodeDecodeError on gdb.execute Simon Sobisch
2021-11-03 21:55 ` Is "forward-search" also possible case insensitive? Simon Sobisch
2021-11-05 9:14 ` Is there a way to know about current "until"/"advance" execution? Simon Sobisch
2021-11-22 14:54 ` Is there a way to get a function's end address other than `disassemble`? Simon Sobisch
2021-11-22 15:14 ` Andreas Schwab
2021-11-22 15:17 ` Simon Sobisch
2021-11-25 19:28 ` Broken source view with Pygments and non-UTF-8 encoded source Simon Sobisch
2021-11-26 11:16 ` Andrew Burgess
2021-11-26 13:39 ` Andrew Burgess
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=6c506574eb7c0464d70421e4ec23c499b5c6a41e.camel@fit.cvut.cz \
--to=jan.vrany@fit.cvut.cz \
--cc=gdb@sourceware.org \
--cc=simonsobisch@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).