Debugger.h revision 5c28dd1daf8de701ce1eeb8f9b8d3e3b5e39ad50
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/Communication.h" 22#include "lldb/Core/FormatManager.h" 23#include "lldb/Core/InputReaderStack.h" 24#include "lldb/Core/Listener.h" 25#include "lldb/Core/StreamFile.h" 26#include "lldb/Core/SourceManager.h" 27#include "lldb/Core/UserID.h" 28#include "lldb/Core/UserSettingsController.h" 29#include "lldb/Target/ExecutionContext.h" 30#include "lldb/Target/Platform.h" 31#include "lldb/Target/TargetList.h" 32 33namespace lldb_private { 34 35//---------------------------------------------------------------------- 36/// @class Debugger Debugger.h "lldb/Core/Debugger.h" 37/// @brief A class to manage flag bits. 38/// 39/// Provides a global root objects for the debugger core. 40//---------------------------------------------------------------------- 41 42 43class DebuggerInstanceSettings : public InstanceSettings 44{ 45public: 46 47 DebuggerInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); 48 49 DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs); 50 51 virtual 52 ~DebuggerInstanceSettings (); 53 54 DebuggerInstanceSettings& 55 operator= (const DebuggerInstanceSettings &rhs); 56 57 void 58 UpdateInstanceSettingsVariable (const ConstString &var_name, 59 const char *index_value, 60 const char *value, 61 const ConstString &instance_name, 62 const SettingEntry &entry, 63 VarSetOperationType op, 64 Error &err, 65 bool pending); 66 67 bool 68 GetInstanceSettingsValue (const SettingEntry &entry, 69 const ConstString &var_name, 70 StringList &value, 71 Error *err); 72 73 uint32_t 74 GetTerminalWidth () const 75 { 76 return m_term_width; 77 } 78 79 void 80 SetTerminalWidth (uint32_t term_width) 81 { 82 m_term_width = term_width; 83 } 84 85 const char * 86 GetPrompt() const 87 { 88 return m_prompt.c_str(); 89 } 90 91 void 92 SetPrompt(const char *p) 93 { 94 if (p) 95 m_prompt.assign (p); 96 else 97 m_prompt.assign ("(lldb) "); 98 BroadcastPromptChange (m_instance_name, m_prompt.c_str()); 99 } 100 101 const char * 102 GetFrameFormat() const 103 { 104 return m_frame_format.c_str(); 105 } 106 107 bool 108 SetFrameFormat(const char *frame_format) 109 { 110 if (frame_format && frame_format[0]) 111 { 112 m_frame_format.assign (frame_format); 113 return true; 114 } 115 return false; 116 } 117 118 const char * 119 GetThreadFormat() const 120 { 121 return m_thread_format.c_str(); 122 } 123 124 bool 125 SetThreadFormat(const char *thread_format) 126 { 127 if (thread_format && thread_format[0]) 128 { 129 m_thread_format.assign (thread_format); 130 return true; 131 } 132 return false; 133 } 134 135 lldb::ScriptLanguage 136 GetScriptLanguage() const 137 { 138 return m_script_lang; 139 } 140 141 void 142 SetScriptLanguage (lldb::ScriptLanguage script_lang) 143 { 144 m_script_lang = script_lang; 145 } 146 147 bool 148 GetUseExternalEditor () const 149 { 150 return m_use_external_editor; 151 } 152 153 bool 154 SetUseExternalEditor (bool use_external_editor_p) 155 { 156 bool old_value = m_use_external_editor; 157 m_use_external_editor = use_external_editor_p; 158 return old_value; 159 } 160 161 bool 162 GetAutoConfirm () const 163 { 164 return m_auto_confirm_on; 165 } 166 167 void 168 SetAutoConfirm (bool auto_confirm_on) 169 { 170 m_auto_confirm_on = auto_confirm_on; 171 } 172 173protected: 174 175 void 176 CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 177 bool pending); 178 179 bool 180 BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt); 181 182 bool 183 ValidTermWidthValue (const char *value, Error err); 184 185 const ConstString 186 CreateInstanceName (); 187 188 static const ConstString & 189 PromptVarName (); 190 191 static const ConstString & 192 GetFrameFormatName (); 193 194 static const ConstString & 195 GetThreadFormatName (); 196 197 static const ConstString & 198 ScriptLangVarName (); 199 200 static const ConstString & 201 TermWidthVarName (); 202 203 static const ConstString & 204 UseExternalEditorVarName (); 205 206 static const ConstString & 207 AutoConfirmName (); 208 209private: 210 211 uint32_t m_term_width; 212 std::string m_prompt; 213 std::string m_frame_format; 214 std::string m_thread_format; 215 lldb::ScriptLanguage m_script_lang; 216 bool m_use_external_editor; 217 bool m_auto_confirm_on; 218}; 219 220 221 222class Debugger : 223 public UserID, 224 public DebuggerInstanceSettings 225{ 226public: 227 228 class SettingsController : public UserSettingsController 229 { 230 public: 231 232 SettingsController (); 233 234 virtual 235 ~SettingsController (); 236 237 static SettingEntry global_settings_table[]; 238 static SettingEntry instance_settings_table[]; 239 240 protected: 241 242 lldb::InstanceSettingsSP 243 CreateInstanceSettings (const char *instance_name); 244 245 private: 246 247 // Class-wide settings. 248 249 DISALLOW_COPY_AND_ASSIGN (SettingsController); 250 }; 251 252 static lldb::UserSettingsControllerSP & 253 GetSettingsController (); 254 255 static lldb::DebuggerSP 256 CreateInstance (); 257 258 static lldb::TargetSP 259 FindTargetWithProcessID (lldb::pid_t pid); 260 261 static void 262 Initialize (); 263 264 static void 265 Terminate (); 266 267 static void 268 SettingsInitialize (); 269 270 static void 271 SettingsTerminate (); 272 273 static void 274 Destroy (lldb::DebuggerSP &debugger_sp); 275 276 ~Debugger (); 277 278 lldb::DebuggerSP 279 GetSP (); 280 281 bool 282 GetAsyncExecution (); 283 284 void 285 SetAsyncExecution (bool async); 286 287 File & 288 GetInputFile () 289 { 290 return m_input_file.GetFile(); 291 } 292 293 File & 294 GetOutputFile () 295 { 296 return m_output_file.GetFile(); 297 } 298 299 File & 300 GetErrorFile () 301 { 302 return m_error_file.GetFile(); 303 } 304 305 void 306 SetInputFileHandle (FILE *fh, bool tranfer_ownership); 307 308 void 309 SetOutputFileHandle (FILE *fh, bool tranfer_ownership); 310 311 void 312 SetErrorFileHandle (FILE *fh, bool tranfer_ownership); 313 314 Stream& 315 GetOutputStream () 316 { 317 return m_output_file; 318 } 319 320 Stream& 321 GetErrorStream () 322 { 323 return m_error_file; 324 } 325 326 lldb::StreamSP 327 GetAsyncOutputStream (); 328 329 lldb::StreamSP 330 GetAsyncErrorStream (); 331 332 CommandInterpreter & 333 GetCommandInterpreter () 334 { 335 assert (m_command_interpreter_ap.get()); 336 return *m_command_interpreter_ap; 337 } 338 339 Listener & 340 GetListener () 341 { 342 return m_listener; 343 } 344 345 SourceManager & 346 GetSourceManager () 347 { 348 return m_source_manager; 349 } 350 351 lldb::TargetSP 352 GetSelectedTarget () 353 { 354 return m_target_list.GetSelectedTarget (); 355 } 356 357 ExecutionContext 358 GetSelectedExecutionContext(); 359 //------------------------------------------------------------------ 360 /// Get accessor for the target list. 361 /// 362 /// The target list is part of the global debugger object. This 363 /// the single debugger shared instance to control where targets 364 /// get created and to allow for tracking and searching for targets 365 /// based on certain criteria. 366 /// 367 /// @return 368 /// A global shared target list. 369 //------------------------------------------------------------------ 370 TargetList & 371 GetTargetList () 372 { 373 return m_target_list; 374 } 375 376 PlatformList & 377 GetPlatformList () 378 { 379 return m_platform_list; 380 } 381 382 void 383 DispatchInputInterrupt (); 384 385 void 386 DispatchInputEndOfFile (); 387 388 void 389 DispatchInput (const char *bytes, size_t bytes_len); 390 391 void 392 WriteToDefaultReader (const char *bytes, size_t bytes_len); 393 394 void 395 PushInputReader (const lldb::InputReaderSP& reader_sp); 396 397 bool 398 PopInputReader (const lldb::InputReaderSP& reader_sp); 399 400 void 401 NotifyTopInputReader (lldb::InputReaderAction notification); 402 403 bool 404 InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp); 405 406 static lldb::DebuggerSP 407 FindDebuggerWithID (lldb::user_id_t id); 408 409 static lldb::DebuggerSP 410 FindDebuggerWithInstanceName (const ConstString &instance_name); 411 412 static bool 413 FormatPrompt (const char *format, 414 const SymbolContext *sc, 415 const ExecutionContext *exe_ctx, 416 const Address *addr, 417 Stream &s, 418 const char **end); 419 420 421 void 422 CleanUpInputReaders (); 423 424 static int 425 TestDebuggerRefCount (); 426 427 bool 428 GetCloseInputOnEOF () const; 429 430 void 431 SetCloseInputOnEOF (bool b); 432 433protected: 434 435 static void 436 DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len); 437 438 lldb::InputReaderSP 439 GetCurrentInputReader (); 440 441 void 442 ActivateInputReader (const lldb::InputReaderSP &reader_sp); 443 444 bool 445 CheckIfTopInputReaderIsDone (); 446 447 void 448 DisconnectInput() 449 { 450 m_input_comm.Clear (); 451 } 452 453 Communication m_input_comm; 454 StreamFile m_input_file; 455 StreamFile m_output_file; 456 StreamFile m_error_file; 457 TargetList m_target_list; 458 PlatformList m_platform_list; 459 Listener m_listener; 460 SourceManager m_source_manager; 461 std::auto_ptr<CommandInterpreter> m_command_interpreter_ap; 462 463 InputReaderStack m_input_reader_stack; 464 std::string m_input_reader_data; 465 466private: 467 468 // Use Debugger::CreateInstance() to get a shared pointer to a new 469 // debugger object 470 Debugger (); 471 472 DISALLOW_COPY_AND_ASSIGN (Debugger); 473 474public: 475 476 static bool 477 GetFormatForType (const ConstString &type, lldb::Format& format, bool& cascade); 478 479 static void 480 AddFormatForType (const ConstString &type, lldb::Format format, bool cascade); 481 482 static bool 483 DeleteFormatForType (const ConstString &type); 484 485 static void 486 LoopThroughFormatList (FormatCallback cback, void* param); 487}; 488 489} // namespace lldb_private 490 491#endif // #if defined(__cplusplus) 492#endif // liblldb_Debugger_h_ 493