]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/TargetList.h
MFV 331710:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / TargetList.h
1 //===-- TargetList.h --------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_TargetList_h_
11 #define liblldb_TargetList_h_
12
13 // C Includes
14 // C++ Includes
15 #include <mutex>
16 #include <vector>
17
18 // Other libraries and framework includes
19 // Project includes
20 #include "lldb/Core/Broadcaster.h"
21 #include "lldb/Target/Target.h"
22
23 namespace lldb_private {
24
25 class TargetList : public Broadcaster {
26 private:
27   friend class Debugger;
28
29   //------------------------------------------------------------------
30   /// Constructor
31   ///
32   /// The constructor for the target list is private. Clients can
33   /// get ahold of of the one and only target list through the
34   /// lldb_private::Debugger::GetSharedInstance().GetTargetList().
35   ///
36   /// @see static TargetList& lldb_private::Debugger::GetTargetList().
37   //------------------------------------------------------------------
38   TargetList(Debugger &debugger);
39
40 public:
41   //------------------------------------------------------------------
42   /// Broadcaster event bits definitions.
43   //------------------------------------------------------------------
44   enum { eBroadcastBitInterrupt = (1 << 0) };
45
46   // These two functions fill out the Broadcaster interface:
47
48   static ConstString &GetStaticBroadcasterClass();
49
50   ConstString &GetBroadcasterClass() const override {
51     return GetStaticBroadcasterClass();
52   }
53
54   ~TargetList() override;
55
56   //------------------------------------------------------------------
57   /// Create a new Target.
58   ///
59   /// Clients must use this function to create a Target. This allows
60   /// a global list of targets to be maintained in a central location
61   /// so signal handlers and other global functions can use it to
62   /// locate an appropriate target to deliver asynchronous information
63   /// to.
64   ///
65   /// @param[in] debugger
66   ///     The debugger to associate this target with
67   ///
68   /// @param[in] file_spec
69   ///     The main executable file for a debug target. This value
70   ///     can be nullptr and the file can be set later using:
71   ///     Target::SetExecutableModule (ModuleSP&)
72   ///
73   /// @param[in] triple_cstr
74   ///     A target triple string to be used for the target. This can
75   ///     be nullptr if the triple is not known or when attaching to a
76   ///     process.
77   ///
78   /// @param[in] get_dependent_modules
79   ///     Track down the dependent modules for an executable and
80   ///     load those into the module list.
81   ///
82   /// @param[in] platform_options
83   ///     A pointer to the platform options to use when creating this
84   ///     target. If this value is nullptr, then the currently selected
85   ///     platform will be used.
86   ///
87   /// @param[out] target_sp
88   ///     A shared pointer to a target that will be filled in if
89   ///     this call is successful.
90   ///
91   /// @return
92   ///     An error object that indicates success or failure
93   //------------------------------------------------------------------
94   Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path,
95                       llvm::StringRef triple_str, bool get_dependent_modules,
96                       const OptionGroupPlatform *platform_options,
97                       lldb::TargetSP &target_sp);
98
99   //------------------------------------------------------------------
100   /// Create a new Target.
101   ///
102   /// Same as the function above, but used when you already know the
103   /// platform you will be using
104   //------------------------------------------------------------------
105   Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path,
106                       const ArchSpec &arch, bool get_dependent_modules,
107                       lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp);
108
109   //------------------------------------------------------------------
110   /// Delete a Target object from the list.
111   ///
112   /// When clients are done with the Target objects, this function
113   /// should be called to release the memory associated with a target
114   /// object.
115   ///
116   /// @param[in] target_sp
117   ///     The shared pointer to a target.
118   ///
119   /// @return
120   ///     Returns \b true if the target was successfully removed from
121   ///     from this target list, \b false otherwise. The client will
122   ///     be left with the last remaining shared pointer to the target
123   ///     in \a target_sp which can then be properly released.
124   //------------------------------------------------------------------
125   bool DeleteTarget(lldb::TargetSP &target_sp);
126
127   int GetNumTargets() const;
128
129   lldb::TargetSP GetTargetAtIndex(uint32_t index) const;
130
131   uint32_t GetIndexOfTarget(lldb::TargetSP target_sp) const;
132
133   //------------------------------------------------------------------
134   /// Find the target that contains has an executable whose path
135   /// matches \a exe_file_spec, and whose architecture matches
136   /// \a arch_ptr if arch_ptr is not nullptr.
137   ///
138   /// @param[in] exe_file_spec
139   ///     A file spec containing a basename, or a full path (directory
140   ///     and basename). If \a exe_file_spec contains only a filename
141   ///     (empty GetDirectory() value) then matching will be done
142   ///     solely based on the filenames and directories won't be
143   ///     compared. If \a exe_file_spec contains a filename and a
144   ///     directory, then both must match.
145   ///
146   /// @param[in] exe_arch_ptr
147   ///     If not nullptr then the architecture also needs to match, else
148   ///     the architectures will be compared.
149   ///
150   /// @return
151   ///     A shared pointer to a target object. The returned shared
152   ///     pointer will contain nullptr if no target objects have a
153   ///     executable whose full or partial path matches
154   ///     with a matching process ID.
155   //------------------------------------------------------------------
156   lldb::TargetSP FindTargetWithExecutableAndArchitecture(
157       const FileSpec &exe_file_spec,
158       const ArchSpec *exe_arch_ptr = nullptr) const;
159
160   //------------------------------------------------------------------
161   /// Find the target that contains a process with process ID \a
162   /// pid.
163   ///
164   /// @param[in] pid
165   ///     The process ID to search our target list for.
166   ///
167   /// @return
168   ///     A shared pointer to a target object. The returned shared
169   ///     pointer will contain nullptr if no target objects own a process
170   ///     with a matching process ID.
171   //------------------------------------------------------------------
172   lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid) const;
173
174   lldb::TargetSP FindTargetWithProcess(lldb_private::Process *process) const;
175
176   lldb::TargetSP GetTargetSP(Target *target) const;
177
178   //------------------------------------------------------------------
179   /// Send an async interrupt to one or all processes.
180   ///
181   /// Find the target that contains the process with process ID \a
182   /// pid and send a LLDB_EVENT_ASYNC_INTERRUPT event to the process's
183   /// event queue.
184   ///
185   /// @param[in] pid
186   ///     The process ID to search our target list for, if \a pid is
187   ///     LLDB_INVALID_PROCESS_ID, then the interrupt will be sent to
188   ///     all processes.
189   ///
190   /// @return
191   ///     The number of async interrupts sent.
192   //------------------------------------------------------------------
193   uint32_t SendAsyncInterrupt(lldb::pid_t pid = LLDB_INVALID_PROCESS_ID);
194
195   uint32_t SignalIfRunning(lldb::pid_t pid, int signo);
196
197   uint32_t SetSelectedTarget(Target *target);
198
199   lldb::TargetSP GetSelectedTarget();
200
201 protected:
202   typedef std::vector<lldb::TargetSP> collection;
203   //------------------------------------------------------------------
204   // Member variables.
205   //------------------------------------------------------------------
206   collection m_target_list;
207   lldb::TargetSP m_dummy_target_sp;
208   mutable std::recursive_mutex m_target_list_mutex;
209   uint32_t m_selected_target_idx;
210
211 private:
212   lldb::TargetSP GetDummyTarget(lldb_private::Debugger &debugger);
213
214   Status CreateDummyTarget(Debugger &debugger,
215                            llvm::StringRef specified_arch_name,
216                            lldb::TargetSP &target_sp);
217
218   Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path,
219                               llvm::StringRef triple_str,
220                               bool get_dependent_files,
221                               const OptionGroupPlatform *platform_options,
222                               lldb::TargetSP &target_sp, bool is_dummy_target);
223
224   Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path,
225                               const ArchSpec &arch, bool get_dependent_modules,
226                               lldb::PlatformSP &platform_sp,
227                               lldb::TargetSP &target_sp, bool is_dummy_target);
228
229   DISALLOW_COPY_AND_ASSIGN(TargetList);
230 };
231
232 } // namespace lldb_private
233
234 #endif // liblldb_TargetList_h_