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.133.124]) by sourceware.org (Postfix) with ESMTPS id 241233882100 for ; Thu, 13 Jun 2024 09:56:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 241233882100 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 241233882100 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718272584; cv=none; b=BXh7dsBX/Ef86hk2C99QY7BOZO0IwqZWzMGGVI3CCgKkL2mnB/7DOZUK/T6Lw6QiUGD3G/0bKI7OY9PMP7ICjhk4yl0WQLNyl9BBc1qGng75MK6JvzSkRUsQgHPHGlicH94J0GFUF6sO87AAjdBUfuW3t8R7v0WTPiSK2TwBzrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718272584; c=relaxed/simple; bh=ycqx2kuiQuGOuugAaF4c05h+I9ezJ6GYcHgTFhGV9JY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ZZVJa+WRfzvMBJ+IKLFxkqfUrwaBlU42Eg5QOtPfmVu+yo+fZGAJft6RMW77Volo8QC1D7qoeTgN4P7ZFabohbia5UTd9AuUvKq1mrYKe3U+Xpwe9XPF9eXWOs/oxEgYY6Zozhy4aSiGaJR5rN09HiIwKZYBVXprl6Zk3w+pOUk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718272581; 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=hXDAnwy2/KLmnJW6IK1lKmmvkOMuGjzd6hvgS36FhiQ=; b=V2r+csGkNKX69VckUg9MnAZU8zt8PoUcIYVpk/qVZW0Ak0ZPUHeMMn/vUm1feCkwjlCaZx ex3C5QP73SBavYgCbK1rVv1bUzJf3OKtpgksPbgvxtdypTqbVkVXNzr0vtdeoRowVIV5Ut k15WB/TfqT5antlvrPulBHCmFDUds3A= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-eiyT-nmFMKSop6Tv3uDDVw-1; Thu, 13 Jun 2024 05:56:16 -0400 X-MC-Unique: eiyT-nmFMKSop6Tv3uDDVw-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-52c9894a547so688272e87.1 for ; Thu, 13 Jun 2024 02:56:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718272574; x=1718877374; 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=hXDAnwy2/KLmnJW6IK1lKmmvkOMuGjzd6hvgS36FhiQ=; b=OgzgsxMSi9aBNWbooPUiVzrHznieZiJwpIXO5lSapamKII9Fionf/uk6AsjrqlWqyV UiJyBvvmbty2XaLJ7MAeJD4Tz/w83/ix+4VthwouqERELi4BcdNTvlyKHQwOADufuMNO 1gwouft6kIs0PrZacGAbx7nuiDIATCxa0RDZ7w7tuOy7eStEppFSaWyq20Ogxwel25Ag hiRVr0tD0xeknSgXy6QwPzs9W7c3C13n/BCKDufaUtVuyPj6z4vYft1jMKoMG964Idic WNOkbJk2h1MuUC1TUiM5l2Ue/4ZNy8Lt6rDuN8cXVyKzEk5i4TsWNZDHN2TOXzCfvj4E DlYw== X-Gm-Message-State: AOJu0YyirdhORlbrDfaJppB5e4Mdzmh4WCgP+dMsnG66uYswojqKTDi1 LZtvxIg61pM6TcDN5LiSd3CuhQ+VNwLnkrAAiBIenF/TjUNP8OLW097ozd9zhcHS3d3zw1TFXVv 4JUU6eGemOyQfPzycuP5aVC0iv1QBzjKKBaqHf4Ob6tE7RHzyjKAxUS/eJDSDz5KHpK+1v0ChLg pwZgSDlVF12R4IXeRLHpY8JIHcQBOJ9T/CXoUc7jvvypc= X-Received: by 2002:a05:6512:a96:b0:52c:a483:4cc6 with SMTP id 2adb3069b0e04-52ca4834d8emr434864e87.36.1718272574233; Thu, 13 Jun 2024 02:56:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2OX0Jzbs1UKtUNy8qzxLFojZ6dQJYJKRcKfha3dZu0nCPfWRkEdYFTIeJaAtLvDfthAg7Cg== X-Received: by 2002:a05:6512:a96:b0:52c:a483:4cc6 with SMTP id 2adb3069b0e04-52ca4834d8emr434833e87.36.1718272573565; Thu, 13 Jun 2024 02:56:13 -0700 (PDT) Received: from localhost ([62.31.95.162]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602efdesm18150875e9.17.2024.06.13.02.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 02:56:11 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb: avoid '//' in filenames when searching for debuginfo Date: Thu, 13 Jun 2024 10:56:08 +0100 Message-Id: <70fd0861b081eafbc89738a7e2582652d2d074fa.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: I spotted that the gdb.base/sysroot-debug-lookup.exp test that I added recently actually had a KPASS when run with the native-extended-gdbserver board. This was an oversight when adding the test. 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 happens in the native-extended-gdbserver case is that GDB doesn't see the target filesystem as local. Now the filename retains the target: prefix, which means that in the child_path() call both the sysroot and the CANON_DIR have a target: prefix, and so the child_path() call succeeds. This allows GDB to progress, try some additional paths, and then find the debug information. So, this commit changes gdb.base/sysroot-debug-lookup.exp to expect the test to succeed when using the native-extended-gdbserver protocol. This leaves one KFAIL when using the native-extended-gdbserver board, we find the debug information but (apparently) find it in the wrong file. What's happening is that when GDB builds the path to the debug information we end up with a '//' string as a directory separator, the test regexp only expects a single separator. Instead of just fixing the test regexp, I've added a new function combine_paths which I then use for building the debug info paths. This function takes care of ensuring only a single '/' is added when joining paths together. With this done I now have no KFAIL when using the native-extended-gdbserver board. The new combine_paths function is similar to the existing path_join function (see gdbsupport/pathstuff.h), but unlike path_join the new function doesn't require that the first path be absolute. For now I've left the new function in symfile.c, it can always be moved if this proves to be more widely useful. After this commit we still have 2 KFAIL when not using the native-extended-gdbserver board. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31804 --- gdb/symfile.c | 80 ++++++++++++------- .../gdb.base/sysroot-debug-lookup.exp | 6 +- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 5a03def91c6..9ef31824fe0 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1344,6 +1344,44 @@ show_debug_file_directory (struct ui_file *file, int from_tty, #define DEBUG_SUBDIRECTORY ".debug" #endif +/* This is like path_join, but does not have the requirement that the first + path be an absolute path. All PATHS are joined together and a directory + separator is added if needed between joined elements. */ + +template +static std::string +combine_paths (Args... paths) +{ + /* It doesn't make sense to join less than two paths. */ + static_assert (sizeof... (Args) >= 2); + + std::array path_array + { paths... }; + + std::string ret; + + for (int i = 0; i < path_array.size (); ++i) + { + const char *path = path_array[i]; + + if (!ret.empty ()) + { + /* If RET doesn't end in a separator then add one now. */ + if (!IS_DIR_SEPARATOR (ret.back ())) + ret += '/'; + + /* Now that RET ends in a separator ignore any at the start of + PATH. */ + while (IS_DIR_SEPARATOR (path[0])) + ++path; + } + + ret.append (path); + } + + return ret; +} + /* Find a separate debuginfo file for OBJFILE, using DIR as the directory where the original file resides (may not be the same as dirname(objfile->name) due to symlinks), and DEBUGLINK as the file we are @@ -1370,17 +1408,13 @@ find_separate_debug_file (const char *dir, objfile_name (objfile)); /* First try in the same directory as the original file. */ - std::string debugfile = dir; - debugfile += debuglink; + std::string debugfile = combine_paths (dir, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */ - debugfile = dir; - debugfile += DEBUG_SUBDIRECTORY; - debugfile += "/"; - debugfile += debuglink; + debugfile = combine_paths (dir, DEBUG_SUBDIRECTORY, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; @@ -1393,6 +1427,7 @@ find_separate_debug_file (const char *dir, bool target_prefix = is_target_filename (dir); const char *dir_notarget = target_prefix ? dir + strlen (TARGET_SYSROOT_PREFIX) : 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 @@ -1421,12 +1456,8 @@ find_separate_debug_file (const char *dir, for (const gdb::unique_xmalloc_ptr &debugdir : debugdir_vec) { - debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : ""; - debugfile += debugdir; - debugfile += "/"; - debugfile += drive; - debugfile += dir_notarget; - debugfile += debuglink; + debugfile = combine_paths (target_prefix_str, debugdir.get (), + drive.c_str (), dir_notarget, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; @@ -1443,12 +1474,8 @@ find_separate_debug_file (const char *dir, { /* If the file is in the sysroot, try using its base path in the global debugfile directory. */ - debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : ""; - debugfile += debugdir; - debugfile += "/"; - debugfile += base_path; - debugfile += "/"; - debugfile += debuglink; + debugfile = combine_paths (target_prefix_str, debugdir.get (), + base_path, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; @@ -1461,21 +1488,18 @@ find_separate_debug_file (const char *dir, same result as above. */ if (gdb_sysroot != TARGET_SYSROOT_PREFIX) { - debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : ""; + std::string root; if (is_target_filename (gdb_sysroot)) { - std::string root - = gdb_sysroot.substr (strlen (TARGET_SYSROOT_PREFIX)); + root = gdb_sysroot.substr (strlen (TARGET_SYSROOT_PREFIX)); gdb_assert (!root.empty ()); - debugfile += root; } else - debugfile += gdb_sysroot; - debugfile += debugdir; - debugfile += "/"; - debugfile += base_path; - debugfile += "/"; - debugfile += debuglink; + root = gdb_sysroot; + + debugfile = combine_paths (target_prefix_str, root.c_str (), + debugdir.get (), base_path, + debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) diff --git a/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp index 5f17315c027..30d492e0d47 100644 --- a/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp +++ b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp @@ -183,13 +183,15 @@ proc_with_prefix lookup_via_debuglink {} { # # Bug PR gdb/30866 seems to be the (or a) relevant bug for # this problem. - if { $sysroot_prefix ne "" } { + 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 "" } { + 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..."] -- 2.25.4