From patchwork Wed Jun 5 01:24:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 33011 Received: (qmail 117397 invoked by alias); 5 Jun 2019 01:24:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 117338 invoked by uid 89); 5 Jun 2019 01:24:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:google X-HELO: mail-qt1-f202.google.com Received: from mail-qt1-f202.google.com (HELO mail-qt1-f202.google.com) (209.85.160.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Jun 2019 01:24:35 +0000 Received: by mail-qt1-f202.google.com with SMTP id l11so9212356qtp.22 for ; Tue, 04 Jun 2019 18:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=BBC/TWOfZUGenCvqcoNNTnHQvy9MkwPQt5Oou3iiG6E=; b=lyalnwpjb0aIFgEjHAlG0vjtPTrAHBT9tVdGZWry3FN3cv9RFFDjPAkI7HPRtq4Yt9 H+Px2QjtQ4LzokrnEnkKBbWUe3B1/c8Dl1cLObYmLe+zjlf4Znya/EyN/hmSBJt5XOem W4lWACxk+975b31aued+BrCDJEe1IBk/BUWHzEPTBtsJ5aPERlcKPCJ7BgOnLkHDMcZX vbCR4IAetagcSljyOtqOPNKFSZX6uxAyVDseaWl4c8UgC0QA1eGbqRejJfEsCZRF+b+B rv1iRFbKCY3ifLiBekxaDsur2V3RGvUL+fScs8d3GyA4zXNm3Yqo7FBphAWdvWFcTMpn v2CA== Date: Tue, 4 Jun 2019 20:24:21 -0500 Message-Id: <20190605012421.252953-1-cbiesinger@google.com> Mime-Version: 1.0 Subject: [PATCH][PR/24474] Make gdb.lookup_static_symbol also check the STATIC_SCOPE X-Patchwork-Original-From: "Christian Biesinger via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: Christian Biesinger To: gdb-patches@sourceware.org Cc: Christian Biesinger gdb/ChangeLog: 2019-06-04 Christian Biesinger PR/24474: Make gdb.lookup_global_symbol also check the STATIC_SCOPE because from a C/C++ developer's perspective, these are also globals. * NEWS: Mention this change. * python/py-symbol.c (gdbpy_lookup_global_symbol): Call lookup_static_symbol if lookup_global_symbol returns NULL. gdb/testsuite/ChangeLog: 2019-06-04 Christian Biesinger * gdb.python/py-symbol.c: Add a static variable and one in an anonymous namespace. * gdb.python/py-symbol.exp: Check that lookup_global_symbol finds those variables. --- gdb/NEWS | 2 ++ gdb/python/py-symbol.c | 11 +++++++++++ gdb/testsuite/gdb.python/py-symbol.c | 5 +++++ gdb/testsuite/gdb.python/py-symbol.exp | 13 +++++++++++++ 4 files changed, 31 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index ded1fce406..bfd8d0a191 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -30,6 +30,8 @@ ** gdb.Type has a new property 'objfile' which returns the objfile the type was defined in. + ** gdb.lookup_global_symbol will now also find symbols with static linkage. + * New built-in convenience variables $_shell_exitcode and $_shell_exitsignal provide the exitcode or exit status of the shell commands launched by GDB commands such as "shell", "pipe" and "make". diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 8605ae71a2..5636ef9013 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -456,6 +456,17 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw) GDB_PY_HANDLE_EXCEPTION (except); } + if (symbol == NULL) { + try + { + symbol = lookup_static_symbol (name, (domain_enum) domain).symbol; + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + } + if (symbol) { sym_obj = symbol_to_symbol_object (symbol); diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c index f77c8c8585..06a931bf5d 100644 --- a/gdb/testsuite/gdb.python/py-symbol.c +++ b/gdb/testsuite/gdb.python/py-symbol.c @@ -32,9 +32,14 @@ class SimpleClass return i; /* Break in class. */ } }; + +namespace { + int anon = 10; +}; #endif int qq = 72; /* line of qq */ +static int rr = 42; /* line of rr */ int func (int arg) { diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp index 5b8a2be7c4..722fcda0f0 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -48,6 +48,16 @@ gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \ "False" \ "print whether qq needs a frame" +set rr_line [gdb_get_line_number "line of rr"] +gdb_test "python print (gdb.lookup_global_symbol ('rr').line)" "$rr_line" \ + "print line number of rr" + +gdb_test "python print (gdb.lookup_global_symbol ('rr').value ())" "42" \ + "print value of rr" + +gdb_test "python print (gdb.lookup_global_symbol ('rr').needs_frame)" \ + "False" \ + "print whether rr needs a frame" if ![runto_main] then { fail "can't run to main" @@ -137,6 +147,9 @@ gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load ${binfile}-cxx +gdb_test "python print (gdb.lookup_global_symbol ('(anonymous namespace)::anon').value ())" "10" \ + "print value of rr" + if ![runto_main] then { fail "can't run to main" return 0