Re: How to get the full source location of a frame via python

Jan Vrany <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.