From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id 23ED039B703F for ; Wed, 21 Apr 2021 12:57:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 23ED039B703F IronPort-SDR: /yb0tqWOrCwAq5921ODGftyqEdyQse/STrTkqhb2khcqGJziQ5ybtGWgLKvSPxe9LxiVQFhWb4 42C7apTX6ZMQ== X-IronPort-AV: E=McAfee;i="6200,9189,9960"; a="175798151" X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="175798151" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2021 05:57:52 -0700 IronPort-SDR: 3C9hQBjU0KEVEhhiqHa54AADba2FPNzouUpnL0+wRa2NujH6ypDM+SEFmnvATwDCMhq5L7th6B uaRgGHRLn5tQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,238,1613462400"; d="scan'208";a="463576372" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga001.jf.intel.com with ESMTP; 21 Apr 2021 05:57:50 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 13LCvopq011363; Wed, 21 Apr 2021 13:57:50 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id 13LCvo2W031963; Wed, 21 Apr 2021 14:57:50 +0200 Received: (from taktemur@localhost) by ulvlx001.iul.intel.com with LOCAL id 13LCvnPM031959; Wed, 21 Apr 2021 14:57:50 +0200 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 6/6] gdb/continuations: turn continuation functions into inferior methods Date: Wed, 21 Apr 2021 14:57:31 +0200 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Wed, 21 Apr 2021 12:58:05 -0000 Turn continuations-related functions into methods of the inferior class. This is a refactoring. gdb/ChangeLog: 2021-04-21 Tankut Baris Aktemur * 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) : Rename into... : ...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/Makefile.in | 1 - gdb/continuations.c | 56 --------------------------------------------- gdb/continuations.h | 39 ------------------------------- gdb/event-top.c | 1 - gdb/inf-loop.c | 3 +-- gdb/infcmd.c | 5 ++-- gdb/inferior.c | 20 ++++++++++++++-- gdb/inferior.h | 16 +++++++++---- 8 files changed, 33 insertions(+), 108 deletions(-) delete mode 100644 gdb/continuations.c delete mode 100644 gdb/continuations.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 490419030a3..ba0cabb0216 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -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 index a552203e106..00000000000 --- a/gdb/continuations.c +++ /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 . */ - -#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 &&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 &cont = inf->continuations.front (); - inf->continuations.pop_front (); - cont (); - } -} - -/* 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 index 4dc15494ae1..00000000000 --- a/gdb/continuations.h +++ /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 . */ - -#ifndef CONTINUATIONS_H -#define CONTINUATIONS_H - -#include - -struct inferior; - -/* To continue the execution commands when running gdb asynchronously. - A continuation is a closure (i.e. a lambda) 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 &&cont); -extern void do_all_inferior_continuations (); -extern void discard_all_inferior_continuations (struct inferior *inf); - -#endif diff --git a/gdb/event-top.c b/gdb/event-top.c index fb0df943f65..002a7dc95e0 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -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" diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c index b8f66c308d2..dc3ffbb27f3 100644 --- a/gdb/inf-loop.c +++ b/gdb/inf-loop.c @@ -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. */ diff --git a/gdb/infcmd.c b/gdb/infcmd.c index e06db492b07..5aa6b00f20f 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -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); }); diff --git a/gdb/inferior.c b/gdb/inferior.c index 9188f72e35d..da8209548c8 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -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 &&cont) +{ + m_continuations.emplace_front (std::move (cont)); +} + +void +inferior::do_all_continuations () +{ + while (!m_continuations.empty ()) + { + auto &cont = m_continuations.front (); + m_continuations.pop_front (); + cont (); + } +} + struct inferior * add_inferior_silent (int pid) { diff --git a/gdb/inferior.h b/gdb/inferior.h index fc072b3576f..258faa5db98 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -422,6 +422,15 @@ class inferior : public refcounted_object inline safe_inf_threads_range threads_safe () { return safe_inf_threads_range (this->thread_list); } + /* Continuations-related methods. A continuation is a closure (i.e. + a lambda) 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 &&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 +517,6 @@ class inferior : public refcounted_object /* 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 > 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 +564,9 @@ class inferior : public refcounted_object /* The name of terminal device to use for I/O. */ gdb::unique_xmalloc_ptr m_terminal; + + /* The list of continuations. */ + std::list > m_continuations; }; /* Keep a registry of per-inferior data-pointers required by other GDB -- 2.17.1