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
0006-py-symbol-Allow-gdb_lookup_symbol-to-accep...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0006-py-symbol-Allow-gdb_lookup_symbol-to-accept-block-No.patch of Package gdb
From 2dc2a55c66df9f718ec35b44e02a8fa6c295b603 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney <jeffm@suse.com> Date: Wed, 18 Mar 2020 10:57:31 -0400 Subject: [PATCH 06/17] py-symbol: Allow gdb_lookup_symbol to accept block=None gdbpy_lookup_symbol refuses to perform a lookup without a valid block. If no block is passed, we look up the block using the selected frame. If there is no selected frame, we return an error. Since a frame isn't required to lookup objects like static functions and variables, we should be able to complete the lookup without a block. This patch allows us to accept block=None to proceed with the lookup without a block. This allows us to lookup static symbols directly from python rather than using gdb.eval_and_parse. --- gdb/doc/python.texi | 5 ++-- gdb/python/py-symbol.c | 39 +++++++++++++++++--------- gdb/testsuite/gdb.python/py-symbol.c | 7 +++++ gdb/testsuite/gdb.python/py-symbol.exp | 7 +++++ 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 918418b08c9..a5012b0ca0d 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5308,8 +5308,9 @@ arguments. @var{name} is the name of the symbol. It must be a string. The optional @var{block} argument restricts the search to symbols visible in that @var{block}. The @var{block} argument must be a -@code{gdb.Block} object. If omitted, the block for the current frame -is used. The optional @var{domain} argument restricts +@code{gdb.Block} object or @code{None}. If omitted, the block for the +current frame is used. If @code{None}, no block will be used to resolve +the symbol. The optional @var{domain} argument restricts the search to the domain type. The @var{domain} argument must be a domain constant defined in the @code{gdb} module and described later in this chapter. diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 8c6d205eb42..93e75ea8ca2 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -376,25 +376,36 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) PyObject *block_obj = NULL, *sym_obj, *bool_obj; const struct block *block = NULL; - if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name, - &block_object_type, &block_obj, - &domain)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|Oi", keywords, &name, + &block_obj, &domain)) return NULL; - if (block_obj) - block = block_object_to_block (block_obj); - else + if (block_obj && block_obj != Py_None && + !PyObject_TypeCheck (block_obj, &block_object_type)) { - struct frame_info *selected_frame; + PyErr_Format (PyExc_TypeError, + "argument 2 must be gdb.Block or None, not %s", + block_obj->ob_type->tp_name); + return NULL; + } - try - { - selected_frame = get_selected_frame (_("No frame selected.")); - block = get_frame_block (selected_frame, NULL); - } - catch (const gdb_exception &except) + if (block_obj != Py_None) + { + if (block_obj) + block = block_object_to_block (block_obj); + else { - GDB_PY_HANDLE_EXCEPTION (except); + struct frame_info *selected_frame; + + try + { + selected_frame = get_selected_frame (_("No frame selected.")); + block = get_frame_block (selected_frame, NULL); + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } } } diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c index 61b2c61b51b..872ddc6313f 100644 --- a/gdb/testsuite/gdb.python/py-symbol.c +++ b/gdb/testsuite/gdb.python/py-symbol.c @@ -52,6 +52,11 @@ int func (int arg) return arg; } +static int staticfunc (int arg) +{ + return 0; +} + struct simple_struct { int a; @@ -70,6 +75,8 @@ int main (int argc, char *argv[]) result = func (42); + result = staticfunc (42); + #ifdef __cplusplus sclass.seti (42); sclass.valueofi (); diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp index ef4f86d005d..19b7dce522b 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -104,6 +104,13 @@ gdb_test "python print (gdb.lookup_static_symbol ('nonexistent') is None)" \ gdb_test "python print (gdb.lookup_static_symbol ('qq') is None)" \ "True" "lookup_static_symbol for global var" +# Test looking up a static symbol that doesn't require a frame +gdb_test_no_output "python staticfunc = gdb.lookup_symbol(\"staticfunc\", None)" "" +gdb_test "python print staticfunc\[0\]" "staticfunc" "Test staticfunc lookup" + +gdb_test_no_output "python staticfunc = gdb.lookup_symbol(\"does_not_exist\", None)" "" +gdb_test "python print staticfunc\[0\]" "None" "Test missing symbol lookup" + if ![runto_main] then { return 0 } -- 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