From 595939dea136aa2721a24e6a71edba78e80fb3f5 Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Mon, 28 Jun 2010 21:16:04 +0000 Subject: 2010-06-28 Phil Muldoon Tom Tromey Thiago Jung Bauermann * value.c (pack_unsigned_long): New function. (value_from_ulongest): New function. * value.h (value_from_ulongest): Declare. * python/python.c (_initialize_python): Call gdbpy_initialize_thread and gdbpy_initialize_inferior. * python/python-internal.h: Define thread_object. (gdbpy_inferiors, gdbpy_selected_thread) (frame_info_to_frame_object, create_thread_object) (find_thread_object, find_inferior_object) (gdbpy_initialize_thread, gdbpy_initialize_inferiors) (gdbpy_is_value_object, get_addr_from_python): Declare. * python/py-value.c (builtin_type_upylong): Define. (convert_value_from_python): Add logic for ulongest. (gdbpy_is_value_object): New function. * python/py-utils.c (get_addr_from_python): New function. * python/py-frame.c (frame_info_to_frame_object): Return a PyObject. (gdbpy_selected_frame): Use PyObject over frame_info. * Makefile.in (SUBDIR_PYTHON_OBS): Add py-inferior and py-infthread. (SUBDIR_PYTHON_SRCS): Likewise. (py-inferior.o): New Rule. (py-infthread.o): New Rule. * python/py-inferior.c: New File. * python/py-infthread.c: New File. 2010-06-28 Phil Muldoon Tom Tromey Thiago Jung Bauermann * gdb.texinfo (Inferiors In Python): New node. * gdb.texinfo (Threads In Python): New node. 2010-06-28 Phil Muldoon Tom Tromey Thiago Jung Bauermann * gdb.python/py-inferior.c: New File. * gdb.python/py-infthread.c: New File. * gdb.python/py-inferior.exp: New File. * gdb.python/py-infthread.exp: New File. --- gdb/python/py-utils.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'gdb/python/py-utils.c') diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 944e6b4..90609fa 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -19,6 +19,7 @@ #include "defs.h" #include "charset.h" +#include "value.h" #include "python-internal.h" @@ -272,3 +273,51 @@ gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue) return str; } + +/* Converts OBJ to a CORE_ADDR value. + + Returns 1 on success or 0 on failure, with a Python exception set. This + function can also throw GDB exceptions. +*/ + +int +get_addr_from_python (PyObject *obj, CORE_ADDR *addr) +{ + if (gdbpy_is_value_object (obj)) + *addr = value_as_address (value_object_to_value (obj)); + else if (PyLong_Check (obj)) + { + /* Assume CORE_ADDR corresponds to unsigned long. */ + *addr = PyLong_AsUnsignedLong (obj); + if (PyErr_Occurred () != NULL) + return 0; + } + else if (PyInt_Check (obj)) + { + long val; + + /* Assume CORE_ADDR corresponds to unsigned long. */ + val = PyInt_AsLong (obj); + + if (val >= 0) + *addr = val; + else + { + /* If no error ocurred, VAL is indeed negative. */ + if (PyErr_Occurred () != NULL) + return 0; + + PyErr_SetString (PyExc_ValueError, + _("Supplied address is negative.")); + return 0; + } + } + else + { + PyErr_SetString (PyExc_TypeError, + _("Invalid type for address.")); + return 0; + } + + return 1; +} -- cgit v1.1