From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6PozAouwhmY/PxsAWB0awg (envelope-from ) for ; Thu, 04 Jul 2024 10:24:11 -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=Fbh01ZOx; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 057B61E0C3; Thu, 4 Jul 2024 10:24:11 -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 E69701E030 for ; Thu, 4 Jul 2024 10:24:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A042D384A41E for ; Thu, 4 Jul 2024 14:24:08 +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 A2AA5384A44B for ; Thu, 4 Jul 2024 14:21:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2AA5384A44B 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 A2AA5384A44B 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=NuoYNMwfQURnOHJaWYx+caUPUfrhIlOXmWroeKfyeRT5nYGaAKVMB7sbYSa8XBIQzl1MdyzqKVf/wRfugy3qDUASOgBqtyEfUHCBuZybrsoCtKc7KnghSkZyLeVZhcYG5CmCFdCGpfOJD/oJ36+h/nY5uKBEDzBRb1vXGJjSYfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720102905; c=relaxed/simple; bh=rpC2h9lPL2AbGnFBds8UAxZl8+HG0R0MUJYp04Ty7lQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=iSlNCyLSs/4CCix6w/iVvteHDafgCzYN4kf8NSoBG2ZeOKjQ23Re+cqY90c1lu7Fsejd53+SeDWSwxR9Es0SfZIOpTOpWXMhoaU4kQwbTCltcTpWUgczeH3osOOZkIXCHSp2z7+0CdJSm0unIsSWKqMYfoF+ruMYc8uJgdr/lCE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720102901; 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=+j3tvhRnjAaYaBfKXtBL3c3CEv0RqKWnfmMlbiEPe6Q=; b=Fbh01ZOxtOwABc4thWMw+4qHPh8wjYlvSV0OVy3PWdg/BwPJazjbisCO+5t3Zh23iPv7pv 56YhmLKQ4SlncAPulEydlAJrwWZNqHChLmfx2TDcISppVmeH04iasEDHvrKlUvZW5km03e 80izzvpgz2C4hdEZf/D81RbXnOle9o8= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-261-7csmj8s4PTaFXSHbqrFNTA-1; Thu, 04 Jul 2024 10:21:40 -0400 X-MC-Unique: 7csmj8s4PTaFXSHbqrFNTA-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-367990a5796so473702f8f.1 for ; Thu, 04 Jul 2024 07:21:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720102898; x=1720707698; 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=+j3tvhRnjAaYaBfKXtBL3c3CEv0RqKWnfmMlbiEPe6Q=; b=auO9dfnmIwX6o1MBO5krFKqECyndosMDzqfnGM6fcLXESnzH1HV+pTAiGs00rv3J4g kW+I05m4GKi0MYndDdv9i+m6o/fVKWYwYnmidoDbYYfQgn5Kx2GTg+EyYhPb+kuX9rhh oM9LMebyKgNfLE5OtefE1DhWpvUCrrBME9vSwMvBlkHBOCtsp1o4jR6PoC8GUvLPiwhg znFtKbf5w8OoY+lBIIJDRFH7sWlHSK9A5K+pw2hz2NYeXOyM8muVxmVoT/unWRPiKxPZ l3maC6gZ8z9Ic6v1RI2f95/HZncKBxGYMJeofl5JI0wsCjZBVqwbmV9uY90L1s9lj1Lx rkHA== X-Gm-Message-State: AOJu0YwyPyfkWyJybaZ49eurFlACIqF/ZDnXeN6H7k6R1qCnDedKls0d km4OCWwaPk+awpQa7oCzVAJRkEhd67ShZbS7/v0/ft2d1qx9MDsZYubJ4Cv+ZARu/LPCVuCFZHr UNXhjIb/lJIO+bbZkSfUxRay+2mSjXwwGdBkkiURf02bGPxuK9yyqnNssgcWBKQcI58H464B6eC r2E4tUHN+18X74btztOAw9O2MKJmpeHq0LAdEY9cjUeUQ= X-Received: by 2002:a5d:608e:0:b0:367:9877:750e with SMTP id ffacd0b85a97d-3679dd3df99mr1289842f8f.25.1720102898192; Thu, 04 Jul 2024 07:21:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvFuXCcCtx2UYC8Z9fFNCzInjV5iKdWQTR75AkUEbFUlXpgnat7we6Vy1+2BatN8itH8u3BA== X-Received: by 2002:a5d:608e:0:b0:367:9877:750e with SMTP id ffacd0b85a97d-3679dd3df99mr1289820f8f.25.1720102897772; Thu, 04 Jul 2024 07:21:37 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367a43e9fbdsm300223f8f.103.2024.07.04.07.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 07:21:37 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 14/14] gdb: 'target ...' commands now expect quoted/escaped filenames Date: Thu, 4 Jul 2024 15:21:09 +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=-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 the 'target ...' commands that accept a filename to take a quoted or escaped filename rather than a literal filename. What this means in practice is that if you are specifying a filename that contains no white space or quote characters, then nothing should change, e.g.: target exec /path/to/some/file works both before and after this commit. However, if a user wishes to specify a file containing white space then either the entire filename needs to be quoted, or the special white space needs to be escaped. Before this patch a user could write: target exec /path/to a file/containing spaces But after this commit the user would have to choose one of: target exec "/path/to a file/containing spaces" or target exec /path/to\ a\ file/containing\ spaces Obviously this is a potentially breaking change. The benefit of making this change is consistency. Commands that take multiple arguments (one of which is a filename) or in the future, commands that take filename options, will always need to use quoted/escaped filenames, so converting all unquoted filename commands to use quoting or escaping makes the UI more consistent. Additionally (though this is probably not a common problem), GDB strips trailing white space from commands that the user enters. As such it is not possible to reference any file that ends in white space unless the quoting / escaping style is used. Though I suspect very few users run into this problem! The downside obviously is that this is a UI breaking change. --- gdb/NEWS | 4 ++++ gdb/corelow.c | 23 ++++++++++--------- gdb/doc/gdb.texinfo | 9 ++++++++ gdb/exec.c | 7 ++++-- gdb/testsuite/gdb.base/batch-exit-status.exp | 4 ++-- .../gdb.base/filename-completion.exp | 3 +-- gdb/tracectf.c | 11 +++++---- gdb/tracefile-tfile.c | 16 ++++++------- 8 files changed, 47 insertions(+), 30 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 4a830a61cda..9058d62d1fb 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -23,6 +23,10 @@ remove-symbol-file -a ADDRESS multiple terms, e.g. 'function + 0x1000' (without quotes), previously only a single term could be given. +target core +target exec +target tfile +target ctf compile file maint print c-tdesc save gdb-index diff --git a/gdb/corelow.c b/gdb/corelow.c index 136f29ea2e8..0f87d565afc 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -614,7 +614,10 @@ core_target_open (const char *arg, int from_tty) int flags; target_preopen (from_tty); - if (!arg) + + std::string filename = extract_single_filename_arg (arg); + + if (filename.empty ()) { if (current_program_space->core_bfd ()) error (_("No core file specified. (Use `detach' " @@ -623,25 +626,23 @@ core_target_open (const char *arg, int from_tty) error (_("No core file specified.")); } - gdb::unique_xmalloc_ptr filename (tilde_expand (arg)); - if (strlen (filename.get ()) != 0 - && !IS_ABSOLUTE_PATH (filename.get ())) - filename = make_unique_xstrdup (gdb_abspath (filename).c_str ()); + if (!IS_ABSOLUTE_PATH (filename.c_str ())) + filename = gdb_abspath (filename); flags = O_BINARY | O_LARGEFILE; if (write_files) flags |= O_RDWR; else flags |= O_RDONLY; - scratch_chan = gdb_open_cloexec (filename.get (), flags, 0).release (); + scratch_chan = gdb_open_cloexec (filename.c_str (), flags, 0).release (); if (scratch_chan < 0) - perror_with_name (filename.get ()); + perror_with_name (filename.c_str ()); - gdb_bfd_ref_ptr temp_bfd (gdb_bfd_fopen (filename.get (), gnutarget, + gdb_bfd_ref_ptr temp_bfd (gdb_bfd_fopen (filename.c_str (), gnutarget, write_files ? FOPEN_RUB : FOPEN_RB, scratch_chan)); if (temp_bfd == NULL) - perror_with_name (filename.get ()); + perror_with_name (filename.c_str ()); if (!bfd_check_format (temp_bfd.get (), bfd_core)) { @@ -650,7 +651,7 @@ core_target_open (const char *arg, int from_tty) thing, on error it does not free all the storage associated with the bfd). */ error (_("\"%s\" is not a core dump: %s"), - filename.get (), bfd_errmsg (bfd_get_error ())); + filename.c_str (), bfd_errmsg (bfd_get_error ())); } current_program_space->cbfd = std::move (temp_bfd); @@ -1521,7 +1522,7 @@ void _initialize_corelow () { add_target (core_target_info, core_target_open, - deprecated_filename_completer); + filename_maybe_quoted_completer); add_cmd ("core-file-backed-mappings", class_maintenance, maintenance_print_core_file_backed_mappings, _("Print core file's file-backed mappings."), diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e35cf45ec31..d95e13f1342 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -16238,6 +16238,9 @@ Both @var{filename} and @var{dirname} must be on a filesystem accessible to the host. +The @var{filename} and @var{dirname} arguments supports escaping and +quoting, see @ref{Filename Arguments,,Filenames As Command Arguments}. + @smallexample (@value{GDBP}) target ctf ctf.ctf (@value{GDBP}) tfind @@ -23159,11 +23162,17 @@ An executable file. @samp{target exec @var{program}} is the same as @samp{exec-file @var{program}}. +The @var{program} argument supports escaping and quoting, see +@ref{Filename Arguments,,Filenames As Command Arguments}. + @item target core @var{filename} @cindex core dump file target A core dump file. @samp{target core @var{filename}} is the same as @samp{core-file @var{filename}}. +The @var{filename} argument supports escaping and quoting, see +@ref{Filename Arguments,,Filenames As Command Arguments}. + @item target remote @var{medium} @cindex remote target A remote system connected to @value{GDBN} via a serial line or network diff --git a/gdb/exec.c b/gdb/exec.c index acd9b04337b..cae08868f8e 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -143,7 +143,10 @@ static void exec_target_open (const char *args, int from_tty) { target_preopen (from_tty); - exec_file_attach (args, from_tty); + + std::string filename = extract_single_filename_arg (args); + exec_file_attach (filename.empty () ? nullptr : filename.c_str (), + from_tty); } /* This is the target_close implementation. Clears all target @@ -1120,5 +1123,5 @@ will be loaded as well."), &setlist, &showlist); add_target (exec_target_info, exec_target_open, - deprecated_filename_completer); + filename_maybe_quoted_completer); } diff --git a/gdb/testsuite/gdb.base/batch-exit-status.exp b/gdb/testsuite/gdb.base/batch-exit-status.exp index 3721fd56018..51514640958 100644 --- a/gdb/testsuite/gdb.base/batch-exit-status.exp +++ b/gdb/testsuite/gdb.base/batch-exit-status.exp @@ -92,5 +92,5 @@ test_exit_status 1 "-batch -x $good_commands -ex \"set not-a-thing 4\"" \ set test "No such file or directory" set no_such_re ": $test\\." test_exit_status 1 "-batch \"\"" "1x: $test" ^[multi_line $no_such_re ""]$ -test_exit_status 1 "-batch \"\" \"\"" "2x: $test" \ - ^[multi_line $no_such_re $no_such_re ""]$ +test_exit_status 1 "-batch \"\" \"\"" "$test and No core file specified" \ + ^[multi_line $no_such_re "No core file specified\\." ""]$ diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index 7ba055b9ae7..95a9fbaa857 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -301,8 +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 { "set logging file" \ - "target core" "add-auto-load-safe-path" } { + foreach_with_prefix cmd { "set logging file" "add-auto-load-safe-path" } { run_unquoted_tests_core $root $cmd } diff --git a/gdb/tracectf.c b/gdb/tracectf.c index 25a8fe7ead9..b4997f8589f 100644 --- a/gdb/tracectf.c +++ b/gdb/tracectf.c @@ -1111,7 +1111,7 @@ ctf_read_tp (struct uploaded_tp **uploaded_tps) second packet which contains events on trace blocks. */ static void -ctf_target_open (const char *dirname, int from_tty) +ctf_target_open (const char *args, int from_tty) { struct bt_ctf_event *event; uint32_t event_id; @@ -1119,10 +1119,11 @@ ctf_target_open (const char *dirname, int from_tty) struct uploaded_tsv *uploaded_tsvs = NULL; struct uploaded_tp *uploaded_tps = NULL; - if (!dirname) + std::string dirname = extract_single_filename_arg (args); + if (dirname.empty ()) error (_("No CTF directory specified.")); - ctf_open_dir (dirname); + ctf_open_dir (dirname.c_str ()); target_preopen (from_tty); @@ -1162,7 +1163,7 @@ ctf_target_open (const char *dirname, int from_tty) start_pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter)); gdb_assert (start_pos->type == BT_SEEK_RESTORE); - trace_dirname = make_unique_xstrdup (dirname); + trace_dirname = make_unique_xstrdup (dirname.c_str ()); current_inferior ()->push_target (&ctf_ops); inferior_appeared (current_inferior (), CTF_PID); @@ -1722,6 +1723,6 @@ _initialize_ctf () { #if HAVE_LIBBABELTRACE add_target (ctf_target_info, ctf_target_open, - deprecated_filename_completer); + filename_maybe_quoted_completer); #endif } diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 66769216a6b..b59b5c73325 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -462,24 +462,24 @@ tfile_target_open (const char *arg, int from_tty) struct uploaded_tsv *uploaded_tsvs = NULL; target_preopen (from_tty); - if (!arg) + std::string filename = extract_single_filename_arg (arg); + if (filename.empty ()) error (_("No trace file specified.")); - gdb::unique_xmalloc_ptr filename (tilde_expand (arg)); - if (!IS_ABSOLUTE_PATH (filename.get ())) - filename = make_unique_xstrdup (gdb_abspath (filename).c_str ()); + if (!IS_ABSOLUTE_PATH (filename.c_str ())) + filename = gdb_abspath (filename); flags = O_BINARY | O_LARGEFILE; flags |= O_RDONLY; - scratch_chan = gdb_open_cloexec (filename.get (), flags, 0).release (); + scratch_chan = gdb_open_cloexec (filename.c_str (), flags, 0).release (); if (scratch_chan < 0) - perror_with_name (filename.get ()); + perror_with_name (filename.c_str ()); /* Looks semi-reasonable. Toss the old trace file and work on the new. */ current_inferior ()->unpush_target (&tfile_ops); - trace_filename = std::move (filename); + trace_filename = make_unique_xstrdup (filename.c_str ()); trace_fd = scratch_chan; /* Make sure this is clear. */ @@ -1121,5 +1121,5 @@ void _initialize_tracefile_tfile () { add_target (tfile_target_info, tfile_target_open, - deprecated_filename_completer); + filename_maybe_quoted_completer); } -- 2.25.4