From 2ce1cdbf84ce883b992bc8ffec3d29b4da229b72 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Wed, 29 Apr 2015 13:24:21 -0700 Subject: PR python/18285 gdb/ChangeLog: PR python/18285 * NEWS: Document new gdb.XMethodWorker.get_result_type method. * eval.c (evaluate_subexp_standard) : Handle EVAL_AVOID_SIDE_EFFECTS for xmethods. * extension-priv.h (struct extension_language_ops) : New member. * extension.c (get_xmethod_result_type): New function. * extension.h (get_xmethod_result_type): Declare. * python/py-xmethods.c (get_result_type_method_name): New static global. (py_get_result_type_method_name): Ditto. (gdbpy_get_xmethod_result_type): New function. (gdbpy_initialize_xmethods): Initialize py_get_result_type_method_name. * python/python-internal.h (gdbpy_get_xmethod_result_type): Declare. * python/python.c (python_extension_ops): Add gdbpy_get_xmethod_result_type. * python/lib/gdb/xmethod.py (XMethodWorker): Add get_result_type. * valarith.c (value_x_binop): Handle EVAL_AVOID_SIDE_EFFECTS for xmethods. (value_x_unop): Ditto. * value.c (result_type_of_xmethod): New function. * value.h (result_type_of_xmethod): Declare. gdb/testsuite/ChangeLog: * gdb.python/py-xmethods.exp: Add ptype tests. * gdb.python/py-xmethods.py (E_method_char_worker): Add get_result_type method. gdb/doc/ChangeLog: * python.texi (Xmethod API) : Document. (Writing an Xmethod): Add get_result_type to example. --- gdb/doc/python.texi | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'gdb/doc/python.texi') diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 12d2b71..fc3c745 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2455,6 +2455,13 @@ If the xmethod takes a single argument, then a single @code{gdb.Type} object corresponding to it can be returned. @end defun +@defun XMethodWorker.get_result_type (self, *args) +This method returns a @code{gdb.Type} object representing the type +of the result of invoking this xmethod. +The @var{args} argument is the same tuple of arguments that would be +passed to the @code{__call__} method of this worker. +@end defun + @defun XMethodWorker.__call__ (self, *args) This is the method which does the @emph{work} of the xmethod. The @var{args} arguments is the tuple of arguments to the xmethod. Each @@ -2571,6 +2578,9 @@ above is as follows: class MyClassWorker_geta(gdb.xmethod.XMethodWorker): def get_arg_types(self): return None + + def get_result_type(self, obj): + return gdb.lookup_type('int') def __call__(self, obj): return obj['a_'] @@ -2579,6 +2589,9 @@ class MyClassWorker_geta(gdb.xmethod.XMethodWorker): class MyClassWorker_plus(gdb.xmethod.XMethodWorker): def get_arg_types(self): return gdb.lookup_type('MyClass') + + def get_result_type(self, obj): + return gdb.lookup_type('int') def __call__(self, obj, other): return obj['a_'] + other['a_'] @@ -2642,10 +2655,13 @@ of the xmethod workers and xmethod matchers is as follows: class MyTemplateWorker_footprint(gdb.xmethod.XMethodWorker): def __init__(self, class_type): self.class_type = class_type - + def get_arg_types(self): return None - + + def get_result_type(self): + return gdb.lookup_type('int') + def __call__(self, obj): return (self.class_type.sizeof + obj['dsize_'] * -- cgit v1.1