public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "hi-angel at yandex dot ru" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug python/27141] [RFE] Getting a python-call result is overly complicated
Date: Sat, 02 Jan 2021 20:45:07 +0000	[thread overview]
Message-ID: <bug-27141-4717-oPqCCagrdT@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27141-4717@http.sourceware.org/bugzilla/>

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.

  reply	other threads:[~2021-01-02 20:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-02 19:12 [Bug python/27141] New: " hi-angel at yandex dot ru
2021-01-02 20:45 ` hi-angel at yandex dot ru [this message]
2021-01-06 18:15 ` [Bug python/27141] " ssbssa at sourceware dot org
2021-01-06 18:47 ` hi-angel at yandex dot ru

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-27141-4717-oPqCCagrdT@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.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).