From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id 4A26E3858D1E for ; Wed, 21 Dec 2022 21:00:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A26E3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2d.google.com with SMTP id p6so11594iod.13 for ; Wed, 21 Dec 2022 13:00:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Nn3QpUSgXAxiTN1zBIyJ/DqywSPOh124zEzTV5TzfX8=; b=gOcZxKHlXnc9a0bEmPIRUMpfGJt4N6LfECULQpEJV1+A0PXa2W2TI4btbXbt5+agMa Hv8tf5ltnyFokZXH1JZV1q61n87qXRdazY/pz5sVrMIRwMV6v/ZjLGxnPp9UuwI5VhFD SjMn0IwubG88XsorlDossO6OUNwS4z/xkCyY+PVgKHg8J1Vqcbo145/nrUp9kHEOm9of 1Yorq2CW3MruzUexCpnWzwri15L0lGGMAMJWR6HUGn/+15/JGpB1vG6LBE++2HxDtjVA wYR5s/St2JgviuK8HIil9OYtsoYYUf7elvkrDKjHxDy7XIbBPpX1uQHzm1OxtzJjAyDu bXag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Nn3QpUSgXAxiTN1zBIyJ/DqywSPOh124zEzTV5TzfX8=; b=X7B4wQPKpwQj4VW8m3upFGaS8WtWZ6aMXI0akBFCCbnoxuZjObau5I32UzNl6q21ay CVLwZgxP+mgRnuvuDVtGjhzOW0TDlZA84eAgS3fvZigGOdFnVr+fmkwlgiJ+JsLTp3n4 J7YpTnVCNFJu9zKLXDFmvJcZU5q8aq6O3J7VW3AdcsTlh1glxKG47ZXhLTmF49F1WxkD Kp4KgRO/39t9kXa0qPD64hrKVbgU14Ofvhd4hawOvN5qzWuy5tYwGfajYKMSKS8hkd6m cQTEt9HAR+V9FZifj9AGduDp4/CbJMySRRaKcRLXLOVQtqhyhbRB/QEyYK7k+kkM8Jry UxdQ== X-Gm-Message-State: AFqh2kqKAXyjfI+hMbCZopmtI984mlFi9iossRwKh47o3k+utVlBjNDu /BYZEbDLfjUcZpqsINoia6FP20efBXVrEPmJ X-Google-Smtp-Source: AMrXdXvLyAsClczl802poJQO5MqZA+F7uXo9Ig1PlqmucWi3OX73I6J+9waD9MPPD8qzZIbS6J5hlg== X-Received: by 2002:a05:6602:2e91:b0:6df:df5b:f86 with SMTP id m17-20020a0566022e9100b006dfdf5b0f86mr3459212iow.8.1671656405495; Wed, 21 Dec 2022 13:00:05 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id m3-20020a02a143000000b0038a6ee3c07bsm5864484jah.62.2022.12.21.13.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 13:00:04 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove target: prefix from gdb_sysroot in find_separate_debug_file Date: Wed, 21 Dec 2022 13:59:58 -0700 Message-Id: <20221221205958.1102648-1-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: I noticed that, when using gdbserver, gdb might print: Reading /usr/lib/debug/lib64//libcap.so.2.48-2.48-4.fc36.x86_64.debug from remote target... Reading target:/usr/lib/debug/lib64//libcap.so.2.48-2.48-4.fc36.x86_64.debug from remote target... The second line has the "target:" prefix, but from the code it's clear that this string is being passed verbatim to gdbserver -- which seems wrong. I filed PR remote/29929 for this. The problem here is that find_separate_debug_file uses gdb_sysroot without checking to see if it starts with the "target:" prefix. This patch changes this code to be a little more careful. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29929 --- gdb/symfile.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index eb27668f9d3..46f4dd28fc1 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1470,19 +1470,32 @@ find_separate_debug_file (const char *dir, return debugfile; /* If the file is in the sysroot, try using its base path in - the sysroot's global debugfile directory. */ - debugfile = target_prefix ? "target:" : ""; - debugfile += gdb_sysroot; - debugfile += debugdir; - debugfile += "/"; - debugfile += base_path; - debugfile += "/"; - debugfile += debuglink; - - if (separate_debug_file_exists (debugfile, crc32, objfile)) - return debugfile; + the sysroot's global debugfile directory. GDB_SYSROOT + might refer to a target: path; we strip the "target:" + prefix -- but if that would yield the empty string, we + don't bother at all, because that would just give the + same result as above. */ + if (gdb_sysroot != "target:") + { + debugfile = target_prefix ? "target:" : ""; + if (startswith (gdb_sysroot, "target:")) + { + std::string root = gdb_sysroot.substr (strlen ("target:")); + gdb_assert (!root.empty ()); + debugfile += root; + } + else + debugfile += gdb_sysroot; + debugfile += debugdir; + debugfile += "/"; + debugfile += base_path; + debugfile += "/"; + debugfile += debuglink; + + if (separate_debug_file_exists (debugfile, crc32, objfile)) + return debugfile; + } } - } return std::string (); -- 2.38.1