From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ANzNMt+u0WZ9+BkAWB0awg (envelope-from ) for ; Fri, 30 Aug 2024 07:37:03 -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=czG9tpxT; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CA2501E0D0; Fri, 30 Aug 2024 07:37:03 -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 99F2C1E08C for ; Fri, 30 Aug 2024 07:37:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55D31384DD00 for ; Fri, 30 Aug 2024 11:37:01 +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 D34E3386076B for ; Fri, 30 Aug 2024 11:34:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D34E3386076B 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 D34E3386076B 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=1725017664; cv=none; b=VV1+AK4iFG3qfnlWRJbs0fI+R+PJ8f9KWYq4+/TMcziYaS2XZ3SblmO6BY/lkqSYK3z6zpGuhMtMUTZpmeluLgEUi2IX7VYTNXXfUJiUZger81WxlYsb5U8ug4UJ98NZ3/H40J9CTEV3eoT5rptYPlaIEI2eo6hW1WrHENJ1x/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725017664; c=relaxed/simple; bh=4EYimHSnHZaWZmFA5uPkxYbgN6H5ug64kZfEnpxhSnc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=NS/4NtwEFPUV0AfDTWD10j++kl7eg9AFIIK0s8nSHIsGzg4mZtobWpO7EWTzKmVd3kZIRtp/nRdjbx2PyrW32r/9Wr+IpJi7Frx0ksO1I/bSlA64hsFrrYYES1xoQLI4SGsQvcdpNZyENlMRB2n/pIJD771uLcQQEDZv69qtP44= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725017660; 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=WivmLGQhBMMe6CFwZKxyk9n+nYN5f0BO+zd3SABRGno=; b=czG9tpxT0Kqfnr+8RE9FvA7V42UqP4hBtNEsrHakpf1wZ4RX5b7nOfwE2gG6fFQFDDzK1T FHCuXOEcd8OXIfiZhFWuzAvpUZe37VOO8KB7sJYugAseV6Cv+U+/mARDOr+PfZ93uXEHLp mTYT1J4lS0B296huqjse9YAtBZq3ULA= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-qVfNDVwQMw2huJR9ssrmYw-1; Fri, 30 Aug 2024 07:34:19 -0400 X-MC-Unique: qVfNDVwQMw2huJR9ssrmYw-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a866eb62868so152178466b.3 for ; Fri, 30 Aug 2024 04:34:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725017658; x=1725622458; 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=WivmLGQhBMMe6CFwZKxyk9n+nYN5f0BO+zd3SABRGno=; b=TorB1HmUFyKFnem+ZonzW/2d3Q8arrjZKSMkuWIZkJdIhw02nGregTyxc/rmG9QqVt XXrTH91Vz97u4wwuKvCh6nHcIv0y9DlMS7iUDXTexxXFliaH6XeW/WbAdp5ZlkqKFWKo YiTdzpZME8FjV6dmueo5zvRKvyYnYuA9A/MZIfTv0qBINVlaQJ8RmHwU8deX7LlKiwEa +IxvXTF3jxmAiQ0C4wJ6eWc9wdXF7K0ztC3S/v4EDdclNUriWF5L03/0tcSNsOHx3oKH b9sWNQEn9FiPA3eWDKEaeOEftpOVZq87jGicMQlqLDzftmS5b1Nf6fIdCyY+65f5ssyT /PDA== X-Gm-Message-State: AOJu0Yy+tgwBEJsfQyt4reFSL4OhJzJTqQOj1eHGplHZpfLCRHMH/J5M X8ZF8sAl53T1Pc7/8M8B4zl1nc0ognBFb9+bF4Y5F1mJgozHtO4CXDfZNzB3vByZI3AWOoB5VA0 6OGzgTew09KvDug6gfk6eFQ5wU1zqD9wALzW4OdWMnpcf2FDRpWit6RDZiOtaJWLiElSTgJPy4q fzj1jsmVDyd7ud2kMlqjQeAUz61Weu2fxzn11dl04fQyM= X-Received: by 2002:a17:906:6a18:b0:a77:deb2:8b01 with SMTP id a640c23a62f3a-a897f789470mr544433366b.1.1725017657495; Fri, 30 Aug 2024 04:34:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGR3I4BJYFI43s5GbYUsmuWgbqhvd09LYouyMF/AeLE4sev5QofNRR3vXBB0xSBxTJtb4VS6w== X-Received: by 2002:a17:906:6a18:b0:a77:deb2:8b01 with SMTP id a640c23a62f3a-a897f789470mr544431066b.1.1725017656572; Fri, 30 Aug 2024 04:34:16 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891daeb1sm204797066b.169.2024.08.30.04.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:34:16 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii Subject: [PATCHv6 13/14] gdb: allow quoted filenames for commands that have custom completion Date: Fri, 30 Aug 2024 12:33:53 +0100 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=-10.3 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 | 6 +++-- gdb/testsuite/gdb.compile/compile.exp | 2 +- 7 files changed, 43 insertions(+), 27 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 8b3b4f13762..87856131f77 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -63,6 +63,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. + * New remote packets vFile:stat 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 67e36fbc442..7721e236712 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -21345,6 +21345,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 @@ -22791,6 +22794,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 @@ -41792,6 +41798,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..d9943afb2e0 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -123,7 +123,9 @@ 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 \ + "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 +300,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