From patchwork Thu Feb 7 15:55:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 31348 Received: (qmail 88029 invoked by alias); 7 Feb 2019 15:55:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 88016 invoked by uid 89); 7 Feb 2019 15:55:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=channel, Doesnt, FSM, Doesn't X-HELO: mail-wm1-f66.google.com Received: from mail-wm1-f66.google.com (HELO mail-wm1-f66.google.com) (209.85.128.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Feb 2019 15:55:28 +0000 Received: by mail-wm1-f66.google.com with SMTP id z5so392459wmf.0 for ; Thu, 07 Feb 2019 07:55:27 -0800 (PST) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:4c97:6d52:2cea:997b? ([2001:8a0:f913:f700:4c97:6d52:2cea:997b]) by smtp.gmail.com with ESMTPSA id i20sm134454wml.9.2019.02.07.07.55.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Feb 2019 07:55:25 -0800 (PST) Subject: [PATCH] thread_fsm: Make data fields private (Re: [PATCH] C++-ify struct thread_fsm) To: Tom Tromey , gdb-patches@sourceware.org References: <20190102232806.14123-1-tom@tromey.com> From: Pedro Alves Message-ID: Date: Thu, 7 Feb 2019 15:55:24 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190102232806.14123-1-tom@tromey.com> On 01/02/2019 11:28 PM, Tom Tromey wrote: > This C++-ifies struct thread_fsm, replacing the "ops" structure with > virtual methods, and changing all the implementations to derive from > thread_fsm. Thanks for doing this. > -extern void thread_fsm_set_finished (struct thread_fsm *fsm); > + /* The interpreter that issued the execution command that caused > + this thread to resume. If the top level interpreter is MI/async, > + and the execution command was a CLI command (next/step/etc.), > + we'll want to print stop event output to the MI console channel > + (the stepped-to line, etc.), as if the user entered the execution > + command on a real GDB console. */ > + struct interp *command_interp = nullptr; > > -/* Returns true if the FSM completed successfully. */ > -extern int thread_fsm_finished_p (struct thread_fsm *fsm); > +protected: > > -/* Calls the FSM's reply_reason method. */ > -extern enum async_reply_reason > - thread_fsm_async_reply_reason (struct thread_fsm *fsm); > + /* Whether the FSM is done successfully. */ > + bool finished = false; > This "protected" data field caught my eye. Doesn't seem to be any reason for that. While at it, we can make command_interp private as well, by adding a getter. From 3c5b0346b49e6eaedcf467d81b46306e1f4d2c8b Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 7 Feb 2019 13:49:04 +0000 Subject: [PATCH] thread_fsm: Make data fields private Make thread_fsm::finish and command_interp data fields private, and add a getter for the latter. gdb/ChangeLog: 2019-02-07 Pedro Alves * cli/cli-interp.c (should_print_stop_to_console): Adjust. * thread-fsm.h (thread_fsm) : Adjust and add comment. : Adjust. : Rename to m_command_interp and make private. : Now a method. : Rename to m_finished and make private. --- gdb/cli/cli-interp.c | 2 +- gdb/thread-fsm.h | 37 ++++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 088f4f1f89..ddbcbd7883 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -112,7 +112,7 @@ should_print_stop_to_console (struct interp *console_interp, if ((bpstat_what (tp->control.stop_bpstat).main_action == BPSTAT_WHAT_STOP_NOISY) || tp->thread_fsm == NULL - || tp->thread_fsm->command_interp == console_interp + || tp->thread_fsm->command_interp () == console_interp || !tp->thread_fsm->finished_p ()) return 1; return 0; diff --git a/gdb/thread-fsm.h b/gdb/thread-fsm.h index 57837bfdfb..82ad9c2410 100644 --- a/gdb/thread-fsm.h +++ b/gdb/thread-fsm.h @@ -30,8 +30,10 @@ struct thread_fsm_ops; struct thread_fsm { + /* CMD_INTERP is the interpreter that issued the execution command + that caused this thread to resume. */ explicit thread_fsm (struct interp *cmd_interp) - : command_interp (cmd_interp) + : m_command_interp (cmd_interp) { } @@ -81,33 +83,42 @@ struct thread_fsm void set_finished () { - finished = true; + m_finished = true; } bool finished_p () const { - return finished; + return m_finished; } - /* The interpreter that issued the execution command that caused - this thread to resume. If the top level interpreter is MI/async, - and the execution command was a CLI command (next/step/etc.), - we'll want to print stop event output to the MI console channel - (the stepped-to line, etc.), as if the user entered the execution - command on a real GDB console. */ - struct interp *command_interp = nullptr; + /* Return the interpreter that issued the execution command that + caused this thread to resume. */ + struct interp *command_interp () + { + return m_command_interp; + } protected: - /* Whether the FSM is done successfully. */ - bool finished = false; - /* The async_reply_reason that is broadcast to MI clients if this FSM finishes successfully. */ virtual enum async_reply_reason do_async_reply_reason () { gdb_assert_not_reached (_("should not call async_reply_reason here")); } + +private: + + /* Whether the FSM is done successfully. */ + bool m_finished = false; + + /* The interpreter that issued the execution command that caused + this thread to resume. If the top level interpreter is MI/async, + and the execution command was a CLI command (next/step/etc.), + we'll want to print stop event output to the MI console channel + (the stepped-to line, etc.), as if the user entered the execution + command on a real GDB console. */ + struct interp *m_command_interp = nullptr; }; #endif /* THREAD_FSM_H */