1 //===-- Debugger.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Debugger_h_
11 #define liblldb_Debugger_h_
12 #if defined(__cplusplus)
19 #include "lldb/lldb-public.h"
20 #include "lldb/Core/Broadcaster.h"
21 #include "lldb/Core/Communication.h"
22 #include "lldb/Core/IOHandler.h"
23 #include "lldb/Core/Listener.h"
24 #include "lldb/Core/SourceManager.h"
25 #include "lldb/Core/UserID.h"
26 #include "lldb/Core/UserSettingsController.h"
27 #include "lldb/DataFormatters/FormatManager.h"
28 #include "lldb/Host/Terminal.h"
29 #include "lldb/Interpreter/OptionValueProperties.h"
30 #include "lldb/Target/ExecutionContext.h"
31 #include "lldb/Target/Platform.h"
32 #include "lldb/Target/TargetList.h"
42 namespace lldb_private {
44 //----------------------------------------------------------------------
45 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
46 /// @brief A class to manage flag bits.
48 /// Provides a global root objects for the debugger core.
49 //----------------------------------------------------------------------
53 public std::enable_shared_from_this<Debugger>,
56 public BroadcasterManager
58 friend class SourceManager; // For GetSourceFileCache.
62 typedef llvm::sys::DynamicLibrary (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp,
66 static lldb::DebuggerSP
67 CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL);
70 FindTargetWithProcessID (lldb::pid_t pid);
73 FindTargetWithProcess (Process *process);
76 Initialize (LoadPluginCallbackType load_plugin_callback);
82 SettingsInitialize ();
88 Destroy (lldb::DebuggerSP &debugger_sp);
99 SetAsyncExecution (bool async);
104 return m_input_file_sp;
110 return m_output_file_sp;
116 return m_error_file_sp;
122 SetInputFileHandle (FILE *fh, bool tranfer_ownership);
125 SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
128 SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
131 SaveInputTerminalState();
134 RestoreInputTerminalState();
137 GetAsyncOutputStream ();
140 GetAsyncErrorStream ();
143 GetCommandInterpreter ()
145 assert (m_command_interpreter_ap.get());
146 return *m_command_interpreter_ap;
155 // This returns the Debugger's scratch source manager. It won't be able to look up files in debug
156 // information, but it can look up files by absolute path and display them to you.
157 // To get the target's source manager, call GetSourceManager on the target instead.
166 return m_target_list.GetSelectedTarget ();
170 GetSelectedExecutionContext();
171 //------------------------------------------------------------------
172 /// Get accessor for the target list.
174 /// The target list is part of the global debugger object. This
175 /// the single debugger shared instance to control where targets
176 /// get created and to allow for tracking and searching for targets
177 /// based on certain criteria.
180 /// A global shared target list.
181 //------------------------------------------------------------------
185 return m_target_list;
191 return m_platform_list;
195 DispatchInputInterrupt ();
198 DispatchInputEndOfFile ();
200 //------------------------------------------------------------------
201 // If any of the streams are not set, set them to the in/out/err
202 // stream of the top most input reader to ensure they at least have
204 //------------------------------------------------------------------
206 AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in,
207 lldb::StreamFileSP &out,
208 lldb::StreamFileSP &err);
211 PushIOHandler (const lldb::IOHandlerSP& reader_sp);
214 PopIOHandler (const lldb::IOHandlerSP& reader_sp);
216 // Synchronously run an input reader until it is done
218 RunIOHandler (const lldb::IOHandlerSP& reader_sp);
221 IsTopIOHandler (const lldb::IOHandlerSP& reader_sp);
224 GetTopIOHandlerControlSequence(char ch);
230 RefreshTopIOHandler();
232 static lldb::DebuggerSP
233 FindDebuggerWithID (lldb::user_id_t id);
235 static lldb::DebuggerSP
236 FindDebuggerWithInstanceName (const ConstString &instance_name);
241 static lldb::DebuggerSP
242 GetDebuggerAtIndex (size_t index);
245 FormatPrompt (const char *format,
246 const SymbolContext *sc,
247 const ExecutionContext *exe_ctx,
250 ValueObject* valobj = NULL);
257 TestDebuggerRefCount ();
260 GetCloseInputOnEOF () const;
263 SetCloseInputOnEOF (bool b);
266 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
269 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
272 //----------------------------------------------------------------------
273 // Properties Functions
274 //----------------------------------------------------------------------
275 enum StopDisassemblyType
277 eStopDisassemblyTypeNever = 0,
278 eStopDisassemblyTypeNoSource,
279 eStopDisassemblyTypeAlways
283 SetPropertyValue (const ExecutionContext *exe_ctx,
284 VarSetOperationType op,
285 const char *property_path,
289 GetAutoConfirm () const;
292 GetFrameFormat() const;
295 GetThreadFormat() const;
298 GetScriptLanguage() const;
301 SetScriptLanguage (lldb::ScriptLanguage script_lang);
304 GetTerminalWidth () const;
307 SetTerminalWidth (uint32_t term_width);
313 SetPrompt(const char *p);
316 GetUseExternalEditor () const;
319 SetUseExternalEditor (bool use_external_editor_p);
322 GetUseColor () const;
325 SetUseColor (bool use_color);
328 GetStopSourceLineCount (bool before) const;
331 GetStopDisassemblyDisplay () const;
334 GetDisassemblyLineCount () const;
337 GetAutoOneLineSummaries () const;
340 GetNotifyVoid () const;
346 return m_instance_name;
350 LoadPlugin (const FileSpec& spec, Error& error);
356 IsForwardingEvents ();
359 EnableForwardEvents (const lldb::ListenerSP &listener_sp);
362 CancelForwardEvents (const lldb::ListenerSP &listener_sp);
365 IsHandlingEvents () const
367 return IS_VALID_LLDB_HOST_THREAD(m_event_handler_thread);
372 friend class CommandInterpreter;
375 StartEventHandlerThread();
378 StopEventHandlerThread();
380 static lldb::thread_result_t
381 EventHandlerThread (lldb::thread_arg_t arg);
384 StartIOHandlerThread();
387 StopIOHandlerThread();
389 static lldb::thread_result_t
390 IOHandlerThread (lldb::thread_arg_t arg);
393 DefaultEventHandler();
396 HandleBreakpointEvent (const lldb::EventSP &event_sp);
399 HandleProcessEvent (const lldb::EventSP &event_sp);
402 HandleThreadEvent (const lldb::EventSP &event_sp);
405 GetProcessSTDOUT (Process *process, Stream *stream);
408 GetProcessSTDERR (Process *process, Stream *stream);
410 SourceManager::SourceFileCache &
411 GetSourceFileCache ()
413 return m_source_file_cache;
415 lldb::StreamFileSP m_input_file_sp;
416 lldb::StreamFileSP m_output_file_sp;
417 lldb::StreamFileSP m_error_file_sp;
418 TerminalState m_terminal_state;
419 TargetList m_target_list;
420 PlatformList m_platform_list;
422 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets.
423 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
424 // source file cache.
425 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
427 IOHandlerStack m_input_reader_stack;
428 typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
429 LogStreamMap m_log_streams;
430 lldb::StreamSP m_log_callback_stream_sp;
431 ConstString m_instance_name;
432 static LoadPluginCallbackType g_load_plugin_callback;
433 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
434 LoadedPluginsList m_loaded_plugins;
435 lldb::thread_t m_event_handler_thread;
436 lldb::thread_t m_io_handler_thread;
437 lldb::ListenerSP m_forward_listener_sp;
439 InstanceInitialize ();
443 // Use Debugger::CreateInstance() to get a shared pointer to a new
445 Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
447 DISALLOW_COPY_AND_ASSIGN (Debugger);
451 } // namespace lldb_private
453 #endif // #if defined(__cplusplus)
454 #endif // liblldb_Debugger_h_