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