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.133.124]) by sourceware.org (Postfix) with ESMTPS id CBEC73858417 for ; Mon, 14 Aug 2023 13:42:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBEC73858417 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692020563; 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=XjPU5OW57BECggwkXIPXIiskVKrOT7cTahf6iSwM4v8=; b=I9PG/s/UD5MMZvihDYZ/cBeeV0gQv7Th8vXwK44V2QZnkgaesqhBGtHQV4ZxgAyVfsayYs m9HbccPMqXcB2b0ENsO1+iuywq+nRuFwsi5LPChdlNndKd3Vz9TsqlDyk32ByWjg5ghof9 amQtkitNU7PDTyR1P7iO7k4P8kgr3VM= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-i5_qvlArNJ2t2QefOSXOow-1; Mon, 14 Aug 2023 09:42:42 -0400 X-MC-Unique: i5_qvlArNJ2t2QefOSXOow-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-99388334de6so261087466b.0 for ; Mon, 14 Aug 2023 06:42:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692020561; x=1692625361; 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=XjPU5OW57BECggwkXIPXIiskVKrOT7cTahf6iSwM4v8=; b=iu7pjaR1lL6FvbYcb5d7Bx0obbZLbD+rZJncdlZcVo32norkvt0r5kdzLI3BD1WZ35 +j5y5BijozbgkZ3lGoiSyMzzrc6Oigd+sf2KUzQmabRNl/hUhiF1YaJMC/WTXi+iyKfm eUDY/VgssNkVRSFEJm4p2uMRXbqPwDi5ciFIPNu+J1NUO4cXA3nz6dgKUblSzLX7hkHJ cdG7VzbiQ1sEF005OF+lRWEVj5D2jqYb3elELHPmaIqHXAPNJqaLwicspF9F0EI1RlOS phyC3TDg5VIMOmEn0EI3uyti9Hs6dMDTK9vIITmxETzAeUSzIxiSTBE8896LOx37359z gRwg== X-Gm-Message-State: AOJu0YylO8e22l6AfIQQPWlZazr5t09JXQxrZUuVBjP8qnCSpPaK8ov0 kTatDKESXOOK2uBcavmTbnvsrm1vx5CiWee5JdMARg6Nf85LevzrByvuz9CF1F8ch+0tMWR4sxJ 63CzbCVL+KBRDisp5F2YBtyYCYEDRIvZAKeVfhOvxleZg7qL7BpaLUVeobUh6u+tqDU6fIrJefv jcu1gFvw== X-Received: by 2002:a17:906:76d3:b0:99b:4fff:6bb with SMTP id q19-20020a17090676d300b0099b4fff06bbmr8407610ejn.4.1692020561110; Mon, 14 Aug 2023 06:42:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHC4UGcSNEmZfHi25U4AqGc0mx83F4KyF01jVBzc4bzKrxsbSH2p0zfW6jdwYKbmB3zLVepEQ== X-Received: by 2002:a17:906:76d3:b0:99b:4fff:6bb with SMTP id q19-20020a17090676d300b0099b4fff06bbmr8407592ejn.4.1692020560674; Mon, 14 Aug 2023 06:42:40 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id kf3-20020a17090776c300b00989027eb30asm5695833ejc.158.2023.08.14.06.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:42:40 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Tom Tromey , Andrew Burgess Subject: [PATCH 3/3] gdb: remove mi_parse::make functions Date: Mon, 14 Aug 2023 14:42:34 +0100 Message-Id: <1c118f2c3ab71038a20e643be4b5ad423d756da0.1692019711.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=-11.8 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 List-Id: Remove the static mi_parse::make functions, and instead use the mi_parse constructor. This is a partial revert of the commit: commit fde3f93adb50c9937cd2e1c93561aea2fd167156 Date: Mon Mar 20 10:56:55 2023 -0600 Introduce "static constructor" for mi_parse which introduced the mi_parse::make functions, though after discussion on the list the reasons for seem to have been lost[1]. Given there are no test regressions when moving back to using the constructors, I propose we should do that for now. There should be no user visible changes after this commit. [1] https://inbox.sourceware.org/gdb-patches/20230404-dap-loaded-sources-v2-5-93f229095e03@adacore.com/ --- gdb/mi/mi-main.c | 2 +- gdb/mi/mi-parse.c | 76 +++++++++++++++++++++------------------------- gdb/mi/mi-parse.h | 18 +++-------- gdb/python/py-mi.c | 4 +-- 4 files changed, 43 insertions(+), 57 deletions(-) diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index f9bc1cb9cfb..573ff9270da 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1935,7 +1935,7 @@ mi_execute_command (const char *cmd, int from_tty) = gdb::checked_static_cast (command_interp ()); try { - command = mi_parse::make (cmd, &token); + command = gdb::make_unique (cmd, &token); } catch (const gdb_exception &exception) { diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c index a9b9cdaf88f..433edbf4140 100644 --- a/gdb/mi/mi-parse.c +++ b/gdb/mi/mi-parse.c @@ -287,13 +287,12 @@ mi_parse::set_language (const char *arg, const char **endp) *endp = arg; } -std::unique_ptr -mi_parse::make (const char *cmd, std::string *token) +/* See mi-parse.h. */ + +mi_parse::mi_parse (const char *cmd, std::string *token) { const char *chp; - std::unique_ptr parse (new struct mi_parse); - /* Before starting, skip leading white space. */ cmd = skip_spaces (cmd); @@ -306,10 +305,10 @@ mi_parse::make (const char *cmd, std::string *token) if (*chp != '-') { chp = skip_spaces (chp); - parse->command = make_unique_xstrdup (chp); - parse->op = CLI_COMMAND; + this->command = make_unique_xstrdup (chp); + this->op = CLI_COMMAND; - return parse; + return; } /* Extract the command. */ @@ -318,14 +317,14 @@ mi_parse::make (const char *cmd, std::string *token) for (; *chp && !isspace (*chp); chp++) ; - parse->command = make_unique_xstrndup (tmp, chp - tmp); + this->command = make_unique_xstrndup (tmp, chp - tmp); } /* Find the command in the MI table. */ - parse->cmd = mi_cmd_lookup (parse->command.get ()); - if (parse->cmd == NULL) + this->cmd = mi_cmd_lookup (this->command.get ()); + if (this->cmd == NULL) throw_error (UNDEFINED_COMMAND_ERROR, - _("Undefined MI command: %s"), parse->command.get ()); + _("Undefined MI command: %s"), this->command.get ()); /* Skip white space following the command. */ chp = skip_spaces (chp); @@ -349,13 +348,13 @@ mi_parse::make (const char *cmd, std::string *token) if (strncmp (chp, "--all ", as) == 0) { - parse->all = 1; + this->all = 1; chp += as; } /* See if --all is the last token in the input. */ if (strcmp (chp, "--all") == 0) { - parse->all = 1; + this->all = 1; chp += strlen (chp); } if (strncmp (chp, "--thread-group ", tgs) == 0) @@ -364,7 +363,7 @@ mi_parse::make (const char *cmd, std::string *token) option = "--thread-group"; chp += tgs; - parse->set_thread_group (chp, &endp); + this->set_thread_group (chp, &endp); chp = endp; } else if (strncmp (chp, "--thread ", ts) == 0) @@ -373,7 +372,7 @@ mi_parse::make (const char *cmd, std::string *token) option = "--thread"; chp += ts; - parse->set_thread (chp, &endp); + this->set_thread (chp, &endp); chp = endp; } else if (strncmp (chp, "--frame ", fs) == 0) @@ -382,14 +381,14 @@ mi_parse::make (const char *cmd, std::string *token) option = "--frame"; chp += fs; - parse->set_frame (chp, &endp); + this->set_frame (chp, &endp); chp = endp; } else if (strncmp (chp, "--language ", ls) == 0) { option = "--language"; chp += ls; - parse->set_language (chp, &chp); + this->set_language (chp, &chp); } else break; @@ -400,37 +399,33 @@ mi_parse::make (const char *cmd, std::string *token) } /* Save the rest of the arguments for the command. */ - parse->m_args = chp; + this->m_args = chp; /* Fully parsed, flag as an MI command. */ - parse->op = MI_COMMAND; - return parse; + this->op = MI_COMMAND; } /* See mi-parse.h. */ -std::unique_ptr -mi_parse::make (gdb::unique_xmalloc_ptr command, - std::vector> args) +mi_parse::mi_parse (gdb::unique_xmalloc_ptr command, + std::vector> args) { - std::unique_ptr parse (new struct mi_parse); - - parse->command = std::move (command); - parse->token = ""; + this->command = std::move (command); + this->token = ""; - if (parse->command.get ()[0] != '-') + if (this->command.get ()[0] != '-') throw_error (UNDEFINED_COMMAND_ERROR, _("MI command '%s' does not start with '-'"), - parse->command.get ()); + this->command.get ()); /* Find the command in the MI table. */ - parse->cmd = mi_cmd_lookup (parse->command.get () + 1); - if (parse->cmd == NULL) + this->cmd = mi_cmd_lookup (this->command.get () + 1); + if (this->cmd == NULL) throw_error (UNDEFINED_COMMAND_ERROR, - _("Undefined MI command: %s"), parse->command.get ()); + _("Undefined MI command: %s"), this->command.get ()); /* This over-allocates slightly, but it seems unimportant. */ - parse->argv = XCNEWVEC (char *, args.size () + 1); + this->argv = XCNEWVEC (char *, args.size () + 1); for (size_t i = 0; i < args.size (); ++i) { @@ -439,43 +434,42 @@ mi_parse::make (gdb::unique_xmalloc_ptr command, /* See if --all is the last token in the input. */ if (strcmp (chp, "--all") == 0) { - parse->all = 1; + this->all = 1; } else if (strcmp (chp, "--thread-group") == 0) { ++i; if (i == args.size ()) error ("No argument to '--thread-group'"); - parse->set_thread_group (args[i].get (), nullptr); + this->set_thread_group (args[i].get (), nullptr); } else if (strcmp (chp, "--thread") == 0) { ++i; if (i == args.size ()) error ("No argument to '--thread'"); - parse->set_thread (args[i].get (), nullptr); + this->set_thread (args[i].get (), nullptr); } else if (strcmp (chp, "--frame") == 0) { ++i; if (i == args.size ()) error ("No argument to '--frame'"); - parse->set_frame (args[i].get (), nullptr); + this->set_frame (args[i].get (), nullptr); } else if (strcmp (chp, "--language") == 0) { ++i; if (i == args.size ()) error ("No argument to '--language'"); - parse->set_language (args[i].get (), nullptr); + this->set_language (args[i].get (), nullptr); } else - parse->argv[parse->argc++] = args[i].release (); + this->argv[this->argc++] = args[i].release (); } /* Fully parsed, flag as an MI command. */ - parse->op = MI_COMMAND; - return parse; + this->op = MI_COMMAND; } enum print_values diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h index c729e94c1f0..6bf516cfc57 100644 --- a/gdb/mi/mi-parse.h +++ b/gdb/mi/mi-parse.h @@ -41,24 +41,18 @@ enum mi_command_type struct mi_parse { - /* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is + /* Attempt to parse CMD creating 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 can be - 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, - std::string *token); + set to the token, even if an exception is thrown. */ + mi_parse (const char *cmd, std::string *token); /* Create an mi_parse object given the command name and a vector of arguments. Unlike with the other constructor, here the arguments are treated "as is" -- no escape processing is done. */ - - static std::unique_ptr make - (gdb::unique_xmalloc_ptr command, - std::vector> args); + mi_parse (gdb::unique_xmalloc_ptr command, + std::vector> args); ~mi_parse (); @@ -91,8 +85,6 @@ struct mi_parse private: - mi_parse () = default; - /* Helper methods for parsing arguments. Each takes the argument to be parsed. It will either set a member of this object, or throw an exception on error. In each case, *ENDP, if non-NULL, diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c index 0fcd57844e7..66dc6fb8a32 100644 --- a/gdb/python/py-mi.c +++ b/gdb/python/py-mi.c @@ -284,8 +284,8 @@ gdbpy_execute_mi_command (PyObject *self, PyObject *args, PyObject *kw) try { scoped_restore save_uiout = make_scoped_restore (¤t_uiout, &uiout); - std::unique_ptr parser - = mi_parse::make (std::move (mi_command), std::move (arg_strings)); + auto parser = gdb::make_unique (std::move (mi_command), + std::move (arg_strings)); mi_execute_command (parser.get ()); } catch (const gdb_exception &except) -- 2.25.4