Debugger.h revision 269024
11638Srgrimes//===-- Debugger.h ----------------------------------------------*- C++ -*-===// 21638Srgrimes// 31638Srgrimes// The LLVM Compiler Infrastructure 41638Srgrimes// 51638Srgrimes// This file is distributed under the University of Illinois Open Source 61638Srgrimes// License. See LICENSE.TXT for details. 71638Srgrimes// 81638Srgrimes//===----------------------------------------------------------------------===// 91638Srgrimes 101638Srgrimes#ifndef liblldb_Debugger_h_ 111638Srgrimes#define liblldb_Debugger_h_ 121638Srgrimes#if defined(__cplusplus) 131638Srgrimes 141638Srgrimes 151638Srgrimes#include <stdint.h> 161638Srgrimes 171638Srgrimes#include <stack> 181638Srgrimes 191638Srgrimes#include "lldb/lldb-public.h" 201638Srgrimes#include "lldb/Core/Broadcaster.h" 211638Srgrimes#include "lldb/Core/Communication.h" 221638Srgrimes#include "lldb/Core/IOHandler.h" 231638Srgrimes#include "lldb/Core/Listener.h" 241638Srgrimes#include "lldb/Core/SourceManager.h" 251638Srgrimes#include "lldb/Core/UserID.h" 261638Srgrimes#include "lldb/Core/UserSettingsController.h" 271638Srgrimes#include "lldb/DataFormatters/FormatManager.h" 281638Srgrimes#include "lldb/Host/Terminal.h" 291638Srgrimes#include "lldb/Interpreter/OptionValueProperties.h" 301638Srgrimes#include "lldb/Target/ExecutionContext.h" 311638Srgrimes#include "lldb/Target/Platform.h" 321638Srgrimes#include "lldb/Target/TargetList.h" 331638Srgrimes 341638Srgrimesnamespace lldb_private { 351638Srgrimes 361638Srgrimes//---------------------------------------------------------------------- 371638Srgrimes/// @class Debugger Debugger.h "lldb/Core/Debugger.h" 381638Srgrimes/// @brief A class to manage flag bits. 391638Srgrimes/// 401638Srgrimes/// Provides a global root objects for the debugger core. 411638Srgrimes//---------------------------------------------------------------------- 421638Srgrimes 431638Srgrimes 441638Srgrimesclass Debugger : 451638Srgrimes public std::enable_shared_from_this<Debugger>, 461638Srgrimes public UserID, 471638Srgrimes public Properties, 481638Srgrimes public BroadcasterManager 491638Srgrimes{ 501638Srgrimesfriend class SourceManager; // For GetSourceFileCache. 511638Srgrimes 521638Srgrimespublic: 531638Srgrimes 541638Srgrimes typedef lldb::DynamicLibrarySP (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp, 551638Srgrimes const FileSpec& spec, 561638Srgrimes Error& error); 571638Srgrimes 581638Srgrimes static lldb::DebuggerSP 591638Srgrimes CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL); 601638Srgrimes 611638Srgrimes static lldb::TargetSP 621638Srgrimes FindTargetWithProcessID (lldb::pid_t pid); 631638Srgrimes 641638Srgrimes static lldb::TargetSP 651638Srgrimes FindTargetWithProcess (Process *process); 661638Srgrimes 671638Srgrimes static void 681638Srgrimes Initialize (LoadPluginCallbackType load_plugin_callback); 691638Srgrimes 701638Srgrimes static void 711638Srgrimes Terminate (); 721638Srgrimes 731638Srgrimes static void 741638Srgrimes SettingsInitialize (); 751638Srgrimes 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 lldb::StreamFileSP 94 GetInputFile () 95 { 96 return m_input_file_sp; 97 } 98 99 lldb::StreamFileSP 100 GetOutputFile () 101 { 102 return m_output_file_sp; 103 } 104 105 lldb::StreamFileSP 106 GetErrorFile () 107 { 108 return m_error_file_sp; 109 } 110 111 112 113 void 114 SetInputFileHandle (FILE *fh, bool tranfer_ownership); 115 116 void 117 SetOutputFileHandle (FILE *fh, bool tranfer_ownership); 118 119 void 120 SetErrorFileHandle (FILE *fh, bool tranfer_ownership); 121 122 void 123 SaveInputTerminalState(); 124 125 void 126 RestoreInputTerminalState(); 127 128 lldb::StreamSP 129 GetAsyncOutputStream (); 130 131 lldb::StreamSP 132 GetAsyncErrorStream (); 133 134 CommandInterpreter & 135 GetCommandInterpreter () 136 { 137 assert (m_command_interpreter_ap.get()); 138 return *m_command_interpreter_ap; 139 } 140 141 Listener & 142 GetListener () 143 { 144 return m_listener; 145 } 146 147 // This returns the Debugger's scratch source manager. It won't be able to look up files in debug 148 // information, but it can look up files by absolute path and display them to you. 149 // To get the target's source manager, call GetSourceManager on the target instead. 150 SourceManager & 151 GetSourceManager (); 152 153public: 154 155 lldb::TargetSP 156 GetSelectedTarget () 157 { 158 return m_target_list.GetSelectedTarget (); 159 } 160 161 ExecutionContext 162 GetSelectedExecutionContext(); 163 //------------------------------------------------------------------ 164 /// Get accessor for the target list. 165 /// 166 /// The target list is part of the global debugger object. This 167 /// the single debugger shared instance to control where targets 168 /// get created and to allow for tracking and searching for targets 169 /// based on certain criteria. 170 /// 171 /// @return 172 /// A global shared target list. 173 //------------------------------------------------------------------ 174 TargetList & 175 GetTargetList () 176 { 177 return m_target_list; 178 } 179 180 PlatformList & 181 GetPlatformList () 182 { 183 return m_platform_list; 184 } 185 186 void 187 DispatchInputInterrupt (); 188 189 void 190 DispatchInputEndOfFile (); 191 192 //------------------------------------------------------------------ 193 // If any of the streams are not set, set them to the in/out/err 194 // stream of the top most input reader to ensure they at least have 195 // something 196 //------------------------------------------------------------------ 197 void 198 AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in, 199 lldb::StreamFileSP &out, 200 lldb::StreamFileSP &err); 201 202 void 203 PushIOHandler (const lldb::IOHandlerSP& reader_sp); 204 205 bool 206 PopIOHandler (const lldb::IOHandlerSP& reader_sp); 207 208 // Synchronously run an input reader until it is done 209 void 210 RunIOHandler (const lldb::IOHandlerSP& reader_sp); 211 212 bool 213 IsTopIOHandler (const lldb::IOHandlerSP& reader_sp); 214 215 ConstString 216 GetTopIOHandlerControlSequence(char ch); 217 218 bool 219 HideTopIOHandler(); 220 221 void 222 RefreshTopIOHandler(); 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 ValueObject* valobj = NULL); 243 244 245 void 246 ClearIOHandlers (); 247 248 static int 249 TestDebuggerRefCount (); 250 251 bool 252 GetCloseInputOnEOF () const; 253 254 void 255 SetCloseInputOnEOF (bool b); 256 257 bool 258 EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream); 259 260 void 261 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton); 262 263 264 //---------------------------------------------------------------------- 265 // Properties Functions 266 //---------------------------------------------------------------------- 267 enum StopDisassemblyType 268 { 269 eStopDisassemblyTypeNever = 0, 270 eStopDisassemblyTypeNoSource, 271 eStopDisassemblyTypeAlways 272 }; 273 274 virtual Error 275 SetPropertyValue (const ExecutionContext *exe_ctx, 276 VarSetOperationType op, 277 const char *property_path, 278 const char *value); 279 280 bool 281 GetAutoConfirm () const; 282 283 const char * 284 GetFrameFormat() const; 285 286 const char * 287 GetThreadFormat() const; 288 289 lldb::ScriptLanguage 290 GetScriptLanguage() const; 291 292 bool 293 SetScriptLanguage (lldb::ScriptLanguage script_lang); 294 295 uint32_t 296 GetTerminalWidth () const; 297 298 bool 299 SetTerminalWidth (uint32_t term_width); 300 301 const char * 302 GetPrompt() const; 303 304 void 305 SetPrompt(const char *p); 306 307 bool 308 GetUseExternalEditor () const; 309 310 bool 311 SetUseExternalEditor (bool use_external_editor_p); 312 313 bool 314 GetUseColor () const; 315 316 bool 317 SetUseColor (bool use_color); 318 319 uint32_t 320 GetStopSourceLineCount (bool before) const; 321 322 StopDisassemblyType 323 GetStopDisassemblyDisplay () const; 324 325 uint32_t 326 GetDisassemblyLineCount () const; 327 328 bool 329 GetAutoOneLineSummaries () const; 330 331 bool 332 GetNotifyVoid () const; 333 334 335 const ConstString & 336 GetInstanceName() 337 { 338 return m_instance_name; 339 } 340 341 bool 342 LoadPlugin (const FileSpec& spec, Error& error); 343 344 void 345 ExecuteIOHanders(); 346 347 bool 348 IsForwardingEvents (); 349 350 void 351 EnableForwardEvents (const lldb::ListenerSP &listener_sp); 352 353 void 354 CancelForwardEvents (const lldb::ListenerSP &listener_sp); 355protected: 356 357 friend class CommandInterpreter; 358 359 bool 360 StartEventHandlerThread(); 361 362 void 363 StopEventHandlerThread(); 364 365 static lldb::thread_result_t 366 EventHandlerThread (lldb::thread_arg_t arg); 367 368 bool 369 StartIOHandlerThread(); 370 371 void 372 StopIOHandlerThread(); 373 374 static lldb::thread_result_t 375 IOHandlerThread (lldb::thread_arg_t arg); 376 377 void 378 DefaultEventHandler(); 379 380 void 381 HandleBreakpointEvent (const lldb::EventSP &event_sp); 382 383 void 384 HandleProcessEvent (const lldb::EventSP &event_sp); 385 386 void 387 HandleThreadEvent (const lldb::EventSP &event_sp); 388 389 size_t 390 GetProcessSTDOUT (Process *process, Stream *stream); 391 392 size_t 393 GetProcessSTDERR (Process *process, Stream *stream); 394 395 SourceManager::SourceFileCache & 396 GetSourceFileCache () 397 { 398 return m_source_file_cache; 399 } 400 lldb::StreamFileSP m_input_file_sp; 401 lldb::StreamFileSP m_output_file_sp; 402 lldb::StreamFileSP m_error_file_sp; 403 TerminalState m_terminal_state; 404 TargetList m_target_list; 405 PlatformList m_platform_list; 406 Listener m_listener; 407 std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch source manager that we return if we have no targets. 408 SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared 409 // source file cache. 410 std::unique_ptr<CommandInterpreter> m_command_interpreter_ap; 411 412 IOHandlerStack m_input_reader_stack; 413 typedef std::map<std::string, lldb::StreamWP> LogStreamMap; 414 LogStreamMap m_log_streams; 415 lldb::StreamSP m_log_callback_stream_sp; 416 ConstString m_instance_name; 417 static LoadPluginCallbackType g_load_plugin_callback; 418 typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList; 419 LoadedPluginsList m_loaded_plugins; 420 lldb::thread_t m_event_handler_thread; 421 lldb::thread_t m_io_handler_thread; 422 lldb::ListenerSP m_forward_listener_sp; 423 bool m_event_handler_thread_alive; 424 void 425 InstanceInitialize (); 426 427private: 428 429 // Use Debugger::CreateInstance() to get a shared pointer to a new 430 // debugger object 431 Debugger (lldb::LogOutputCallback m_log_callback, void *baton); 432 433 DISALLOW_COPY_AND_ASSIGN (Debugger); 434 435}; 436 437} // namespace lldb_private 438 439#endif // #if defined(__cplusplus) 440#endif // liblldb_Debugger_h_ 441