From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QMJ6N9awhmY/PxsAWB0awg (envelope-from ) for ; Thu, 04 Jul 2024 10:25:26 -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=QgvpCvou; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E00661E0C3; Thu, 4 Jul 2024 10:25:26 -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 CC39A1E030 for ; Thu, 4 Jul 2024 10:25:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65953384A422 for ; Thu, 4 Jul 2024 14:25:24 +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 80FF8384A45B for ; Thu, 4 Jul 2024 14:21:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80FF8384A45B 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 80FF8384A45B 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=1720102904; cv=none; b=lLoiPabOKzYnpQpbEtMywg2tzSqEL93EAsNY0YDTDBieOixBQCsWQBt7G2x/2zMz/5uVkfCNdW/L2JJTpRpnVkEenjFSDnEQwKh0ufZQEX/1bSjLN1fa+nW776PFbNnlJxVg1b/dAJ9ASt6pWDECC7iwOq6Mb1Xr4+N35hClFog= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720102904; c=relaxed/simple; bh=ECphfNatEkMncKOxvPGJKr/LLGOU/qOusGwYVbuG7rw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=xqLo3wcBfJS8zjxitiCj7wnK4erw4QcA2up15Ap/+MK5RTI3mpSejwIb5aMFJy6NSxyCr/0iGxHKcRj6ajfQixOKd6w7eshYaT/HAba8OdxpgNgI0++qX7zMWqsN20Pkr4k2prSgKGncajnn0709i6Kd1OMTJcDb2PeUIx+0a/Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720102895; 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=N0uyiUSmfT9wQlNEK2t3Oxsg75snkyJIf/EYSYwKcRI=; b=QgvpCvoukM6/gPGc50ybqYJYnrOmYKAD/0q9ngbXOkKVUCKYSxseUCvh981CNO8hTZQCMr AJ4IWRGbJk6n2QsjehtSRQKNb4joOnLZ4VK+WwaGDpPbzVXunwopd6l0MenKmOZTV9vl13 Pwiz7UlDrV9djz376J7KvjiAYyGOiaI= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-0jyDwuJTOAyhssb2DKXO-A-1; Thu, 04 Jul 2024 10:21:34 -0400 X-MC-Unique: 0jyDwuJTOAyhssb2DKXO-A-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2ee49ce152eso7507801fa.3 for ; Thu, 04 Jul 2024 07:21:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720102892; x=1720707692; 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=N0uyiUSmfT9wQlNEK2t3Oxsg75snkyJIf/EYSYwKcRI=; b=NSL53fTgNXXWUUu6uC1EuWCXMx8xgLzcfvUAR+ugO/au3a+pK1Yf7wpz129u4FLwZn uZv2UxWU+aAnwwQgCbyINyybHCJkZws1ctMhC8himTMLtQDKgo31kpqGvlVuIfoqdWUU QUlS9QYAPHEvM8wk9MrYrbrimyMwVlGSEcL2nrJ0pv/N/+ZrQftYStjpF9D+eT0r49/x gAuimihFbsAK366qsEg+D4BRFy4nmmJv9i5AwmhCzWVIcXfpWEq5hMe7rBjkD6zJy8z3 SOCi1bQy2Afzsm0rlGhJ4RlwEQiZy2WtMo8GuHVycxZZ5Un+kfLH5/x/lSqmYT6ETNUJ VKQA== X-Gm-Message-State: AOJu0Yx0Tr4MAgC/vHBdLqZu9kYEYE2Qxjp0jai8tWkwbizV1rNnptT0 ZGuDNBts5GOmx48PIsTywZ50FYdHY+pTmcIWPBFdBRfjFS10qQa6jpI42IFFJtuWrWI+VboPw9b j1xnA38bTbkA4bEo3mkTcIDp4wujqcfFSEIc2jHtvVezTJcpHOkBa1QqqITPEXst0HJaqa8Aeti lA+7M0s4fPZh7u4zlrOF3oDxSv9tVzzECkXzUKIJkMOH8= X-Received: by 2002:a2e:9083:0:b0:2ee:6cda:6380 with SMTP id 38308e7fff4ca-2ee8ed4259cmr13050491fa.18.1720102892328; Thu, 04 Jul 2024 07:21:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZ1UaJboMp1ouo2z6lmiFrh2kUCxDwzHCwsrWzuRt1/TjWwZZdHMiJw59XJMMmWMZoV9aVgw== X-Received: by 2002:a2e:9083:0:b0:2ee:6cda:6380 with SMTP id 38308e7fff4ca-2ee8ed4259cmr13050301fa.18.1720102891925; Thu, 04 Jul 2024 07:21:31 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4264a21d2adsm26312485e9.29.2024.07.04.07.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 07:21:31 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 10/14] gdb: new extract_single_filename_arg helper function Date: Thu, 4 Jul 2024 15:21:05 +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 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 17498e04312..f80e72a6ddd 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