xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/process-stratum-target.h (revision 782713e6c126f1866c6d9cfdee4ceb49483b5828)
1 /* Abstract base class inherited by all process_stratum targets
2 
3    Copyright (C) 2018-2020 Free Software Foundation, Inc.
4 
5    This file is part of GDB.
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19 
20 #ifndef PROCESS_STRATUM_TARGET_H
21 #define PROCESS_STRATUM_TARGET_H
22 
23 #include "target.h"
24 #include <set>
25 
26 /* Abstract base class inherited by all process_stratum targets.  */
27 
28 class process_stratum_target : public target_ops
29 {
30 public:
31   ~process_stratum_target () override = 0;
32 
33   strata stratum () const final override { return process_stratum; }
34 
35   /* Return a string representation of this target's open connection.
36      This string is used to distinguish different instances of a given
37      target type.  For example, when remote debugging, the target is
38      called "remote", but since we may have more than one remote
39      target open, connection_string() returns the connection serial
40      connection name, e.g., "localhost:10001", "192.168.0.1:20000",
41      etc.  This string is shown in several places, e.g., in "info
42      connections" and "info inferiors".  */
43   virtual const char *connection_string () { return nullptr; }
44 
45   /* We must default these because they must be implemented by any
46      target that can run.  */
47   bool can_async_p () override { return false; }
48   bool supports_non_stop () override { return false; }
49   bool supports_disable_randomization () override { return false; }
50 
51   /* This default implementation returns the inferior's address
52      space.  */
53   struct address_space *thread_address_space (ptid_t ptid) override;
54 
55   /* This default implementation always returns target_gdbarch ().  */
56   struct gdbarch *thread_architecture (ptid_t ptid) override;
57 
58   /* Default implementations for process_stratum targets.  Return true
59      if there's a selected inferior, false otherwise.  */
60   bool has_all_memory () override;
61   bool has_memory () override;
62   bool has_stack () override;
63   bool has_registers () override;
64   bool has_execution (inferior *inf) override;
65 
66   /* True if any thread is, or may be executing.  We need to track
67      this separately because until we fully sync the thread list, we
68      won't know whether the target is fully stopped, even if we see
69      stop events for all known threads, because any of those threads
70      may have spawned new threads we haven't heard of yet.  */
71   bool threads_executing = false;
72 
73   /* The connection number.  Visible in "info connections".  */
74   int connection_number = 0;
75 };
76 
77 /* Downcast TARGET to process_stratum_target.  */
78 
79 static inline process_stratum_target *
80 as_process_stratum_target (target_ops *target)
81 {
82   gdb_assert (target->stratum () == process_stratum);
83   return static_cast<process_stratum_target *> (target);
84 }
85 
86 /* Return a collection of targets that have non-exited inferiors.  */
87 
88 extern std::set<process_stratum_target *> all_non_exited_process_targets ();
89 
90 /* Switch to the first inferior (and program space) of TARGET, and
91    switch to no thread selected.  */
92 
93 extern void switch_to_target_no_thread (process_stratum_target *target);
94 
95 #endif /* !defined (PROCESS_STRATUM_TARGET_H) */
96