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"
21 #include "lldb/API/SBDefines.h"
23 #include "lldb/Core/Broadcaster.h"
24 #include "lldb/Core/Communication.h"
25 #include "lldb/Core/InputReaderStack.h"
26 #include "lldb/Core/Listener.h"
27 #include "lldb/Core/StreamFile.h"
28 #include "lldb/Core/SourceManager.h"
29 #include "lldb/Core/UserID.h"
30 #include "lldb/Core/UserSettingsController.h"
31 #include "lldb/DataFormatters/FormatManager.h"
32 #include "lldb/Host/Terminal.h"
33 #include "lldb/Interpreter/OptionValueProperties.h"
34 #include "lldb/Target/ExecutionContext.h"
35 #include "lldb/Target/Platform.h"
36 #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);
74 SettingsInitialize ();
80 Destroy (lldb::DebuggerSP &debugger_sp);
91 SetAsyncExecution (bool async);
96 return m_input_file.GetFile();
102 return m_output_file.GetFile();
108 return m_error_file.GetFile();
112 SetInputFileHandle (FILE *fh, bool tranfer_ownership);
115 SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
118 SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
121 SaveInputTerminalState();
124 RestoreInputTerminalState();
129 return m_output_file;
139 GetAsyncOutputStream ();
142 GetAsyncErrorStream ();
145 GetCommandInterpreter ()
147 assert (m_command_interpreter_ap.get());
148 return *m_command_interpreter_ap;
157 // This returns the Debugger's scratch source manager. It won't be able to look up files in debug
158 // information, but it can look up files by absolute path and display them to you.
159 // To get the target's source manager, call GetSourceManager on the target instead.
168 return m_target_list.GetSelectedTarget ();
172 GetSelectedExecutionContext();
173 //------------------------------------------------------------------
174 /// Get accessor for the target list.
176 /// The target list is part of the global debugger object. This
177 /// the single debugger shared instance to control where targets
178 /// get created and to allow for tracking and searching for targets
179 /// based on certain criteria.
182 /// A global shared target list.
183 //------------------------------------------------------------------
187 return m_target_list;
193 return m_platform_list;
197 DispatchInputInterrupt ();
200 DispatchInputEndOfFile ();
203 DispatchInput (const char *bytes, size_t bytes_len);
206 WriteToDefaultReader (const char *bytes, size_t bytes_len);
209 PushInputReader (const lldb::InputReaderSP& reader_sp);
212 PopInputReader (const lldb::InputReaderSP& reader_sp);
215 NotifyTopInputReader (lldb::InputReaderAction notification);
218 InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp);
220 static lldb::DebuggerSP
221 FindDebuggerWithID (lldb::user_id_t id);
223 static lldb::DebuggerSP
224 FindDebuggerWithInstanceName (const ConstString &instance_name);
229 static lldb::DebuggerSP
230 GetDebuggerAtIndex (size_t index);
233 FormatPrompt (const char *format,
234 const SymbolContext *sc,
235 const ExecutionContext *exe_ctx,
238 ValueObject* valobj = NULL);
242 CleanUpInputReaders ();
245 TestDebuggerRefCount ();
248 GetCloseInputOnEOF () const;
251 SetCloseInputOnEOF (bool b);
254 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
257 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
260 //----------------------------------------------------------------------
261 // Properties Functions
262 //----------------------------------------------------------------------
263 enum StopDisassemblyType
265 eStopDisassemblyTypeNever = 0,
266 eStopDisassemblyTypeNoSource,
267 eStopDisassemblyTypeAlways
271 SetPropertyValue (const ExecutionContext *exe_ctx,
272 VarSetOperationType op,
273 const char *property_path,
277 GetAutoConfirm () const;
280 GetFrameFormat() const;
283 GetThreadFormat() const;
286 GetScriptLanguage() const;
289 SetScriptLanguage (lldb::ScriptLanguage script_lang);
292 GetTerminalWidth () const;
295 SetTerminalWidth (uint32_t term_width);
301 SetPrompt(const char *p);
304 GetUseExternalEditor () const;
307 SetUseExternalEditor (bool use_external_editor_p);
310 GetUseColor () const;
313 SetUseColor (bool use_color);
316 GetStopSourceLineCount (bool before) const;
319 GetStopDisassemblyDisplay () const;
322 GetDisassemblyLineCount () const;
325 GetAutoOneLineSummaries () const;
328 GetNotifyVoid () const;
334 return m_instance_name;
337 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
340 LoadPlugin (const FileSpec& spec, Error& error);
345 DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len);
348 GetCurrentInputReader ();
351 ActivateInputReader (const lldb::InputReaderSP &reader_sp);
354 CheckIfTopInputReaderIsDone ();
356 SourceManager::SourceFileCache &
357 GetSourceFileCache ()
359 return m_source_file_cache;
361 Communication m_input_comm;
362 StreamFile m_input_file;
363 StreamFile m_output_file;
364 StreamFile m_error_file;
365 TerminalState m_terminal_state;
366 TargetList m_target_list;
367 PlatformList m_platform_list;
369 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets.
370 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
371 // source file cache.
372 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
374 InputReaderStack m_input_reader_stack;
375 std::string m_input_reader_data;
376 typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
377 LogStreamMap m_log_streams;
378 lldb::StreamSP m_log_callback_stream_sp;
379 ConstString m_instance_name;
380 typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
381 LoadedPluginsList m_loaded_plugins;
384 InstanceInitialize ();
388 // Use Debugger::CreateInstance() to get a shared pointer to a new
390 Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
392 DISALLOW_COPY_AND_ASSIGN (Debugger);
396 } // namespace lldb_private
398 #endif // #if defined(__cplusplus)
399 #endif // liblldb_Debugger_h_