From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iBGOGf3OxGZv+A0AWB0awg (envelope-from ) for ; Tue, 20 Aug 2024 13:14:37 -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=MLvi5Ngk; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 619D31E0C0; Tue, 20 Aug 2024 13:14:37 -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 4AF7A1E0D1 for ; Tue, 20 Aug 2024 13:14:35 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1584238449C8 for ; Tue, 20 Aug 2024 17:14:35 +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 ESMTP id 9801D386F43A for ; Tue, 20 Aug 2024 17:11:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9801D386F43A 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 9801D386F43A 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=1724173870; cv=none; b=qK60ttWZKBz6S+ghHXKOGXxUR+P2ewtxda65HUOJl5MSVI1Lh8W3ALQoVyfFJg2qIVV+VGouJJHouKjyxP+AQUlPwhSJ/OQMLtMGQFIa9WnLAvCeklgFoCSQLjKHRskPRor8a5I88D6djW2jEBftPd5hWa9BhQOyUwsGRasalYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724173870; c=relaxed/simple; bh=GNIayhkkHjJsCMAjhF/wvDneGtfF7PecwCWvd4nD5Ew=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=I9r5XIEKmNonLStM46EOusR8dkXxK2tqcAMfVbJ3cYm7Iqz9/6IVtHKVNdcWRHcJi9oGsz7JlhlqoUDLHXrj8Nhn0CmjzDFH/12iU74J6m0OzOK5JcJ3LLcM2biYGhCAtYbs0Cg1sDzZqa662oSZwVt5aKBP9TzeG5PE9Xi57To= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724173867; 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=/ud0+6q8LhbKheLGnZOm0r7htxKg1F3N0rBfHYhjUDE=; b=MLvi5NgkY+rX4qJK/t8fAV45rDEz7IfuLtwXtV2sfKXOUkeBsL1W+iwWv29bZPSWCgmEuG 57HiDhXPBWRjwjbw1OhMvBXmbP8iSF6gMCUoOEBgM3HVe5NSCVquvExLRI+d8/weufmH9+ /IQyqMo+nU1HIQCyMA/7Yz8js15eJts= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-RMuPZxWoOVyB0qN0LC1Ncw-1; Tue, 20 Aug 2024 13:11:06 -0400 X-MC-Unique: RMuPZxWoOVyB0qN0LC1Ncw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3719ce5627eso2408275f8f.1 for ; Tue, 20 Aug 2024 10:11:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724173865; x=1724778665; 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=/ud0+6q8LhbKheLGnZOm0r7htxKg1F3N0rBfHYhjUDE=; b=cOattwzgP2UEpPwOABXrRFAOWcQ54XA5Qi/i+ObotjMRcJDQxNximA+IxcwRGGXsDm NwD6UkQOUgINOPnYkUBNt3XtV2FO+nCFqvzxtM299UbvkPWe+Kr3OwSss0U1eBqdrgG8 UJIkEjN37MTjgNRRUMagfp9ebIc/hOrXZdFDnxM70C42TylD8RSLQfoaDB48LknlEl1f lDsbgofxh/Z8oel+CRQ7Z9wTIPU9KYCZLbFh7T9t7oZkXxUV2snXMY5c72HX9dF6rECS NgqGsbjncZU330GOLTNn8xyOFn+44ZU1vVe0svmgQiwkVLRtyNbVbLNKNR1yku6spOCK 7jbg== X-Gm-Message-State: AOJu0YxOT8xvVEHEThiOX2vcnSB07+hqqg9k+EWhfjxfgnFiWjQjoGGD pZO+uDZpx4nd9nfC3MRhC0zuX+/2wfF+levX7+9w9CpNZAEjyledtAhaj8QbI4h0Nb/cOK4C7Ze ZB1N45UoAATcKKcUEn1N1uSyaILRmbBYhT6OOoobBhH4FB1mG+FS7b5YDrcMSO9Eo6jexnslg8O MbO7dD0fOdv4SnDF4BRSgAhT9jrzw/gLgxad/gTzGS32Y= X-Received: by 2002:a5d:654e:0:b0:371:8eb3:8c64 with SMTP id ffacd0b85a97d-371946a5d52mr12349830f8f.54.1724173864587; Tue, 20 Aug 2024 10:11:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGekw03rR2fQFJowqqnHT+XFBnnAKmazXtsim22PvOcH5D/Kyfhlo1KcGd5Eczg4HDQc60J4Q== X-Received: by 2002:a5d:654e:0:b0:371:8eb3:8c64 with SMTP id ffacd0b85a97d-371946a5d52mr12349792f8f.54.1724173863608; Tue, 20 Aug 2024 10:11:03 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded28cdasm199526755e9.16.2024.08.20.10.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 10:11:02 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii Subject: [PATCHv5 13/14] gdb: allow quoted filenames for commands that have custom completion Date: Tue, 20 Aug 2024 18:10:43 +0100 Message-Id: <82288d6aab448ec71e2902e48ab8d2b057d415a3.1724173728.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=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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 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. Reviewed-By: Eli Zaretskii --- 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 6161d40bcff..ee453ed376d 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -45,6 +45,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 white space or quote characters. If the argument + contains no such 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 6c5f33e0c19..89f979000ba 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -303,14 +303,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); } @@ -328,8 +327,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 e7f862e80f8..f158d3dafb1 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -21344,6 +21344,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 @@ -22790,6 +22793,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 @@ -41791,6 +41797,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 d3ee4e9f8ca..d78da14918f 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -1691,14 +1691,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 @@ -1706,26 +1707,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 @@ -1736,13 +1735,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); } @@ -1760,8 +1759,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