From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id C49213858C2F for ; Thu, 18 May 2023 20:18:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C49213858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-76c7dfc2e8dso63616639f.0 for ; Thu, 18 May 2023 13:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684441092; x=1687033092; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=a86gpxxU92zJSsk6KF8a1BPXHNbIF4wXRprKKpyq4qw=; b=SIB5TIXGciM3y/aVR2pqz/jb5u9BjhxciFoLTHOYd+tKZf5kKIdciTPEM3TN7zrXYz B6YW1BvP4bICoCHQcGe6CgGClcOSGx7fGeWD1a5oVyCU5CBbLuEkMRo7dMACc4dvX7ST v5kY+a3rJ9Msjjlc8/F48DXOshPKx8wUJoMle0DKviCe7fOgXoN+GkcyCvJyTYP1oFUL 4aW2dUAlLEeh3kbvGEWJFW4IS0KlSS6KAKuhuChm4uUdLLSRfFLbXZk0zXediJjLVFye wgbJuwJsAqhJNDNTg19LF4UFfVaVPzYoYX9mIsXTBjqTDUY7Y2Tp8pW/LK1Qztji3bgY +S2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684441092; x=1687033092; 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=a86gpxxU92zJSsk6KF8a1BPXHNbIF4wXRprKKpyq4qw=; b=MaWRtTvwO0p2O9HE6HhIGD29kR8Q0mbTFyPEr8Zw9Q7/Qok3HT8z7AM5KRP4hiNV8n 20mgI+C4kYlBCwCt7SNx5chUTuDzDCdeXKRvF3rGOcac1YiK/MULXmBxREy8hMPCm0DU mPbMvV/4fS80Q3dc37S6RMZXjVzzuYZj5sp5uO9J0a1ExIZoPmvdoYuryZVMZA3unHBo bUk1gkZynzdYb8lcSIwC+yKHMjdVnIuMKoVjv+Yqv9ZqWz1ZkYtW56pWNvmz8FiEhtBp RpJvwIJfN87YT7Xa4A6JUCmTBn7ntk5BXY6K1Ate8QLy09iLKxAzYBB3qAl69TxiQADj Eh+Q== X-Gm-Message-State: AC+VfDwkP8C4wGBHBIgBABTEggUtl5RqR147Pyf9sjJH+AIpKmWBOTQe DuNu6iqfangeri1UBSPmbwnuRaCe6s22ATTwERx91g== X-Google-Smtp-Source: ACHHUZ4CNgMAfVcHZDRICHw1YrUNPALiSy9aOFBcKS3Ur/ehUROd9lFcO7HSIob2ZF5/iCJIKhT3Fw== X-Received: by 2002:a92:c8c3:0:b0:331:1836:1bdc with SMTP id c3-20020a92c8c3000000b0033118361bdcmr4904397ilq.31.1684441092037; Thu, 18 May 2023 13:18:12 -0700 (PDT) Received: from localhost.localdomain (75-166-157-55.hlrn.qwest.net. [75.166.157.55]) by smtp.gmail.com with ESMTPSA id i9-20020a05663813c900b00418ba399842sm703087jaj.13.2023.05.18.13.18.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 13:18:11 -0700 (PDT) From: Tom Tromey Date: Thu, 18 May 2023 14:18:11 -0600 Subject: [PATCH v2 5/9] Introduce "static constructor" for mi_parse MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230404-dap-loaded-sources-v2-5-93f229095e03@adacore.com> References: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com> In-Reply-To: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.1 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,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: 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 aaebce40fac..b430115daea 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1919,7 +1919,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 f077eb36a7c..b7c5a8cecdf 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; @@ -345,7 +345,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); -- 2.40.0