From patchwork Sun Oct 29 23:23:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 78723 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 798C93831E0A for ; Sun, 29 Oct 2023 23:25:23 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 747B0386193A for ; Sun, 29 Oct 2023 23:23:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 747B0386193A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 747B0386193A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698621800; cv=none; b=Eo2Uu4bitO/QEO0NG5GFsXKLf+5bL5RthV/iD/1wWpFhz1sRBX9vRs5E/erVdOw+K1LeR1GDewemo0TuHzkMchrcU36HBGkQDcKM6E/Bm+7X87yNw1c8dtH+mIXiKe+0bja08KPTstVSmVlmLyV/kDSNiQRlBh8SkczgB0GuQsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698621800; c=relaxed/simple; bh=zodlxV7qQb0L1LZY8UnoqOoqUbhsF7BiWeJxuFXCgfo=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=aF/k83I0YrlNrvh0IyJ+aEaLGpw3AvJ91fGkDxJBEItyvbpqZuT3QOVijXjrGuZu5YX6zR742pkzutdFyZ8NoTyLeHAaN2WKP84SwHfUgp+laGOGGKPc3WBdWE280jGLc1BvaojJYpMx4tlCO16HUOAQ9tszQKjBF0d9Ofhqx/M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6009a.ext.cloudfilter.net ([10.0.30.184]) by cmsmtp with ESMTPS id x83rqnfdI8HtexF7eqEXeS; Sun, 29 Oct 2023 23:23:10 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id xF7dqb5lmOk5SxF7eqGq5p; Sun, 29 Oct 2023 23:23:10 +0000 X-Authority-Analysis: v=2.4 cv=E+DeGIRl c=1 sm=1 tr=0 ts=653ee95e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=bhdUkHdE2iEA:10 a=Qbun_eYptAEA:10 a=fT4md5XmbbeE4dyhzB8A:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Kq+sHPrs0hjywFBC7MNC8nLIMGwHh7P3BVa19D6VHok=; b=e9h1lmbcSBfBEIbVpueNLKR6di 2R0wNB8B5q/od/zOLZe52Y31GGqOoReUDDk39c6ygeUuwTyy/1usoOJAija7hUjJFxIv1JCJwfIQE ZzNU74jz5NEyA72vFWQ8cCxHV; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:56344 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1qxF7d-0042zY-2R for gdb-patches@sourceware.org; Sun, 29 Oct 2023 17:23:09 -0600 From: Tom Tromey Date: Sun, 29 Oct 2023 17:23:49 -0600 Subject: [PATCH 28/30] Use read_var_value overload in Python MIME-Version: 1.0 Message-Id: <20231029-split-objfile-2023-bound-sym-october-v1-28-612531df2734@tromey.com> References: <20231029-split-objfile-2023-bound-sym-october-v1-0-612531df2734@tromey.com> In-Reply-To: <20231029-split-objfile-2023-bound-sym-october-v1-0-612531df2734@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.77.73 X-Source-L: No X-Exim-ID: 1qxF7d-0042zY-2R X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net ([192.168.0.21]) [97.122.77.73]:56344 X-Source-Auth: tom+tromey.com X-Email-Count: 29 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfDujMSEPN0uz7uMhLM2mJLm5fjaysFvHl9MPoevt1F78IWhBPcqJAlVhNDM2RL61fi1gtEwNHNG7sZBJlSrcLL4BmpveFDi09XjFccTHkwsPrkT8sct9 xkp/ktytqoPbs53TMzLYCAvEylu01qvCONBfOGB0kYTtS6UKIJgSI17kiUh/jy0azS3rdzoTRo3oAzOGVM2itzmXTDWGnsWH7Rk= X-Spam-Status: No, score=-3024.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This changes the Python layer to store a block_symbol in its symbol wrapper, and to use the new read_var_value overload. --- gdb/python/py-block.c | 6 +- gdb/python/py-finishbreakpoint.c | 6 +- gdb/python/py-frame.c | 19 +++--- gdb/python/py-framefilter.c | 6 +- gdb/python/py-objfile.c | 16 +++-- gdb/python/py-symbol.c | 143 +++++++++++++++++++-------------------- gdb/python/py-unwind.c | 8 +-- gdb/python/python-internal.h | 4 +- 8 files changed, 100 insertions(+), 108 deletions(-) diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index dd6d6d278a0..48921c38af2 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -156,7 +156,7 @@ blpy_get_function (PyObject *self, void *closure) sym = block->function (); if (sym) - return symbol_to_symbol_object (sym); + return symbol_to_symbol_object ({ sym, block }); Py_RETURN_NONE; } @@ -272,7 +272,7 @@ blpy_getitem (PyObject *self, PyObject *key) for (struct symbol *sym : block_iterator_range (block, &lookup_name)) { /* Just stop at the first match */ - return symbol_to_symbol_object (sym); + return symbol_to_symbol_object ({ sym, block }); } PyErr_SetObject (PyExc_KeyError, key); @@ -376,7 +376,7 @@ blpy_block_syms_iternext (PyObject *self) return NULL; } - return symbol_to_symbol_object (sym); + return symbol_to_symbol_object ({ sym, iter_obj->block }); } static void diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index 53ba41bd157..673283ce2c6 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -115,12 +115,12 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj) { scoped_value_mark free_values; - struct symbol *func_symbol = + block_symbol func_symbol = symbol_object_to_symbol (self_finishbp->func_symbol); struct value *function = value_object_to_value (self_finishbp->function_value); struct value *ret = - get_return_value (func_symbol, function); + get_return_value (func_symbol.symbol, function); if (ret) { @@ -271,7 +271,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) PyErr_Clear (); self_bpfinish->func_symbol - = symbol_to_symbol_object (function); + = symbol_to_symbol_object (b_fun); PyErr_Clear (); } } diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 555354df920..d4e3f263d5f 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -316,8 +316,7 @@ frapy_block (PyObject *self, PyObject *args) static PyObject * frapy_function (PyObject *self, PyObject *args) { - block_symbol bsym = {}; - struct symbol *sym = NULL; + block_symbol sym = {}; frame_info_ptr frame; try @@ -327,15 +326,14 @@ frapy_function (PyObject *self, PyObject *args) FRAPY_REQUIRE_VALID (self, frame); gdb::unique_xmalloc_ptr funname - = find_frame_funname (frame, &funlang, &bsym); - sym = bsym.symbol; + = find_frame_funname (frame, &funlang, &sym); } catch (const gdb_exception &except) { GDB_PY_HANDLE_EXCEPTION (except); } - if (sym) + if (sym.symbol != nullptr) return symbol_to_symbol_object (sym); Py_RETURN_NONE; @@ -481,8 +479,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw) { frame_info_ptr frame; PyObject *sym_obj, *block_obj = NULL; - struct symbol *var = NULL; /* gcc-4.3.2 false warning. */ - const struct block *block = NULL; + block_symbol var; static const char *keywords[] = { "variable", "block", nullptr }; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O|O!", keywords, @@ -500,6 +497,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw) if (!var_name) return NULL; + const struct block *block = NULL; if (block_obj != nullptr) { /* This call should only fail if the type of BLOCK_OBJ is wrong, @@ -517,8 +515,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw) if (!block) block = get_frame_block (frame, NULL); lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN, NULL); - var = lookup_sym.symbol; - block = lookup_sym.block; + var = lookup_sym; } catch (const gdb_exception &except) { @@ -526,7 +523,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (!var) + if (var.symbol == nullptr) { PyErr_Format (PyExc_ValueError, _("Variable '%s' not found."), var_name.get ()); @@ -548,7 +545,7 @@ frapy_read_var (PyObject *self, PyObject *args, PyObject *kw) FRAPY_REQUIRE_VALID (self, frame); scoped_value_mark free_values; - struct value *val = read_var_value (var, block, frame); + struct value *val = read_var_value (var, frame); result = value_to_value_object (val); } catch (const gdb_exception &except) diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index b214e82628f..b2f2d81d4de 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -83,11 +83,7 @@ extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr *name, { /* This type checks 'result' during the conversion so we just call it unconditionally and check the return. */ - /* TODO: currently, we have no way to recover the block in which SYMBOL - was found, so we have no block to return. Trying to evaluate SYMBOL - will yield an incorrect value when it's located in a FRAME and - evaluated from another frame (as permitted in nested functions). */ - *sym = { symbol_object_to_symbol (result.get ()), nullptr }; + *sym = symbol_object_to_symbol (result.get ()); if (sym->symbol == NULL) { diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index bb5d0d92aba..ee0a262e0fb 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -479,9 +479,11 @@ objfpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw) try { - struct symbol *sym = lookup_global_symbol_from_objfile - (obj->objfile, GLOBAL_BLOCK, symbol_name, (domain_enum) domain).symbol; - if (sym == nullptr) + block_symbol sym + = lookup_global_symbol_from_objfile (obj->objfile, GLOBAL_BLOCK, + symbol_name, + (domain_enum) domain); + if (sym.symbol == nullptr) Py_RETURN_NONE; return symbol_to_symbol_object (sym); @@ -513,9 +515,11 @@ objfpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw) try { - struct symbol *sym = lookup_global_symbol_from_objfile - (obj->objfile, STATIC_BLOCK, symbol_name, (domain_enum) domain).symbol; - if (sym == nullptr) + block_symbol sym + = lookup_global_symbol_from_objfile (obj->objfile, STATIC_BLOCK, + symbol_name, + (domain_enum) domain); + if (sym.symbol == nullptr) Py_RETURN_NONE; return symbol_to_symbol_object (sym); diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 99724cfc95b..b802a7fdb45 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -29,7 +29,7 @@ struct symbol_object { PyObject_HEAD /* The GDB symbol structure this object is wrapping. */ - struct symbol *symbol; + block_symbol symbol; /* A symbol object is associated with an objfile, so keep track with doubly-linked list, rooted in the objfile. This lets us invalidate the underlying struct symbol when the objfile is @@ -40,10 +40,10 @@ struct symbol_object { /* Require a valid symbol. All access to symbol_object->symbol should be gated by this call. */ -#define SYMPY_REQUIRE_VALID(symbol_obj, symbol) \ +#define SYMPY_REQUIRE_VALID(symbol_obj, val) \ do { \ - symbol = symbol_object_to_symbol (symbol_obj); \ - if (symbol == NULL) \ + val = symbol_object_to_symbol (symbol_obj); \ + if (val.symbol == NULL) \ { \ PyErr_SetString (PyExc_RuntimeError, \ _("Symbol is invalid.")); \ @@ -60,7 +60,7 @@ struct symbol_object_deleter { symbol_object *next = obj->next; - obj->symbol = NULL; + obj->symbol = {}; obj->next = NULL; obj->prev = NULL; @@ -76,11 +76,11 @@ static PyObject * sympy_str (PyObject *self) { PyObject *result; - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - result = PyUnicode_FromString (symbol->print_name ()); + result = PyUnicode_FromString (symbol.symbol->print_name ()); return result; } @@ -88,56 +88,56 @@ sympy_str (PyObject *self) static PyObject * sympy_get_type (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - if (symbol->type () == NULL) + if (symbol.symbol->type () == NULL) { Py_INCREF (Py_None); return Py_None; } - return type_to_type_object (symbol->type ()); + return type_to_type_object (symbol.symbol->type ()); } static PyObject * sympy_get_symtab (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - if (!symbol->is_objfile_owned ()) + if (!symbol.symbol->is_objfile_owned ()) Py_RETURN_NONE; - return symtab_to_symtab_object (symbol->symtab ()); + return symtab_to_symtab_object (symbol.symbol->symtab ()); } static PyObject * sympy_get_name (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - return PyUnicode_FromString (symbol->natural_name ()); + return PyUnicode_FromString (symbol.symbol->natural_name ()); } static PyObject * sympy_get_linkage_name (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - return PyUnicode_FromString (symbol->linkage_name ()); + return PyUnicode_FromString (symbol.symbol->linkage_name ()); } static PyObject * sympy_get_print_name (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); @@ -147,32 +147,32 @@ sympy_get_print_name (PyObject *self, void *closure) static PyObject * sympy_get_addr_class (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - return gdb_py_object_from_longest (symbol->aclass ()).release (); + return gdb_py_object_from_longest (symbol.symbol->aclass ()).release (); } static PyObject * sympy_is_argument (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - return PyBool_FromLong (symbol->is_argument ()); + return PyBool_FromLong (symbol.symbol->is_argument ()); } static PyObject * sympy_is_constant (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; enum address_class theclass; SYMPY_REQUIRE_VALID (self, symbol); - theclass = symbol->aclass (); + theclass = symbol.symbol->aclass (); return PyBool_FromLong (theclass == LOC_CONST || theclass == LOC_CONST_BYTES); } @@ -180,12 +180,12 @@ sympy_is_constant (PyObject *self, void *closure) static PyObject * sympy_is_function (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; enum address_class theclass; SYMPY_REQUIRE_VALID (self, symbol); - theclass = symbol->aclass (); + theclass = symbol.symbol->aclass (); return PyBool_FromLong (theclass == LOC_BLOCK); } @@ -193,14 +193,14 @@ sympy_is_function (PyObject *self, void *closure) static PyObject * sympy_is_variable (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; enum address_class theclass; SYMPY_REQUIRE_VALID (self, symbol); - theclass = symbol->aclass (); + theclass = symbol.symbol->aclass (); - return PyBool_FromLong (!symbol->is_argument () + return PyBool_FromLong (!symbol.symbol->is_argument () && (theclass == LOC_LOCAL || theclass == LOC_REGISTER || theclass == LOC_STATIC || theclass == LOC_COMPUTED || theclass == LOC_OPTIMIZED_OUT)); @@ -212,14 +212,14 @@ sympy_is_variable (PyObject *self, void *closure) static PyObject * sympy_needs_frame (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; int result = 0; SYMPY_REQUIRE_VALID (self, symbol); try { - result = symbol_read_needs_frame (symbol); + result = symbol_read_needs_frame (symbol.symbol); } catch (const gdb_exception &except) { @@ -237,11 +237,11 @@ sympy_needs_frame (PyObject *self, void *closure) static PyObject * sympy_line (PyObject *self, void *closure) { - struct symbol *symbol = NULL; + block_symbol symbol; SYMPY_REQUIRE_VALID (self, symbol); - return gdb_py_object_from_longest (symbol->line ()).release (); + return gdb_py_object_from_longest (symbol.symbol->line ()).release (); } /* Implementation of gdb.Symbol.is_valid (self) -> Boolean. @@ -250,10 +250,10 @@ sympy_line (PyObject *self, void *closure) static PyObject * sympy_is_valid (PyObject *self, PyObject *args) { - struct symbol *symbol = NULL; + block_symbol symbol; symbol = symbol_object_to_symbol (self); - if (symbol == NULL) + if (symbol.symbol == NULL) Py_RETURN_FALSE; Py_RETURN_TRUE; @@ -265,7 +265,7 @@ sympy_is_valid (PyObject *self, PyObject *args) static PyObject * sympy_value (PyObject *self, PyObject *args) { - struct symbol *symbol = NULL; + block_symbol symbol; frame_info_ptr frame_info = NULL; PyObject *frame_obj = NULL; @@ -279,7 +279,7 @@ sympy_value (PyObject *self, PyObject *args) } SYMPY_REQUIRE_VALID (self, symbol); - if (symbol->aclass () == LOC_TYPEDEF) + if (symbol.symbol->aclass () == LOC_TYPEDEF) { PyErr_SetString (PyExc_TypeError, "cannot get the value of a typedef"); return NULL; @@ -295,15 +295,11 @@ sympy_value (PyObject *self, PyObject *args) error (_("invalid frame")); } - if (symbol_read_needs_frame (symbol) && frame_info == NULL) + if (symbol_read_needs_frame (symbol.symbol) && frame_info == NULL) error (_("symbol requires a frame to compute its value")); - /* TODO: currently, we have no way to recover the block in which SYMBOL - was found, so we have no block to pass to read_var_value. This will - yield an incorrect value when symbol is not local to FRAME_INFO (this - can happen with nested functions). */ scoped_value_mark free_values; - struct value *value = read_var_value (symbol, NULL, frame_info); + struct value *value = read_var_value (symbol, frame_info); result = value_to_value_object (value); } catch (const gdb_exception &except) @@ -320,14 +316,14 @@ sympy_value (PyObject *self, PyObject *args) with the life-cycle of the object file associated with this symbol, if needed. */ static void -set_symbol (symbol_object *obj, struct symbol *symbol) +set_symbol (symbol_object *obj, block_symbol symbol) { obj->symbol = symbol; obj->prev = NULL; - if (symbol->is_objfile_owned () - && symbol->symtab () != NULL) + if (symbol.symbol->is_objfile_owned () + && symbol.symbol->symtab () != NULL) { - struct objfile *objfile = symbol->objfile (); + struct objfile *objfile = symbol.symbol->objfile (); obj->next = sympy_objfile_data_key.get (objfile); if (obj->next) @@ -341,7 +337,7 @@ set_symbol (symbol_object *obj, struct symbol *symbol) /* Create a new symbol object (gdb.Symbol) that encapsulates the struct symbol object from GDB. */ PyObject * -symbol_to_symbol_object (struct symbol *sym) +symbol_to_symbol_object (block_symbol sym) { symbol_object *sym_obj; @@ -353,11 +349,11 @@ symbol_to_symbol_object (struct symbol *sym) } /* Return the symbol that is wrapped by this symbol object. */ -struct symbol * +block_symbol symbol_object_to_symbol (PyObject *obj) { if (! PyObject_TypeCheck (obj, &symbol_object_type)) - return NULL; + return {}; return ((symbol_object *) obj)->symbol; } @@ -368,13 +364,14 @@ sympy_dealloc (PyObject *obj) if (sym_obj->prev) sym_obj->prev->next = sym_obj->next; - else if (sym_obj->symbol != NULL - && sym_obj->symbol->is_objfile_owned () - && sym_obj->symbol->symtab () != NULL) - sympy_objfile_data_key.set (sym_obj->symbol->objfile (), sym_obj->next); + else if (sym_obj->symbol.symbol != NULL + && sym_obj->symbol.symbol->is_objfile_owned () + && sym_obj->symbol.symbol->symtab () != NULL) + sympy_objfile_data_key.set (sym_obj->symbol.symbol->objfile (), + sym_obj->next); if (sym_obj->next) sym_obj->next->prev = sym_obj->prev; - sym_obj->symbol = NULL; + sym_obj->symbol = {}; Py_TYPE (obj)->tp_free (obj); } @@ -384,11 +381,11 @@ static PyObject * sympy_repr (PyObject *self) { const auto symbol = symbol_object_to_symbol (self); - if (symbol == nullptr) + if (symbol.symbol == nullptr) return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name); return PyUnicode_FromFormat ("<%s print_name=%s>", Py_TYPE (self)->tp_name, - symbol->print_name ()); + symbol.symbol->print_name ()); } /* Implementation of @@ -404,7 +401,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) struct field_of_this_result is_a_field_of_this; const char *name; static const char *keywords[] = { "name", "block", "domain", NULL }; - struct symbol *symbol = NULL; + block_symbol symbol; PyObject *block_obj = NULL, *sym_obj, *bool_obj; const struct block *block = NULL; @@ -433,7 +430,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) try { symbol = lookup_symbol (name, block, (domain_enum) domain, - &is_a_field_of_this).symbol; + &is_a_field_of_this); } catch (const gdb_exception &except) { @@ -444,7 +441,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) if (ret_tuple == NULL) return NULL; - if (symbol) + if (symbol.symbol != nullptr) { sym_obj = symbol_to_symbol_object (symbol); if (!sym_obj) @@ -472,7 +469,7 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw) int domain = VAR_DOMAIN; const char *name; static const char *keywords[] = { "name", "domain", NULL }; - struct symbol *symbol = NULL; + block_symbol symbol; PyObject *sym_obj; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name, @@ -481,14 +478,14 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw) try { - symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol; + symbol = lookup_global_symbol (name, NULL, (domain_enum) domain); } catch (const gdb_exception &except) { GDB_PY_HANDLE_EXCEPTION (except); } - if (symbol) + if (symbol.symbol != nullptr) { sym_obj = symbol_to_symbol_object (symbol); if (!sym_obj) @@ -512,7 +509,7 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw) const char *name; int domain = VAR_DOMAIN; static const char *keywords[] = { "name", "domain", NULL }; - struct symbol *symbol = NULL; + block_symbol symbol = {}; PyObject *sym_obj; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name, @@ -543,19 +540,18 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw) try { if (block != nullptr) - symbol - = lookup_symbol_in_static_block (name, block, - (domain_enum) domain).symbol; + symbol = lookup_symbol_in_static_block (name, block, + (domain_enum) domain); - if (symbol == nullptr) - symbol = lookup_static_symbol (name, (domain_enum) domain).symbol; + if (symbol.symbol == nullptr) + symbol = lookup_static_symbol (name, (domain_enum) domain); } catch (const gdb_exception &except) { GDB_PY_HANDLE_EXCEPTION (except); } - if (symbol) + if (symbol.symbol != nullptr) { sym_obj = symbol_to_symbol_object (symbol); if (!sym_obj) @@ -612,10 +608,11 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw) if (block != nullptr) { - symbol *symbol = lookup_symbol_in_static_block - (name, block, (domain_enum) domain).symbol; + block_symbol symbol + = lookup_symbol_in_static_block (name, block, + (domain_enum) domain); - if (symbol != nullptr) + if (symbol.symbol != nullptr) { PyObject *sym_obj = symbol_to_symbol_object (symbol); diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 97035c5a140..7229ac86889 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -657,8 +657,7 @@ pending_framepy_function (PyObject *self, PyObject *args) PENDING_FRAMEPY_REQUIRE_VALID (pending_frame); - struct symbol *sym = nullptr; - block_symbol bsym = {}; + block_symbol sym = {}; try { @@ -666,15 +665,14 @@ pending_framepy_function (PyObject *self, PyObject *args) frame_info_ptr frame = pending_frame->frame_info; gdb::unique_xmalloc_ptr funname - = find_frame_funname (frame, &funlang, &bsym); - sym = bsym.symbol; + = find_frame_funname (frame, &funlang, &sym); } catch (const gdb_exception &except) { GDB_PY_HANDLE_EXCEPTION (except); } - if (sym != nullptr) + if (sym.symbol != nullptr) return symbol_to_symbol_object (sym); Py_RETURN_NONE; diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 847bed84dfe..a4c392085a6 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -435,7 +435,7 @@ PyObject *gdbpy_register_tui_window (PyObject *self, PyObject *args, PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal); PyObject *symtab_to_symtab_object (struct symtab *symtab); -PyObject *symbol_to_symbol_object (struct symbol *sym); +PyObject *symbol_to_symbol_object (block_symbol sym); PyObject *block_to_block_object (const struct block *block, struct objfile *objfile); PyObject *value_to_value_object (struct value *v); @@ -474,7 +474,7 @@ gdbpy_ref<> target_to_connection_object (process_stratum_target *target); PyObject *gdbpy_connections (PyObject *self, PyObject *args); const struct block *block_object_to_block (PyObject *obj); -struct symbol *symbol_object_to_symbol (PyObject *obj); +block_symbol symbol_object_to_symbol (PyObject *obj); struct value *value_object_to_value (PyObject *self); struct value *convert_value_from_python (PyObject *obj); struct type *type_object_to_type (PyObject *obj);