gdb/continuations: turn continuation functions into inferior methods
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 22 Apr 2021 15:22:39 +0000 (17:22 +0200)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 22 Apr 2021 15:22:39 +0000 (17:22 +0200)
Turn continuations-related functions into methods of the inferior
class.  This is a refactoring.

gdb/ChangeLog:
2021-04-22  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* Makefile.in (COMMON_SFILES): Remove continuations.c.
* inferior.c (inferior::add_continuation): New method, adapted
from 'add_inferior_continuation'.
(inferior::do_all_continuations): New method, adapted from
'do_all_inferior_continuations'.
(inferior::~inferior): Clear the list of continuations directly.
* inferior.h (class inferior) <continuations>: Rename into...
<m_continuations>: ...this and make private.
* continuations.c: Remove.
* continuations.h: Remove.
* event-top.c: Don't include "continuations.h".

Update the users below.
* inf-loop.c (inferior_event_handler)
* infcmd.c (attach_command)
(notice_new_inferior): Update.

gdb/ChangeLog
gdb/Makefile.in
gdb/continuations.c [deleted file]
gdb/continuations.h [deleted file]
gdb/event-top.c
gdb/inf-loop.c
gdb/infcmd.c
gdb/inferior.c
gdb/inferior.h

index 36ea18aafac0facf17afd02fbe9302bfa39aae3e..d9d0f85135f9327edd2425b5a3e608a3b56dcad8 100644 (file)
@@ -1,3 +1,22 @@
+2021-04-22  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       * Makefile.in (COMMON_SFILES): Remove continuations.c.
+       * inferior.c (inferior::add_continuation): New method, adapted
+       from 'add_inferior_continuation'.
+       (inferior::do_all_continuations): New method, adapted from
+       'do_all_inferior_continuations'.
+       (inferior::~inferior): Clear the list of continuations directly.
+       * inferior.h (class inferior) <continuations>: Rename into...
+       <m_continuations>: ...this and make private.
+       * continuations.c: Remove.
+       * continuations.h: Remove.
+       * event-top.c: Don't include "continuations.h".
+
+       Update the users below.
+       * inf-loop.c (inferior_event_handler)
+       * infcmd.c (attach_command)
+       (notice_new_inferior): Update.
+
 2021-04-22  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        * inferior.h (class inferior) <continuations>: Change the type
index 490419030a32085f8d316eb70388546474fc78fb..ba0cabb0216ab5f3faa6c6b4e0e9241c9da11e26 100644 (file)
@@ -1004,7 +1004,6 @@ COMMON_SFILES = \
        coffread.c \
        complaints.c \
        completer.c \
-       continuations.c \
        copying.c \
        corefile.c \
        corelow.c \
diff --git a/gdb/continuations.c b/gdb/continuations.c
deleted file mode 100644 (file)
index 2edfd98..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Continuations for GDB, the GNU debugger.
-
-   Copyright (C) 1986-2021 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#include "defs.h"
-#include "gdbthread.h"
-#include "inferior.h"
-#include "continuations.h"
-
-/* Add a continuation to the continuation list of INFERIOR.  The new
-   continuation will be added at the front.  */
-
-void
-add_inferior_continuation (std::function<void ()> &&cont)
-{
-  struct inferior *inf = current_inferior ();
-
-  inf->continuations.emplace_front (std::move (cont));
-}
-
-/* Do all continuations of the current inferior.  */
-
-void
-do_all_inferior_continuations ()
-{
-  struct inferior *inf = current_inferior ();
-  while (!inf->continuations.empty ())
-    {
-      auto iter = inf->continuations.begin ();
-      (*iter) ();
-      inf->continuations.erase (iter);
-    }
-}
-
-/* Get rid of all the inferior-wide continuations of INF.  */
-
-void
-discard_all_inferior_continuations (struct inferior *inf)
-{
-  inf->continuations.clear ();
-}
diff --git a/gdb/continuations.h b/gdb/continuations.h
deleted file mode 100644 (file)
index 0ad5fc6..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Continuations for GDB, the GNU debugger.
-
-   Copyright (C) 1999-2021 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef CONTINUATIONS_H
-#define CONTINUATIONS_H
-
-#include <functional>
-
-struct inferior;
-
-/* To continue the execution commands when running gdb asynchronously.
-   A continuation is an std::function to be called to finish the
-   command, once the target has stopped.  Such mechanism is used by
-   the attach command and the remote target when a new inferior is
-   detected.  */
-
-/* Inferior specific (any thread) continuations.  */
-
-extern void add_inferior_continuation (std::function<void ()> &&cont);
-extern void do_all_inferior_continuations ();
-extern void discard_all_inferior_continuations (struct inferior *inf);
-
-#endif
index fb0df943f650cb3b3a084f50b34033de78d5d18e..002a7dc95e065c7425134b15507e76b45d193d85 100644 (file)
@@ -33,7 +33,6 @@
 #include "main.h"
 #include "gdbthread.h"
 #include "observable.h"
-#include "continuations.h"
 #include "gdbcmd.h"            /* for dont_repeat() */
 #include "annotate.h"
 #include "maint.h"
index b8f66c308d271742cd32d6c163771c57fc6f4c62..dc3ffbb27f3b115e1e3ad80412b8c04949cdc07a 100644 (file)
@@ -26,7 +26,6 @@
 #include "remote.h"
 #include "language.h"
 #include "gdbthread.h"
-#include "continuations.h"
 #include "interps.h"
 #include "top.h"
 #include "observable.h"
@@ -55,7 +54,7 @@ inferior_event_handler (enum inferior_event_type event_type)
       /* Do all continuations associated with the whole inferior (not
         a particular thread).  */
       if (inferior_ptid != null_ptid)
-       do_all_inferior_continuations ();
+       current_inferior ()->do_all_continuations ();
 
       /* When running a command list (from a user command, say), these
         are only run when the command list is all done.  */
index e06db492b07c0f8c4931c7662f91608d2cbf1955..5aa6b00f20f3da8681a0c736d2b7df85996d6c26 100644 (file)
@@ -47,7 +47,6 @@
 #include "inline-frame.h"
 #include "tracepoint.h"
 #include "inf-loop.h"
-#include "continuations.h"
 #include "linespec.h"
 #include "thread-fsm.h"
 #include "top.h"
@@ -2645,7 +2644,7 @@ attach_command (const char *args, int from_tty)
       inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
 
       /* Wait for stop.  */
-      add_inferior_continuation ([=] ()
+      inferior->add_continuation ([=] ()
        {
          attach_post_wait (from_tty, mode);
        });
@@ -2702,7 +2701,7 @@ notice_new_inferior (thread_info *thr, int leave_running, int from_tty)
       inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
 
       /* Wait for stop before proceeding.  */
-      add_inferior_continuation ([=] ()
+      inferior->add_continuation ([=] ()
        {
          attach_post_wait (from_tty, mode);
        });
index 9188f72e35d2a10f7c094fbdb1fac7549d018362..df3b7bf81f02d65a57f5853942bf57501bda6d28 100644 (file)
@@ -31,7 +31,6 @@
 #include "symfile.h"
 #include "gdbsupport/environ.h"
 #include "cli/cli-utils.h"
-#include "continuations.h"
 #include "arch-utils.h"
 #include "target-descriptions.h"
 #include "readline/tilde.h"
@@ -74,7 +73,7 @@ inferior::~inferior ()
 {
   inferior *inf = this;
 
-  discard_all_inferior_continuations (inf);
+  m_continuations.clear ();
   inferior_free_data (inf);
   xfree (inf->args);
   target_desc_info_free (inf->tdesc_info);
@@ -106,6 +105,23 @@ inferior::tty ()
   return m_terminal.get ();
 }
 
+void
+inferior::add_continuation (std::function<void ()> &&cont)
+{
+  m_continuations.emplace_front (std::move (cont));
+}
+
+void
+inferior::do_all_continuations ()
+{
+  while (!m_continuations.empty ())
+    {
+      auto iter = m_continuations.begin ();
+      (*iter) ();
+      m_continuations.erase (iter);
+    }
+}
+
 struct inferior *
 add_inferior_silent (int pid)
 {
index 9e7291aa733f3621c2001f80a08fdd596240265b..e0a7d622ccbb2d9323905bfa1612aeffc916e44a 100644 (file)
@@ -422,6 +422,14 @@ public:
   inline safe_inf_threads_range threads_safe ()
   { return safe_inf_threads_range (this->thread_list); }
 
+  /* Continuations-related methods.  A continuation is an std::function
+     to be called to finish the execution of a command when running
+     GDB asynchronously.  A continuation is executed after any thread
+     of this inferior stops.  Continuations are used by the attach
+     command and the remote target when a new inferior is detected.  */
+  void add_continuation (std::function<void ()> &&cont);
+  void do_all_continuations ();
+
   /* Set/get file name for default use for standard in/out in the
      inferior.  On Unix systems, we try to make TERMINAL_NAME the
      inferior's controlling terminal.  If TERMINAL_NAME is nullptr or
@@ -508,10 +516,6 @@ public:
   /* True if we're in the process of detaching from this inferior.  */
   bool detaching = false;
 
-  /* What is left to do for an execution command after any thread of
-     this inferior stops.  */
-  std::list<std::function<void ()>> continuations;
-
   /* True if setup_inferior wasn't called for this inferior yet.
      Until that is done, we must not access inferior memory or
      registers, as we haven't determined the target
@@ -559,6 +563,9 @@ private:
 
   /* The name of terminal device to use for I/O.  */
   gdb::unique_xmalloc_ptr<char> m_terminal;
+
+  /* The list of continuations.  */
+  std::list<std::function<void ()>> m_continuations;
 };
 
 /* Keep a registry of per-inferior data-pointers required by other GDB
This page took 0.032836 seconds and 4 git commands to generate.