From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 ACB563882072 for ; Thu, 13 Jun 2024 09:56:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACB563882072 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ACB563882072 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718272583; cv=none; b=F+Gi3xAW3tLZwCmECmCuG/HAdiaDiW2SnZFez4pTfzbihEt7apvPLDYvyeaoduTrdrXz4P/S8titnt5FrCeFLkG4SHdq4HvxX+0JjH1Z75+/Q+PIKqNCU/n+hIMt7cnD9rBsAr2PSFeOpYz6bdN4y44Hz2JMr4VVSStjGGo3cKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718272583; c=relaxed/simple; bh=8eKhe+uxqToFwyNhnhR7SRW1mIv7wgm2pUJrYTksM8g=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=d1wIFtXaq/wwHJmkBh64eoXCsrVYAx6vEBr7a+nt3w6lhBs/tDokC2jtMOFZOyTTNG6i4/AYyZ+6Z3/GembUM9tcz8Cso/SbIedTVe1GWWfNgHwYaeuJKu+v9e2GCTAJ+tUiter8pcPdLjvLdkhJDQmvqWvwc5pywni64HDkycg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718272580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iJEazVe0LTcOTl34ks8QFWFCrJHUNB3g/cO1AHE7PFo=; b=c5QFLoxy8BlJh3FLAYxeP64FcJ3MtpwJZZ9H4Cqo8B6J+M8UrdWP7qpyGY2lzh3NldQzQM EPEB24DSYmeJSy1qJI5+kx+GuRpz0UrjjmqZniUOd5Qv/dZa/TlqUEoh3OtYB9L1qkrCvq JTOGsDxX77DS+4BHAAM4ORpQThE0zbc= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-XXDQZsc3NYOVlQarWd0o5A-1; Thu, 13 Jun 2024 05:56:19 -0400 X-MC-Unique: XXDQZsc3NYOVlQarWd0o5A-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-35e7cce4c32so471948f8f.3 for ; Thu, 13 Jun 2024 02:56:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718272576; x=1718877376; 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=iJEazVe0LTcOTl34ks8QFWFCrJHUNB3g/cO1AHE7PFo=; b=jYh1fPbZsN+7QIw+aHpWss5xjYlh+C11O72y/CuSnn6iHhay+iCADg3GUJ8zE8F+9j f1jjUqFqvVh3UHZS/92eTWQ0o223O70g39KJ7nxVr7gsqheR45nDyh+vbewNpU0VTtsj zrwQ8KH7zQG/fOe8asN4+SCPYBTOUTp7cVycl5zm1rTyg+q/F9HZJnD4PMmzXk5nqsIR TorzzlBQ+sk7PHbXz2gbX5UNuMNXZoytswJ3wl9vj3oV+kdcpIAw4geezaWNxSiI3Vxe 0pB9xbdx4NcnwsqPue1Sj24+s8xFP9uFENpD6DCp5Xs+Hfo+RBxAlGOLhcOF3jXqaE94 2AYw== X-Gm-Message-State: AOJu0YyKm0iiyVVVU5zJIlw7007za1wL4qlBOA0gE0H45fP5eK2rfZ2O lFS/7dVww+2oWy79R5FpRb2ALhhuya1tiRbxpv6Y8CsKqYl1IIe5USHv93NhyAys/a8qVAALBAq 3Rqx6+TpgidSiGwIljn1f9Sx1zgcmdKwF7alFF0IzimCzW30vwwHnexkE+CmHZ8UIMSLSddnZNL gPwAa0Xzvylt5nZmcZehGnpjJmO54971F+2rBrpBsqin8= X-Received: by 2002:a5d:40c1:0:b0:35f:2b18:7618 with SMTP id ffacd0b85a97d-35fdf79bdc0mr2973227f8f.12.1718272576226; Thu, 13 Jun 2024 02:56:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHe0fPsLYS+cxy1fV+6cpO70I9HjM3B4/yIgTo3kx207MBkrWVbYLdLl+KNMGWgl9W+fz3J3A== X-Received: by 2002:a5d:40c1:0:b0:35f:2b18:7618 with SMTP id ffacd0b85a97d-35fdf79bdc0mr2973206f8f.12.1718272575697; Thu, 13 Jun 2024 02:56:15 -0700 (PDT) Received: from localhost ([62.31.95.162]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36075093a3fsm1225632f8f.1.2024.06.13.02.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 02:56:14 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/2] gdb: fix a target: prefix issue in find_separate_debug_file Date: Thu, 13 Jun 2024 10:56:09 +0100 Message-Id: <38dc7fd623617ed33dd252f344afc156cacca8b3.1718272366.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.0 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Following on from the previous commit, this commit fixes the two KFAIL in gdb.base/sysroot-debug-lookup.exp when not using the native-extended-gdbserver board. The failures in this test, when using the 'unix' board, are logged as bug PR gdb/31804. The problem appears to be caused by the use of the child_path function in find_separate_debug_file. What happens on the 'unix' board is that the file is specified to GDB with a target: prefix, however GDB spots that the target filesystem is local to GDB and so opens the file without a target: prefix. When we call into find_separate_debug_file the DIR and CANON_DIR arguments, which are computed from the objfile_name() no longer have a target: prefix. However, in this test if the file was opened with a target: prefix, then the sysroot also has a target: prefix. When child_path is called it looks for a common prefix between CANON_DIR (from the objfile_name) and the sysroot. However, the sysroot still has the target: prefix, which means the child_path() call fails and returns nullptr. What I think we need to do is this: if the sysroot has a target: prefix, and the target filesystem is local to GDB, then we should strip the target: prefix from the sysroot, just as we do when opening a file (see gdb_bfd_open in gdb_bfd.c). Now, when we make the child_path() call neither the sysroot nor CANON_DIR will have a target: prefix, the child_path() call will succeed, and GDB will correctly find the debug information. There is just one remaining issue, the last path we look in when searching for debug information is built by starting with the sysroot, then adding the debug directory, see this line: debugfile = combine_paths (target_prefix_str, root.c_str (), debugdir.get (), base_path, debuglink); Now the target_prefix_str is set to target: if DIR has a target: prefix, and DIR has a target: prefix if the file we're looking for was opened with a target: prefix. However, in our case the file was specified with a target: prefix, but GDB stripped this off, so DIR does not have the target: prefix. The sysroot however, does have the prefix. I think in this case, as the path we're building starts with the sysroot, then target_prefix_str should be target: if the sysroot has the prefix, so I've arranged for this to be the case. With these fixes in place I now see no failures when using the 'unix' or 'native-gdbserver' boards with this test, and the KFAILs can be removed. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31804 --- gdb/symfile.c | 7 +++++-- gdb/testsuite/gdb.base/sysroot-debug-lookup.exp | 17 ----------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 9ef31824fe0..54cc4f4f9d4 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1430,8 +1430,10 @@ find_separate_debug_file (const char *dir, const char *target_prefix_str = target_prefix ? TARGET_SYSROOT_PREFIX : ""; std::vector> debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory.c_str ()); - gdb::unique_xmalloc_ptr canon_sysroot - = gdb_realpath (gdb_sysroot.c_str ()); + const char *sysroot_str = gdb_sysroot.c_str (); + if (is_target_filename (sysroot_str) && target_filesystem_is_local ()) + sysroot_str += strlen (TARGET_SYSROOT_PREFIX); + gdb::unique_xmalloc_ptr canon_sysroot = gdb_realpath (sysroot_str); /* MS-Windows/MS-DOS don't allow colons in file names; we must convert the drive letter into a one-letter directory, so that the @@ -1493,6 +1495,7 @@ find_separate_debug_file (const char *dir, { root = gdb_sysroot.substr (strlen (TARGET_SYSROOT_PREFIX)); gdb_assert (!root.empty ()); + target_prefix_str = TARGET_SYSROOT_PREFIX; } else root = gdb_sysroot; diff --git a/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp index 30d492e0d47..7baf7c9c9ec 100644 --- a/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp +++ b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp @@ -174,26 +174,9 @@ proc_with_prefix lookup_via_debuglink {} { # in the sysroot. gdb_file_cmd ${sysroot_prefix}$exec_in_sysroot - # Giving a sysroot a 'target:' prefix doesn't seem to work as - # might be expected for debug-link based lookups. For this - # style of lookup GDB only seems to care if the original file - # itself had a 'target:' prefix. The 'target:' prefix on the - # sysroot just seems to cause GDB to bail on looking up via - # the 'target:' prefixed sysroot. - # - # Bug PR gdb/30866 seems to be the (or a) relevant bug for - # this problem. - if { $sysroot_prefix ne "" - && [target_info gdb_protocol] ne "extended-remote" } { - setup_kfail "*-*-*" 31804 - } gdb_assert { $::gdb_file_cmd_debug_info eq "debug" } \ "ensure debug information was found" - if { $sysroot_prefix ne "" - && [target_info gdb_protocol] ne "extended-remote" } { - setup_kfail "*-*-*" 31804 - } set re [string_to_regexp "Reading symbols from ${sysroot_prefix}$debug_symlink..."] gdb_assert {[regexp $re $::gdb_file_cmd_msg]} \ "debug symbols read from correct file" -- 2.25.4