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 1E7DC3858C2D for ; Mon, 27 Nov 2023 17:56:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E7DC3858C2D 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 1E7DC3858C2D 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=1701107773; cv=none; b=AKrsYycrUsvjYgdYIL0U/wCMF28Zu8GFENZwRl3MAGIVxECF/8zqi80j/ylhKzqudfm28+vmkBm3Ut8/nq/jw8bJnete3suADWRep63gc6+9ftYNMBA9Vu1Yt6SHX0tnm8HFDknt3ZEkaiAf+UYAzMxT+tyc0ykmJWrgU9LZdgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701107773; c=relaxed/simple; bh=ruaBwHt3fQAwVrANCXrtIEQMGunhB16OzjIkWITalIc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=pLDp2vXlNO6InoLBHpLQQWmTr3q+DIqc4rwG+PNcWM5/WumM32H9sZBXgKc9k96BXWgj4VULLObzkoYXQ6tl58IoiOKbdR7M0mlwUhucIWkd+/Ds3/WMkuO0eshoNC4gvf96RqaLBHhk+m+8zpB37OCs0IFFwj3P+ng7zL9KcTM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701107767; 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=mG8FaJ0CGlWPfBeSHOUFggkFtvkSBEZsmBKWvlzRliM=; b=BXa0aNRsU15N4m5pV82E5Xsube1dI1chi/aAC5QKwV8WCpjvGhsJBJr4gDPL0s0lysXPfP zYx7kkabzkCFPJXzh0ZwKsYaPoxv7sP9GvhxAKkfSB+W8LS6CigHy4FLFM9lx0RF7KlndW S95JF4LBNSFrepkcS+wnFXKHji6++mU= 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_256_GCM_SHA384) id us-mta-609-UTCrOK9ZNTivdRmy5YdEvA-1; Mon, 27 Nov 2023 12:56:06 -0500 X-MC-Unique: UTCrOK9ZNTivdRmy5YdEvA-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40b32faeb7eso25736455e9.1 for ; Mon, 27 Nov 2023 09:56:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701107765; x=1701712565; 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=mG8FaJ0CGlWPfBeSHOUFggkFtvkSBEZsmBKWvlzRliM=; b=QWvqSpWpeNpgf4NXS6F4xN7U1tfb7D4vSrCRiL1r6Jyh5LVvHg63pCEmBBIyRmLK+F +Oi033Oq06ZaqMbA0fyIMqbs0hja7thH2mnA1LY0X0FBmKByAHd4/3fWqIvSOHaO/Hr3 ieU8SAHABkdWMw8JcGK47vZFCxILeiz4D0ixUQ5BExQ+8okmwJVX8SkLSg6C6AXL7FX2 C0f1XCPlV966G5dzR8RZWsMUvC5AbIh6RBuHAAkewogyp7BEQ9Vj6WwI4/lbjb0Xx1TA YiKmUtoS2LscsvveP5LSnU7M68T9/NEIaMTVcx9YB/IpmeDjRSIc4p9tqkhcvWyaXZx9 H7Yg== X-Gm-Message-State: AOJu0YyHrQY1ffXANRUwr3ipimYpQ7PukLyUUYF3mdq1L4wIXcgHQhkI 1JSvNJhTD7k8wDY7L1rX52HIuP+3q4+8Kp+0DB6C7Y0OKPqjTpnHWqBeF7/MjPWzOHFTeJbisup ZrJdmI7nJQXSdR39p+TkFhd5UaufOa2XU7oJ9GBQMlTd9jwjJF6CLoDmcNzw7pOqi1xcuvaKZcY cp8bx9pQ== X-Received: by 2002:a5d:4ac6:0:b0:332:caa2:fd30 with SMTP id y6-20020a5d4ac6000000b00332caa2fd30mr8768826wrs.40.1701107765039; Mon, 27 Nov 2023 09:56:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYEca803sTRTSfxhCk7OJa1ZiEKrkRZSKIRh0BVN8xQa+YaqSICekg6YEw5ZsrXO2Y78lT9w== X-Received: by 2002:a5d:4ac6:0:b0:332:caa2:fd30 with SMTP id y6-20020a5d4ac6000000b00332caa2fd30mr8768808wrs.40.1701107764592; Mon, 27 Nov 2023 09:56:04 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id e11-20020a5d500b000000b00332cba50ac3sm12506964wrt.45.2023.11.27.09.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 09:56:04 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/7] gdb: allow use of ~ in 'save gdb-index' command Date: Mon, 27 Nov 2023 17:55:55 +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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 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_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: Add a call to gdb_tilde_expand in the save_gdb_index_command function, this means that we can now do: (gdb) save gdb-index ~/blah/ Previous this wouldn't work. --- gdb/dwarf2/index-write.c | 7 +- gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp | 91 ++++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index d1b10a28823..8ee5e420936 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -39,6 +39,7 @@ #include "objfiles.h" #include "ada-lang.h" #include "dwarf2/tag.h" +#include "gdbsupport/gdb_tilde_expand.h" #include #include @@ -1548,6 +1549,8 @@ save_gdb_index_command (const char *arg, int from_tty) if (!*arg) error (_("usage: save gdb-index [-dwarf-5] DIRECTORY")); + std::string directory (gdb_tilde_expand (arg)); + for (objfile *objfile : current_program_space->objfiles ()) { /* If the objfile does not correspond to an actual file, skip it. */ @@ -1567,8 +1570,8 @@ save_gdb_index_command (const char *arg, int from_tty) if (dwz != NULL) dwz_basename = lbasename (dwz->filename ()); - write_dwarf_index (per_objfile->per_bfd, arg, basename, - dwz_basename, index_kind); + write_dwarf_index (per_objfile->per_bfd, directory.c_str (), + basename, dwz_basename, index_kind); } catch (const gdb_exception_error &except) { diff --git a/gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp b/gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp new file mode 100644 index 00000000000..d30d0e86cf2 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/gdb-index-tilde.exp @@ -0,0 +1,91 @@ +# Copyright 2023 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 . + +# Test that tilde expansion works for the 'save gdb-index' command. + +# This test relies on using the $HOME directory. We could make this +# work for remote hosts, but right now, this isn't supported. +require {!is_remote host} + +# Can't save an index with readnow. +require !readnow + +standard_testfile main.c + +# Create a directory to generate an index file into. +set full_dir [standard_output_file "index_files"] +remote_exec host "mkdir -p ${full_dir}" + +# The users home directory. +set home $::env(HOME) + +# Check that FULL_DIR is within the $HOME directory. If it's not, then +# that's fine, but we can't test tilde expansion in this case. +if { [string compare -length [string length $home] $full_dir $home] != 0 } { + unsupported "test not run within home directory" + return -1 +} + +# Convert the $HOME prefix in to ~. +set dir "~[string range $full_dir [string length $home] end]" + +# Build the test executable. +if { [prepare_for_testing "failed to prepare" "${testfile}" ${srcfile}] } { + return -1 +} + +# Start GDB and load in the executable. +clean_restart ${binfile} + +# If the executable was built with an index, or lacks the debug +# information required to create an index, then we'll not be able to +# generate an index, so lets not even try. +set has_index false +set can_dump_index false +gdb_test_multiple "maint print objfile $binfile" "check we can generate an index" { + -re "\r\n\\.gdb_index: version ${decimal}(?=\r\n)" { + set has_index true + gdb_test_lines "" $gdb_test_name ".*" + } + -re "\r\n\\.debug_names: exists(?=\r\n)" { + set has_index true + gdb_test_lines "" $gdb_test_name ".*" + } + -re "\r\n(Cooked index in use:|Psymtabs)(?=\r\n)" { + set can_dump_index true + gdb_test_lines "" $gdb_test_name ".*" + } + -re -wrap "" { + } +} + +if { $has_index } { + unsupported "already have an index" + return -1 +} + +if { !$can_dump_index } { + unsupported "lacks debug information needed to dump index" + return -1 +} + +# Generate an index file. +gdb_test_no_output "save gdb-index $dir" +gdb_exit + +# Confirm that the index file exists. +set index_filename "${full_dir}/${gdb_test_file_name}.gdb-index" +gdb_assert { [remote_file host exists $index_filename] } \ + "confirm the index file exists" -- 2.25.4