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/HostThread.h"
29 #include "lldb/Host/Terminal.h"
30 #include "lldb/Interpreter/OptionValueProperties.h"
31 #include "lldb/Target/ExecutionContext.h"
32 #include "lldb/Target/Platform.h"
33 #include "lldb/Target/TargetList.h"
43 namespace lldb_private {
45 //----------------------------------------------------------------------
46 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
47 /// @brief A class to manage flag bits.
49 /// Provides a global root objects for the debugger core.
50 //----------------------------------------------------------------------
54 public std::enable_shared_from_this<Debugger>,
57 public BroadcasterManager
59 friend class SourceManager; // For GetSourceFileCache.
63 typedef llvm::sys::DynamicLibrary (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp,
67 static lldb::DebuggerSP
68 CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL);
71 FindTargetWithProcessID (lldb::pid_t pid);
74 FindTargetWithProcess (Process *process);
77 Initialize (LoadPluginCallbackType load_plugin_callback);
83 SettingsInitialize ();
89 Destroy (lldb::DebuggerSP &debugger_sp);
100 SetAsyncExecution (bool async);
105 return m_input_file_sp;
111 return m_output_file_sp;
117 return m_error_file_sp;
123 SetInputFileHandle (FILE *fh, bool tranfer_ownership);
126 SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
129 SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
132 SaveInputTerminalState();
135 RestoreInputTerminalState();
138 GetAsyncOutputStream ();
141 GetAsyncErrorStream ();
144 GetCommandInterpreter ()
146 assert (m_command_interpreter_ap.get());
147 return *m_command_interpreter_ap;
156 // This returns the Debugger's scratch source manager. It won't be able to look up files in debug
157 // information, but it can look up files by absolute path and display them to you.
158 // To get the target's source manager, call GetSourceManager on the target instead.
167 return m_target_list.GetSelectedTarget ();
171 GetSelectedExecutionContext();
172 //------------------------------------------------------------------
173 /// Get accessor for the target list.
175 /// The target list is part of the global debugger object. This
176 /// the single debugger shared instance to control where targets
177 /// get created and to allow for tracking and searching for targets
178 /// based on certain criteria.
181 /// A global shared target list.
182 //------------------------------------------------------------------
186 return m_target_list;
192 return m_platform_list;
196 DispatchInputInterrupt ();
199 DispatchInputEndOfFile ();
201 //------------------------------------------------------------------
202 // If any of the streams are not set, set them to the in/out/err
203 // stream of the top most input reader to ensure they at least have
205 //------------------------------------------------------------------
207 AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in,
208 lldb::StreamFileSP &out,
209 lldb::StreamFileSP &err);
212 PushIOHandler (const lldb::IOHandlerSP& reader_sp);
215 PopIOHandler (const lldb::IOHandlerSP& reader_sp);
217 // Synchronously run an input reader until it is done
219 RunIOHandler (const lldb::IOHandlerSP& reader_sp);
222 IsTopIOHandler (const lldb::IOHandlerSP& reader_sp);
225 GetTopIOHandlerControlSequence(char ch);
231 RefreshTopIOHandler();
233 static lldb::DebuggerSP
234 FindDebuggerWithID (lldb::user_id_t id);
236 static lldb::DebuggerSP
237 FindDebuggerWithInstanceName (const ConstString &instance_name);
242 static lldb::DebuggerSP
243 GetDebuggerAtIndex (size_t index);
246 FormatPrompt (const char *format,
247 const SymbolContext *sc,
248 const ExecutionContext *exe_ctx,
251 ValueObject* valobj = NULL);
254 FormatDisassemblerAddress (const char *format,
255 const SymbolContext *sc,
256 const SymbolContext *prev_sc,
257 const ExecutionContext *exe_ctx,
265 TestDebuggerRefCount ();
268 GetCloseInputOnEOF () const;
271 SetCloseInputOnEOF (bool b);
274 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
277 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
280 //----------------------------------------------------------------------
281 // Properties Functions
282 //----------------------------------------------------------------------
283 enum StopDisassemblyType
285 eStopDisassemblyTypeNever = 0,
286 eStopDisassemblyTypeNoSource,
287 eStopDisassemblyTypeAlways
291 SetPropertyValue (const ExecutionContext *exe_ctx,
292 VarSetOperationType op,
293 const char *property_path,
297 GetAutoConfirm () const;
300 GetDisassemblyFormat() const;
303 GetFrameFormat() const;
306 GetThreadFormat() const;
309 GetScriptLanguage() const;
312 SetScriptLanguage (lldb::ScriptLanguage script_lang);
315 GetTerminalWidth () const;
318 SetTerminalWidth (uint32_t term_width);
324 SetPrompt(const char *p);
327 GetUseExternalEditor () const;
330 SetUseExternalEditor (bool use_external_editor_p);
333 GetUseColor () const;
336 SetUseColor (bool use_color);
339 GetStopSourceLineCount (bool before) const;
342 GetStopDisassemblyDisplay () const;
345 GetDisassemblyLineCount () const;
348 GetAutoOneLineSummaries () const;
351 GetEscapeNonPrintables () const;
354 GetNotifyVoid () const;
360 return m_instance_name;
364 LoadPlugin (const FileSpec& spec, Error& error);
370 IsForwardingEvents ();
373 EnableForwardEvents (const lldb::ListenerSP &listener_sp);
376 CancelForwardEvents (const lldb::ListenerSP &listener_sp);
379 IsHandlingEvents () const
381 return m_event_handler_thread.IsJoinable();
384 // This is for use in the command interpreter, when you either want the selected target, or if no target
385 // is present you want to prime the dummy target with entities that will be copied over to new targets.
386 Target *GetSelectedOrDummyTarget(bool prefer_dummy = false);
387 Target *GetDummyTarget();
391 friend class CommandInterpreter;
394 StartEventHandlerThread();
397 StopEventHandlerThread();
399 static lldb::thread_result_t
400 EventHandlerThread (lldb::thread_arg_t arg);
403 StartIOHandlerThread();
406 StopIOHandlerThread();
408 static lldb::thread_result_t
409 IOHandlerThread (lldb::thread_arg_t arg);
412 DefaultEventHandler();
415 HandleBreakpointEvent (const lldb::EventSP &event_sp);
418 HandleProcessEvent (const lldb::EventSP &event_sp);
421 HandleThreadEvent (const lldb::EventSP &event_sp);
424 GetProcessSTDOUT (Process *process, Stream *stream);
427 GetProcessSTDERR (Process *process, Stream *stream);
429 SourceManager::SourceFileCache &
430 GetSourceFileCache ()
432 return m_source_file_cache;
436 InstanceInitialize ();
438 lldb::StreamFileSP m_input_file_sp;
439 lldb::StreamFileSP m_output_file_sp;
440 lldb::StreamFileSP m_error_file_sp;
441 TerminalState m_terminal_state;
442 TargetList m_target_list;
444 PlatformList m_platform_list;
446 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets.
447 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
448 // source file cache.
449 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
451 IOHandlerStack m_input_reader_stack;
452 typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
453 LogStreamMap m_log_streams;
454 lldb::StreamSP m_log_callback_stream_sp;
455 ConstString m_instance_name;
456 static LoadPluginCallbackType g_load_plugin_callback;
457 typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
458 LoadedPluginsList m_loaded_plugins;
459 HostThread m_event_handler_thread;
460 HostThread m_io_handler_thread;
461 Broadcaster m_sync_broadcaster;
462 lldb::ListenerSP m_forward_listener_sp;
464 //----------------------------------------------------------------------
465 // Events for m_sync_broadcaster
466 //----------------------------------------------------------------------
469 eBroadcastBitEventThreadIsListening = (1 << 0),
474 // Use Debugger::CreateInstance() to get a shared pointer to a new
476 Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
478 DISALLOW_COPY_AND_ASSIGN (Debugger);
482 } // namespace lldb_private
484 #endif // #if defined(__cplusplus)
485 #endif // liblldb_Debugger_h_