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