public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@yahoo.de>
To: Tom Tromey <tom@tromey.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Allow calling of C++ methods from python
Date: Sat, 16 Dec 2023 11:40:05 +0000 (UTC)	[thread overview]
Message-ID: <1291602277.3277863.1702726805678@mail.yahoo.com> (raw)
In-Reply-To: <87msub56qk.fsf@tromey.com>

 Am Samstag, 16. Dezember 2023, 01:30:31 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:

> >>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>
> Hannes>  static int static_func ();
>
> Hannes> (gdb) py b_obj = gdb.parse_and_eval('b_obj')
> Hannes> (gdb) py print(b_obj['static_func']())
> Hannes> Traceback (most recent call last):
> Hannes>  File "<string>", line 1, in <module>
> Hannes> RuntimeError: Value is not callable (not TYPE_CODE_FUNC).
>
> I'm a bit surprised that a static method is not TYPE_CODE_FUNC.
> It seems like it should be, because these are really just functions.

I never really questioned it being TYPE_CODE_METHOD, I was just wondering
instead if there is a flag that tells us that it is a static method.


> Hannes> (gdb) py print(b_obj['arg0_func']())
> Hannes> Traceback (most recent call last):
> Hannes>  File "<string>", line 1, in <module>
> Hannes> gdb.error: Too few arguments in function call.
> Hannes> Error while executing Python code.
> Hannes> (gdb) py print(b_obj['arg0_func'](b_obj))
> Hannes> 198
>
> How does this interact with overloading?

Probably as you expected, it doesn't work, since the [] operator
of gdb.Value doesn't know what to do:

(gdb) py print(b_obj['overloaded_func'])
Traceback (most recent call last):
  File "<string>", line 1, in <module>
gdb.error: cannot resolve overloaded method `overloaded_func': no arguments supplied
Error while executing Python code.


> It seems to me that either b_obj['name'] has to return some kind of
> overload set, or we need a different API, like b_obj.call_method('name', ...).
>
> In the latter case we could have it automatically supply 'this', at
> least when it's needed.

The overload set would probably be relatively easy to implement, while
the call_method would be easier to use, if it automatically chooses the
right one based on the arguments.


Regards
Hannes

  reply	other threads:[~2023-12-16 11:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20231215151938.3887-1-ssbssa.ref@yahoo.de>
2023-12-15 15:19 ` Hannes Domani
2023-12-16  0:30   ` Tom Tromey
2023-12-16 11:40     ` Hannes Domani [this message]
2024-01-03 10:38       ` Hannes Domani
2024-01-17 15:52         ` Hannes Domani
2024-01-26 17:02           ` Hannes Domani
2024-02-08 16:29   ` Tom Tromey
2024-02-08 19:11     ` Hannes Domani

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=1291602277.3277863.1702726805678@mail.yahoo.com \
    --to=ssbssa@yahoo.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).