Debugger.h revision c3c24084efb0e1c4734c136532c1e43e9427c912
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, 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 void 64 GetInstanceSettingsValue (const SettingEntry &entry, 65 const ConstString &var_name, 66 StringList &value); 67 68protected: 69 70 void 71 CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 72 bool pending); 73 74 bool 75 BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt); 76 77 const ConstString 78 CreateInstanceName (); 79 80 static const ConstString & 81 PromptVarName (); 82 83 static const ConstString & 84 ScriptLangVarName (); 85 86private: 87 88 std::string m_prompt; 89 lldb::ScriptLanguage m_script_lang; 90}; 91 92 93 94class Debugger : 95 public UserID, 96 public DebuggerInstanceSettings 97{ 98public: 99 100 class DebuggerSettingsController : public UserSettingsController 101 { 102 public: 103 104 DebuggerSettingsController (); 105 106 virtual 107 ~DebuggerSettingsController (); 108 109 void 110 UpdateGlobalVariable (const ConstString &var_name, 111 const char *index_value, 112 const char *value, 113 const SettingEntry &entry, 114 lldb::VarSetOperationType op, 115 Error&err); 116 117 void 118 GetGlobalSettingsValue (const ConstString &var_name, 119 StringList &value); 120 121 static SettingEntry global_settings_table[]; 122 static SettingEntry instance_settings_table[]; 123 124 protected: 125 126 lldb::InstanceSettingsSP 127 CreateNewInstanceSettings (); 128 129 bool 130 ValidTermWidthValue (const char *value, Error err); 131 132 private: 133 134 // Class-wide settings. 135 int m_term_width; 136 137 DISALLOW_COPY_AND_ASSIGN (DebuggerSettingsController); 138 }; 139 140 static lldb::UserSettingsControllerSP & 141 GetSettingsController (bool finish = false); 142 143 static lldb::DebuggerSP 144 CreateInstance (); 145 146 static lldb::TargetSP 147 FindTargetWithProcessID (lldb::pid_t pid); 148 149 static void 150 Initialize (); 151 152 static void 153 Terminate (); 154 155 ~Debugger (); 156 157 lldb::DebuggerSP 158 GetSP (); 159 160 bool 161 GetAsyncExecution (); 162 163 void 164 SetAsyncExecution (bool async); 165 166 void 167 SetInputFileHandle (FILE *fh, bool tranfer_ownership); 168 169 void 170 SetOutputFileHandle (FILE *fh, bool tranfer_ownership); 171 172 void 173 SetErrorFileHandle (FILE *fh, bool tranfer_ownership); 174 175 FILE * 176 GetInputFileHandle (); 177 178 FILE * 179 GetOutputFileHandle (); 180 181 FILE * 182 GetErrorFileHandle (); 183 184 Stream& 185 GetOutputStream () 186 { 187 return m_output_file; 188 } 189 190 Stream& 191 GetErrorStream () 192 { 193 return m_error_file; 194 } 195 196 CommandInterpreter & 197 GetCommandInterpreter (); 198 199 Listener & 200 GetListener (); 201 202 SourceManager & 203 GetSourceManager (); 204 205 lldb::TargetSP 206 GetSelectedTarget (); 207 208 ExecutionContext 209 GetSelectedExecutionContext(); 210 //------------------------------------------------------------------ 211 /// Get accessor for the target list. 212 /// 213 /// The target list is part of the global debugger object. This 214 /// the single debugger shared instance to control where targets 215 /// get created and to allow for tracking and searching for targets 216 /// based on certain criteria. 217 /// 218 /// @return 219 /// A global shared target list. 220 //------------------------------------------------------------------ 221 TargetList& 222 GetTargetList (); 223 224 void 225 DispatchInput (const char *bytes, size_t bytes_len); 226 227 void 228 WriteToDefaultReader (const char *bytes, size_t bytes_len); 229 230 void 231 PushInputReader (const lldb::InputReaderSP& reader_sp); 232 233 bool 234 PopInputReader (const lldb::InputReaderSP& reader_sp); 235 236 ExecutionContext & 237 GetExecutionContext() 238 { 239 return m_exe_ctx; 240 } 241 242 void 243 UpdateExecutionContext (ExecutionContext *override_context); 244 245 static lldb::DebuggerSP 246 FindDebuggerWithID (lldb::user_id_t id); 247 248 bool 249 SetUseExternalEditor (bool value) 250 { 251 bool old_value = m_use_external_editor; 252 m_use_external_editor = value; 253 return old_value; 254 } 255 256 bool 257 UseExternalEditor () 258 { 259 return m_use_external_editor; 260 } 261 262 static lldb::DebuggerSP 263 FindDebuggerWithInstanceName (const ConstString &instance_name); 264 265protected: 266 267 static void 268 DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len); 269 270 void 271 ActivateInputReader (const lldb::InputReaderSP &reader_sp); 272 273 bool 274 CheckIfTopInputReaderIsDone (); 275 276 void 277 DisconnectInput(); 278 279 Communication m_input_comm; 280 StreamFile m_input_file; 281 StreamFile m_output_file; 282 StreamFile m_error_file; 283 TargetList m_target_list; 284 Listener m_listener; 285 SourceManager m_source_manager; 286 std::auto_ptr<CommandInterpreter> m_command_interpreter_ap; 287 ExecutionContext m_exe_ctx; 288 289 std::stack<lldb::InputReaderSP> m_input_readers; 290 std::string m_input_reader_data; 291 bool m_use_external_editor; // FIXME: Convert this to a set/show variable on the debugger. 292 293private: 294 295 // Use Debugger::CreateInstance() to get a shared pointer to a new 296 // debugger object 297 Debugger (); 298 299 DISALLOW_COPY_AND_ASSIGN (Debugger); 300}; 301 302} // namespace lldb_private 303 304#endif // #if defined(__cplusplus) 305#endif // liblldb_Debugger_h_ 306