1 //===-- ProcessKDP.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_ProcessKDP_h_
11 #define liblldb_ProcessKDP_h_
12 
13 // C Includes
14 
15 // C++ Includes
16 #include <list>
17 #include <vector>
18 
19 // Other libraries and framework includes
20 #include "lldb/Core/ArchSpec.h"
21 #include "lldb/Core/Broadcaster.h"
22 #include "lldb/Core/ConstString.h"
23 #include "lldb/Core/Error.h"
24 #include "lldb/Core/InputReader.h"
25 #include "lldb/Core/StreamString.h"
26 #include "lldb/Core/StringList.h"
27 #include "lldb/Core/ThreadSafeValue.h"
28 #include "lldb/Target/Process.h"
29 #include "lldb/Target/Thread.h"
30 
31 #include "CommunicationKDP.h"
32 #include "Utility/StringExtractor.h"
33 
34 class ThreadKDP;
35 
36 class ProcessKDP : public lldb_private::Process
37 {
38 public:
39     //------------------------------------------------------------------
40     // Constructors and Destructors
41     //------------------------------------------------------------------
42     static lldb::ProcessSP
43     CreateInstance (lldb_private::Target& target,
44                     lldb_private::Listener &listener,
45                     const lldb_private::FileSpec *crash_file_path);
46 
47     static void
48     Initialize();
49 
50     static void
51     DebuggerInitialize (lldb_private::Debugger &debugger);
52 
53     static void
54     Terminate();
55 
56     static lldb_private::ConstString
57     GetPluginNameStatic();
58 
59     static const char *
60     GetPluginDescriptionStatic();
61 
62     //------------------------------------------------------------------
63     // Constructors and Destructors
64     //------------------------------------------------------------------
65     ProcessKDP(lldb_private::Target& target, lldb_private::Listener &listener);
66 
67     virtual
68     ~ProcessKDP();
69 
70     //------------------------------------------------------------------
71     // Check if a given Process
72     //------------------------------------------------------------------
73     virtual bool
74     CanDebug (lldb_private::Target &target,
75               bool plugin_specified_by_name);
76 
77     virtual lldb_private::CommandObject *
78     GetPluginCommandObject();
79 
80     //------------------------------------------------------------------
81     // Creating a new process, or attaching to an existing one
82     //------------------------------------------------------------------
83     virtual lldb_private::Error
84     WillLaunch (lldb_private::Module* module);
85 
86     virtual lldb_private::Error
87     DoLaunch (lldb_private::Module *exe_module,
88               const lldb_private::ProcessLaunchInfo &launch_info);
89 
90     virtual lldb_private::Error
91     WillAttachToProcessWithID (lldb::pid_t pid);
92 
93     virtual lldb_private::Error
94     WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
95 
96     virtual lldb_private::Error
97     DoConnectRemote (lldb_private::Stream *strm, const char *remote_url);
98 
99     virtual lldb_private::Error
100     DoAttachToProcessWithID (lldb::pid_t pid);
101 
102     virtual lldb_private::Error
103     DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
104 
105     virtual lldb_private::Error
106     DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const lldb_private::ProcessAttachInfo &attach_info);
107 
108     virtual void
109     DidAttach ();
110 
111     lldb::addr_t
112     GetImageInfoAddress();
113 
114     lldb_private::DynamicLoader *
115     GetDynamicLoader ();
116 
117     //------------------------------------------------------------------
118     // PluginInterface protocol
119     //------------------------------------------------------------------
120     virtual lldb_private::ConstString
121     GetPluginName();
122 
123     virtual uint32_t
124     GetPluginVersion();
125 
126     //------------------------------------------------------------------
127     // Process Control
128     //------------------------------------------------------------------
129     virtual lldb_private::Error
130     WillResume ();
131 
132     virtual lldb_private::Error
133     DoResume ();
134 
135     virtual lldb_private::Error
136     DoHalt (bool &caused_stop);
137 
138     virtual lldb_private::Error
139     DoDetach (bool keep_stopped);
140 
141     virtual lldb_private::Error
142     DoSignal (int signal);
143 
144     virtual lldb_private::Error
145     DoDestroy ();
146 
147     virtual void
148     RefreshStateAfterStop();
149 
150     //------------------------------------------------------------------
151     // Process Queries
152     //------------------------------------------------------------------
153     virtual bool
154     IsAlive ();
155 
156     //------------------------------------------------------------------
157     // Process Memory
158     //------------------------------------------------------------------
159     virtual size_t
160     DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
161 
162     virtual size_t
163     DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
164 
165     virtual lldb::addr_t
166     DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
167 
168     virtual lldb_private::Error
169     DoDeallocateMemory (lldb::addr_t ptr);
170 
171     //----------------------------------------------------------------------
172     // Process Breakpoints
173     //----------------------------------------------------------------------
174     virtual lldb_private::Error
175     EnableBreakpointSite (lldb_private::BreakpointSite *bp_site);
176 
177     virtual lldb_private::Error
178     DisableBreakpointSite (lldb_private::BreakpointSite *bp_site);
179 
180     //----------------------------------------------------------------------
181     // Process Watchpoints
182     //----------------------------------------------------------------------
183     virtual lldb_private::Error
184     EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
185 
186     virtual lldb_private::Error
187     DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
188 
189     CommunicationKDP &
GetCommunication()190     GetCommunication()
191     {
192         return m_comm;
193     }
194 
195 protected:
196     friend class ThreadKDP;
197     friend class CommunicationKDP;
198 
199     //----------------------------------------------------------------------
200     // Accessors
201     //----------------------------------------------------------------------
202     bool
IsRunning(lldb::StateType state)203     IsRunning ( lldb::StateType state )
204     {
205         return    state == lldb::eStateRunning || IsStepping(state);
206     }
207 
208     bool
IsStepping(lldb::StateType state)209     IsStepping ( lldb::StateType state)
210     {
211         return    state == lldb::eStateStepping;
212     }
213 
214     bool
CanResume(lldb::StateType state)215     CanResume ( lldb::StateType state)
216     {
217         return state == lldb::eStateStopped;
218     }
219 
220     bool
HasExited(lldb::StateType state)221     HasExited (lldb::StateType state)
222     {
223         return state == lldb::eStateExited;
224     }
225 
226     bool
227     ProcessIDIsValid ( ) const;
228 
229     void
230     Clear ( );
231 
232     virtual bool
233     UpdateThreadList (lldb_private::ThreadList &old_thread_list,
234                       lldb_private::ThreadList &new_thread_list);
235 
236     enum
237     {
238         eBroadcastBitAsyncContinue                  = (1 << 0),
239         eBroadcastBitAsyncThreadShouldExit          = (1 << 1)
240     };
241 
242     lldb::ThreadSP
243     GetKernelThread ();
244 
245     //------------------------------------------------------------------
246     /// Broadcaster event bits definitions.
247     //------------------------------------------------------------------
248     CommunicationKDP m_comm;
249     lldb_private::Broadcaster m_async_broadcaster;
250     lldb::thread_t m_async_thread;
251     lldb_private::ConstString m_dyld_plugin_name;
252     lldb::addr_t m_kernel_load_addr;
253     lldb::CommandObjectSP m_command_sp;
254     lldb::ThreadWP m_kernel_thread_wp;
255 
256 
257     bool
258     StartAsyncThread ();
259 
260     void
261     StopAsyncThread ();
262 
263     static void *
264     AsyncThread (void *arg);
265 
266 private:
267     //------------------------------------------------------------------
268     // For ProcessKDP only
269     //------------------------------------------------------------------
270 
271     DISALLOW_COPY_AND_ASSIGN (ProcessKDP);
272 
273 };
274 
275 #endif  // liblldb_ProcessKDP_h_
276