Debugger.h revision 263363
1//===-- Debugger.h ----------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_Debugger_h_ 11#define liblldb_Debugger_h_ 12#if defined(__cplusplus) 13 14 15#include <stdint.h> 16 17#include <stack> 18 19#include "lldb/lldb-public.h" 20 21#include "lldb/API/SBDefines.h" 22 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" 37 38namespace lldb_private { 39 40//---------------------------------------------------------------------- 41/// @class Debugger Debugger.h "lldb/Core/Debugger.h" 42/// @brief A class to manage flag bits. 43/// 44/// Provides a global root objects for the debugger core. 45//---------------------------------------------------------------------- 46 47 48class Debugger : 49 public std::enable_shared_from_this<Debugger>, 50 public UserID, 51 public Properties, 52 public BroadcasterManager 53{ 54friend class SourceManager; // For GetSourceFileCache. 55 56public: 57 58 static lldb::DebuggerSP 59 CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL); 60 61 static lldb::TargetSP 62 FindTargetWithProcessID (lldb::pid_t pid); 63 64 static lldb::TargetSP 65 FindTargetWithProcess (Process *process); 66 67 static void 68 Initialize (); 69 70 static void 71 Terminate (); 72 73 static void 74 SettingsInitialize (); 75 76 static void 77 SettingsTerminate (); 78 79 static void 80 Destroy (lldb::DebuggerSP &debugger_sp); 81 82 virtual 83 ~Debugger (); 84 85 void Clear(); 86 87 bool 88 GetAsyncExecution (); 89 90 void 91 SetAsyncExecution (bool async); 92 93 File & 94 GetInputFile () 95 { 96 return m_input_file.GetFile(); 97 } 98 99 File & 100 GetOutputFile () 101 { 102 return m_output_file.GetFile(); 103 } 104 105 File & 106 GetErrorFile () 107 { 108 return m_error_file.GetFile(); 109 } 110 111 void 112 SetInputFileHandle (FILE *fh, bool tranfer_ownership); 113 114 void 115 SetOutputFileHandle (FILE *fh, bool tranfer_ownership); 116 117 void 118 SetErrorFileHandle (FILE *fh, bool tranfer_ownership); 119 120 void 121 SaveInputTerminalState(); 122 123 void 124 RestoreInputTerminalState(); 125 126 Stream& 127 GetOutputStream () 128 { 129 return m_output_file; 130 } 131 132 Stream& 133 GetErrorStream () 134 { 135 return m_error_file; 136 } 137 138 lldb::StreamSP 139 GetAsyncOutputStream (); 140 141 lldb::StreamSP 142 GetAsyncErrorStream (); 143 144 CommandInterpreter & 145 GetCommandInterpreter () 146 { 147 assert (m_command_interpreter_ap.get()); 148 return *m_command_interpreter_ap; 149 } 150 151 Listener & 152 GetListener () 153 { 154 return m_listener; 155 } 156 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. 160 SourceManager & 161 GetSourceManager (); 162 163public: 164 165 lldb::TargetSP 166 GetSelectedTarget () 167 { 168 return m_target_list.GetSelectedTarget (); 169 } 170 171 ExecutionContext 172 GetSelectedExecutionContext(); 173 //------------------------------------------------------------------ 174 /// Get accessor for the target list. 175 /// 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. 180 /// 181 /// @return 182 /// A global shared target list. 183 //------------------------------------------------------------------ 184 TargetList & 185 GetTargetList () 186 { 187 return m_target_list; 188 } 189 190 PlatformList & 191 GetPlatformList () 192 { 193 return m_platform_list; 194 } 195 196 void 197 DispatchInputInterrupt (); 198 199 void 200 DispatchInputEndOfFile (); 201 202 void 203 DispatchInput (const char *bytes, size_t bytes_len); 204 205 void 206 WriteToDefaultReader (const char *bytes, size_t bytes_len); 207 208 void 209 PushInputReader (const lldb::InputReaderSP& reader_sp); 210 211 bool 212 PopInputReader (const lldb::InputReaderSP& reader_sp); 213 214 void 215 NotifyTopInputReader (lldb::InputReaderAction notification); 216 217 bool 218 InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp); 219 220 static lldb::DebuggerSP 221 FindDebuggerWithID (lldb::user_id_t id); 222 223 static lldb::DebuggerSP 224 FindDebuggerWithInstanceName (const ConstString &instance_name); 225 226 static size_t 227 GetNumDebuggers(); 228 229 static lldb::DebuggerSP 230 GetDebuggerAtIndex (size_t index); 231 232 static bool 233 FormatPrompt (const char *format, 234 const SymbolContext *sc, 235 const ExecutionContext *exe_ctx, 236 const Address *addr, 237 Stream &s, 238 ValueObject* valobj = NULL); 239 240 241 void 242 CleanUpInputReaders (); 243 244 static int 245 TestDebuggerRefCount (); 246 247 bool 248 GetCloseInputOnEOF () const; 249 250 void 251 SetCloseInputOnEOF (bool b); 252 253 bool 254 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream); 255 256 void 257 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton); 258 259 260 //---------------------------------------------------------------------- 261 // Properties Functions 262 //---------------------------------------------------------------------- 263 enum StopDisassemblyType 264 { 265 eStopDisassemblyTypeNever = 0, 266 eStopDisassemblyTypeNoSource, 267 eStopDisassemblyTypeAlways 268 }; 269 270 virtual Error 271 SetPropertyValue (const ExecutionContext *exe_ctx, 272 VarSetOperationType op, 273 const char *property_path, 274 const char *value); 275 276 bool 277 GetAutoConfirm () const; 278 279 const char * 280 GetFrameFormat() const; 281 282 const char * 283 GetThreadFormat() const; 284 285 lldb::ScriptLanguage 286 GetScriptLanguage() const; 287 288 bool 289 SetScriptLanguage (lldb::ScriptLanguage script_lang); 290 291 uint32_t 292 GetTerminalWidth () const; 293 294 bool 295 SetTerminalWidth (uint32_t term_width); 296 297 const char * 298 GetPrompt() const; 299 300 void 301 SetPrompt(const char *p); 302 303 bool 304 GetUseExternalEditor () const; 305 306 bool 307 SetUseExternalEditor (bool use_external_editor_p); 308 309 bool 310 GetUseColor () const; 311 312 bool 313 SetUseColor (bool use_color); 314 315 uint32_t 316 GetStopSourceLineCount (bool before) const; 317 318 StopDisassemblyType 319 GetStopDisassemblyDisplay () const; 320 321 uint32_t 322 GetDisassemblyLineCount () const; 323 324 bool 325 GetAutoOneLineSummaries () const; 326 327 bool 328 GetNotifyVoid () const; 329 330 331 const ConstString & 332 GetInstanceName() 333 { 334 return m_instance_name; 335 } 336 337 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger); 338 339 bool 340 LoadPlugin (const FileSpec& spec, Error& error); 341 342protected: 343 344 static void 345 DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len); 346 347 lldb::InputReaderSP 348 GetCurrentInputReader (); 349 350 void 351 ActivateInputReader (const lldb::InputReaderSP &reader_sp); 352 353 bool 354 CheckIfTopInputReaderIsDone (); 355 356 SourceManager::SourceFileCache & 357 GetSourceFileCache () 358 { 359 return m_source_file_cache; 360 } 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; 368 Listener m_listener; 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; 373 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; 382 383 void 384 InstanceInitialize (); 385 386private: 387 388 // Use Debugger::CreateInstance() to get a shared pointer to a new 389 // debugger object 390 Debugger (lldb::LogOutputCallback m_log_callback, void *baton); 391 392 DISALLOW_COPY_AND_ASSIGN (Debugger); 393 394}; 395 396} // namespace lldb_private 397 398#endif // #if defined(__cplusplus) 399#endif // liblldb_Debugger_h_ 400