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_
21 // Other libraries and framework includes
23 #include "lldb/lldb-public.h"
24 #include "lldb/Core/Broadcaster.h"
25 #include "lldb/Core/FormatEntity.h"
26 #include "lldb/Core/IOHandler.h"
27 #include "lldb/Core/Listener.h"
28 #include "lldb/Core/SourceManager.h"
29 #include "lldb/Core/UserID.h"
30 #include "lldb/Core/UserSettingsController.h"
31 #include "lldb/Host/HostThread.h"
32 #include "lldb/Host/Terminal.h"
33 #include "lldb/Target/Platform.h"
34 #include "lldb/Target/TargetList.h"
44 namespace lldb_private {
46 //----------------------------------------------------------------------
47 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
48 /// @brief A class to manage flag bits.
50 /// Provides a global root objects for the debugger core.
51 //----------------------------------------------------------------------
54 public std::enable_shared_from_this<Debugger>,
57 public BroadcasterManager
59 friend class SourceManager; // For GetSourceFileCache.
64 static lldb::DebuggerSP
65 CreateInstance(lldb::LogOutputCallback log_callback = nullptr, void *baton = nullptr);
68 FindTargetWithProcessID (lldb::pid_t pid);
71 FindTargetWithProcess (Process *process);
74 Initialize(LoadPluginCallbackType load_plugin_callback);
80 SettingsInitialize ();
86 Destroy (lldb::DebuggerSP &debugger_sp);
88 static lldb::DebuggerSP
89 FindDebuggerWithID(lldb::user_id_t id);
91 static lldb::DebuggerSP
92 FindDebuggerWithInstanceName(const ConstString &instance_name);
97 static lldb::DebuggerSP
98 GetDebuggerAtIndex(size_t index);
101 FormatDisassemblerAddress(const FormatEntity::Entry *format,
102 const SymbolContext *sc,
103 const SymbolContext *prev_sc,
104 const ExecutionContext *exe_ctx,
111 GetAsyncExecution ();
114 SetAsyncExecution (bool async);
119 return m_input_file_sp;
125 return m_output_file_sp;
131 return m_error_file_sp;
135 SetInputFileHandle (FILE *fh, bool tranfer_ownership);
138 SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
141 SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
144 SaveInputTerminalState();
147 RestoreInputTerminalState();
150 GetAsyncOutputStream ();
153 GetAsyncErrorStream ();
156 GetCommandInterpreter ()
158 assert (m_command_interpreter_ap.get());
159 return *m_command_interpreter_ap;
168 // This returns the Debugger's scratch source manager. It won't be able to look up files in debug
169 // information, but it can look up files by absolute path and display them to you.
170 // To get the target's source manager, call GetSourceManager on the target instead.
177 return m_target_list.GetSelectedTarget ();
181 GetSelectedExecutionContext();
182 //------------------------------------------------------------------
183 /// Get accessor for the target list.
185 /// The target list is part of the global debugger object. This
186 /// the single debugger shared instance to control where targets
187 /// get created and to allow for tracking and searching for targets
188 /// based on certain criteria.
191 /// A global shared target list.
192 //------------------------------------------------------------------
196 return m_target_list;
202 return m_platform_list;
206 DispatchInputInterrupt ();
209 DispatchInputEndOfFile ();
211 //------------------------------------------------------------------
212 // If any of the streams are not set, set them to the in/out/err
213 // stream of the top most input reader to ensure they at least have
215 //------------------------------------------------------------------
217 AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in,
218 lldb::StreamFileSP &out,
219 lldb::StreamFileSP &err);
222 PushIOHandler (const lldb::IOHandlerSP& reader_sp);
225 PopIOHandler (const lldb::IOHandlerSP& reader_sp);
227 // Synchronously run an input reader until it is done
229 RunIOHandler (const lldb::IOHandlerSP& reader_sp);
232 IsTopIOHandler (const lldb::IOHandlerSP& reader_sp);
235 CheckTopIOHandlerTypes (IOHandler::Type top_type,
236 IOHandler::Type second_top_type);
239 PrintAsync (const char *s, size_t len, bool is_stdout);
242 GetTopIOHandlerControlSequence(char ch);
245 GetIOHandlerCommandPrefix();
248 GetIOHandlerHelpPrologue();
254 GetCloseInputOnEOF () const;
257 SetCloseInputOnEOF (bool b);
260 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
263 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
265 //----------------------------------------------------------------------
266 // Properties Functions
267 //----------------------------------------------------------------------
268 enum StopDisassemblyType
270 eStopDisassemblyTypeNever = 0,
271 eStopDisassemblyTypeNoDebugInfo,
272 eStopDisassemblyTypeNoSource,
273 eStopDisassemblyTypeAlways
277 SetPropertyValue(const ExecutionContext *exe_ctx,
278 VarSetOperationType op,
279 const char *property_path,
280 const char *value) override;
283 GetAutoConfirm () const;
285 const FormatEntity::Entry *
286 GetDisassemblyFormat() const;
288 const FormatEntity::Entry *
289 GetFrameFormat() const;
291 const FormatEntity::Entry *
292 GetThreadFormat() const;
295 GetScriptLanguage() const;
298 SetScriptLanguage (lldb::ScriptLanguage script_lang);
301 GetTerminalWidth () const;
304 SetTerminalWidth (uint32_t term_width);
310 SetPrompt(const char *p);
313 GetUseExternalEditor () const;
316 SetUseExternalEditor (bool use_external_editor_p);
319 GetUseColor () const;
322 SetUseColor (bool use_color);
325 GetStopSourceLineCount (bool before) const;
328 GetStopDisassemblyDisplay () const;
331 GetDisassemblyLineCount () const;
334 GetAutoOneLineSummaries () const;
337 GetAutoIndent () const;
340 SetAutoIndent (bool b);
343 GetPrintDecls () const;
346 SetPrintDecls (bool b);
352 SetTabSize (uint32_t tab_size);
355 GetEscapeNonPrintables () const;
358 GetNotifyVoid () const;
363 return m_instance_name;
367 LoadPlugin (const FileSpec& spec, Error& error);
373 IsForwardingEvents ();
376 EnableForwardEvents (const lldb::ListenerSP &listener_sp);
379 CancelForwardEvents (const lldb::ListenerSP &listener_sp);
382 IsHandlingEvents () const
384 return m_event_handler_thread.IsJoinable();
388 RunREPL (lldb::LanguageType language, const char *repl_options);
390 // This is for use in the command interpreter, when you either want the selected target, or if no target
391 // is present you want to prime the dummy target with entities that will be copied over to new targets.
392 Target *GetSelectedOrDummyTarget(bool prefer_dummy = false);
393 Target *GetDummyTarget();
396 friend class CommandInterpreter;
400 StartEventHandlerThread();
403 StopEventHandlerThread();
405 static lldb::thread_result_t
406 EventHandlerThread (lldb::thread_arg_t arg);
409 HasIOHandlerThread();
412 StartIOHandlerThread();
415 StopIOHandlerThread();
418 JoinIOHandlerThread();
420 static lldb::thread_result_t
421 IOHandlerThread (lldb::thread_arg_t arg);
424 DefaultEventHandler();
427 HandleBreakpointEvent (const lldb::EventSP &event_sp);
430 HandleProcessEvent (const lldb::EventSP &event_sp);
433 HandleThreadEvent (const lldb::EventSP &event_sp);
436 GetProcessSTDOUT (Process *process, Stream *stream);
439 GetProcessSTDERR (Process *process, Stream *stream);
441 SourceManager::SourceFileCache &
442 GetSourceFileCache ()
444 return m_source_file_cache;
448 InstanceInitialize ();
450 lldb::StreamFileSP m_input_file_sp;
451 lldb::StreamFileSP m_output_file_sp;
452 lldb::StreamFileSP m_error_file_sp;
453 TerminalState m_terminal_state;
454 TargetList m_target_list;
456 PlatformList m_platform_list;
458 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets.
459 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
460 // source file cache.
461 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
463 IOHandlerStack m_input_reader_stack;
464 typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
465 LogStreamMap m_log_streams;
466 lldb::StreamSP m_log_callback_stream_sp;
467 ConstString m_instance_name;
468 static LoadPluginCallbackType g_load_plugin_callback;
469 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
470 LoadedPluginsList m_loaded_plugins;
471 HostThread m_event_handler_thread;
472 HostThread m_io_handler_thread;
473 Broadcaster m_sync_broadcaster;
474 lldb::ListenerSP m_forward_listener_sp;
476 //----------------------------------------------------------------------
477 // Events for m_sync_broadcaster
478 //----------------------------------------------------------------------
481 eBroadcastBitEventThreadIsListening = (1 << 0),
485 // Use Debugger::CreateInstance() to get a shared pointer to a new
487 Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
489 DISALLOW_COPY_AND_ASSIGN (Debugger);
492 } // namespace lldb_private
494 #endif // liblldb_Debugger_h_