public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug python/13326] Need support for C++ method call for a gdb.Value object from within python
Date: Thu, 08 Feb 2024 19:10:27 +0000	[thread overview]
Message-ID: <bug-13326-4717-d0JIRpac5T@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-13326-4717@http.sourceware.org/bugzilla/>

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

--- Comment #4 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2e08907d0672711617f71ef4604df190106b992e

commit 2e08907d0672711617f71ef4604df190106b992e
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Thu Feb 8 20:09:25 2024 +0100

    Allow calling of C++ methods from python

    Currently it's not possible to call C++ methods from python.
    Using this example:
    ```
    class B
    {
      static int static_func ();
      int arg0_func ();
      int arg1_func (int arg1);
      int arg2_func (int arg1, int arg2);
    };

    B *b_obj = new B;
    ```

    Trying to call B::static_func gives this error:
    ```
    (gdb) py b_obj = gdb.parse_and_eval('b_obj')
    (gdb) py print(b_obj['static_func']())
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    RuntimeError: Value is not callable (not TYPE_CODE_FUNC).
    Error while executing Python code.
    ```

    TYPE_CODE_METHOD was simply missing as a possible type in
    valpy_call, now the same is possible:
    ```
    (gdb) py b_obj = gdb.parse_and_eval('b_obj')
    (gdb) py print(b_obj['static_func']())
    1111
    ```

    Note that it's necessary to explicitely add the this pointer
    as the first argument in a call of non-static methods:
    ```
    (gdb) py print(b_obj['arg0_func']())
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    gdb.error: Too few arguments in function call.
    Error while executing Python code.
    (gdb) py print(b_obj['arg0_func'](b_obj))
    198
    ```

    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13326
    Approved-By: Tom Tromey <tom@tromey.com>

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

  parent reply	other threads:[~2024-02-08 19:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-20  5:14 [Bug python/13326] New: " lxmachine at gmail dot com
2012-05-05 20:13 ` [Bug python/13326] " vmiklos at frugalware dot org
2013-02-25 17:42 ` tfogal at alumni dot unh.edu
2021-01-21 19:27 ` malcolm.parsons at gmail dot com
2021-08-12 19:24 ` jwakely.gcc at gmail dot com
2023-07-24 16:30 ` joelhock at gmail dot com
2023-12-15 16:11 ` ssbssa at sourceware dot org
2024-02-08 19:10 ` cvs-commit at gcc dot gnu.org [this message]
2024-02-08 19:13 ` ssbssa at sourceware dot org
2024-06-03 15:19 ` cvs-commit at gcc dot gnu.org
2024-06-03 15:26 ` ssbssa at sourceware dot org

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-13326-4717-d0JIRpac5T@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).