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"
34 namespace lldb_private {
36 //----------------------------------------------------------------------
37 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
38 /// @brief A class to manage flag bits.
40 /// Provides a global root objects for the debugger core.
41 //----------------------------------------------------------------------
45 public std::enable_shared_from_this<Debugger>,
48 public BroadcasterManager
50 friend class SourceManager; // For GetSourceFileCache.
54 typedef lldb::DynamicLibrarySP (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp,
58 static lldb::DebuggerSP
59 CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL);
62 FindTargetWithProcessID (lldb::pid_t pid);
65 FindTargetWithProcess (Process *process);
68 Initialize (LoadPluginCallbackType load_plugin_callback);
74 SettingsInitialize ();
80 Destroy (lldb::DebuggerSP &debugger_sp);
91 SetAsyncExecution (bool async);
96 return m_input_file_sp;
102 return m_output_file_sp;
108 return m_error_file_sp;
114 SetInputFileHandle (FILE *fh, bool tranfer_ownership);
117 SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
120 SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
123 SaveInputTerminalState();
126 RestoreInputTerminalState();
129 GetAsyncOutputStream ();
132 GetAsyncErrorStream ();
135 GetCommandInterpreter ()
137 assert (m_command_interpreter_ap.get());
138 return *m_command_interpreter_ap;
147 // This returns the Debugger's scratch source manager. It won't be able to look up files in debug
148 // information, but it can look up files by absolute path and display them to you.
149 // To get the target's source manager, call GetSourceManager on the target instead.
158 return m_target_list.GetSelectedTarget ();
162 GetSelectedExecutionContext();
163 //------------------------------------------------------------------
164 /// Get accessor for the target list.
166 /// The target list is part of the global debugger object. This
167 /// the single debugger shared instance to control where targets
168 /// get created and to allow for tracking and searching for targets
169 /// based on certain criteria.
172 /// A global shared target list.
173 //------------------------------------------------------------------
177 return m_target_list;
183 return m_platform_list;
187 DispatchInputInterrupt ();
190 DispatchInputEndOfFile ();
192 //------------------------------------------------------------------
193 // If any of the streams are not set, set them to the in/out/err
194 // stream of the top most input reader to ensure they at least have
196 //------------------------------------------------------------------
198 AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in,
199 lldb::StreamFileSP &out,
200 lldb::StreamFileSP &err);
203 PushIOHandler (const lldb::IOHandlerSP& reader_sp);
206 PopIOHandler (const lldb::IOHandlerSP& reader_sp);
208 // Synchronously run an input reader until it is done
210 RunIOHandler (const lldb::IOHandlerSP& reader_sp);
213 IsTopIOHandler (const lldb::IOHandlerSP& reader_sp);
216 GetTopIOHandlerControlSequence(char ch);
222 RefreshTopIOHandler();
224 static lldb::DebuggerSP
225 FindDebuggerWithID (lldb::user_id_t id);
227 static lldb::DebuggerSP
228 FindDebuggerWithInstanceName (const ConstString &instance_name);
233 static lldb::DebuggerSP
234 GetDebuggerAtIndex (size_t index);
237 FormatPrompt (const char *format,
238 const SymbolContext *sc,
239 const ExecutionContext *exe_ctx,
242 ValueObject* valobj = NULL);
249 TestDebuggerRefCount ();
252 GetCloseInputOnEOF () const;
255 SetCloseInputOnEOF (bool b);
258 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
261 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
264 //----------------------------------------------------------------------
265 // Properties Functions
266 //----------------------------------------------------------------------
267 enum StopDisassemblyType
269 eStopDisassemblyTypeNever = 0,
270 eStopDisassemblyTypeNoSource,
271 eStopDisassemblyTypeAlways
275 SetPropertyValue (const ExecutionContext *exe_ctx,
276 VarSetOperationType op,
277 const char *property_path,
281 GetAutoConfirm () const;
284 GetFrameFormat() const;
287 GetThreadFormat() const;
290 GetScriptLanguage() const;
293 SetScriptLanguage (lldb::ScriptLanguage script_lang);
296 GetTerminalWidth () const;
299 SetTerminalWidth (uint32_t term_width);
305 SetPrompt(const char *p);
308 GetUseExternalEditor () const;
311 SetUseExternalEditor (bool use_external_editor_p);
314 GetUseColor () const;
317 SetUseColor (bool use_color);
320 GetStopSourceLineCount (bool before) const;
323 GetStopDisassemblyDisplay () const;
326 GetDisassemblyLineCount () const;
329 GetAutoOneLineSummaries () const;
332 GetNotifyVoid () const;
338 return m_instance_name;
342 LoadPlugin (const FileSpec& spec, Error& error);
348 IsForwardingEvents ();
351 EnableForwardEvents (const lldb::ListenerSP &listener_sp);
354 CancelForwardEvents (const lldb::ListenerSP &listener_sp);
357 friend class CommandInterpreter;
360 StartEventHandlerThread();
363 StopEventHandlerThread();
365 static lldb::thread_result_t
366 EventHandlerThread (lldb::thread_arg_t arg);
369 StartIOHandlerThread();
372 StopIOHandlerThread();
374 static lldb::thread_result_t
375 IOHandlerThread (lldb::thread_arg_t arg);
378 DefaultEventHandler();
381 HandleBreakpointEvent (const lldb::EventSP &event_sp);
384 HandleProcessEvent (const lldb::EventSP &event_sp);
387 HandleThreadEvent (const lldb::EventSP &event_sp);
390 GetProcessSTDOUT (Process *process, Stream *stream);
393 GetProcessSTDERR (Process *process, Stream *stream);
395 SourceManager::SourceFileCache &
396 GetSourceFileCache ()
398 return m_source_file_cache;
400 lldb::StreamFileSP m_input_file_sp;
401 lldb::StreamFileSP m_output_file_sp;
402 lldb::StreamFileSP m_error_file_sp;
403 TerminalState m_terminal_state;
404 TargetList m_target_list;
405 PlatformList m_platform_list;
407 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets.
408 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
409 // source file cache.
410 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
412 IOHandlerStack m_input_reader_stack;
413 typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
414 LogStreamMap m_log_streams;
415 lldb::StreamSP m_log_callback_stream_sp;
416 ConstString m_instance_name;
417 static LoadPluginCallbackType g_load_plugin_callback;
418 typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
419 LoadedPluginsList m_loaded_plugins;
420 lldb::thread_t m_event_handler_thread;
421 lldb::thread_t m_io_handler_thread;
422 lldb::ListenerSP m_forward_listener_sp;
423 bool m_event_handler_thread_alive;
425 InstanceInitialize ();
429 // Use Debugger::CreateInstance() to get a shared pointer to a new
431 Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
433 DISALLOW_COPY_AND_ASSIGN (Debugger);
437 } // namespace lldb_private
439 #endif // #if defined(__cplusplus)
440 #endif // liblldb_Debugger_h_