From patchwork Thu Dec 8 15:38:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61700 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 0C2F53AA983C for ; Thu, 8 Dec 2022 15:39:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C2F53AA983C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670513950; bh=8ROqOuItzwEOFU0c5MLVDwaLU6bJP+EEZyhIaReF5CA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=TsawLVCoKOakBpttU1bK38HcYCwhLii8F8jcVnmCMDQ9p9tdDpzuNVgJ/4cMr82YK LdJLelBDHNYjcsjejkzS6NOXafLbX9WicCZ6dr3ghrsR4zgbH1Cxjzp1NfUf2Z0s/4 ifnX2VSZi2JzaweT9cfFhDeuesOgzdf3QvN3JAWc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C084239385B5 for ; Thu, 8 Dec 2022 15:38:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C084239385B5 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-374-yO6WOieAOiqFBMwb4H_fhw-1; Thu, 08 Dec 2022 10:38:39 -0500 X-MC-Unique: yO6WOieAOiqFBMwb4H_fhw-1 Received: by mail-wm1-f70.google.com with SMTP id n2-20020a05600c3b8200b003d07aea2209so2968794wms.1 for ; Thu, 08 Dec 2022 07:38:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8ROqOuItzwEOFU0c5MLVDwaLU6bJP+EEZyhIaReF5CA=; b=e3aUcg2vX1v+D8cBhxogIXICKrwp055IF/D6Q9dER5h9vDTwT+x8Bd0YJ19I7Kyiju ufd9/UkB9ib35F4oZeOx8NbO//hL8caoIJaQHI8XRS4wMAf4KXSuQXLMIbdxe6SK2S07 /wNoYL9ZYqZas/hknRyG3MhFLQ+kErLB71mypKja+M6ZY0/RyzqKGW03x5LlTp9NDGch u03lCARjqVcNT5eFUkTGnCS80pCr21Vp4RD+DYDx4iVvlA5xtN1N3zPu5DqOAu4psRaw dOgYj+WZOj+6c8e1tZWeL/5CBAXyoSs6rr/t8CiwdYKNNoHkHigvxBgQnCJRfSVbB+p2 Y6CQ== X-Gm-Message-State: ANoB5pmuzqNTis4bR2IJT0zLHsm2PATx7o+simdEUSe2ZIDyPTHXIvVu 4BVClyA3385OeQaXlfEZUrCzXlIHLw+1utBB9DI3pLrQP5XrUbJIcwRuq2i64AJcbzhhzvJId7W wcTWiqByqf/ErFBAD/U6f67bgj+1GS01OWiAHjnUXkMeV0ciZKAU6WWCZzB7BKon9wruFjOKQgA == X-Received: by 2002:adf:a4d0:0:b0:242:3be9:71c5 with SMTP id h16-20020adfa4d0000000b002423be971c5mr1714039wrb.54.1670513917956; Thu, 08 Dec 2022 07:38:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Qh5turL6C4Rn5D2/rtL3oT/9q4CpWxhR+d/K+ujSB0oUW+y4JEb/ITPktwOiZO5u+aFg7jw== X-Received: by 2002:adf:a4d0:0:b0:242:3be9:71c5 with SMTP id h16-20020adfa4d0000000b002423be971c5mr1714019wrb.54.1670513917268; Thu, 08 Dec 2022 07:38:37 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id l7-20020a5d4107000000b00242246c2f7csm22485582wrp.101.2022.12.08.07.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 07:38:36 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey , Andrew Burgess Subject: [PATCH 1/2] gdb/testsuite: fix readnow detection Date: Thu, 8 Dec 2022 15:38:32 +0000 Message-Id: <69eaee80b5b0a72649d6046d9d63d90938e67e14.1670513780.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The following commit broke the readnow detection in the testsuite: commit dfaa040b440084dd73ebd359326752d5f44fc02c Date: Mon Mar 29 18:31:31 2021 -0600 Remove some "OBJF_READNOW" code from dwarf2_debug_names_index The testsuite checks if GDB was started with the -readnow flag by using the 'maintenance print objfiles' command, and looking for the string 'faked for "readnow"' in the output. This is implemented in two helper procs `readnow` (gdb.exp) and `mi_readnow` (mi-support.exp). The following tests all currently depend on this detection: gdb.base/maint.exp gdb.cp/nsalias.exp gdb.dwarf2/debug-aranges-duplicate-offset-warning.exp gdb.dwarf2/dw2-stack-boundary.exp gdb.dwarf2/dw2-zero-range.exp gdb.dwarf2/gdb-index-nodebug.exp gdb.mi/mi-info-sources.exp gdb.python/py-symbol.exp gdb.rust/traits.exp The following test also includes detection of 'readnow', but does the detection itself by checking $::GDBFLAGS for the readnow flag: gdb.opt/break-on-_exit.exp The above commit removed from GDB the code that produced the 'faked for "readnow"' string, as a consequence the testsuite can no longer correctly spot when readnow is in use, and many of the above tests will fail (at least partially). When looking at the above tests, I noticed that gdb.rust/traits.exp does call `readnow`, but doesn't actually use the result, so I've removed the readnow call, this simplifies the next part of this patch as gdb.rust/traits.exp was the only place an extra regexp was passed to the readnow call. Next I have rewritten `readnow` to check the $GDBFLAGS for the -readnow flag, and removed the `maintenance print objfiles` check. At least for all the tests above, when using the readnow board, this is good enough to get everything passing again. For the `mi_readnow` proc, I changed this to just call `readnow` from gdb.exp, I left the mi_readnow name in place - in the future it might be the case that we want to do some different checks here. Finally, I updated gdb.opt/break-on-_exit.exp to call the `readnow` proc. With these changes, all of the tests listed above now pass correctly when using the readnow board. --- gdb/testsuite/gdb.opt/break-on-_exit.exp | 3 +-- gdb/testsuite/gdb.rust/traits.exp | 2 -- gdb/testsuite/lib/gdb.exp | 30 ++++-------------------- gdb/testsuite/lib/mi-support.exp | 28 ++++------------------ 4 files changed, 10 insertions(+), 53 deletions(-) diff --git a/gdb/testsuite/gdb.opt/break-on-_exit.exp b/gdb/testsuite/gdb.opt/break-on-_exit.exp index 7c2fda6af69..3d18cd70bb9 100644 --- a/gdb/testsuite/gdb.opt/break-on-_exit.exp +++ b/gdb/testsuite/gdb.opt/break-on-_exit.exp @@ -36,8 +36,7 @@ standard_testfile # See if we have target board readnow.exp or similar. -if { [lsearch -exact $GDBFLAGS -readnow] != -1 \ - || [lsearch -exact $GDBFLAGS --readnow] != -1 } { +if {[readnow]} { untested "--readnever not allowed in combination with --readnow" return -1 } diff --git a/gdb/testsuite/gdb.rust/traits.exp b/gdb/testsuite/gdb.rust/traits.exp index aa45e64b877..949e7cb919e 100644 --- a/gdb/testsuite/gdb.rust/traits.exp +++ b/gdb/testsuite/gdb.rust/traits.exp @@ -43,7 +43,5 @@ if {![runto ${srcfile}:$line]} { return -1 } -set readnow_p [readnow $binfile] - gdb_test "print *td" " = 23.5" gdb_test "print *tu" " = 23" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 008f59b9f30..132d538957c 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -8553,32 +8553,12 @@ gdb_caching_proc supports_fcf_protection { } executable "additional_flags=-fcf-protection=full"] } -# Return 1 if symbols were read in using -readnow. Otherwise, return 0. +# Return true if symbols were read in using -readnow. Otherwise, +# return false. -proc readnow { args } { - if { [llength $args] == 1 } { - set re [lindex $args 0] - } else { - set re "" - } - - set readnow_p 0 - # Given the listing from the following command can be very verbose, match - # the patterns line-by-line. This prevents timeouts from waiting for - # too much data to come at once. - set cmd "maint print objfiles $re" - gdb_test_multiple $cmd "" -lbl { - -re "\r\n.gdb_index: faked for \"readnow\"" { - # Record the we've seen the above pattern. - set readnow_p 1 - exp_continue - } - -re -wrap "" { - # We don't care about any other input. - } - } - - return $readnow_p +proc readnow { } { + return [expr {[lsearch -exact $::GDBFLAGS -readnow] != -1 + || [lsearch -exact $::GDBFLAGS --readnow] != -1}] } # Return index name if symbols were read in using an index. diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index 18a2a04def8..2dccb8924b1 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -671,32 +671,12 @@ proc mi_gdb_load { arg } { return 0 } -# Return 1 if symbols were read in using -readnow. Otherwise, return 0. -# Based on readnow from lib/gdb.exp. +# Return true if symbols were read in using -readnow. Otherwise, +# return false. proc mi_readnow { args } { - global mi_gdb_prompt - - if { [llength $args] == 1 } { - set re [lindex $args 0] - } else { - set re "" - } - - set readnow_p 0 - set cmd "maint print objfiles $re" - send_gdb "$cmd\n" - gdb_expect { - -re ".gdb_index: faked for ..readnow.." { - # Record that we've seen the above pattern. - set readnow_p 1 - exp_continue - } - -re "\\^done\r\n$mi_gdb_prompt$" { - } - } - - return $readnow_p + # Just defer to gdb.exp. + return [readnow] } # mi_gdb_test COMMAND [PATTERN [MESSAGE [IPATTERN]]] -- send a command to gdb; From patchwork Thu Dec 8 15:38:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 61701 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 1C9F53AA88B4 for ; Thu, 8 Dec 2022 15:39:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C9F53AA88B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670513951; bh=pyV23A4onCLoG9g2roNBWT4F1oipV08Zk8vK7VNCrwA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pfzTQbFLhNFMDDkyQCpooB9FsqJIvm7LgA4BIxTX/gOywa7M5wGdi1FCAqOLZD6mc vky6wz6hxLhgCt3Q9HdDZUqCEhY7xTE8b8PXHBV/sZsGxRy208Z7FuSP6Obnlv6WDv qnISQ10TBP8m0WiuTYY4LDbqJLBc9iPI2LTTpoIo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4F95339A7B9E for ; Thu, 8 Dec 2022 15:38:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F95339A7B9E Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-515-SRsWws6YMBWxEsu4DXQV8Q-1; Thu, 08 Dec 2022 10:38:40 -0500 X-MC-Unique: SRsWws6YMBWxEsu4DXQV8Q-1 Received: by mail-wm1-f71.google.com with SMTP id v188-20020a1cacc5000000b003cf76c4ae66so2545263wme.7 for ; Thu, 08 Dec 2022 07:38:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pyV23A4onCLoG9g2roNBWT4F1oipV08Zk8vK7VNCrwA=; b=5LlxEouvREsWvME39SnXeKX4l6CSv3f3ICImBRlz2YBEyk9bC9se/Z0IkArD9knhLd 7M83qrl5PkznMwdlUsZlMOEeK0f/Qq1JVXVoKkuFdKZs/S1CVy9m2vlL+SE53Oy/P3G1 ZN8mY4609ZAor+Tg5Cfz0isJv5PeoOdiyCmdiE4X5MdG+R4AtVpicJQnMBcPNQnKx/+P Kx5Bx9QTuEGPsFPr86gOl8p9aLJKpSZgFoNL1fZnJOEOrTJdWT2hESv7nydS4FQdnqaN 5cFGFqMvK/nslTGs5ELNVUbFIKg6TDkqYyQkbrfJ03WTVBfqvdwI3jUH6ya+eMUOszjn eD+g== X-Gm-Message-State: ANoB5pkelVEcJ2C/pg1rqrImiftwVG9atHytC6NyEZWxRAgOdXfCesKp pvkjR/XdKPfIS3NEymCkCABMD/eG2Fe2nB99J4iGY3pBlZkBFIS8Tk4cozVXF+4FsPXCM2/hCic Lecf2yNlTcXTHysNSZvrsqvpdpzfcS+A9YHlJooB0vqcyjdnx5HGkZlQxWeYg7iX4wF2c7djdEg == X-Received: by 2002:adf:fa51:0:b0:242:5a9e:4568 with SMTP id y17-20020adffa51000000b002425a9e4568mr1600535wrr.45.1670513919209; Thu, 08 Dec 2022 07:38:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Kg7VEjVh3P4IOdVjcJQKmMMCA0Nxpq5+2ZcNsfFLWQtiLhAvRasbjEcV6a0D5F/qAoXIM4g== X-Received: by 2002:adf:fa51:0:b0:242:5a9e:4568 with SMTP id y17-20020adffa51000000b002425a9e4568mr1600521wrr.45.1670513918721; Thu, 08 Dec 2022 07:38:38 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id r15-20020adfdc8f000000b002425787c5easm13916408wrj.96.2022.12.08.07.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 07:38:38 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey , Andrew Burgess Subject: [PATCH 2/2] gdb/testsuite: new test for recent dwarf reader issue Date: Thu, 8 Dec 2022 15:38:33 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit provides a test for this commit: commit 55fc1623f942fba10362cb199f9356d75ca5835b Date: Thu Nov 3 13:49:17 2022 -0600 Add name canonicalization for C Which resolves PR gdb/29105. My reason for writing this test was a desire to better understand the above commit, my process was to study the commit until I thought I understood it, then write a test to expose the issue. As the original commit didn't have a test, I thought it wouldn't hurt to commit this upstream. The problem tested for here is already described in the above commit, but I'll give a brief description here. This description describes GDB prior to the above commit: - Builtin types are added to GDB using their canonical name, e.g. "short", not "signed short", - When the user does something like 'p sizeof(short)', then this is handled in c-exp.y, and results in a call to lookup_signed_type for the name "int". The "int" here is actually being looked up as the type for the result of the 'sizeof' expression, - In lookup_signed_type GDB first adds a 'signed' and looks for that type, so in this case 'signed int', and, if that lookup fails, GDB then looks up 'int', - The problem is that 'signed int' is not the canonical name for a signed int, so no builtin type with that name will be found, GDB will then go to each object file in turn looking for a matching type, - When checking each object file, GDB will first check the partial symtab to see if the full symtab should be expanded or not. Remember, at this point GDB is looking for 'signed int', there will be no partial symbols with that name, so GDB will not expand anything, - However, GDB checks each partial symbol using multiple languages, not just the current language (C in this case), so, when GDB checks using the C++ language, the symbol name is first demangled, the code that does this can be found lookup_name_info::language_lookup_name. As the demangled form of 'signed int' is just 'int', GDB then looks for any symbols with the name 'int', most partial symtabs will contain such a symbol, so GDB ends up expanding pretty much every symtab. The above commit fixes this by avoiding the use of non-canonical names with C, now the initial builtin type lookup will succeed, and GDB never even considers whether to expand any additional symtabs. The test case creates a library that includes char, short, int, and long types, and a test program that links against the library. In the test script we start the inferior, but don't allow it to progress far enough that the debug information for the library has been fully expanded yet. Then we evaluate some 'sizeof(TYPE)' expressions. In the buggy version of GDB this would cause the debug information for the library to be fully expanded, while in the fixed version of GDB this will not be the case. We use 'info sources' to determine if the debug information has been fully expanded or not. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29105 --- .../gdb.base/signed-builtin-types-lib.c | 30 +++++ gdb/testsuite/gdb.base/signed-builtin-types.c | 25 ++++ .../gdb.base/signed-builtin-types.exp | 112 ++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 gdb/testsuite/gdb.base/signed-builtin-types-lib.c create mode 100644 gdb/testsuite/gdb.base/signed-builtin-types.c create mode 100644 gdb/testsuite/gdb.base/signed-builtin-types.exp diff --git a/gdb/testsuite/gdb.base/signed-builtin-types-lib.c b/gdb/testsuite/gdb.base/signed-builtin-types-lib.c new file mode 100644 index 00000000000..a32ec223ec1 --- /dev/null +++ b/gdb/testsuite/gdb.base/signed-builtin-types-lib.c @@ -0,0 +1,30 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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 . */ + +extern int foo (void); + +short short_var = 1; +int int_var = 2; +long long_var = 3; +char char_var = 4; + +int +foo (void) +{ + /* Just use all the globals! This works out as zero. */ + return (char_var / int_var) - (long_var - short_var); +} diff --git a/gdb/testsuite/gdb.base/signed-builtin-types.c b/gdb/testsuite/gdb.base/signed-builtin-types.c new file mode 100644 index 00000000000..1975b20e277 --- /dev/null +++ b/gdb/testsuite/gdb.base/signed-builtin-types.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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 . */ + +extern int foo (void); + +int +main (void) +{ + int result = foo (); + return result; +} diff --git a/gdb/testsuite/gdb.base/signed-builtin-types.exp b/gdb/testsuite/gdb.base/signed-builtin-types.exp new file mode 100644 index 00000000000..e9784330fee --- /dev/null +++ b/gdb/testsuite/gdb.base/signed-builtin-types.exp @@ -0,0 +1,112 @@ +# 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 . + +if {[skip_shlib_tests]} { + return -1 +} + +standard_testfile .c -lib.c + +# Compile the shared library. +set srcdso [file join $srcdir $subdir $srcfile2] +set objdso [standard_output_file lib${gdb_test_file_name}.so] +if {[gdb_compile_shlib $srcdso $objdso {debug}] != ""} { + untested "failed to compile dso" + return -1 +} + +# Build the test executable and runto main. +set opts [list debug shlib=$objdso] +if { [prepare_for_testing "failed to " $testfile $srcfile $opts] } { + return -1 +} + +if {![runto_main]} { + return -1 +} + +if {[readnow]} { + untested "this test checks for delayed symtab expansion" + return -1 +} + +# Use 'info sources' to check if the debug information for the shared +# library has been fully expanded or not. Return true if the debug +# information has NOT been fully expanded (which is what we want for this +# test). +proc shared_library_debug_not_fully_expanded {} { + set library_expanded "" + gdb_test_multiple "info sources" "" { + -re "^info sources\r\n" { + exp_continue + } + -re "^(\[^\r\n\]+):\r\n\\(Full debug information has not yet been read for this file\\.\\)\r\n\r\n" { + set libname $expect_out(1,string) + if {$libname == $::objdso} { + set library_expanded "no" + } + exp_continue + } + -re "^(\[^\r\n\]+):\r\n\\(Objfile has no debug information\\.\\)\r\n\r\n" { + set libname $expect_out(1,string) + if {$libname == $::objdso} { + # For some reason the shared library has no debug + # information, this is not expected. + set library_expanded "missing debug" + } + exp_continue + } + -re "^(\[^\r\n\]+):\r\n\r\n" { + set libname $expect_out(1,string) + if {$libname == $::objdso} { + set library_expanded "yes" + } + exp_continue + } + -re "^$::gdb_prompt $" { + gdb_assert {[string equal $library_expanded "yes"] \ + || [string equal $library_expanded "no"]} \ + $gdb_test_name + } + -re "^(\[^\r\n:\]*)\r\n" { + exp_continue + } + } + + return [expr $library_expanded == "no"] +} + +foreach_with_prefix type_name {"short" "int" "long" "char"} { + foreach_with_prefix type_prefix {"" "signed" "unsigned"} { + with_test_prefix "before sizeof expression" { + # Check that the debug information for the shared library has + # not yet been read in. + gdb_assert { [shared_library_debug_not_fully_expanded] } + } + + # Evaluate a sizeof expression for a builtin type. At one point GDB + # would fail to find the builtin type, and would then start + # expanding compilation units looking for a suitable debug entry, + # for some builtin types GDB would never find a suitable match, and + # so would end up expanding all available compilation units. + gdb_test "print/d sizeof ($type_prefix $type_name)" " = $decimal" + + with_test_prefix "after sizeof expression" { + # Check that the debug information for the shared library has not + # yet been read in. + gdb_assert { [shared_library_debug_not_fully_expanded] } + } + } +}