Re: gdb.execute and redirect

Stefan Puiu via Gdb <[email protected]> Wed, 18 Feb 2026 13:24:51 +0200
Newsgroups gmane.comp.gdb.devel
Message-ID <CACKs7VBh69Ji9HN-1cL+1ujqck=6_J4RgWvE7a3kf7CdaPyW+w@mail.gmail.com>
On Wed, Feb 18, 2026 at 1:05 PM Stefan Puiu <[email protected]> wrote:
>
> On Fri, Feb 13, 2026 at 11:29 PM Paul Koning via Gdb <[email protected]> wrote:
> >
> > I noticed the other day that logging redirect is not honored by gdb.execute, at least not in GDB 8.2 which is what came with my OS kit.
> >
> > I can work around this by doing something like this:
> >
> >         s = gdb.execute(cmd, False, True)
> >         print (s)
> >
> > but it's surprising that this would be needed.  Is it intentional?  Is it fixed in a more recent release?
>
> I have gdb 14.2 built with yocto on x86-64, running on a custom board,
> and even the above workaround isn't working:
>
> # gdb --version
> GNU gdb (GDB) 14.2
>
> (gdb) python
> res = gdb.execute("pipe info files | grep '.text.*libsmth'", False, True)
> print("Done execute")
> print("Now res is %s" %res)
>         0x00007f6b6793f760 - 0x00007f6b6b148ed1 is .text in
> /path/to/libsmth.so.1
> Done execute
> Now res is
>
> On the other hand, the workaround seems to work on gdb 15 from Ubuntu
> 24.04, in an x86-64 VMWare VM:
>
> stefan@stefpuiu-linvm:~/git/bb/me/code-tests/interviuri$ gdb ./int_to_string1
> GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
> Copyright (C) 2024 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> [...]
> (gdb) python
> >res = gdb.execute("info shared", False, True)
> >print("Done execute")
> print("Now res is %s" %res)
> >end
> Done execute
> Now res is No shared libraries loaded at this time.
>
> On the latter, I get the same result if using:
>
> gdb.execute("info shared", to_string=True)

OTOH, since you asked whether the workaround is necessary, at least
that seems to be the case on Ubuntu noble. Without to_string=True the
output isn't redirected:

(gdb) python
res = gdb.execute("info shared")
print("Done execute")
print("Now res is %s" %res)
No shared libraries loaded at this time.
Done execute
Now res is None

Regards,
Stefan.

>
>
> Regards,
> Stefan.
>
> >
> >         paul
> >