From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SNp6CL6whmY/PxsAWB0awg (envelope-from ) for ; Thu, 04 Jul 2024 10:25:02 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MdQEiOx5; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1D4AE1E0C3; Thu, 4 Jul 2024 10:25:02 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 012E41E030 for ; Thu, 4 Jul 2024 10:25:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A8A5384A4B6 for ; Thu, 4 Jul 2024 14:24:59 +0000 (GMT) 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 7F65A384A443 for ; Thu, 4 Jul 2024 14:21:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F65A384A443 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 7F65A384A443 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=1720102905; cv=none; b=PyRtT+svebCR5RSI2nHQ4+6XxfNIUcasIcrafW5IRnyg6S2lYT7yrsXxUA3QcwVo+P0Y6h+vvEvnhs5OC36rkGke9pxcc6nAK/5BnGsXOT7b6U6VU7i6up5UBWhLNSv6175nSBXdMevMoL7R2nzbcXk/8Xd5ezg5feCcblAHkHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720102905; c=relaxed/simple; bh=Ok5QGig7fqFhuPwl2YhpnQ/mWzHnfQVaqCA5BMJGWso=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JG5GHasOyRtXQ548Y/1NgQ7VB4BvO1rZwpMXAvxV6uO6iZlAav+RSraj7l5y8jl8ZkxiXqUNr4sVuQlBkHHi6WOQ7Ou+fuPix1OMUHumQLqYuesAPbhKFGJfBV1lEX79B1t+7TFWaD/QcaQljNe4cQ3dgpdW8o1tS4ETqZpugio= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720102900; 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=ANNtfIsUCnMTNjwSXTEfB3LwZFOs59+P877Vuq8ulgo=; b=MdQEiOx5rNlCCFqLlwjMbp3M5EXcU6ma5lhSEYZJ8KjHEDLPBXLJkHylUejtsKaqN6d3b1 MGrPqaNUXVHjUB2Ok0ShWsEx1BDmbhXBKPStgrYRuowYUr9yMWzYxd77sIxT4N+N/uwiwD DweJQJjhrgFxLiYoQzPkJnS9g+PoII4= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-cr3nfRV8OoCsHEJViVC70w-1; Thu, 04 Jul 2024 10:21:38 -0400 X-MC-Unique: cr3nfRV8OoCsHEJViVC70w-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3679aa0ee0aso460073f8f.2 for ; Thu, 04 Jul 2024 07:21:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720102897; x=1720707697; 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=ANNtfIsUCnMTNjwSXTEfB3LwZFOs59+P877Vuq8ulgo=; b=gj3YJJIuIx0LXywNjOzH+BvnugdBHgCwHT+b3j6IxVqDuHmYYnTtZuT/BVOCGKL2/h 9Pcl/NdFbfheCO/CFEgQRTGyt8OIAQqvfmq08TtUX5dtvWn/anm+O8P32yHj45Msbirl zQ1MCbNIftR5Fkz8yTpx7eSMCEOP7Wx2eQhRpUxlp27cXSWRxPAjFy5EIrS8o0QOU4eI N2uFUxw2kWZH712OmUE5yvBQ89yu6LTc2Rl77nkoSwwHSwtfMC5fYcKls+9YU5FNFHvj m6bfn1K7vZgBSzb54MUXBjoV536B2J90++p6j7TtgY3d/AGOXT6MJly03LJD/xgFzuvh HdDg== X-Gm-Message-State: AOJu0Yzb4ueaDl3LLZTFKkdQETGHstxi4ZXRefbyBU61w+JbXUlIqFkZ CsfB/z4YX6O/tb2rcm8oHaPvwTz/0Xdvcnj39fJuVwoopmM+qmBKTKGDAw1wz9/oa8CXzc99/FI tsG5+Zb4efY2wzxCwoUpObEVHZLCjFU0KVP71gLn+qc1/UFF53IErUOuJnuihhDj6Ljs6IGuzkJ PJXZNg38kSKUdjCOVaslk5YpN+ZYOx2e52qeCfMi4YD2M= X-Received: by 2002:adf:f0c2:0:b0:367:9769:35a5 with SMTP id ffacd0b85a97d-3679dd103f5mr1350987f8f.7.1720102896842; Thu, 04 Jul 2024 07:21:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJGIzabtpe7KVseoEbZxlsAIDCVMRT1JO0xLjz0xonnFHrhS/Xs8uIlGtr2JiT4vAwLF7ooQ== X-Received: by 2002:adf:f0c2:0:b0:367:9769:35a5 with SMTP id ffacd0b85a97d-3679dd103f5mr1350965f8f.7.1720102896312; Thu, 04 Jul 2024 07:21:36 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36796351169sm3674562f8f.95.2024.07.04.07.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 07:21:36 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 13/14] gdb: allow quoted filenames for commands that have custom completion Date: Thu, 4 Jul 2024 15:21:08 +0100 Message-Id: <351179c8d62d8dbd971679c1322757eb35ff4713.1720101827.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=-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_H4, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This commit changes how GDB processes command arguments for the following commands: compile file maint print c-tdesc save gdb-index After this commit these commands will now expect their single filename argument to be (optionally) quoted if it contains any special characters (e.g. whit space or quotes). If the filename does not contain any special characters then nothing changes. As an example: (gdb) save gdb-index /path/to/some/directory/ will work before and after this patch. However, if the directory name contains a white space then before this patch a user would write: (gdb) save gdb-index /path/to some/directory/ But this will now fail as GDB will consider this as two arguments, '/path/to' and 'some/directory/'. To pass this single directory name a user must now do one of these: (gdb) save gdb-index "/path/to some/directory/" (gdb) save gdb-index '/path/to some/directory/' (gdb) save gdb-index /path/to\ some/directory/ This brings these commands into line with commands like 'file' and 'symbol-file', which have supported quoted filenames for a while. The motivation for this change is to make handling of filename arguments consistent throughout GDB. We can't move to all commands taking non-quoted filenames as the non-quoted style only allows for a single argument. Additionally, the non-quoted style doesn't allow for filenames that end in white space (though this is probably pretty rare). So, if we want to have consistency the only choice is to move towards supporting quote filenames. --- gdb/NEWS | 7 +++++ gdb/compile/compile.c | 11 ++++---- gdb/doc/gdb.texinfo | 9 +++++++ gdb/dwarf2/index-write.c | 8 +++--- gdb/target-descriptions.c | 27 +++++++++---------- .../gdb.base/filename-completion.exp | 7 +++-- gdb/testsuite/gdb.compile/compile.exp | 2 +- 7 files changed, 44 insertions(+), 27 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 8808fb3e1f6..4a830a61cda 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -23,6 +23,13 @@ remove-symbol-file -a ADDRESS multiple terms, e.g. 'function + 0x1000' (without quotes), previously only a single term could be given. +compile file +maint print c-tdesc +save gdb-index + These commands now require their filename argument to be quoted if + it contains with white space or quote characters. If the argument + contains no special characters then quoting is not required. + *** Changes in GDB 15 * The MPX commands "show/set mpx bound" have been deprecated, as Intel diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 24d911dbb10..b5aac495563 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -302,14 +302,13 @@ compile_file_command (const char *args, int from_tty) enum compile_i_scope_types scope = options.raw ? COMPILE_I_RAW_SCOPE : COMPILE_I_SIMPLE_SCOPE; - args = skip_spaces (args); + std::string filename = extract_single_filename_arg (args); /* After processing options, check whether we have a filename. */ - if (args == nullptr || args[0] == '\0') + if (filename.empty ()) error (_("You must provide a filename for this command.")); - args = skip_spaces (args); - std::string abspath = gdb_abspath (args); + std::string abspath = gdb_abspath (filename.c_str ()); std::string buffer = string_printf ("#include \"%s\"\n", abspath.c_str ()); eval_compile_command (NULL, buffer.c_str (), scope, NULL); } @@ -327,8 +326,8 @@ compile_file_command_completer (struct cmd_list_element *ignore, (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group)) return; - word = advance_to_deprecated_filename_complete_word_point (tracker, text); - deprecated_filename_completer (ignore, tracker, text, word); + word = advance_to_filename_maybe_quoted_complete_word_point (tracker, text); + filename_maybe_quoted_completer (ignore, tracker, text, word); } /* Handle the input from the 'compile code' command. The diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 7261a5559c4..e35cf45ec31 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -21337,6 +21337,9 @@ @smallexample compile file /home/user/example.c @end smallexample + +The @var{filename} argument supports escaping and quoting, see +@ref{Filename Arguments,,Filenames As Command Arguments}. @end table @table @code @@ -22783,6 +22786,9 @@ @file{@var{symbol-file}.debug_names} and @file{@var{symbol-file}.debug_str}. The files are created in the given @var{directory}. + +The @var{directory} argument supports escaping and quoting, see +@ref{Filename Arguments,,Filenames As Command Arguments}. @end table Once you have created an index file you can merge it into your symbol @@ -41779,6 +41785,9 @@ @var{file}) must only contain a single feature. The source file produced is different in this case. +The @var{file} argument supports escaping and quoting, see +@ref{Filename Arguments,,Filenames As Command Arguments}. + @kindex maint print xml-tdesc @item maint print xml-tdesc @r{[}@var{file}@r{]} Print the target description (@pxref{Target Descriptions}) as an XML diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index ccbaea73380..2633a69df3b 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1621,8 +1621,8 @@ gdb_save_index_cmd_completer (struct cmd_list_element *ignore, (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp)) return; - word = advance_to_deprecated_filename_complete_word_point (tracker, text); - deprecated_filename_completer (ignore, tracker, text, word); + word = advance_to_filename_maybe_quoted_complete_word_point (tracker, text); + filename_maybe_quoted_completer (ignore, tracker, text, word); } /* Implementation of the `save gdb-index' command. @@ -1639,10 +1639,10 @@ save_gdb_index_command (const char *args, int from_tty) gdb::option::process_options (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group); - if (args == nullptr || *args == '\0') + std::string directory = extract_single_filename_arg (args); + if (directory.empty ()) error (_("usage: save gdb-index [-dwarf-5] DIRECTORY")); - std::string directory (gdb_tilde_expand (args)); dw_index_kind index_kind = (opts.dwarf_5 ? dw_index_kind::DEBUG_NAMES : dw_index_kind::GDB_INDEX); diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index bdd7f19d60f..65d0d563e7f 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -1693,14 +1693,15 @@ static void maint_print_c_tdesc_cmd (const char *args, int from_tty) { const struct target_desc *tdesc; - const char *filename; maint_print_c_tdesc_options opts; auto grp = make_maint_print_c_tdesc_options_def_group (&opts); gdb::option::process_options (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp); - if (args == NULL) + std::string filename = extract_single_filename_arg (args); + + if (filename.empty ()) { /* Use the global target-supplied description, not the current architecture's. This lets a GDB for one architecture generate C @@ -1708,26 +1709,24 @@ maint_print_c_tdesc_cmd (const char *args, int from_tty) initialization code will reject the new description. */ target_desc_info *tdesc_info = ¤t_inferior ()->tdesc_info; tdesc = tdesc_info->tdesc; - filename = tdesc_info->filename.data (); + if (tdesc_info->filename.data () != nullptr) + filename = std::string (tdesc_info->filename.data ()); } else { /* Use the target description from the XML file. */ - filename = args; - tdesc = file_read_description_xml (filename); + tdesc = file_read_description_xml (filename.c_str ()); } if (tdesc == NULL) error (_("There is no target description to print.")); - if (filename == NULL) + if (filename.empty ()) filename = "fetched from target"; - std::string filename_after_features (filename); - auto loc = filename_after_features.rfind ("/features/"); - + auto loc = filename.rfind ("/features/"); if (loc != std::string::npos) - filename_after_features = filename_after_features.substr (loc + 10); + filename = filename.substr (loc + 10); /* Print c files for target features instead of target descriptions, because c files got from target features are more flexible than the @@ -1738,13 +1737,13 @@ maint_print_c_tdesc_cmd (const char *args, int from_tty) error (_("only target descriptions with 1 feature can be used " "with -single-feature option")); - print_c_feature v (filename_after_features); + print_c_feature v (filename); tdesc->accept (v); } else { - print_c_tdesc v (filename_after_features); + print_c_tdesc v (filename); tdesc->accept (v); } @@ -1762,8 +1761,8 @@ maint_print_c_tdesc_cmd_completer (struct cmd_list_element *ignore, (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp)) return; - word = advance_to_deprecated_filename_complete_word_point (tracker, text); - deprecated_filename_completer (ignore, tracker, text, word); + word = advance_to_filename_maybe_quoted_complete_word_point (tracker, text); + filename_maybe_quoted_completer (ignore, tracker, text, word); } /* Implement the maintenance print xml-tdesc command. */ diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index 62fb49570a6..7ba055b9ae7 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -123,7 +123,10 @@ proc run_quoting_and_escaping_tests { root } { # Test all the commands which allow quoting of filenames, and # which require whitespace to be escaped in unquoted filenames. foreach_with_prefix cmd { file exec-file symbol-file add-symbol-file \ - remove-symbol-file } { + remove-symbol-file \ + "target core" "target exec" "target tfile" \ + "maint print c-tdesc" "compile file" \ + "save gdb-index" "save gdb-index -dwarf-5" } { gdb_start # Completing 'thread apply all ...' commands uses a custom word @@ -298,7 +301,7 @@ proc run_unquoted_tests_core { root cmd { prefix "" } } { proc run_unquoted_tests { root } { # Test all the commands which allow quoting of filenames, and # which require whitespace to be escaped in unquoted filenames. - foreach_with_prefix cmd { "maint print c-tdesc" "set logging file" \ + foreach_with_prefix cmd { "set logging file" \ "target core" "add-auto-load-safe-path" } { run_unquoted_tests_core $root $cmd } diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp index cd596335859..2c2e3217b19 100644 --- a/gdb/testsuite/gdb.compile/compile.exp +++ b/gdb/testsuite/gdb.compile/compile.exp @@ -66,7 +66,7 @@ if {[skip_compile_feature_untested]} { gdb_test_no_output "compile -- f = 10" \ "test abbreviations and code delimiter" -gdb_test "compile f = 10;" ".*= 10;: No such file.*" \ +gdb_test "compile f = 10;" "^Junk after filename \"=\": 10;" \ "Test abbreviations and code collision" gdb_test_no_output "compile -r -- void _gdb_expr(){int i = 5;}" \ -- 2.25.4