From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 2ED4E3888C42 for ; Fri, 18 Mar 2022 16:42:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2ED4E3888C42 Received: by mail-io1-xd35.google.com with SMTP id b16so9921789ioz.3 for ; Fri, 18 Mar 2022 09:42:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XGt3ofcnW/tFEZxIjtKCrAS1pLtOiNapCjU+Ltp95CY=; b=6in7hsghHQ877+iGuPdzMojajBnyNL6jkt8Hlc0OUF12Lz6W+YlMraCJE+5eO4XySn H+xh855TfX3Rv0fc4SbucAABYqiz4X/YF0+JX1kFg1/5k+/nwf76H0NPlLGgnKTMQIMH wbMAm2cV+0OSIlYmemxsg7Xu4yZvZMtSShYjE4y9AlrvngYrd58k4BkhrjcHDpfeDEhv Ts012GhRWnmrWGikhTqJMXu6Xa/zql/fcZBIlFHCLMTyx6tu5YmMQZt/jNn6mBxSgnji epBnwaXPERR2S7IquU5IRcYdJI+7qyZHhO4Fx+fjLXwh4sM/cCj7LCbsaKYzzYCSRbca A/dA== X-Gm-Message-State: AOAM530AENXnUGTtvOlsxWM0wYENWI2IGbCUXa9LDVvqK/nPe7HOrMZZ V1d9n9SmAdzdeAeRTnIKqbYgpgGd1cHOyQ== X-Google-Smtp-Source: ABdhPJwvLkm5cXno6YferTv/wsPn++sGjcPNWXh9R1UAbwO9EbRx+Xy2uaNSuu++z9QfZdMyW3PNIw== X-Received: by 2002:a05:6602:3ca:b0:63d:dfc8:fa66 with SMTP id g10-20020a05660203ca00b0063ddfc8fa66mr4774090iov.128.1647621770277; Fri, 18 Mar 2022 09:42:50 -0700 (PDT) Received: from murgatroyd.Home (71-211-175-224.hlrn.qwest.net. [71.211.175.224]) by smtp.gmail.com with ESMTPSA id w5-20020a056e021c8500b002c7f39eba1bsm2494017ill.82.2022.03.18.09.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 09:42:49 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Handle ghost entities in symbol lookup Date: Fri, 18 Mar 2022 10:42:47 -0600 Message-Id: <20220318164247.2322667-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Mar 2022 16:42:53 -0000 Normally, SPARK ghost entities are removed from the executable. However, with -gnata, they will be preserved. In this situation, it's handy to be able to inspect them. This patch allows this by removing the "___ghost_" prefix in the appropriate places. --- gdb/ada-lang.c | 12 +++++++++ gdb/testsuite/gdb.ada/ghost.exp | 37 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/ghost/gpck.ads | 18 ++++++++++++++ gdb/testsuite/gdb.ada/ghost/main.adb | 22 +++++++++++++++++ gdb/testsuite/gdb.ada/ghost/pck.ads | 19 ++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 gdb/testsuite/gdb.ada/ghost.exp create mode 100644 gdb/testsuite/gdb.ada/ghost/gpck.ads create mode 100644 gdb/testsuite/gdb.ada/ghost/main.adb create mode 100644 gdb/testsuite/gdb.ada/ghost/pck.ads diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 0f772fd7b46..71757e6ee2a 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -1323,6 +1323,11 @@ ada_decode (const char *encoded, bool wrap) if we see this prefix. */ if (startswith (encoded, "_ada_")) encoded += 5; + /* The "___ghost_" prefix is used for ghost entities. Normally + these aren't preserved but when they are, it's useful to see + them. */ + if (startswith (encoded, "___ghost_")) + encoded += 9; /* If the name starts with '_', then it is not a properly encoded name, so do not attempt to decode it. Similarly, if the name @@ -6016,6 +6021,9 @@ wild_match (const char *name, const char *patn) const char *p; const char *name0 = name; + if (startswith (name, "___ghost_")) + name += 9; + while (1) { const char *match = name; @@ -13193,6 +13201,10 @@ do_full_match (const char *symbol_search_name, if (startswith (symbol_search_name, "_ada_") && !startswith (lname, "_ada")) symbol_search_name += 5; + /* Likewise for ghost entities. */ + if (startswith (symbol_search_name, "___ghost_") + && !startswith (lname, "___ghost_")) + symbol_search_name += 9; int uscore_count = 0; while (*lname != '\0') diff --git a/gdb/testsuite/gdb.ada/ghost.exp b/gdb/testsuite/gdb.ada/ghost.exp new file mode 100644 index 00000000000..7f92b130eff --- /dev/null +++ b/gdb/testsuite/gdb.ada/ghost.exp @@ -0,0 +1,37 @@ +# Copyright 2022 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 . + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile main + +set flags [list debug additional_flags=-gnata] +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable $flags] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/main.adb] +if ![runto "main.adb:$bp_location" ] then { + perror "Couldn't run ${testfile}" + return +} + +gdb_test "print value" " = 64 '@'" +gdb_test "print ghost_value" " = 64 '@'" +gdb_test "print value2" " = 33 '!'" diff --git a/gdb/testsuite/gdb.ada/ghost/gpck.ads b/gdb/testsuite/gdb.ada/ghost/gpck.ads new file mode 100644 index 00000000000..5a38ed4f94e --- /dev/null +++ b/gdb/testsuite/gdb.ada/ghost/gpck.ads @@ -0,0 +1,18 @@ +-- Copyright 2022 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 . + +package GPck with Ghost is + Value2 : Character := '!'; +end GPck; diff --git a/gdb/testsuite/gdb.ada/ghost/main.adb b/gdb/testsuite/gdb.ada/ghost/main.adb new file mode 100644 index 00000000000..7da25422071 --- /dev/null +++ b/gdb/testsuite/gdb.ada/ghost/main.adb @@ -0,0 +1,22 @@ +-- Copyright 2022 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 . + +with Pck; use Pck; +with GPck; use GPck; + +procedure Main with Ghost is +begin + null; -- START +end Main; diff --git a/gdb/testsuite/gdb.ada/ghost/pck.ads b/gdb/testsuite/gdb.ada/ghost/pck.ads new file mode 100644 index 00000000000..f56aa509822 --- /dev/null +++ b/gdb/testsuite/gdb.ada/ghost/pck.ads @@ -0,0 +1,19 @@ +-- Copyright 2022 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 . + +package Pck is + Value : Character := '@'; + Ghost_Value : Character := '@' with Ghost; +end Pck; -- 2.34.1