This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Debug Operators with GDB Python


Hello,

We are proposing to add the ability to define (what I call as) 'Debug
Operators' using the GDB Python API. The idea behind this is that a
user should be able to define operators for the types in his program
using the GDB Python API. When the user uses these operators (for
example, at the GDB command line to evaluate expressions), GDB
performs the operations using the Python implementation of the
operators if they exist. For languages like C++, which can have
operators defined in the source, debug operators enable performing an
operation without running the inferior. In general, it can be a
convenient debug aid (think unary * for a smart pointer, or a
subscript [] operator for a container class).

The work is at a state wherein I have a patch as a proof of concept of
my design. We would like to get feedback on the idea as well as the
design before me move ahead further. I have the patch attached. Also
attached are a simple C++ program and a Python file with operator
definitions so that you can try the patch.

As I mentioned earlier, the patch is definitely not complete. What I
am looking for is a feedback on the way I am intercepting (in
value_x_binop and value_x_unop) to perform the operation using the
Python implementation of the operator. Dynamic types and inheritance
are handled on the Python side using the currently available API. One
problem I see with this approach is resolution of typedef equivalence
when looking for appropriate operator functions. If we have a class A
and its typedef TA, then using the Python API we can figure that TA is
same as A, but I do not at this point know of a way for the other way
round. Other approaches we have considered do not cater well to
template types.

The Changelog for the patch is as follows:

2012-11-29  Siva Chandra Reddy  <sivachandra@google.com>

        * Makefile.in: Add entries for new files py-operator.c/o.
        * valarith.c (value_x_binop, value_x_unop): Use Python operators
        if present.
        * data-directory/Makefile.in: Add entries for new files
        gdb/operator.py and gdb/command/debug-operator.py
        * python/py-operator.c: C side implementation of the debug
        operators support.
        * python/python-internal.h: Add new declarations.
        * python/python.h: Add new declarations.
        * python/python.c: Add initializations for the debug operator
        support.
        * python/lib/gdb/operator.py: Python side implementation of the
        support for debug operators.
        * python/lib/gdb/command/debug-operator.py: Implementation of
        the command 'enable debug-operators'.

Thanks,
Siva Chandra

Attachment: dop_patch.txt
Description: Text document

Attachment: dop.cc
Description: Binary data

Attachment: dop.py
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]