diff options
author | Hannes Domani <ssbssa@yahoo.de> | 2024-02-08 20:09:25 +0100 |
---|---|---|
committer | Hannes Domani <ssbssa@yahoo.de> | 2024-02-08 20:09:56 +0100 |
commit | 2e08907d0672711617f71ef4604df190106b992e (patch) | |
tree | 80b10c2c6194c72f70449ee7f6141a5afe315f00 /gdb/python | |
parent | 51d525db2edce2708d85c4ff63e82269bbe0f3fc (diff) | |
download | gdb-2e08907d0672711617f71ef4604df190106b992e.zip gdb-2e08907d0672711617f71ef4604df190106b992e.tar.gz gdb-2e08907d0672711617f71ef4604df190106b992e.tar.bz2 |
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>
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-value.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 151b880..89ca098 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1214,10 +1214,11 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords) GDB_PY_HANDLE_EXCEPTION (except); } - if (ftype->code () != TYPE_CODE_FUNC) + if (ftype->code () != TYPE_CODE_FUNC && ftype->code () != TYPE_CODE_METHOD) { PyErr_SetString (PyExc_RuntimeError, - _("Value is not callable (not TYPE_CODE_FUNC).")); + _("Value is not callable (not TYPE_CODE_FUNC" + " or TYPE_CODE_METHOD).")); return NULL; } |