Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:tabraham1:branches:home:jeff_mahoney:crash-python:devel
gdb
0008-py-minsymbol-Add-interface-to-access-minim...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0008-py-minsymbol-Add-interface-to-access-minimal_symbols.patch of Package gdb
From 099b10d2b2e8709ccfa5234ab7465afdcce86a1d Mon Sep 17 00:00:00 2001 From: Jeff Mahoney <jeffm@suse.com> Date: Wed, 18 Mar 2020 11:03:28 -0400 Subject: [PATCH 08/17] py-minsymbol: Add interface to access minimal_symbols This patch adds a new gdb.MinSymbol object to export the minimal_symbol interface. These objects can be resolved using a new gdb.lookup_minimal_symbol call. --- gdb/Makefile.in | 1 + gdb/doc/python.texi | 139 +++++++ gdb/python/py-minsymbol.c | 453 ++++++++++++++++++++++ gdb/python/py-objfile.c | 10 +- gdb/python/python-internal.h | 7 + gdb/python/python.c | 5 + gdb/testsuite/gdb.python/Makefile.in | 22 ++ gdb/testsuite/gdb.python/py-minsymbol.exp | 59 +++ 8 files changed, 695 insertions(+), 1 deletion(-) create mode 100644 gdb/python/py-minsymbol.c create mode 100644 gdb/testsuite/gdb.python/Makefile.in create mode 100644 gdb/testsuite/gdb.python/py-minsymbol.exp diff --git a/gdb/Makefile.in b/gdb/Makefile.in index aecab41eeb8..14f5b448991 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -410,6 +410,7 @@ SUBDIR_PYTHON_SRCS = \ python/py-linetable.c \ python/py-membuf.c \ python/py-micmd.c \ + python/py-minsymbol.c \ python/py-newobjfileevent.c \ python/py-objfile.c \ python/py-param.c \ diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 0b3391e28d7..b23741e751f 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -214,6 +214,7 @@ optional arguments while skipping others. Example: * Frames In Python:: Accessing inferior stack frames from Python. * Blocks In Python:: Accessing blocks from Python. * Symbols In Python:: Python representation of symbols. +* Minimal Symbols In Python:: Python representation of minimal symbols. * Symbol Tables In Python:: Python representation of symbol tables. * Line Tables In Python:: Python representation of line tables. * Breakpoints In Python:: Manipulating breakpoints using Python. @@ -5579,6 +5580,144 @@ The value's address is a symbol. This is only used for Fortran common blocks. @end vtable +@node Minimal Symbols In Python +@subsubsection Python representation of Minimal Symbols. + +@cindex minsymbols in python +@tindex gdb.MinSymbol + +@value{GDBN} represents every variable, function and type as an +entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}. +Typical symbols like functions, variables, etc are represented by +gdb.Symbol objects in Python. Some symbols are defined with less +information associated with them, like linker script variables +or assembly labels. Python represents these minimal symbols in @value{GDBN} +with the @code{gdb.MinSymbol} object. + +The following minimal symbol-related functions are available in the @code{gdb} +module: + +@findex gdb.lookup_minimal_symbol +@defun gdb.lookup_minimal_symbol (name @r{[}, sfile@r{]}, objfile@r{[}) +This function searches for a minimal symbol by name. +The search scope can be restricted by the sfile and objfile arguments. + +@var{name} is the name of the minimal symbol. It must be a string. +The optional @var{sfile} argument restricts the search to the source file +in which the minimal symbol was defined. +The @var{sfile} argument must be a string. The optional @var{objfile} +restricts the search to the objfile that contains the minimal symbol. The @var{objfile} argument must be a @code{gdb.Objfile} object. + +The result is a @code{gdb.MinSymbol} object or @code{None} if the symbol +is not found. +@end defun + +A @code{gdb.MinSymbol} object has the following attributes: + +@defvar MinSymbol.name +The name of the symbol as a string. This attribute is not writable. +@end defvar + +@defvar MinSymbol.linkage_name +The name of the symbol, as used by the linker (i.e., may be mangled). +This attribute is not writable. +@end defvar + +@defvar MinSymbol.print_name +The name of the symbol in a form suitable for output. This is either +@code{name} or @code{linkage_name}, depending on whether the user +asked @value{GDBN} to display demangled or mangled names. +@end defvar + +@defvar MinSymbol.filename +The file name of the source file where the minimal symbol is defined. This +value may represent filenames used internally by the compiler rather +than a viewable/editable source file. +@end defvar + +@defvar MinSymbol.section +The name of the binary section containing this minimal symbol. +@end defvar + +@defvar MinSymbol.is_code +@code{True} if the minimal symbol is a function or a method. +@end defvar + +@defvar MinSymbol.is_data +@code{True} if the symbol is a variable or other data. +@end defvar + +A @code{gdb.MinSymbol} object has the following methods: + +@defun MinSymbol.is_valid () +Returns @code{True} if the @code{gdb.MinSymbol} object is valid, +@code{False} if not. A @code{gdb.MinSymbol} object can become invalid if +the symbol it refers to does not exist in @value{GDBN} any longer. +All other @code{gdb.MinSymbol} methods will throw an exception if it is +invalid at the time the method is called. +@end defun + +@defun MinSymbol.value () +Compute the value of the minimal symbol, as a @code{gdb.Value}. The value +returned represents the address of the minimal symbol. Since minimal symbols +represent objects without rich type information, the @code{gdb.Type} +associated with the @code{gdb.Value} objects will be limited to whether +the minimal symbol describes executable code or data. +@end defun + +The available types for @code{gdb.MinSymbol} are represented +as constants in the @code{gdb} module. They are distinctly separate from the +types represented by the @code{gdb.Type} object. + +@vtable @code +@vindex MINSYMBOL_TYPE_UNKNOWN +@item gdb.MINSYMBOL_TYPE_UNKNOWN +This is used when the type has not been discovered or none of the +following types apply. This usually indicates an error either +in the symbol information or in @value{GDBN}'s handling of symbols. + +@vindex MINSYMBOL_TYPE_TEXT +@item gdb.MINSYMBOL_TYPE_TEXT +This type represents executable code. + +@vindex MINSYMBOL_TYPE_TEXT_GNU_IFUNC +@item gdb.MINSYMBOL_TYPE_TEXT_GNU_IFUNC +This type represents executable code that returns the address +of executable code. + +@vindex MINSYMBOL_TYPE_SLOT_GOT_PLT +@item gdb.MINSYMBOL_TYPE_SLOT_GOT_PLT +This type represents GOT for .plt sections. + +@vindex MINSYMBOL_TYPE_DATA +@item gdb.MINSYMBOL_TYPE_DATA +This type represents generally initialized (nonzero) data. + +@vindex MINSYMBOL_TYPE_BSS +@item gdb.MINSYMBOL_TYPE_BSS +This type represents generally uninitialized (zeroed) data. + +@vindex MINSYMBOL_TYPE_ABS +@item gdb.MINSYMBOL_TYPE_ABS +This type represents generally absolute (non-relocatable) data. + +@vindex MINSYMBOL_TYPE_SOLIB_TRAMPOLINE +@item gdb.MINSYMBOL_TYPE_SOLIB_TRAMPOLINE +This type represents the start address of a shared library trampoline entry. + +@vindex MINSYMBOL_TYPE_FILE_TEXT +@item gdb.MINSYMBOL_TYPE_FILE_TEXT +This type represents the static version of gdb.MINSYMBOL_TYPE_TEXT. + +@vindex MINSYMBOL_TYPE_FILE_DATA +@item gdb.MINSYMBOL_TYPE_FILE_DATA +This type represents the static version of gdb.MINSYMBOL_TYPE_DATA. + +@vindex MINSYMBOL_TYPE_FILE_BSS +@item gdb.MINSYMBOL_TYPE_FILE_BSS +This type represents the static version of gdb.MINSYMBOL_TYPE_BSS. +@end vtable + @node Symbol Tables In Python @subsubsection Symbol table representation in Python diff --git a/gdb/python/py-minsymbol.c b/gdb/python/py-minsymbol.c new file mode 100644 index 00000000000..32cf47fd864 --- /dev/null +++ b/gdb/python/py-minsymbol.c @@ -0,0 +1,453 @@ +/* Python interface to minsymbols. + + Copyright (C) 2008-2013 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "defs.h" +#include "block.h" +#include "exceptions.h" +#include "frame.h" +#include "symtab.h" +#include "python-internal.h" +#include "objfiles.h" +#include "value.h" + +typedef struct msympy_symbol_object { + PyObject_HEAD + + /* The GDB bound_minimal_symbol structure this object is wrapping. */ + struct bound_minimal_symbol bound; + + /* A minsym object is associated with an objfile, so keep track with + doubly-linked list, rooted in the objfile. This lets us + invalidate the underlying struct minimal_symbol when the objfile is + deleted. */ + struct msympy_symbol_object *prev; + struct msympy_symbol_object *next; +} minsym_object; + +/* Return the symbol that is wrapped by this symbol object. */ +static struct minimal_symbol * +minsym_object_to_minsym (PyObject *obj) +{ + if (! PyObject_TypeCheck (obj, &minsym_object_type)) + return NULL; + return ((minsym_object *) obj)->bound.minsym; +} + +static struct objfile * +minsym_object_to_objfile (PyObject *obj) +{ + if (! PyObject_TypeCheck (obj, &minsym_object_type)) + return NULL; + return ((minsym_object *) obj)->bound.objfile; +} + +/* Require a valid symbol. All access to minsym_object->symbol should be + gated by this call. */ +#define MSYMPY_REQUIRE_VALID(minsym_obj, minsym) \ + do { \ + minsym = minsym_object_to_minsym (minsym_obj); \ + if (minsym == NULL) \ + { \ + PyErr_SetString (PyExc_RuntimeError, \ + _("MinSymbol is invalid.")); \ + return NULL; \ + } \ + } while (0) + +#define MSYMPY_REQUIRE_VALID_BOUND(minsym_obj, minsym, objfile) \ + do { \ + minsym = minsym_object_to_minsym (minsym_obj); \ + objfile = minsym_object_to_objfile (minsym_obj); \ + if (minsym == NULL || objfile == NULL) \ + { \ + PyErr_SetString (PyExc_RuntimeError, \ + _("MinSymbol is invalid.")); \ + return NULL; \ + } \ + } while (0) + +static const struct objfile_data *msympy_objfile_data_key; + +static PyObject * +msympy_str (PyObject *self) +{ + struct minimal_symbol *minsym = NULL; + + MSYMPY_REQUIRE_VALID (self, minsym); + + return PyString_FromString (minsym->print_name ()); +} + +static PyObject * +msympy_get_name (PyObject *self, void *closure) +{ + struct minimal_symbol *minsym = NULL; + + MSYMPY_REQUIRE_VALID (self, minsym); + + return PyString_FromString (minsym->natural_name ()); +} + +static PyObject * +msympy_get_file_name (PyObject *self, void *closure) +{ + struct minimal_symbol *minsym = NULL; + + MSYMPY_REQUIRE_VALID (self, minsym); + + return PyString_FromString (minsym->filename); +} + +static PyObject * +msympy_get_linkage_name (PyObject *self, void *closure) +{ + struct minimal_symbol *minsym = NULL; + + MSYMPY_REQUIRE_VALID (self, minsym); + + return PyString_FromString (minsym->linkage_name ()); +} + +static PyObject * +msympy_get_print_name (PyObject *self, void *closure) +{ + struct minimal_symbol *minsym = NULL; + + MSYMPY_REQUIRE_VALID (self, minsym); + + return msympy_str (self); +} + +static PyObject * +msympy_get_type (PyObject *self, void *closure) +{ + struct minimal_symbol *minsym = NULL; + + MSYMPY_REQUIRE_VALID (self, minsym); + return PyLong_FromLong(MSYMBOL_TYPE(minsym)); +} + +static PyObject * +msympy_is_valid (PyObject *self, PyObject *args) +{ + struct minimal_symbol *minsym = NULL; + + minsym = minsym_object_to_minsym (self); + if (minsym == NULL) + Py_RETURN_FALSE; + + Py_RETURN_TRUE; +} + +static struct type * +minsym_type(struct minimal_symbol *minsym) +{ + struct type *type; + switch (minsym->type) { + case mst_text: + case mst_solib_trampoline: + case mst_file_text: + case mst_text_gnu_ifunc: + case mst_slot_got_plt: + type = builtin_type (gdbpy_enter::get_gdbarch ())->builtin_func_ptr; + break; + + case mst_data: + case mst_abs: + case mst_bss: + case mst_file_data: + case mst_file_bss: + type = builtin_type (gdbpy_enter::get_gdbarch ())->builtin_data_ptr; + break; + + case mst_unknown: + default: + type = builtin_type (gdbpy_enter::get_gdbarch ())->builtin_void; + break; + } + + return type; +} + +static PyObject * +msympy_is_code (PyObject *self, PyObject *args) +{ + struct minimal_symbol *minsym = NULL; + struct type *type = builtin_type (gdbpy_enter::get_gdbarch ())->builtin_func_ptr; + MSYMPY_REQUIRE_VALID (self, minsym); + + if (minsym_type(minsym) == type) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; +} + +static PyObject * +msympy_is_data (PyObject *self, PyObject *args) +{ + struct minimal_symbol *minsym = NULL; + struct type *type = builtin_type (gdbpy_enter::get_gdbarch ())->builtin_data_ptr; + MSYMPY_REQUIRE_VALID (self, minsym); + + if (minsym_type(minsym) == type) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; +} + +/* Implementation of gdb.MinSymbol.value (self) -> gdb.Value. Returns + the value of the symbol, or an error in various circumstances. */ + +static PyObject * +msympy_value (PyObject *self, PyObject *args) +{ + struct minimal_symbol *minsym = NULL; + struct objfile *objfile = NULL; + struct value *value = NULL; + + if (!PyArg_ParseTuple (args, "")) + return NULL; + + MSYMPY_REQUIRE_VALID (self, minsym); + try + { + objfile = minsym_object_to_objfile (self); + if (!objfile) + error(_("gdb.MinSymbol has no objfile")); + value = evaluate_var_msym_value (EVAL_NORMAL, objfile, minsym); + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + + return value_to_value_object (value); +} + +static void +set_symbol (minsym_object *obj, struct bound_minimal_symbol *bound) +{ + obj->bound = *bound; + obj->prev = NULL; + if (bound->objfile) + { + obj->next = (minsym_object *) objfile_data (bound->objfile, + msympy_objfile_data_key); + if (obj->next) + obj->next->prev = obj; + set_objfile_data (bound->objfile, msympy_objfile_data_key, obj); + } + else + obj->next = NULL; +} + +static PyObject * +bound_minsym_to_minsym_object (struct bound_minimal_symbol *bound) +{ + minsym_object *msym_obj; + + msym_obj = PyObject_New (minsym_object, &minsym_object_type); + if (msym_obj) + set_symbol (msym_obj, bound); + + return (PyObject *) msym_obj; +} + +static void +msympy_dealloc (PyObject *obj) +{ + minsym_object *msym_obj = (minsym_object *) obj; + + if (msym_obj->prev) + msym_obj->prev->next = msym_obj->next; + else if (msym_obj->bound.objfile != NULL) + set_objfile_data (msym_obj->bound.objfile, + msympy_objfile_data_key, msym_obj->next); + if (msym_obj->next) + msym_obj->next->prev = msym_obj->prev; + msym_obj->bound.minsym = NULL; + msym_obj->bound.objfile = NULL; +} + +/* Implementation of + gdb.lookup_minimal_symbol (name, [sfile, [objfile]]) -> symbol or None. */ + +PyObject * +gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw) +{ + const char *name, *sfile = NULL; + struct objfile *objfile = NULL; + static const char *keywords[] = { "name", "sfile", "objfile", NULL }; + struct bound_minimal_symbol bound_minsym = {}; + PyObject *msym_obj = NULL, *sfile_obj = NULL, *objfile_obj = NULL; + + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|OO", keywords, &name, + &sfile_obj, &objfile_obj)) + return NULL; + + if (sfile_obj && sfile_obj != Py_None) + { + gdb::unique_xmalloc_ptr<char> + str(python_string_to_host_string(sfile_obj)); + if (!str) + return NULL; + sfile = str.get(); + } + + if (objfile_obj && objfile_obj != Py_None) + { + objfile = objfpy_object_to_objfile (objfile_obj); + if (!objfile) + return NULL; + } + + try + { + bound_minsym = lookup_minimal_symbol (name, sfile, objfile); + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + + if (bound_minsym.minsym) + msym_obj = bound_minsym_to_minsym_object (&bound_minsym); + + if (msym_obj) + return msym_obj; + + Py_RETURN_NONE; +} + +static void +del_objfile_msymbols (struct objfile *objfile, void *datum) +{ + minsym_object *obj = (minsym_object *) datum; + while (obj) + { + obj->bound.minsym = NULL; + obj->bound.objfile = NULL; + obj->next = NULL; + obj->prev = NULL; + + obj = obj->next; + } +} + +int +gdbpy_initialize_minsymbols (void) +{ + if (PyType_Ready (&minsym_object_type) < 0) + return -1; + + msympy_objfile_data_key + = register_objfile_data_with_cleanup (NULL, del_objfile_msymbols); + + if (PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_UNKNOWN", + mst_unknown) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_TEXT", mst_text) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_TEXT_GNU_IFUNC", + mst_text_gnu_ifunc) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_SLOT_GOT_PLT", + mst_slot_got_plt) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_DATA", mst_data) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_BSS", mst_bss) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_ABS", mst_abs) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_SOLIB_TRAMPOLINE", + mst_solib_trampoline) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_FILE_TEXT", + mst_file_text) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_FILE_DATA", + mst_file_data) < 0 + || PyModule_AddIntConstant (gdb_module, "MINSYMBOL_TYPE_FILE_BSS", + mst_file_bss) < 0) + return -1; + + return gdb_pymodule_addobject (gdb_module, "MinSymbol", + (PyObject *) &minsym_object_type); +} + + + +static gdb_PyGetSetDef minsym_object_getset[] = { + { "name", msympy_get_name, NULL, + "Name of the minimal symbol, as it appears in the source code.", NULL }, + { "linkage_name", msympy_get_linkage_name, NULL, + "Name of the minimal symbol, as used by the linker (i.e., may be mangled).", + NULL }, + { "filename", msympy_get_file_name, NULL, + "Name of source file that contains this minimal symbol. Only applies for mst_file_*.", + NULL }, + { "print_name", msympy_get_print_name, NULL, + "Name of the minimal symbol in a form suitable for output.\n\ +This is either name or linkage_name, depending on whether the user asked GDB\n\ +to display demangled or mangled names.", NULL }, + { "type", msympy_get_type, NULL, + "Type that this minimal symbol represents." }, + { NULL } /* Sentinel */ +}; + +static PyMethodDef minsym_object_methods[] = { + { "is_valid", msympy_is_valid, METH_NOARGS, + "is_valid () -> Boolean.\n\ +Return true if this minimal symbol is valid, false if not." }, + { "is_code", msympy_is_code, METH_NOARGS, + "is_code () -> Boolean.\n\ +Return true if this minimal symbol represents code." }, + { "is_data", msympy_is_data, METH_NOARGS, + "is_data () -> Boolean.\n\ +Return true if this minimal symbol represents data." }, + { "value", msympy_value, METH_VARARGS, + "value ([frame]) -> gdb.Value\n\ +Return the value of the minimal symbol." }, + {NULL} /* Sentinel */ +}; + +PyTypeObject minsym_object_type = { + PyVarObject_HEAD_INIT (NULL, 0) + "gdb.MinSymbol", /*tp_name*/ + sizeof (minsym_object), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + msympy_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + msympy_str, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + "GDB minimal symbol object", /*tp_doc */ + 0, /*tp_traverse */ + 0, /*tp_clear */ + 0, /*tp_richcompare */ + 0, /*tp_weaklistoffset */ + 0, /*tp_iter */ + 0, /*tp_iternext */ + minsym_object_methods, /*tp_methods */ + 0, /*tp_members */ + minsym_object_getset /*tp_getset */ +}; diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 8c568799843..cddb102cffd 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -405,8 +405,16 @@ objfpy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } -/* Implementation of gdb.Objfile.add_separate_debug_file (self, string). */ +struct objfile * +objfpy_object_to_objfile(PyObject *self) +{ + objfile_object *obj = (objfile_object *) self; + OBJFPY_REQUIRE_VALID(obj); + return obj->objfile; +} + +/* Implementation of gdb.Objfile.add_separate_debug_file (self, string). */ static PyObject * objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw) { diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 098d9130bf5..f37c75fb97b 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -308,6 +308,8 @@ extern PyTypeObject block_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("block_object"); extern PyTypeObject symbol_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symbol_object"); +extern PyTypeObject minsym_object_type; + CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("minsym_object"); extern PyTypeObject event_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object"); extern PyTypeObject breakpoint_object_type @@ -427,6 +429,8 @@ PyObject *gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *gdbpy_start_recording (PyObject *self, PyObject *args); PyObject *gdbpy_current_recording (PyObject *self, PyObject *args); PyObject *gdbpy_stop_recording (PyObject *self, PyObject *args); +PyObject *gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, + PyObject *kw); PyObject *gdbpy_newest_frame (PyObject *self, PyObject *args); PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args); PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw); @@ -468,6 +472,7 @@ PyObject *objfpy_get_frame_filters (PyObject *, void *); PyObject *objfpy_get_frame_unwinders (PyObject *, void *); PyObject *objfpy_get_xmethods (PyObject *, void *); PyObject *gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw); +struct objfile *objfpy_object_to_objfile(PyObject *self); PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch); PyObject *gdbpy_all_architecture_names (PyObject *self, PyObject *args); @@ -516,6 +521,8 @@ int gdbpy_initialize_commands (void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; int gdbpy_initialize_symbols (void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; +int gdbpy_initialize_minsymbols (void) + CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; int gdbpy_initialize_symtabs (void) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; int gdbpy_initialize_blocks (void) diff --git a/gdb/python/python.c b/gdb/python/python.c index 26278bdfbd0..db5891d7fc2 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1963,6 +1963,7 @@ do_start_initialization () || gdbpy_initialize_record () < 0 || gdbpy_initialize_btrace () < 0 || gdbpy_initialize_symbols () < 0 + || gdbpy_initialize_minsymbols () < 0 || gdbpy_initialize_symtabs () < 0 || gdbpy_initialize_blocks () < 0 || gdbpy_initialize_functions () < 0 @@ -2363,6 +2364,10 @@ Return the static-linkage symbol corresponding to the given name (or None)." }, METH_VARARGS | METH_KEYWORDS, "lookup_static_symbols (name [, domain]) -> symbol\n\ Return a list of all static-linkage symbols corresponding to the given name." }, +{ "lookup_minimal_symbol", (PyCFunction) gdbpy_lookup_minimal_symbol, + METH_VARARGS | METH_KEYWORDS, + "lookup_minimal_symbol (name, [sfile, [objfile]]) -> minsym\n\ +Return the symbol corresponding to the given name (or None)." }, { "lookup_objfile", (PyCFunction) gdbpy_lookup_objfile, METH_VARARGS | METH_KEYWORDS, diff --git a/gdb/testsuite/gdb.python/Makefile.in b/gdb/testsuite/gdb.python/Makefile.in new file mode 100644 index 00000000000..46280d7989e --- /dev/null +++ b/gdb/testsuite/gdb.python/Makefile.in @@ -0,0 +1,22 @@ +VPATH = @srcdir@ +srcdir = @srcdir@ + +EXECUTABLES = py-type py-value py-prettyprint py-template py-block \ + py-symbol py-mi py-breakpoint py-inferior py-infthread \ + py-shared python lib-types py-events py-evthreads py-frame \ + py-mi py-pp-maint py-progspace py-section-script py-objfile \ + py-finish-breakpoint py-finish-breakpoint2 py-value-cc py-explore \ + py-explore-cc py-arch py-minsymbol + +MISCELLANEOUS = py-shared-sl.sl py-events-shlib.so py-events-shlib-nodebug.so + +all info install-info dvi install uninstall installcheck check: + @echo "Nothing to be done for $@..." + +clean mostlyclean: + -rm -f *~ *.o *.ci + -rm -f *.dwo *.dwp + -rm -f core $(EXECUTABLES) $(MISCELLANEOUS) + +distclean maintainer-clean realclean: clean + -rm -f Makefile config.status config.log gdb.log gdb.sum diff --git a/gdb/testsuite/gdb.python/py-minsymbol.exp b/gdb/testsuite/gdb.python/py-minsymbol.exp new file mode 100644 index 00000000000..877e17fc130 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-minsymbol.exp @@ -0,0 +1,59 @@ +# Copyright (C) 2010-2015 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing values to Python. + +load_lib gdb-python.exp + +standard_testfile + +if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { + return -1 +} + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +# Test looking up missing value +gdb_test "python print gdb.lookup_minimal_symbol('xyz')" "None" "lookup missing symbol" + +# Test looking up a minimal symbol of text type +gdb_test "print text_msym" " = \{<text variable, no debug info>\} 0x\[0-9a-f\]* <text_msym>" "locate text_msym with print" +gdb_py_test_silent_cmd "python x = gdb.lookup_minimal_symbol('text_msym')" "Lookup text_msym" 1 +gdb_test "python print x" "text_msym" "lookup text min sym" +gdb_test "python print x.name" "text_msym" "get text minsym name" +gdb_test "python print x.linkage_name" "text_msym" "get text minsym linkage_name" +# Using asm() ends up inventing a compiler-dependent filename +gdb_test "python print x.filename" ".*" "get text minsym filename" +gdb_test "python print x.print_name" "text_msym" "get text minsym print_name" +gdb_test "python print x.section" ".text" "get text minsym section" +gdb_test "python print x.value()" "0x\[0-9a-f\]*.*" "get text minsym value" +gdb_test "python print x.value().type" "void \\(\\*\\)\\(\\)" "get text minsym value type" + +# Test looking up a minimal symbol of data type +gdb_test "print data_msym" " = \[0-9\]*" "locate data_msym with print" +gdb_py_test_silent_cmd "python x = gdb.lookup_minimal_symbol('data_msym')" "Lookup data_msym" 1 +gdb_test "python print x.name" "data_msym" "get data minsym name" +gdb_test "python print x.linkage_name" "data_msym" "get data minsym linkage_name" +# Using asm() ends up inventing a compiler-dependent filename +gdb_test "python print x.filename" ".*" "get data minsym filename" +gdb_test "python print x.print_name" "data_msym" "get data minsym print_name" +gdb_test "python print x.section" ".data" "get data minsym section" +gdb_test "python print x.value()" "0x\[0-9a-f\]*.*" "get data minsym value" + +gdb_unload +gdb_test "python print (x.is_valid())" "False" "Test symbol non-validity" +gdb_test_no_output "python a = None" "Test symbol destructor" -- 2.37.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor