public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/27141] New: [RFE] Getting a python-call result is overly complicated
@ 2021-01-02 19:12 hi-angel at yandex dot ru
  2021-01-02 20:45 ` [Bug python/27141] " hi-angel at yandex dot ru
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hi-angel at yandex dot ru @ 2021-01-02 19:12 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27141

            Bug ID: 27141
           Summary: [RFE] Getting a python-call result is overly
                    complicated
           Product: gdb
           Version: 10.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: hi-angel at yandex dot ru
  Target Milestone: ---

Unless I'm missing something, the only way to get a return value from python is
to write a whole separate class with two methods.¹ This is unwieldy and hinders
quick scripting.

For example, right now I want to set `commands` to a breakpoint so the debugee
gets only paused when there's a certain string somewhere in the `bt` command.
Well, the check is really easy to script up:

    py 'my_string' in gdb.execute('bt', to_string=True)

But then if I execute it as part of gdb "if" statement, I'll get

    No symbol "py" in current context.

Having to write a whole "convenience" function means not only a redundant text,
but also a need to debug it. Also, if one has to debug it in the current
session, my experience says that unless they already know how it works, they
might screw up the current session (that's what happened to me back when I was
trying to make pretty-printers work with no experience on them)

So, it would be really helpful to either teach `py` and/or `pi` calls to return
values, so they can be executed as part of any other GDB command chain, or to
introduce a new (a `p1`?) call for that purpose.

1: https://sourceware.org/gdb/current/onlinedocs/gdb/Functions-In-Python.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug python/27141] [RFE] Getting a python-call result is overly complicated
  2021-01-02 19:12 [Bug python/27141] New: [RFE] Getting a python-call result is overly complicated hi-angel at yandex dot ru
@ 2021-01-02 20:45 ` hi-angel at yandex dot ru
  2021-01-06 18:15 ` ssbssa at sourceware dot org
  2021-01-06 18:47 ` hi-angel at yandex dot ru
  2 siblings, 0 replies; 4+ messages in thread
From: hi-angel at yandex dot ru @ 2021-01-02 20:45 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27141

--- Comment #1 from Hi-Angel <hi-angel at yandex dot ru> ---
UPD: turns out, current situation is worse. Even if we only consider
workarounds such as using a convenience function, gdb does not allow returning
a value from them. To make it work one have to be really tricky, and instead
assign the value to a gdb variable, and then check value of that variable in
the command chain. Example:

    class is_in_bt (gdb.Command):
        """Check if a string is in backtrace"""

        def __init__ (_):
            super ().__init__ ("is_in_bt", gdb.COMMAND_STATUS)

        def invoke (_, args_raw, __):
            args = gdb.string_to_argv(args_raw)
            if len(args) != 1:
                raise Exception("Wrong parameters number. Usage: is_in_bt <cmd>
<pattern>")
            else:
                ret = args[0] in gdb.execute('bt', to_string=True)
                gdb.execute(f'set var $retval = {int(ret)}') # gdb doesn't know
what is true or True, so gotta convert it to an int

    is_in_bt() # required to get it registered

And then inside gdb:

    if $retval
     >p 1
     >end
    $9 = 1

So, yeah, I feel like a number of people might not even figure out there's a
way to do that with convenience functions.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug python/27141] [RFE] Getting a python-call result is overly complicated
  2021-01-02 19:12 [Bug python/27141] New: [RFE] Getting a python-call result is overly complicated hi-angel at yandex dot ru
  2021-01-02 20:45 ` [Bug python/27141] " hi-angel at yandex dot ru
@ 2021-01-06 18:15 ` ssbssa at sourceware dot org
  2021-01-06 18:47 ` hi-angel at yandex dot ru
  2 siblings, 0 replies; 4+ messages in thread
From: ssbssa at sourceware dot org @ 2021-01-06 18:15 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27141

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ssbssa at sourceware dot org

--- Comment #2 from Hannes Domani <ssbssa at sourceware dot org> ---
(In reply to Hi-Angel from comment #1)
> UPD: turns out, current situation is worse. Even if we only consider
> workarounds such as using a convenience function, gdb does not allow
> returning a value from them.

That's not true, you can return a value from a convenience function.
And I think this kind of situation is a perfect example where I would use it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug python/27141] [RFE] Getting a python-call result is overly complicated
  2021-01-02 19:12 [Bug python/27141] New: [RFE] Getting a python-call result is overly complicated hi-angel at yandex dot ru
  2021-01-02 20:45 ` [Bug python/27141] " hi-angel at yandex dot ru
  2021-01-06 18:15 ` ssbssa at sourceware dot org
@ 2021-01-06 18:47 ` hi-angel at yandex dot ru
  2 siblings, 0 replies; 4+ messages in thread
From: hi-angel at yandex dot ru @ 2021-01-06 18:47 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27141

--- Comment #3 from Hi-Angel <hi-angel at yandex dot ru> ---
Ah, right, I stand corrected: the reason it didn't work for me is that I used
gdb.Command, whereas instead I should've used gdb.Function. The example in docs
works for example¹

1: https://sourceware.org/gdb/current/onlinedocs/gdb/Functions-In-Python.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-06 18:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-02 19:12 [Bug python/27141] New: [RFE] Getting a python-call result is overly complicated hi-angel at yandex dot ru
2021-01-02 20:45 ` [Bug python/27141] " hi-angel at yandex dot ru
2021-01-06 18:15 ` ssbssa at sourceware dot org
2021-01-06 18:47 ` hi-angel at yandex dot ru

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).