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)
20 #include "lldb/lldb-public.h"
22 #include "lldb/API/SBDefines.h"
24 #include "lldb/Core/Broadcaster.h"
25 #include "lldb/Core/Communication.h"
26 #include "lldb/Core/InputReaderStack.h"
27 #include "lldb/Core/Listener.h"
28 #include "lldb/Core/StreamFile.h"
29 #include "lldb/Core/SourceManager.h"
30 #include "lldb/Core/UserID.h"
31 #include "lldb/Core/UserSettingsController.h"
32 #include "lldb/DataFormatters/FormatManager.h"
33 #include "lldb/Host/Terminal.h"
34 #include "lldb/Interpreter/OptionValueProperties.h"
35 #include "lldb/Target/ExecutionContext.h"
36 #include "lldb/Target/Platform.h"
37 #include "lldb/Target/TargetList.h"
39 namespace lldb_private {
41 //----------------------------------------------------------------------
42 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
43 /// @brief A class to manage flag bits.
45 /// Provides a global root objects for the debugger core.
46 //----------------------------------------------------------------------
50 public std::enable_shared_from_this<Debugger>,
53 public BroadcasterManager
55 friend class SourceManager; // For GetSourceFileCache.
59 static lldb::DebuggerSP
60 CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL);
63 FindTargetWithProcessID (lldb::pid_t pid);
66 FindTargetWithProcess (Process *process);
75 SettingsInitialize ();
81 Destroy (lldb::DebuggerSP &debugger_sp);
92 SetAsyncExecution (bool async);
97 return m_input_file.GetFile();
103 return m_output_file.GetFile();
109 return m_error_file.GetFile();
113 SetInputFileHandle (FILE *fh, bool tranfer_ownership);
116 SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
119 SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
122 SaveInputTerminalState();
125 RestoreInputTerminalState();
130 return m_output_file;
140 GetAsyncOutputStream ();
143 GetAsyncErrorStream ();
146 GetCommandInterpreter ()
148 assert (m_command_interpreter_ap.get());
149 return *m_command_interpreter_ap;
158 // This returns the Debugger's scratch source manager. It won't be able to look up files in debug
159 // information, but it can look up files by absolute path and display them to you.
160 // To get the target's source manager, call GetSourceManager on the target instead.
169 return m_target_list.GetSelectedTarget ();
173 GetSelectedExecutionContext();
174 //------------------------------------------------------------------
175 /// Get accessor for the target list.
177 /// The target list is part of the global debugger object. This
178 /// the single debugger shared instance to control where targets
179 /// get created and to allow for tracking and searching for targets
180 /// based on certain criteria.
183 /// A global shared target list.
184 //------------------------------------------------------------------
188 return m_target_list;
194 return m_platform_list;
198 DispatchInputInterrupt ();
201 DispatchInputEndOfFile ();
204 DispatchInput (const char *bytes, size_t bytes_len);
207 WriteToDefaultReader (const char *bytes, size_t bytes_len);
210 PushInputReader (const lldb::InputReaderSP& reader_sp);
213 PopInputReader (const lldb::InputReaderSP& reader_sp);
216 NotifyTopInputReader (lldb::InputReaderAction notification);
219 InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp);
221 static lldb::DebuggerSP
222 FindDebuggerWithID (lldb::user_id_t id);
224 static lldb::DebuggerSP
225 FindDebuggerWithInstanceName (const ConstString &instance_name);
230 static lldb::DebuggerSP
231 GetDebuggerAtIndex (size_t index);
234 FormatPrompt (const char *format,
235 const SymbolContext *sc,
236 const ExecutionContext *exe_ctx,
239 ValueObject* valobj = NULL);
243 CleanUpInputReaders ();
246 TestDebuggerRefCount ();
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;
281 GetFrameFormat() const;
284 GetThreadFormat() const;
287 GetScriptLanguage() const;
290 SetScriptLanguage (lldb::ScriptLanguage script_lang);
293 GetTerminalWidth () const;
296 SetTerminalWidth (uint32_t term_width);
302 SetPrompt(const char *p);
305 GetUseExternalEditor () const;
308 SetUseExternalEditor (bool use_external_editor_p);
311 GetUseColor () const;
314 SetUseColor (bool use_color);
317 GetStopSourceLineCount (bool before) const;
320 GetStopDisassemblyDisplay () const;
323 GetDisassemblyLineCount () const;
326 GetNotifyVoid () const;
332 return m_instance_name;
335 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
338 LoadPlugin (const FileSpec& spec, Error& error);
343 DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len);
346 GetCurrentInputReader ();
349 ActivateInputReader (const lldb::InputReaderSP &reader_sp);
352 CheckIfTopInputReaderIsDone ();
354 SourceManager::SourceFileCache &
355 GetSourceFileCache ()
357 return m_source_file_cache;
359 Communication m_input_comm;
360 StreamFile m_input_file;
361 StreamFile m_output_file;
362 StreamFile m_error_file;
363 TerminalState m_terminal_state;
364 TargetList m_target_list;
365 PlatformList m_platform_list;
367 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets.
368 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
369 // source file cache.
370 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
372 InputReaderStack m_input_reader_stack;
373 std::string m_input_reader_data;
374 typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
375 LogStreamMap m_log_streams;
376 lldb::StreamSP m_log_callback_stream_sp;
377 ConstString m_instance_name;
378 typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
379 LoadedPluginsList m_loaded_plugins;
382 InstanceInitialize ();
386 // Use Debugger::CreateInstance() to get a shared pointer to a new
388 Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
390 DISALLOW_COPY_AND_ASSIGN (Debugger);
394 } // namespace lldb_private
396 #endif // #if defined(__cplusplus)
397 #endif // liblldb_Debugger_h_