From patchwork Tue Apr 4 17:08:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67273 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97E9738515F4 for ; Tue, 4 Apr 2023 17:09:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97E9738515F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680628182; bh=2j8GmxYcemfdPyFLqyWblCIyu3No/ppk8nyFxE83C+0=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=MydL9cjXWMRwHwnTNhVisTulbylZTiGwONhc22O6n4k851/ytu/MeejLmbrpIZC6z DFd6mfYuAJw0QsdT3xJreYe3u8C+zPJq7BAprNtz7YtzeMGFPrz8NGUiUQ/4ztLU1+ R8otnEKZovorzm+trb4t2wivSAYXIiCjMAeCNyZo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 90DA93858C20 for ; Tue, 4 Apr 2023 17:08:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90DA93858C20 Received: by mail-il1-x135.google.com with SMTP id t5so6117249ilu.5 for ; Tue, 04 Apr 2023 10:08:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680628134; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2j8GmxYcemfdPyFLqyWblCIyu3No/ppk8nyFxE83C+0=; b=8MMcacjIotPM/jpO41CVRh0nKvZ/jbMV2KbU5WCS6ZC7g3IfUyCVPdXtxaIfyanaDV GPoHuaybwmJ2Zv9ZqyLWtxx05XCfNQhyvCDOzkF4ulBvcPE6KUxeiQs7mtzTbuweYLqr sHdOO/2DyAS+UJ3dvBH4Z2LvXwybwUOkG0gJJ8A/BZGpKKTgK3ZZKiDu0aHfY3Edv/iN HIxAj2q5IYvyWzaWquYcXDDiqjxgyodE/qE9dzrhH7LGim24jytsgfwwDkrvvcOfkWUx 6IqJhiliiL3hsjkk9xUksp+/HftNkiQVZrrGBQityFEb8dk3wk1nes379xi04UZpiYxh DhfQ== X-Gm-Message-State: AAQBX9cvbwoMPCRROkiygrvgXCBBmlbWo5TYQhjc0ZWhAieFq18/68to x+Sl62RVy7Cguw4Oc8D4QZxIp4pYSTei0Iza/WSQ3g== X-Google-Smtp-Source: AKy350Zx4qbPYlKlnw7+uA9s8BzXohu1X26bgAxRqVTVsUDjrim+kx4yT5mYqT9YNZ/seMDFbdfoqA== X-Received: by 2002:a92:c84c:0:b0:325:b52f:2e3d with SMTP id b12-20020a92c84c000000b00325b52f2e3dmr2368151ilq.27.1680628134166; Tue, 04 Apr 2023 10:08:54 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id f4-20020a02a104000000b0040b4c29010fsm1188306jag.140.2023.04.04.10.08.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 10:08:53 -0700 (PDT) Date: Tue, 04 Apr 2023 11:08:53 -0600 Subject: [PATCH 5/9] Introduce "static constructor" for mi_parse MIME-Version: 1.0 Message-Id: <20230404-dap-loaded-sources-v1-5-75c796bd644b@adacore.com> References: <20230404-dap-loaded-sources-v1-0-75c796bd644b@adacore.com> In-Reply-To: <20230404-dap-loaded-sources-v1-0-75c796bd644b@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Change the mi_parse function to be a static method of mi_parse. This lets us remove the 'set_args' setter function. --- gdb/mi/mi-main.c | 2 +- gdb/mi/mi-parse.c | 6 +++--- gdb/mi/mi-parse.h | 28 +++++++++++++--------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 1149cb984d3..3a114589e7c 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1917,7 +1917,7 @@ mi_execute_command (const char *cmd, int from_tty) try { - command = mi_parse (cmd, &token); + command = mi_parse::make (cmd, &token); } catch (const gdb_exception &exception) { diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c index db3c4ae2368..57b9c46fc24 100644 --- a/gdb/mi/mi-parse.c +++ b/gdb/mi/mi-parse.c @@ -109,7 +109,7 @@ mi_parse_escape (const char **string_ptr) void mi_parse::parse_argv () { - const char *chp = m_args.get (); + const char *chp = m_args.c_str (); int argc = 0; char **argv = XNEWVEC (char *, argc + 1); @@ -216,7 +216,7 @@ mi_parse::~mi_parse () } std::unique_ptr -mi_parse (const char *cmd, char **token) +mi_parse::make (const char *cmd, char **token) { const char *chp; @@ -346,7 +346,7 @@ mi_parse (const char *cmd, char **token) } /* Save the rest of the arguments for the command. */ - parse->set_args (chp); + parse->m_args = chp; /* Fully parsed, flag as an MI command. */ parse->op = MI_COMMAND; diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h index edb61547354..6f1da6e6eb5 100644 --- a/gdb/mi/mi-parse.h +++ b/gdb/mi/mi-parse.h @@ -41,7 +41,17 @@ enum mi_command_type struct mi_parse { - mi_parse () = default; + /* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is + invalid, an exception is thrown. For an MI_COMMAND COMMAND, ARGS + and OP are initialized. Un-initialized fields are zero. *TOKEN is + set to the token, even if an exception is thrown. It is allocated + with xmalloc; it must either be freed with xfree, or assigned to + the TOKEN field of the resultant mi_parse object, to be freed by + mi_parse_free. */ + + static std::unique_ptr make (const char *cmd, + char **token); + ~mi_parse (); DISABLE_COPY_AND_ASSIGN (mi_parse); @@ -54,9 +64,6 @@ struct mi_parse const char *args () const { return m_args.c_str (); } - void set_args (const char *args) - { m_args = args; } - enum mi_command_type op = MI_COMMAND; char *command = nullptr; char *token = nullptr; @@ -75,20 +82,11 @@ struct mi_parse private: + mi_parse () = default; + std::string m_args; }; -/* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is - invalid, an exception is thrown. For an MI_COMMAND COMMAND, ARGS - and OP are initialized. Un-initialized fields are zero. *TOKEN is - set to the token, even if an exception is thrown. It is allocated - with xmalloc; it must either be freed with xfree, or assigned to - the TOKEN field of the resultant mi_parse object, to be freed by - mi_parse_free. */ - -extern std::unique_ptr mi_parse (const char *cmd, - char **token); - /* Parse a string argument into a print_values value. */ enum print_values mi_parse_print_values (const char *name);