From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 0A279386D61B for ; Tue, 20 Aug 2024 17:11:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A279386D61B 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 0A279386D61B 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=1724173866; cv=none; b=ZCCvTger6YCyRe6TQs+BJPQ7CONMClovAm7Oon8QGsSxPCr9LaTEnqRXFUrdcXsBz9OhdmMs9pdyWSwtYbpcM4EBcv5Y+7R+M4bFyRvFtjAbQ1cuX8CMpzEQiDCwN3H9K3bR8uNZj/W3wdWojWD5PkiInheNwSHfDbcyweetfXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724173866; c=relaxed/simple; bh=eAVXMGrEJIrucxg6ccShUBFX17urrAEeIFJy7X3dGs0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=PIm0a5zMkSDeJ6NJs9rTxHVoyGfng/xT4MiAXCp8dPInaybF0MkytY84D4saoIqRmDSOLOircIOZgqUD4HcVZEbkngwI9rN6/BNdkQA9BpjIif99TBEoocWamvym3MKNi/X4YGfXbJLHvDFIHiMT0Vdj1/2KVQn1UjH7xCOOFE0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724173863; 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=RYMr42yEIWys5KFaiRzzA/HvDtnkJJYnNc1LEP7chs946fpUsgzaKVCAd1bbkxiUOgsWCj mnOSiP9kUE4Xw4SZAUqcA7htkASzch7trHZeiRPtLIBXjYSFe44pbz89Zl8I/96/ZQg1sY uo0A2FkbpVMjlWb7ClvTbhFzzG3rabI= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-QIC_5pgaOO6OEV4KrCy2Xg-1; Tue, 20 Aug 2024 13:11:02 -0400 X-MC-Unique: QIC_5pgaOO6OEV4KrCy2Xg-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4280a434147so48754065e9.3 for ; Tue, 20 Aug 2024 10:11:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724173860; x=1724778660; 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=Sem8Upj9YcYvGEMYlycXc4ciA+nrHpsRQhkNj6MV0716P/d6fYrFy2PlZRHZaJUojJ IHBKjY7ofsCqlywucwwIcJRVC6A+ZoGAn4vO2INZsSuOZEcZMh5fsz73BGPLxPf8sVk2 MuGa4Svq0xOCpizijV3a1qJI4d+nbKIm6CB/zpFuc4mdcyLp3yRH4nw0kQQ+1zuNrRxb bLXSsjjg90OFFm3zvCHPgXGi4bGAIA9CIGevIp+XPvZ5OPXrSrZgb8fcX+afqFQREnkK ng7xtuBmBggvlS0/2xTz1qf2n87vPMAPd4bhUrJiKLKlHJvW8RaCq2WUt9g3ExUKco3M sWtA== X-Gm-Message-State: AOJu0YzY3xvi3Nw9omncAL8HtDJZYkc7qRtqYqn+k7vCo73d+QhGiefu W+2IiV40D9M2R1X/dWRQl29fj1qbBYxoO/NCjgRzVLp+TPwsFpvBdN23ndWk11lLSCNCLxgJu2W dY8hxkkMuRVHqqANWELTPl7X9t3/2J4UZxUgSKf091soa6o7vU2IYO0nbzxxjzOW/paoE5K+F1H B1os1/hjAFzq6n3ix2UsOJa5XVzPnizEgqNAuF05Keyao= X-Received: by 2002:a05:600c:198f:b0:428:23c8:1e54 with SMTP id 5b1f17b1804b1-42abd23bb28mr331855e9.18.1724173860483; Tue, 20 Aug 2024 10:11:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMmMK5rThzFF0HWihNu68oNFfU6LjwbLdEvjy3Pj2tS8Vh4WKrl1vniEXESpjCuG0UmaPeEQ== X-Received: by 2002:a05:600c:198f:b0:428:23c8:1e54 with SMTP id 5b1f17b1804b1-42abd23bb28mr331625e9.18.1724173859791; Tue, 20 Aug 2024 10:10:59 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718984993fsm13528020f8f.31.2024.08.20.10.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 10:10:59 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv5 10/14] gdb: new extract_single_filename_arg helper function Date: Tue, 20 Aug 2024 18:10:40 +0100 Message-Id: <176cf23fc8a811802a6e818a5c09ffc3838a990d.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 List-Id: 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