From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CWlnNtyu0WZ9+BkAWB0awg (envelope-from ) for ; Fri, 30 Aug 2024 07:37:00 -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=bRTNhUdv; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D426E1E0D1; Fri, 30 Aug 2024 07:37:00 -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 B5A141E08C for ; Fri, 30 Aug 2024 07:36:58 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39ABA385DDC8 for ; Fri, 30 Aug 2024 11:36:58 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 9F52F385DC32 for ; Fri, 30 Aug 2024 11:34:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F52F385DC32 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 9F52F385DC32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725017659; cv=none; b=QFEdi0jFphhsbKTSOjNzLJ65gGXr7tkn0F9aaEuU7XQwLnpjpM41VyqC7ryBfKJsOqu1c3dgbcvf9YDNdNi2prWMGxJMOAX2AW8yD395C64QL8eKMOj+0525ea0Iahc2AbvQMLgsNFMpju88c7W9fNG2+cBDPjuE1nrCQCd+lVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725017659; c=relaxed/simple; bh=eAVXMGrEJIrucxg6ccShUBFX17urrAEeIFJy7X3dGs0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=nc7TrKXze3gbN6p66peIpHuYl7NPsIvUrwCQUe5wptJt5oLvfK/1+j7MCofOxX5BwEKS3MqYxFuTbqlfk4oYlNn6WsNhSby682Yj/T2QhmYC/IJ0LiWgAAjwHaa/kcb/NtyiBujkCEbnlQ72W7UHfV4F7t2Vn8HuGPBBJQvDDUk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725017657; 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=AgiRYunwb1sqINzabu/hONw5ELu3zFdGmFiZATxPpzI=; b=bRTNhUdvcJJ8HfrYs/9fvMeJDVqsOI9gJxx1G/0Mo3AasGYvLhGzfG3EnUKQPxQ7idi5YU W/e3NrZYKbpQVIedoH/C7a+8q6isF3B9kdV39rcoie5hKJJyimzP1yXlp5PE6b1EjNo+0p TEztsSgTqHUHRa7YmveaC3wFGi7VAxY= 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-630-551j0hHuPUeZTiSEa0df9w-1; Fri, 30 Aug 2024 07:34:16 -0400 X-MC-Unique: 551j0hHuPUeZTiSEa0df9w-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-371ab0c02e0so1483423f8f.3 for ; Fri, 30 Aug 2024 04:34:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725017654; x=1725622454; 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=AgiRYunwb1sqINzabu/hONw5ELu3zFdGmFiZATxPpzI=; b=eWm/AMtlMb1yzSaOBNa0CLrPDxZFFoTQ5hzfGafWZiKWkcCx578t8FYhQxhWXOAgZ1 tWSpTyKGFpb12rmZF37Pemz2/zFXgxxh8bY9hnN6GdLSETOAeByHlPe4qLpHeWMB8E6f Sjt0L+xjfPBNKDkAZLctP/VBYFU0mFlO2GHXIj3ilWFHdfxvlbOmR0Tnu3gfWGw6QTTg 6EKDrTmRHJuBTzxDRTpojfdY7JfUEu92LejKnA/3ulTmrzvDAAa2Ie95WlNL2vhVzigk jj38JeR6vIDXS0lbTfd1U1rWQ4PxlmSvp+EC4u3n7s7P5X/fSt7cuMvxnpdkd45+VOuX H7ew== X-Gm-Message-State: AOJu0Yyiq7dhvTOnuU4i0pV5JdJNVvJq1wNgkASYp2WZILKVsG6zTqW4 N4cYh8UBfWnXqDVKGh1z6hqK4pH7j0Nw2Z/TmQHjM5donEHbxZunefGpTr6vD3fFhGX8fPphLzK lNxDbMcnqqA70nJagCbGSbeVVpAXCYKYf/wR0J74m8CqcLz0u4T53iwUZL/+93ywbGlDTnuMOIO JovkY4M8gXq/xHWIjuw1cVbeab970dXt/Y/QVnJLSyQ8U= X-Received: by 2002:adf:b312:0:b0:371:869b:4e5e with SMTP id ffacd0b85a97d-3749b526b5dmr4922600f8f.1.1725017653802; Fri, 30 Aug 2024 04:34:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEF73jslxNN5JZUkv6CiGhIWFUfNqq4u3WEpnHaeYFIRrvJcKIcyK2ED500GiIRuWnzs922pA== X-Received: by 2002:adf:b312:0:b0:371:869b:4e5e with SMTP id ffacd0b85a97d-3749b526b5dmr4922560f8f.1.1725017652923; Fri, 30 Aug 2024 04:34:12 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891daf9dsm205440866b.164.2024.08.30.04.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 04:34:11 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv6 10/14] gdb: new extract_single_filename_arg helper function Date: Fri, 30 Aug 2024 12:33:50 +0100 Message-Id: <592023767a0ff5ff92fae75b0373387c98bb89db.1725017349.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.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_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 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 is in preparation for the next few commits, this commit adds a new function extract_single_filename_arg. This new function will be used to convert GDB commands that expect a single filename argument to have these commands take a possibly quoted or escaped string. There's no use of the new function in this commit, for that see the following commits. --- gdb/utils.c | 18 ++++++++++++++++++ gdb/utils.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/gdb/utils.c b/gdb/utils.c index 94310300fb5..07c5d3c5f5b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -80,6 +80,7 @@ #include "gdbsupport/buildargv.h" #include "pager.h" #include "run-on-main-thread.h" +#include "gdbsupport/gdb_tilde_expand.h" void (*deprecated_error_begin_hook) (void); @@ -3667,6 +3668,23 @@ copy_bitwise (gdb_byte *dest, ULONGEST dest_offset, } } +/* See utils.h. */ + +std::string +extract_single_filename_arg (const char *args) +{ + if (args == nullptr) + return {}; + + std::string filename = extract_string_maybe_quoted (&args); + args = skip_spaces (args); + if (*args != '\0') + error (_("Junk after filename \"%s\": %s"), filename.c_str (), args); + if (!filename.empty ()) + filename = gdb_tilde_expand (filename.c_str ()); + return filename; +} + #if GDB_SELF_TEST static void test_assign_set_return_if_changed () diff --git a/gdb/utils.h b/gdb/utils.h index 90c8012e73b..d69c81ca834 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -371,6 +371,20 @@ assign_return_if_changed (T &lval, const T &val) return true; } +/* ARG is an argument string as passed to a GDB command which is expected + to contain a single, possibly quoted, filename argument. Extract the + filename and return it as a string. If the filename is quoted then the + quotes will have been removed. If the filename is not quoted then any + escaping within the filename will have been removed. + + If there is any content in ARG after the filename then an error will be + thrown complaining about the extra content. + + If there is no filename in ARG, or if ARG is nullptr, then an empty + string will be returned. */ + +extern std::string extract_single_filename_arg (const char *arg); + /* A class that can be used to intercept warnings. A class is used here, rather than a gdb::function_view because it proved difficult to use a function view in conjunction with ATTRIBUTE_PRINTF in a -- 2.25.4