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)
17 #include "lldb/lldb-public.h"
18 #include "lldb/Core/Broadcaster.h"
19 #include "lldb/Core/FormatEntity.h"
20 #include "lldb/Core/IOHandler.h"
21 #include "lldb/Core/Listener.h"
22 #include "lldb/Core/SourceManager.h"
23 #include "lldb/Core/UserID.h"
24 #include "lldb/Core/UserSettingsController.h"
25 #include "lldb/Host/HostThread.h"
26 #include "lldb/Host/Terminal.h"
27 #include "lldb/Target/Platform.h"
28 #include "lldb/Target/TargetList.h"
38 namespace lldb_private {
40 //----------------------------------------------------------------------
41 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
42 /// @brief A class to manage flag bits.
44 /// Provides a global root objects for the debugger core.
45 //----------------------------------------------------------------------
49 public std::enable_shared_from_this<Debugger>,
52 public BroadcasterManager
54 friend class SourceManager; // For GetSourceFileCache.
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.
156 return m_target_list.GetSelectedTarget ();
160 GetSelectedExecutionContext();
161 //------------------------------------------------------------------
162 /// Get accessor for the target list.
164 /// The target list is part of the global debugger object. This
165 /// the single debugger shared instance to control where targets
166 /// get created and to allow for tracking and searching for targets
167 /// based on certain criteria.
170 /// A global shared target list.
171 //------------------------------------------------------------------
175 return m_target_list;
181 return m_platform_list;
185 DispatchInputInterrupt ();
188 DispatchInputEndOfFile ();
190 //------------------------------------------------------------------
191 // If any of the streams are not set, set them to the in/out/err
192 // stream of the top most input reader to ensure they at least have
194 //------------------------------------------------------------------
196 AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in,
197 lldb::StreamFileSP &out,
198 lldb::StreamFileSP &err);
201 PushIOHandler (const lldb::IOHandlerSP& reader_sp);
204 PopIOHandler (const lldb::IOHandlerSP& reader_sp);
206 // Synchronously run an input reader until it is done
208 RunIOHandler (const lldb::IOHandlerSP& reader_sp);
211 IsTopIOHandler (const lldb::IOHandlerSP& reader_sp);
214 PrintAsync (const char *s, size_t len, bool is_stdout);
217 GetTopIOHandlerControlSequence(char ch);
220 GetIOHandlerCommandPrefix();
223 GetIOHandlerHelpPrologue();
225 static lldb::DebuggerSP
226 FindDebuggerWithID (lldb::user_id_t id);
228 static lldb::DebuggerSP
229 FindDebuggerWithInstanceName (const ConstString &instance_name);
234 static lldb::DebuggerSP
235 GetDebuggerAtIndex (size_t index);
238 FormatDisassemblerAddress (const FormatEntity::Entry *format,
239 const SymbolContext *sc,
240 const SymbolContext *prev_sc,
241 const ExecutionContext *exe_ctx,
249 GetCloseInputOnEOF () const;
252 SetCloseInputOnEOF (bool b);
255 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
258 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
261 //----------------------------------------------------------------------
262 // Properties Functions
263 //----------------------------------------------------------------------
264 enum StopDisassemblyType
266 eStopDisassemblyTypeNever = 0,
267 eStopDisassemblyTypeNoSource,
268 eStopDisassemblyTypeAlways
272 SetPropertyValue (const ExecutionContext *exe_ctx,
273 VarSetOperationType op,
274 const char *property_path,
278 GetAutoConfirm () const;
280 const FormatEntity::Entry *
281 GetDisassemblyFormat() const;
283 const FormatEntity::Entry *
284 GetFrameFormat() const;
286 const FormatEntity::Entry *
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 GetEscapeNonPrintables () const;
335 GetNotifyVoid () const;
340 return m_instance_name;
344 LoadPlugin (const FileSpec& spec, Error& error);
350 IsForwardingEvents ();
353 EnableForwardEvents (const lldb::ListenerSP &listener_sp);
356 CancelForwardEvents (const lldb::ListenerSP &listener_sp);
359 IsHandlingEvents () const
361 return m_event_handler_thread.IsJoinable();
364 // This is for use in the command interpreter, when you either want the selected target, or if no target
365 // is present you want to prime the dummy target with entities that will be copied over to new targets.
366 Target *GetSelectedOrDummyTarget(bool prefer_dummy = false);
367 Target *GetDummyTarget();
371 friend class CommandInterpreter;
374 StartEventHandlerThread();
377 StopEventHandlerThread();
379 static lldb::thread_result_t
380 EventHandlerThread (lldb::thread_arg_t arg);
383 StartIOHandlerThread();
386 StopIOHandlerThread();
388 static lldb::thread_result_t
389 IOHandlerThread (lldb::thread_arg_t arg);
392 DefaultEventHandler();
395 HandleBreakpointEvent (const lldb::EventSP &event_sp);
398 HandleProcessEvent (const lldb::EventSP &event_sp);
401 HandleThreadEvent (const lldb::EventSP &event_sp);
404 GetProcessSTDOUT (Process *process, Stream *stream);
407 GetProcessSTDERR (Process *process, Stream *stream);
409 SourceManager::SourceFileCache &
410 GetSourceFileCache ()
412 return m_source_file_cache;
416 InstanceInitialize ();
418 lldb::StreamFileSP m_input_file_sp;
419 lldb::StreamFileSP m_output_file_sp;
420 lldb::StreamFileSP m_error_file_sp;
421 TerminalState m_terminal_state;
422 TargetList m_target_list;
424 PlatformList m_platform_list;
426 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets.
427 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
428 // source file cache.
429 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
431 IOHandlerStack m_input_reader_stack;
432 typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
433 LogStreamMap m_log_streams;
434 lldb::StreamSP m_log_callback_stream_sp;
435 ConstString m_instance_name;
436 static LoadPluginCallbackType g_load_plugin_callback;
437 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
438 LoadedPluginsList m_loaded_plugins;
439 HostThread m_event_handler_thread;
440 HostThread m_io_handler_thread;
441 Broadcaster m_sync_broadcaster;
442 lldb::ListenerSP m_forward_listener_sp;
444 //----------------------------------------------------------------------
445 // Events for m_sync_broadcaster
446 //----------------------------------------------------------------------
449 eBroadcastBitEventThreadIsListening = (1 << 0),
454 // Use Debugger::CreateInstance() to get a shared pointer to a new
456 Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
458 DISALLOW_COPY_AND_ASSIGN (Debugger);
462 } // namespace lldb_private
464 #endif // #if defined(__cplusplus)
465 #endif // liblldb_Debugger_h_