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