Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Debugger.cpp --------------------------------------------*- 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 | |
Greg Clayton | 4a33d31 | 2011-06-23 17:59:56 +0000 | [diff] [blame] | 10 | #include "lldb/Core/Debugger.h" |
| 11 | |
| 12 | #include <map> |
| 13 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 14 | #include "clang/AST/DeclCXX.h" |
| 15 | #include "clang/AST/Type.h" |
| 16 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/lldb-private.h" |
| 18 | #include "lldb/Core/ConnectionFileDescriptor.h" |
Greg Clayton | 4a33d31 | 2011-06-23 17:59:56 +0000 | [diff] [blame] | 19 | #include "lldb/Core/FormatManager.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/InputReader.h" |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 21 | #include "lldb/Core/RegisterValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/State.h" |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 23 | #include "lldb/Core/StreamAsynchronousIO.h" |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 24 | #include "lldb/Core/StreamCallback.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StreamString.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Core/Timer.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 27 | #include "lldb/Core/ValueObject.h" |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 28 | #include "lldb/Core/ValueObjectVariable.h" |
Greg Clayton | a340661 | 2011-02-07 23:24:47 +0000 | [diff] [blame] | 29 | #include "lldb/Host/Terminal.h" |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 30 | #include "lldb/Interpreter/CommandInterpreter.h" |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 31 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Target/TargetList.h" |
| 33 | #include "lldb/Target/Process.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 34 | #include "lldb/Target/RegisterContext.h" |
| 35 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Target/Thread.h" |
Greg Clayton | 5a31471 | 2011-10-14 07:41:33 +0000 | [diff] [blame] | 37 | #include "lldb/Utility/AnsiTerminal.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | |
| 39 | using namespace lldb; |
| 40 | using namespace lldb_private; |
| 41 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 43 | static uint32_t g_shared_debugger_refcount = 0; |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 44 | static lldb::user_id_t g_unique_id = 1; |
| 45 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 46 | #pragma mark Static Functions |
| 47 | |
| 48 | static Mutex & |
| 49 | GetDebuggerListMutex () |
| 50 | { |
| 51 | static Mutex g_mutex(Mutex::eMutexTypeRecursive); |
| 52 | return g_mutex; |
| 53 | } |
| 54 | |
| 55 | typedef std::vector<DebuggerSP> DebuggerList; |
| 56 | |
| 57 | static DebuggerList & |
| 58 | GetDebuggerList() |
| 59 | { |
| 60 | // hide the static debugger list inside a singleton accessor to avoid |
| 61 | // global init contructors |
| 62 | static DebuggerList g_list; |
| 63 | return g_list; |
| 64 | } |
| 65 | |
| 66 | |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 67 | static const ConstString & |
| 68 | PromptVarName () |
| 69 | { |
| 70 | static ConstString g_const_string ("prompt"); |
| 71 | return g_const_string; |
| 72 | } |
| 73 | |
| 74 | static const ConstString & |
| 75 | GetFrameFormatName () |
| 76 | { |
| 77 | static ConstString g_const_string ("frame-format"); |
| 78 | return g_const_string; |
| 79 | } |
| 80 | |
| 81 | static const ConstString & |
| 82 | GetThreadFormatName () |
| 83 | { |
| 84 | static ConstString g_const_string ("thread-format"); |
| 85 | return g_const_string; |
| 86 | } |
| 87 | |
| 88 | static const ConstString & |
| 89 | ScriptLangVarName () |
| 90 | { |
| 91 | static ConstString g_const_string ("script-lang"); |
| 92 | return g_const_string; |
| 93 | } |
| 94 | |
| 95 | static const ConstString & |
| 96 | TermWidthVarName () |
| 97 | { |
| 98 | static ConstString g_const_string ("term-width"); |
| 99 | return g_const_string; |
| 100 | } |
| 101 | |
| 102 | static const ConstString & |
| 103 | UseExternalEditorVarName () |
| 104 | { |
| 105 | static ConstString g_const_string ("use-external-editor"); |
| 106 | return g_const_string; |
| 107 | } |
| 108 | |
| 109 | static const ConstString & |
| 110 | AutoConfirmName () |
| 111 | { |
| 112 | static ConstString g_const_string ("auto-confirm"); |
| 113 | return g_const_string; |
| 114 | } |
| 115 | |
| 116 | static const ConstString & |
| 117 | StopSourceContextBeforeName () |
| 118 | { |
| 119 | static ConstString g_const_string ("stop-line-count-before"); |
| 120 | return g_const_string; |
| 121 | } |
| 122 | |
| 123 | static const ConstString & |
| 124 | StopSourceContextAfterName () |
| 125 | { |
| 126 | static ConstString g_const_string ("stop-line-count-after"); |
| 127 | return g_const_string; |
| 128 | } |
| 129 | |
| 130 | static const ConstString & |
| 131 | StopDisassemblyCountName () |
| 132 | { |
| 133 | static ConstString g_const_string ("stop-disassembly-count"); |
| 134 | return g_const_string; |
| 135 | } |
| 136 | |
| 137 | static const ConstString & |
| 138 | StopDisassemblyDisplayName () |
| 139 | { |
| 140 | static ConstString g_const_string ("stop-disassembly-display"); |
| 141 | return g_const_string; |
| 142 | } |
| 143 | |
| 144 | OptionEnumValueElement |
| 145 | DebuggerInstanceSettings::g_show_disassembly_enum_values[] = |
| 146 | { |
| 147 | { eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."}, |
| 148 | { eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."}, |
| 149 | { eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."}, |
| 150 | { 0, NULL, NULL } |
| 151 | }; |
| 152 | |
| 153 | |
| 154 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 155 | #pragma mark Debugger |
| 156 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 157 | UserSettingsControllerSP & |
| 158 | Debugger::GetSettingsController () |
| 159 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 160 | static UserSettingsControllerSP g_settings_controller_sp; |
| 161 | if (!g_settings_controller_sp) |
| 162 | { |
| 163 | g_settings_controller_sp.reset (new Debugger::SettingsController); |
| 164 | |
| 165 | // The first shared pointer to Debugger::SettingsController in |
| 166 | // g_settings_controller_sp must be fully created above so that |
| 167 | // the DebuggerInstanceSettings can use a weak_ptr to refer back |
| 168 | // to the master setttings controller |
| 169 | InstanceSettingsSP default_instance_settings_sp (new DebuggerInstanceSettings (g_settings_controller_sp, |
| 170 | false, |
| 171 | InstanceSettings::GetDefaultName().AsCString())); |
| 172 | g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp); |
| 173 | } |
| 174 | return g_settings_controller_sp; |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 177 | int |
| 178 | Debugger::TestDebuggerRefCount () |
| 179 | { |
| 180 | return g_shared_debugger_refcount; |
| 181 | } |
| 182 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 183 | void |
| 184 | Debugger::Initialize () |
| 185 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 186 | if (g_shared_debugger_refcount == 0) |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 187 | { |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 188 | lldb_private::Initialize(); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 189 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 190 | g_shared_debugger_refcount++; |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 191 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void |
| 195 | Debugger::Terminate () |
| 196 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 197 | if (g_shared_debugger_refcount > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 199 | g_shared_debugger_refcount--; |
| 200 | if (g_shared_debugger_refcount == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | { |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 202 | lldb_private::WillTerminate(); |
| 203 | lldb_private::Terminate(); |
Caroline Tice | 6760a51 | 2011-01-17 21:55:19 +0000 | [diff] [blame] | 204 | |
| 205 | // Clear our master list of debugger objects |
| 206 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 207 | GetDebuggerList().clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 208 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 212 | void |
| 213 | Debugger::SettingsInitialize () |
| 214 | { |
| 215 | static bool g_initialized = false; |
| 216 | |
| 217 | if (!g_initialized) |
| 218 | { |
| 219 | g_initialized = true; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 220 | UserSettingsController::InitializeSettingsController (GetSettingsController(), |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 221 | SettingsController::global_settings_table, |
| 222 | SettingsController::instance_settings_table); |
| 223 | // Now call SettingsInitialize for each settings 'child' of Debugger |
| 224 | Target::SettingsInitialize (); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void |
| 229 | Debugger::SettingsTerminate () |
| 230 | { |
| 231 | |
| 232 | // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's |
| 233 | // Settings. |
| 234 | |
| 235 | Target::SettingsTerminate (); |
| 236 | |
| 237 | // Now terminate the Debugger Settings. |
| 238 | |
| 239 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 240 | UserSettingsController::FinalizeSettingsController (usc); |
| 241 | usc.reset(); |
| 242 | } |
| 243 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 244 | DebuggerSP |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 245 | Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 246 | { |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 247 | DebuggerSP debugger_sp (new Debugger(log_callback, baton)); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 248 | // Scope for locker |
| 249 | { |
| 250 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 251 | GetDebuggerList().push_back(debugger_sp); |
| 252 | } |
| 253 | return debugger_sp; |
| 254 | } |
| 255 | |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 256 | void |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 257 | Debugger::Destroy (DebuggerSP &debugger_sp) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 258 | { |
| 259 | if (debugger_sp.get() == NULL) |
| 260 | return; |
| 261 | |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 262 | debugger_sp->Clear(); |
| 263 | |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 264 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 265 | DebuggerList &debugger_list = GetDebuggerList (); |
| 266 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 267 | for (pos = debugger_list.begin (); pos != end; ++pos) |
| 268 | { |
| 269 | if ((*pos).get() == debugger_sp.get()) |
| 270 | { |
| 271 | debugger_list.erase (pos); |
| 272 | return; |
| 273 | } |
| 274 | } |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 277 | DebuggerSP |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 278 | Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) |
| 279 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 280 | DebuggerSP debugger_sp; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 281 | |
| 282 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 283 | DebuggerList &debugger_list = GetDebuggerList(); |
| 284 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 285 | |
| 286 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 287 | { |
| 288 | if ((*pos).get()->m_instance_name == instance_name) |
| 289 | { |
| 290 | debugger_sp = *pos; |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | return debugger_sp; |
| 295 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 296 | |
| 297 | TargetSP |
| 298 | Debugger::FindTargetWithProcessID (lldb::pid_t pid) |
| 299 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 300 | TargetSP target_sp; |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 301 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 302 | DebuggerList &debugger_list = GetDebuggerList(); |
| 303 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 304 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 305 | { |
| 306 | target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid); |
| 307 | if (target_sp) |
| 308 | break; |
| 309 | } |
| 310 | return target_sp; |
| 311 | } |
| 312 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 313 | TargetSP |
| 314 | Debugger::FindTargetWithProcess (Process *process) |
| 315 | { |
| 316 | TargetSP target_sp; |
| 317 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 318 | DebuggerList &debugger_list = GetDebuggerList(); |
| 319 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 320 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 321 | { |
| 322 | target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process); |
| 323 | if (target_sp) |
| 324 | break; |
| 325 | } |
| 326 | return target_sp; |
| 327 | } |
| 328 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 329 | |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 330 | Debugger::Debugger (lldb::LogOutputCallback log_callback, void *baton) : |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 331 | UserID (g_unique_id++), |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 332 | DebuggerInstanceSettings (GetSettingsController()), |
Greg Clayton | d46c87a | 2010-12-04 02:39:47 +0000 | [diff] [blame] | 333 | m_input_comm("debugger.input"), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | m_input_file (), |
| 335 | m_output_file (), |
| 336 | m_error_file (), |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 337 | m_target_list (*this), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 338 | m_platform_list (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 339 | m_listener ("lldb.Debugger"), |
Jim Ingham | e37d605 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 340 | m_source_manager(*this), |
| 341 | m_source_file_cache(), |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 342 | m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)), |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 343 | m_input_reader_stack (), |
Greg Clayton | 4957bf6 | 2010-09-30 21:49:03 +0000 | [diff] [blame] | 344 | m_input_reader_data () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | { |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 346 | if (log_callback) |
| 347 | m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton)); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 348 | m_command_interpreter_ap->Initialize (); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 349 | // Always add our default platform to the platform list |
| 350 | PlatformSP default_platform_sp (Platform::GetDefaultPlatform()); |
| 351 | assert (default_platform_sp.get()); |
| 352 | m_platform_list.Append (default_platform_sp, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | Debugger::~Debugger () |
| 356 | { |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 357 | Clear(); |
| 358 | } |
| 359 | |
| 360 | void |
| 361 | Debugger::Clear() |
| 362 | { |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 363 | CleanUpInputReaders(); |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 364 | m_listener.Clear(); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 365 | int num_targets = m_target_list.GetNumTargets(); |
| 366 | for (int i = 0; i < num_targets; i++) |
| 367 | { |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 368 | TargetSP target_sp (m_target_list.GetTargetAtIndex (i)); |
| 369 | if (target_sp) |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 370 | { |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 371 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 372 | if (process_sp) |
| 373 | { |
| 374 | if (process_sp->GetShouldDetach()) |
| 375 | process_sp->Detach(); |
| 376 | } |
| 377 | target_sp->Destroy(); |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 378 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 379 | } |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 380 | BroadcasterManager::Clear (); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 381 | DisconnectInput(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 382 | |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 383 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | |
| 385 | bool |
Greg Clayton | fc3f027 | 2011-05-29 04:06:55 +0000 | [diff] [blame] | 386 | Debugger::GetCloseInputOnEOF () const |
| 387 | { |
| 388 | return m_input_comm.GetCloseOnEOF(); |
| 389 | } |
| 390 | |
| 391 | void |
| 392 | Debugger::SetCloseInputOnEOF (bool b) |
| 393 | { |
| 394 | m_input_comm.SetCloseOnEOF(b); |
| 395 | } |
| 396 | |
| 397 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | Debugger::GetAsyncExecution () |
| 399 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 400 | return !m_command_interpreter_ap->GetSynchronous(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void |
| 404 | Debugger::SetAsyncExecution (bool async_execution) |
| 405 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 406 | m_command_interpreter_ap->SetSynchronous (!async_execution); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | |
| 410 | void |
| 411 | Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership) |
| 412 | { |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 413 | File &in_file = GetInputFile(); |
| 414 | in_file.SetStream (fh, tranfer_ownership); |
| 415 | if (in_file.IsValid() == false) |
| 416 | in_file.SetStream (stdin, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 417 | |
| 418 | // Disconnect from any old connection if we had one |
| 419 | m_input_comm.Disconnect (); |
Greg Clayton | 32720b5 | 2012-01-14 20:47:38 +0000 | [diff] [blame] | 420 | // Pass false as the second argument to ConnectionFileDescriptor below because |
| 421 | // our "in_file" above will already take ownership if requested and we don't |
| 422 | // want to objects trying to own and close a file descriptor. |
| 423 | m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this); |
| 425 | |
| 426 | Error error; |
| 427 | if (m_input_comm.StartReadThread (&error) == false) |
| 428 | { |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 429 | File &err_file = GetErrorFile(); |
| 430 | |
| 431 | err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error"); |
| 432 | exit(1); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 433 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | void |
| 437 | Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership) |
| 438 | { |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 439 | File &out_file = GetOutputFile(); |
| 440 | out_file.SetStream (fh, tranfer_ownership); |
| 441 | if (out_file.IsValid() == false) |
| 442 | out_file.SetStream (stdout, false); |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 443 | |
| 444 | GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | void |
| 448 | Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership) |
| 449 | { |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 450 | File &err_file = GetErrorFile(); |
| 451 | err_file.SetStream (fh, tranfer_ownership); |
| 452 | if (err_file.IsValid() == false) |
| 453 | err_file.SetStream (stderr, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | ExecutionContext |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 457 | Debugger::GetSelectedExecutionContext () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | { |
| 459 | ExecutionContext exe_ctx; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 460 | TargetSP target_sp(GetSelectedTarget()); |
| 461 | exe_ctx.SetTargetSP (target_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 462 | |
| 463 | if (target_sp) |
| 464 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 465 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 466 | exe_ctx.SetProcessSP (process_sp); |
| 467 | if (process_sp && process_sp->IsRunning() == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 468 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 469 | ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread()); |
| 470 | if (thread_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 471 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 472 | exe_ctx.SetThreadSP (thread_sp); |
| 473 | exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame()); |
| 474 | if (exe_ctx.GetFramePtr() == NULL) |
| 475 | exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | } |
| 479 | return exe_ctx; |
| 480 | |
| 481 | } |
| 482 | |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 483 | InputReaderSP |
| 484 | Debugger::GetCurrentInputReader () |
| 485 | { |
| 486 | InputReaderSP reader_sp; |
| 487 | |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 488 | if (!m_input_reader_stack.IsEmpty()) |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 489 | { |
| 490 | // Clear any finished readers from the stack |
| 491 | while (CheckIfTopInputReaderIsDone()) ; |
| 492 | |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 493 | if (!m_input_reader_stack.IsEmpty()) |
| 494 | reader_sp = m_input_reader_stack.Top(); |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | return reader_sp; |
| 498 | } |
| 499 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | void |
| 501 | Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len) |
| 502 | { |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 503 | if (bytes_len > 0) |
| 504 | ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len); |
| 505 | else |
| 506 | ((Debugger *)baton)->DispatchInputEndOfFile (); |
| 507 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 508 | |
| 509 | |
| 510 | void |
| 511 | Debugger::DispatchInput (const char *bytes, size_t bytes_len) |
| 512 | { |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 513 | if (bytes == NULL || bytes_len == 0) |
| 514 | return; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 515 | |
| 516 | WriteToDefaultReader (bytes, bytes_len); |
| 517 | } |
| 518 | |
| 519 | void |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 520 | Debugger::DispatchInputInterrupt () |
| 521 | { |
| 522 | m_input_reader_data.clear(); |
| 523 | |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 524 | InputReaderSP reader_sp (GetCurrentInputReader ()); |
| 525 | if (reader_sp) |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 526 | { |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 527 | reader_sp->Notify (eInputReaderInterrupt); |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 528 | |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 529 | // If notifying the reader of the interrupt finished the reader, we should pop it off the stack. |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 530 | while (CheckIfTopInputReaderIsDone ()) ; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | void |
| 535 | Debugger::DispatchInputEndOfFile () |
| 536 | { |
| 537 | m_input_reader_data.clear(); |
| 538 | |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 539 | InputReaderSP reader_sp (GetCurrentInputReader ()); |
| 540 | if (reader_sp) |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 541 | { |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 542 | reader_sp->Notify (eInputReaderEndOfFile); |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 543 | |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 544 | // If notifying the reader of the end-of-file finished the reader, we should pop it off the stack. |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 545 | while (CheckIfTopInputReaderIsDone ()) ; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | void |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 550 | Debugger::CleanUpInputReaders () |
| 551 | { |
| 552 | m_input_reader_data.clear(); |
| 553 | |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 554 | // The bottom input reader should be the main debugger input reader. We do not want to close that one here. |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 555 | while (m_input_reader_stack.GetSize() > 1) |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 556 | { |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 557 | InputReaderSP reader_sp (GetCurrentInputReader ()); |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 558 | if (reader_sp) |
| 559 | { |
| 560 | reader_sp->Notify (eInputReaderEndOfFile); |
| 561 | reader_sp->SetIsDone (true); |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | void |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 567 | Debugger::NotifyTopInputReader (InputReaderAction notification) |
| 568 | { |
| 569 | InputReaderSP reader_sp (GetCurrentInputReader()); |
| 570 | if (reader_sp) |
| 571 | { |
| 572 | reader_sp->Notify (notification); |
| 573 | |
| 574 | // Flush out any input readers that are done. |
| 575 | while (CheckIfTopInputReaderIsDone ()) |
| 576 | /* Do nothing. */; |
| 577 | } |
| 578 | } |
| 579 | |
Caroline Tice | 9088b06 | 2011-05-09 23:06:58 +0000 | [diff] [blame] | 580 | bool |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 581 | Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp) |
Caroline Tice | 9088b06 | 2011-05-09 23:06:58 +0000 | [diff] [blame] | 582 | { |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 583 | InputReaderSP top_reader_sp (GetCurrentInputReader()); |
Caroline Tice | 9088b06 | 2011-05-09 23:06:58 +0000 | [diff] [blame] | 584 | |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 585 | return (reader_sp.get() == top_reader_sp.get()); |
Caroline Tice | 9088b06 | 2011-05-09 23:06:58 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 589 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 590 | Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len) |
| 591 | { |
| 592 | if (bytes && bytes_len) |
| 593 | m_input_reader_data.append (bytes, bytes_len); |
| 594 | |
| 595 | if (m_input_reader_data.empty()) |
| 596 | return; |
| 597 | |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 598 | while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 600 | // Get the input reader from the top of the stack |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 601 | InputReaderSP reader_sp (GetCurrentInputReader ()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 602 | if (!reader_sp) |
| 603 | break; |
| 604 | |
Greg Clayton | 471b31c | 2010-07-20 22:52:08 +0000 | [diff] [blame] | 605 | size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 606 | m_input_reader_data.size()); |
| 607 | if (bytes_handled) |
| 608 | { |
| 609 | m_input_reader_data.erase (0, bytes_handled); |
| 610 | } |
| 611 | else |
| 612 | { |
| 613 | // No bytes were handled, we might not have reached our |
| 614 | // granularity, just return and wait for more data |
| 615 | break; |
| 616 | } |
| 617 | } |
| 618 | |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 619 | // Flush out any input readers that are done. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | while (CheckIfTopInputReaderIsDone ()) |
| 621 | /* Do nothing. */; |
| 622 | |
| 623 | } |
| 624 | |
| 625 | void |
| 626 | Debugger::PushInputReader (const InputReaderSP& reader_sp) |
| 627 | { |
| 628 | if (!reader_sp) |
| 629 | return; |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 630 | |
| 631 | // Deactivate the old top reader |
| 632 | InputReaderSP top_reader_sp (GetCurrentInputReader ()); |
| 633 | |
| 634 | if (top_reader_sp) |
| 635 | top_reader_sp->Notify (eInputReaderDeactivate); |
| 636 | |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 637 | m_input_reader_stack.Push (reader_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | reader_sp->Notify (eInputReaderActivate); |
| 639 | ActivateInputReader (reader_sp); |
| 640 | } |
| 641 | |
| 642 | bool |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 643 | Debugger::PopInputReader (const InputReaderSP& pop_reader_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | { |
| 645 | bool result = false; |
| 646 | |
| 647 | // The reader on the stop of the stack is done, so let the next |
| 648 | // read on the stack referesh its prompt and if there is one... |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 649 | if (!m_input_reader_stack.IsEmpty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | { |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 651 | // Cannot call GetCurrentInputReader here, as that would cause an infinite loop. |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 652 | InputReaderSP reader_sp(m_input_reader_stack.Top()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 653 | |
| 654 | if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get()) |
| 655 | { |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 656 | m_input_reader_stack.Pop (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 657 | reader_sp->Notify (eInputReaderDeactivate); |
| 658 | reader_sp->Notify (eInputReaderDone); |
| 659 | result = true; |
| 660 | |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 661 | if (!m_input_reader_stack.IsEmpty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | { |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 663 | reader_sp = m_input_reader_stack.Top(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | if (reader_sp) |
| 665 | { |
| 666 | ActivateInputReader (reader_sp); |
| 667 | reader_sp->Notify (eInputReaderReactivate); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | return result; |
| 673 | } |
| 674 | |
| 675 | bool |
| 676 | Debugger::CheckIfTopInputReaderIsDone () |
| 677 | { |
| 678 | bool result = false; |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 679 | if (!m_input_reader_stack.IsEmpty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | { |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 681 | // Cannot call GetCurrentInputReader here, as that would cause an infinite loop. |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 682 | InputReaderSP reader_sp(m_input_reader_stack.Top()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | |
| 684 | if (reader_sp && reader_sp->IsDone()) |
| 685 | { |
| 686 | result = true; |
| 687 | PopInputReader (reader_sp); |
| 688 | } |
| 689 | } |
| 690 | return result; |
| 691 | } |
| 692 | |
| 693 | void |
| 694 | Debugger::ActivateInputReader (const InputReaderSP &reader_sp) |
| 695 | { |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 696 | int input_fd = m_input_file.GetFile().GetDescriptor(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 697 | |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 698 | if (input_fd >= 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 699 | { |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 700 | Terminal tty(input_fd); |
Greg Clayton | a340661 | 2011-02-07 23:24:47 +0000 | [diff] [blame] | 701 | |
| 702 | tty.SetEcho(reader_sp->GetEcho()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 703 | |
Greg Clayton | a340661 | 2011-02-07 23:24:47 +0000 | [diff] [blame] | 704 | switch (reader_sp->GetGranularity()) |
| 705 | { |
| 706 | case eInputReaderGranularityByte: |
| 707 | case eInputReaderGranularityWord: |
| 708 | tty.SetCanonical (false); |
| 709 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | |
Greg Clayton | a340661 | 2011-02-07 23:24:47 +0000 | [diff] [blame] | 711 | case eInputReaderGranularityLine: |
| 712 | case eInputReaderGranularityAll: |
| 713 | tty.SetCanonical (true); |
| 714 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | |
Greg Clayton | a340661 | 2011-02-07 23:24:47 +0000 | [diff] [blame] | 716 | default: |
| 717 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 721 | |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 722 | StreamSP |
| 723 | Debugger::GetAsyncOutputStream () |
| 724 | { |
| 725 | return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(), |
| 726 | CommandInterpreter::eBroadcastBitAsynchronousOutputData)); |
| 727 | } |
| 728 | |
| 729 | StreamSP |
| 730 | Debugger::GetAsyncErrorStream () |
| 731 | { |
| 732 | return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(), |
| 733 | CommandInterpreter::eBroadcastBitAsynchronousErrorData)); |
| 734 | } |
| 735 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 736 | uint32_t |
| 737 | Debugger::GetNumDebuggers() |
| 738 | { |
| 739 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 740 | return GetDebuggerList().size(); |
| 741 | } |
| 742 | |
| 743 | lldb::DebuggerSP |
| 744 | Debugger::GetDebuggerAtIndex (uint32_t index) |
| 745 | { |
| 746 | DebuggerSP debugger_sp; |
| 747 | |
| 748 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 749 | DebuggerList &debugger_list = GetDebuggerList(); |
| 750 | |
| 751 | if (index < debugger_list.size()) |
| 752 | debugger_sp = debugger_list[index]; |
| 753 | |
| 754 | return debugger_sp; |
| 755 | } |
| 756 | |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 757 | DebuggerSP |
| 758 | Debugger::FindDebuggerWithID (lldb::user_id_t id) |
| 759 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 760 | DebuggerSP debugger_sp; |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 761 | |
| 762 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 763 | DebuggerList &debugger_list = GetDebuggerList(); |
| 764 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 765 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 766 | { |
| 767 | if ((*pos).get()->GetID() == id) |
| 768 | { |
| 769 | debugger_sp = *pos; |
| 770 | break; |
| 771 | } |
| 772 | } |
| 773 | return debugger_sp; |
| 774 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 775 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 776 | static void |
| 777 | TestPromptFormats (StackFrame *frame) |
| 778 | { |
| 779 | if (frame == NULL) |
| 780 | return; |
| 781 | |
| 782 | StreamString s; |
| 783 | const char *prompt_format = |
| 784 | "{addr = '${addr}'\n}" |
| 785 | "{process.id = '${process.id}'\n}" |
| 786 | "{process.name = '${process.name}'\n}" |
| 787 | "{process.file.basename = '${process.file.basename}'\n}" |
| 788 | "{process.file.fullpath = '${process.file.fullpath}'\n}" |
| 789 | "{thread.id = '${thread.id}'\n}" |
| 790 | "{thread.index = '${thread.index}'\n}" |
| 791 | "{thread.name = '${thread.name}'\n}" |
| 792 | "{thread.queue = '${thread.queue}'\n}" |
| 793 | "{thread.stop-reason = '${thread.stop-reason}'\n}" |
| 794 | "{target.arch = '${target.arch}'\n}" |
| 795 | "{module.file.basename = '${module.file.basename}'\n}" |
| 796 | "{module.file.fullpath = '${module.file.fullpath}'\n}" |
| 797 | "{file.basename = '${file.basename}'\n}" |
| 798 | "{file.fullpath = '${file.fullpath}'\n}" |
| 799 | "{frame.index = '${frame.index}'\n}" |
| 800 | "{frame.pc = '${frame.pc}'\n}" |
| 801 | "{frame.sp = '${frame.sp}'\n}" |
| 802 | "{frame.fp = '${frame.fp}'\n}" |
| 803 | "{frame.flags = '${frame.flags}'\n}" |
| 804 | "{frame.reg.rdi = '${frame.reg.rdi}'\n}" |
| 805 | "{frame.reg.rip = '${frame.reg.rip}'\n}" |
| 806 | "{frame.reg.rsp = '${frame.reg.rsp}'\n}" |
| 807 | "{frame.reg.rbp = '${frame.reg.rbp}'\n}" |
| 808 | "{frame.reg.rflags = '${frame.reg.rflags}'\n}" |
| 809 | "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}" |
| 810 | "{frame.reg.carp = '${frame.reg.carp}'\n}" |
| 811 | "{function.id = '${function.id}'\n}" |
| 812 | "{function.name = '${function.name}'\n}" |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 813 | "{function.name-with-args = '${function.name-with-args}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 814 | "{function.addr-offset = '${function.addr-offset}'\n}" |
| 815 | "{function.line-offset = '${function.line-offset}'\n}" |
| 816 | "{function.pc-offset = '${function.pc-offset}'\n}" |
| 817 | "{line.file.basename = '${line.file.basename}'\n}" |
| 818 | "{line.file.fullpath = '${line.file.fullpath}'\n}" |
| 819 | "{line.number = '${line.number}'\n}" |
| 820 | "{line.start-addr = '${line.start-addr}'\n}" |
| 821 | "{line.end-addr = '${line.end-addr}'\n}" |
| 822 | ; |
| 823 | |
| 824 | SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything)); |
| 825 | ExecutionContext exe_ctx; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 826 | frame->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 827 | const char *end = NULL; |
| 828 | if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end)) |
| 829 | { |
| 830 | printf("%s\n", s.GetData()); |
| 831 | } |
| 832 | else |
| 833 | { |
| 834 | printf ("error: at '%s'\n", end); |
| 835 | printf ("what we got: %s\n", s.GetData()); |
| 836 | } |
| 837 | } |
| 838 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 839 | static bool |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 840 | ScanFormatDescriptor (const char* var_name_begin, |
| 841 | const char* var_name_end, |
| 842 | const char** var_name_final, |
| 843 | const char** percent_position, |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 844 | Format* custom_format, |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 845 | ValueObject::ValueObjectRepresentationStyle* val_obj_display) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 846 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 847 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 848 | *percent_position = ::strchr(var_name_begin,'%'); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 849 | if (!*percent_position || *percent_position > var_name_end) |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 850 | { |
| 851 | if (log) |
| 852 | log->Printf("no format descriptor in string, skipping"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 853 | *var_name_final = var_name_end; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 854 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 855 | else |
| 856 | { |
| 857 | *var_name_final = *percent_position; |
| 858 | char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0'; |
| 859 | memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 860 | if (log) |
| 861 | log->Printf("parsing %s as a format descriptor", format_name); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 862 | if ( !FormatManager::GetFormatFromCString(format_name, |
| 863 | true, |
| 864 | *custom_format) ) |
| 865 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 866 | if (log) |
| 867 | log->Printf("%s is an unknown format", format_name); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 868 | // if this is an @ sign, print ObjC description |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 869 | if (*format_name == '@') |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 870 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleLanguageSpecific; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 871 | // if this is a V, print the value using the default format |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 872 | else if (*format_name == 'V') |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 873 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 874 | // if this is an L, print the location of the value |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 875 | else if (*format_name == 'L') |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 876 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleLocation; |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 877 | // if this is an S, print the summary after all |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 878 | else if (*format_name == 'S') |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 879 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary; |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 880 | else if (*format_name == '#') |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 881 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleChildrenCount; |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 882 | else if (*format_name == 'T') |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 883 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleType; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 884 | else if (log) |
| 885 | log->Printf("%s is an error, leaving the previous value alone", format_name); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 886 | } |
| 887 | // a good custom format tells us to print the value using it |
| 888 | else |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 889 | { |
| 890 | if (log) |
| 891 | log->Printf("will display value for this VO"); |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 892 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 893 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 894 | delete format_name; |
| 895 | } |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 896 | if (log) |
| 897 | log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d", |
| 898 | *custom_format, |
| 899 | *val_obj_display); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 900 | return true; |
| 901 | } |
| 902 | |
| 903 | static bool |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 904 | ScanBracketedRange (const char* var_name_begin, |
| 905 | const char* var_name_end, |
| 906 | const char* var_name_final, |
| 907 | const char** open_bracket_position, |
| 908 | const char** separator_position, |
| 909 | const char** close_bracket_position, |
| 910 | const char** var_name_final_if_array_range, |
| 911 | int64_t* index_lower, |
| 912 | int64_t* index_higher) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 913 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 914 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 915 | *open_bracket_position = ::strchr(var_name_begin,'['); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 916 | if (*open_bracket_position && *open_bracket_position < var_name_final) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 917 | { |
| 918 | *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield |
| 919 | *close_bracket_position = ::strchr(*open_bracket_position,']'); |
| 920 | // as usual, we assume that [] will come before % |
| 921 | //printf("trying to expand a []\n"); |
| 922 | *var_name_final_if_array_range = *open_bracket_position; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 923 | if (*close_bracket_position - *open_bracket_position == 1) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 924 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 925 | if (log) |
| 926 | log->Printf("[] detected.. going from 0 to end of data"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 927 | *index_lower = 0; |
| 928 | } |
| 929 | else if (*separator_position == NULL || *separator_position > var_name_end) |
| 930 | { |
| 931 | char *end = NULL; |
| 932 | *index_lower = ::strtoul (*open_bracket_position+1, &end, 0); |
| 933 | *index_higher = *index_lower; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 934 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 935 | log->Printf("[%lld] detected, high index is same", *index_lower); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 936 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 937 | else if (*close_bracket_position && *close_bracket_position < var_name_end) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 938 | { |
| 939 | char *end = NULL; |
| 940 | *index_lower = ::strtoul (*open_bracket_position+1, &end, 0); |
| 941 | *index_higher = ::strtoul (*separator_position+1, &end, 0); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 942 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 943 | log->Printf("[%lld-%lld] detected", *index_lower, *index_higher); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 944 | } |
| 945 | else |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 946 | { |
| 947 | if (log) |
| 948 | log->Printf("expression is erroneous, cannot extract indices out of it"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 949 | return false; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 950 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 951 | if (*index_lower > *index_higher && *index_higher > 0) |
| 952 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 953 | if (log) |
| 954 | log->Printf("swapping indices"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 955 | int temp = *index_lower; |
| 956 | *index_lower = *index_higher; |
| 957 | *index_higher = temp; |
| 958 | } |
| 959 | } |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 960 | else if (log) |
| 961 | log->Printf("no bracketed range, skipping entirely"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 962 | return true; |
| 963 | } |
| 964 | |
| 965 | |
| 966 | static ValueObjectSP |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 967 | ExpandExpressionPath (ValueObject* valobj, |
| 968 | StackFrame* frame, |
| 969 | bool* do_deref_pointer, |
| 970 | const char* var_name_begin, |
| 971 | const char* var_name_final, |
| 972 | Error& error) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 973 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 974 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 975 | StreamString sstring; |
| 976 | VariableSP var_sp; |
| 977 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 978 | if (*do_deref_pointer) |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 979 | { |
| 980 | if (log) |
| 981 | log->Printf("been told to deref_pointer by caller"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 982 | sstring.PutChar('*'); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 983 | } |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 984 | else if (valobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(valobj->GetParent()->GetClangType()) && !valobj->IsArrayItemForPointer()) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 985 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 986 | if (log) |
| 987 | log->Printf("decided to deref_pointer myself"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 988 | sstring.PutChar('*'); |
| 989 | *do_deref_pointer = true; |
| 990 | } |
| 991 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 992 | valobj->GetExpressionPath(sstring, true, ValueObject::eGetExpressionPathFormatHonorPointers); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 993 | if (log) |
| 994 | log->Printf("expression path to expand in phase 0: %s",sstring.GetData()); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 995 | sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 996 | if (log) |
| 997 | log->Printf("expression path to expand in phase 1: %s",sstring.GetData()); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 998 | std::string name = std::string(sstring.GetData()); |
| 999 | ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(), |
| 1000 | eNoDynamicValues, |
| 1001 | 0, |
| 1002 | var_sp, |
| 1003 | error); |
| 1004 | return target; |
| 1005 | } |
| 1006 | |
| 1007 | static ValueObjectSP |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1008 | ExpandIndexedExpression (ValueObject* valobj, |
| 1009 | uint32_t index, |
| 1010 | StackFrame* frame, |
| 1011 | bool deref_pointer) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1012 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1013 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1014 | const char* ptr_deref_format = "[%d]"; |
| 1015 | std::auto_ptr<char> ptr_deref_buffer(new char[10]); |
| 1016 | ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1017 | if (log) |
| 1018 | log->Printf("name to deref: %s",ptr_deref_buffer.get()); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1019 | const char* first_unparsed; |
| 1020 | ValueObject::GetValueForExpressionPathOptions options; |
| 1021 | ValueObject::ExpressionPathEndResultType final_value_type; |
| 1022 | ValueObject::ExpressionPathScanEndReason reason_to_stop; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1023 | ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing); |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1024 | ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(), |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1025 | &first_unparsed, |
| 1026 | &reason_to_stop, |
| 1027 | &final_value_type, |
| 1028 | options, |
| 1029 | &what_next); |
| 1030 | if (!item) |
| 1031 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1032 | if (log) |
| 1033 | log->Printf("ERROR: unparsed portion = %s, why stopping = %d," |
| 1034 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1035 | first_unparsed, reason_to_stop, final_value_type); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1036 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1037 | else |
| 1038 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1039 | if (log) |
| 1040 | log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d," |
| 1041 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1042 | first_unparsed, reason_to_stop, final_value_type); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1043 | } |
| 1044 | return item; |
| 1045 | } |
| 1046 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1047 | bool |
| 1048 | Debugger::FormatPrompt |
| 1049 | ( |
| 1050 | const char *format, |
| 1051 | const SymbolContext *sc, |
| 1052 | const ExecutionContext *exe_ctx, |
| 1053 | const Address *addr, |
| 1054 | Stream &s, |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1055 | const char **end, |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1056 | ValueObject* valobj |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1057 | ) |
| 1058 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1059 | ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1060 | bool success = true; |
| 1061 | const char *p; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1062 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1063 | for (p = format; *p != '\0'; ++p) |
| 1064 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1065 | if (realvalobj) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1066 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1067 | valobj = realvalobj; |
| 1068 | realvalobj = NULL; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1069 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1070 | size_t non_special_chars = ::strcspn (p, "${}\\"); |
| 1071 | if (non_special_chars > 0) |
| 1072 | { |
| 1073 | if (success) |
| 1074 | s.Write (p, non_special_chars); |
| 1075 | p += non_special_chars; |
| 1076 | } |
| 1077 | |
| 1078 | if (*p == '\0') |
| 1079 | { |
| 1080 | break; |
| 1081 | } |
| 1082 | else if (*p == '{') |
| 1083 | { |
| 1084 | // Start a new scope that must have everything it needs if it is to |
| 1085 | // to make it into the final output stream "s". If you want to make |
| 1086 | // a format that only prints out the function or symbol name if there |
| 1087 | // is one in the symbol context you can use: |
| 1088 | // "{function =${function.name}}" |
| 1089 | // The first '{' starts a new scope that end with the matching '}' at |
| 1090 | // the end of the string. The contents "function =${function.name}" |
| 1091 | // will then be evaluated and only be output if there is a function |
| 1092 | // or symbol with a valid name. |
| 1093 | StreamString sub_strm; |
| 1094 | |
| 1095 | ++p; // Skip the '{' |
| 1096 | |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1097 | if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj)) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1098 | { |
| 1099 | // The stream had all it needed |
| 1100 | s.Write(sub_strm.GetData(), sub_strm.GetSize()); |
| 1101 | } |
| 1102 | if (*p != '}') |
| 1103 | { |
| 1104 | success = false; |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
| 1108 | else if (*p == '}') |
| 1109 | { |
| 1110 | // End of a enclosing scope |
| 1111 | break; |
| 1112 | } |
| 1113 | else if (*p == '$') |
| 1114 | { |
| 1115 | // We have a prompt variable to print |
| 1116 | ++p; |
| 1117 | if (*p == '{') |
| 1118 | { |
| 1119 | ++p; |
| 1120 | const char *var_name_begin = p; |
| 1121 | const char *var_name_end = ::strchr (p, '}'); |
| 1122 | |
| 1123 | if (var_name_end && var_name_begin < var_name_end) |
| 1124 | { |
| 1125 | // if we have already failed to parse, skip this variable |
| 1126 | if (success) |
| 1127 | { |
| 1128 | const char *cstr = NULL; |
| 1129 | Address format_addr; |
| 1130 | bool calculate_format_addr_function_offset = false; |
| 1131 | // Set reg_kind and reg_num to invalid values |
| 1132 | RegisterKind reg_kind = kNumRegisterKinds; |
| 1133 | uint32_t reg_num = LLDB_INVALID_REGNUM; |
| 1134 | FileSpec format_file_spec; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1135 | const RegisterInfo *reg_info = NULL; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1136 | RegisterContext *reg_ctx = NULL; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1137 | bool do_deref_pointer = false; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1138 | ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; |
| 1139 | ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1140 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1141 | // Each variable must set success to true below... |
| 1142 | bool var_success = false; |
| 1143 | switch (var_name_begin[0]) |
| 1144 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1145 | case '*': |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1146 | case 'v': |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1147 | case 's': |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1148 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1149 | if (!valobj) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1150 | break; |
| 1151 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1152 | if (log) |
| 1153 | log->Printf("initial string: %s",var_name_begin); |
| 1154 | |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1155 | // check for *var and *svar |
| 1156 | if (*var_name_begin == '*') |
| 1157 | { |
| 1158 | do_deref_pointer = true; |
| 1159 | var_name_begin++; |
| 1160 | } |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1161 | |
| 1162 | if (log) |
| 1163 | log->Printf("initial string: %s",var_name_begin); |
| 1164 | |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1165 | if (*var_name_begin == 's') |
| 1166 | { |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1167 | valobj = valobj->GetSyntheticValue().get(); |
| 1168 | if (!valobj) |
| 1169 | break; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1170 | var_name_begin++; |
| 1171 | } |
| 1172 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1173 | if (log) |
| 1174 | log->Printf("initial string: %s",var_name_begin); |
| 1175 | |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1176 | // should be a 'v' by now |
| 1177 | if (*var_name_begin != 'v') |
| 1178 | break; |
| 1179 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1180 | if (log) |
| 1181 | log->Printf("initial string: %s",var_name_begin); |
| 1182 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1183 | ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ? |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1184 | ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1185 | ValueObject::GetValueForExpressionPathOptions options; |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 1186 | options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren(); |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1187 | ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1188 | ValueObject* target = NULL; |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1189 | Format custom_format = eFormatInvalid; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1190 | const char* var_name_final = NULL; |
| 1191 | const char* var_name_final_if_array_range = NULL; |
| 1192 | const char* close_bracket_position = NULL; |
| 1193 | int64_t index_lower = -1; |
| 1194 | int64_t index_higher = -1; |
| 1195 | bool is_array_range = false; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1196 | const char* first_unparsed; |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1197 | bool was_plain_var = false; |
| 1198 | bool was_var_format = false; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1199 | |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1200 | if (!valobj) break; |
| 1201 | // simplest case ${var}, just print valobj's value |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1202 | if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1203 | { |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1204 | was_plain_var = true; |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1205 | target = valobj; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1206 | val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1207 | } |
| 1208 | else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0) |
| 1209 | { |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1210 | was_var_format = true; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1211 | // this is a variable with some custom format applied to it |
| 1212 | const char* percent_position; |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1213 | target = valobj; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1214 | val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1215 | ScanFormatDescriptor (var_name_begin, |
| 1216 | var_name_end, |
| 1217 | &var_name_final, |
| 1218 | &percent_position, |
| 1219 | &custom_format, |
| 1220 | &val_obj_display); |
| 1221 | } |
| 1222 | // this is ${var.something} or multiple .something nested |
| 1223 | else if (::strncmp (var_name_begin, "var", strlen("var")) == 0) |
| 1224 | { |
| 1225 | |
| 1226 | const char* percent_position; |
| 1227 | ScanFormatDescriptor (var_name_begin, |
| 1228 | var_name_end, |
| 1229 | &var_name_final, |
| 1230 | &percent_position, |
| 1231 | &custom_format, |
| 1232 | &val_obj_display); |
| 1233 | |
| 1234 | const char* open_bracket_position; |
| 1235 | const char* separator_position; |
| 1236 | ScanBracketedRange (var_name_begin, |
| 1237 | var_name_end, |
| 1238 | var_name_final, |
| 1239 | &open_bracket_position, |
| 1240 | &separator_position, |
| 1241 | &close_bracket_position, |
| 1242 | &var_name_final_if_array_range, |
| 1243 | &index_lower, |
| 1244 | &index_higher); |
| 1245 | |
| 1246 | Error error; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1247 | |
| 1248 | std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]); |
| 1249 | ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1); |
| 1250 | memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3); |
| 1251 | |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1252 | if (log) |
| 1253 | log->Printf("symbol to expand: %s",expr_path.get()); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1254 | |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1255 | target = valobj->GetValueForExpressionPath(expr_path.get(), |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1256 | &first_unparsed, |
| 1257 | &reason_to_stop, |
| 1258 | &final_value_type, |
| 1259 | options, |
| 1260 | &what_next).get(); |
| 1261 | |
| 1262 | if (!target) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1263 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1264 | if (log) |
| 1265 | log->Printf("ERROR: unparsed portion = %s, why stopping = %d," |
| 1266 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1267 | first_unparsed, reason_to_stop, final_value_type); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1268 | break; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1269 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1270 | else |
| 1271 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1272 | if (log) |
| 1273 | log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d," |
| 1274 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1275 | first_unparsed, reason_to_stop, final_value_type); |
| 1276 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1277 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1278 | else |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1279 | break; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1280 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1281 | is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange || |
| 1282 | final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1283 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1284 | do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1285 | |
Enrico Granata | a7187d0 | 2011-07-06 19:27:11 +0000 | [diff] [blame] | 1286 | if (do_deref_pointer && !is_array_range) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1287 | { |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1288 | // I have not deref-ed yet, let's do it |
| 1289 | // this happens when we are not going through GetValueForVariableExpressionPath |
| 1290 | // to get to the target ValueObject |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1291 | Error error; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1292 | target = target->Dereference(error).get(); |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1293 | if (error.Fail()) |
| 1294 | { |
| 1295 | if (log) |
| 1296 | log->Printf("ERROR: %s\n", error.AsCString("unknown")); \ |
| 1297 | break; |
| 1298 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1299 | do_deref_pointer = false; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1300 | } |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1301 | |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1302 | // TODO use flags for these |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1303 | bool is_array = ClangASTContext::IsArrayType(target->GetClangType()); |
| 1304 | bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType()); |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1305 | bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType()); |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1306 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1307 | if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) // this should be wrong, but there are some exceptions |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1308 | { |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1309 | StreamString str_temp; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1310 | if (log) |
| 1311 | log->Printf("I am into array || pointer && !range"); |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1312 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1313 | if (target->HasSpecialPrintableRepresentation(val_obj_display, |
| 1314 | custom_format)) |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1315 | { |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1316 | // try to use the special cases |
| 1317 | var_success = target->DumpPrintableRepresentation(str_temp, |
| 1318 | val_obj_display, |
| 1319 | custom_format); |
| 1320 | if (log) |
| 1321 | log->Printf("special cases did%s match", var_success ? "" : "n't"); |
| 1322 | |
| 1323 | // should not happen |
| 1324 | if (!var_success) |
| 1325 | s << "<invalid usage of pointer value as object>"; |
| 1326 | else |
| 1327 | s << str_temp.GetData(); |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1328 | var_success = true; |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1329 | break; |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1330 | } |
| 1331 | else |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1332 | { |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1333 | if (was_plain_var) // if ${var} |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1334 | { |
| 1335 | s << target->GetTypeName() << " @ " << target->GetLocationAsCString(); |
| 1336 | } |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1337 | else if (is_pointer) // if pointer, value is the address stored |
| 1338 | { |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1339 | var_success = target->DumpPrintableRepresentation(s, |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1340 | val_obj_display, |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1341 | custom_format, |
| 1342 | ValueObject::ePrintableRepresentationSpecialCasesDisable); |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1343 | } |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1344 | else |
| 1345 | { |
| 1346 | s << "<invalid usage of pointer value as object>"; |
| 1347 | } |
| 1348 | var_success = true; |
| 1349 | break; |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | // if directly trying to print ${var}, and this is an aggregate, display a nice |
| 1354 | // type @ location message |
| 1355 | if (is_aggregate && was_plain_var) |
| 1356 | { |
| 1357 | s << target->GetTypeName() << " @ " << target->GetLocationAsCString(); |
| 1358 | var_success = true; |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1359 | break; |
| 1360 | } |
| 1361 | |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1362 | // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame^] | 1363 | if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue))) |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1364 | { |
| 1365 | s << "<invalid use of aggregate type>"; |
| 1366 | var_success = true; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1367 | break; |
| 1368 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1369 | |
| 1370 | if (!is_array_range) |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1371 | { |
| 1372 | if (log) |
| 1373 | log->Printf("dumping ordinary printable output"); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1374 | var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1375 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1376 | else |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1377 | { |
| 1378 | if (log) |
| 1379 | log->Printf("checking if I can handle as array"); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1380 | if (!is_array && !is_pointer) |
| 1381 | break; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1382 | if (log) |
| 1383 | log->Printf("handle as array"); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1384 | const char* special_directions = NULL; |
| 1385 | StreamString special_directions_writer; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1386 | if (close_bracket_position && (var_name_end-close_bracket_position > 1)) |
| 1387 | { |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1388 | ConstString additional_data; |
| 1389 | additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1); |
| 1390 | special_directions_writer.Printf("${%svar%s}", |
| 1391 | do_deref_pointer ? "*" : "", |
| 1392 | additional_data.GetCString()); |
| 1393 | special_directions = special_directions_writer.GetData(); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | // let us display items index_lower thru index_higher of this array |
| 1397 | s.PutChar('['); |
| 1398 | var_success = true; |
| 1399 | |
| 1400 | if (index_higher < 0) |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1401 | index_higher = valobj->GetNumChildren() - 1; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1402 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1403 | uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 1404 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1405 | for (;index_lower<=index_higher;index_lower++) |
| 1406 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1407 | ValueObject* item = ExpandIndexedExpression (target, |
| 1408 | index_lower, |
| 1409 | exe_ctx->GetFramePtr(), |
| 1410 | false).get(); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1411 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1412 | if (!item) |
| 1413 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1414 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1415 | log->Printf("ERROR in getting child item at index %lld", index_lower); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1416 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1417 | else |
| 1418 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1419 | if (log) |
| 1420 | log->Printf("special_directions for child item: %s",special_directions); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1421 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1422 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1423 | if (!special_directions) |
| 1424 | var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format); |
| 1425 | else |
| 1426 | var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item); |
| 1427 | |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 1428 | if (--max_num_children == 0) |
| 1429 | { |
| 1430 | s.PutCString(", ..."); |
| 1431 | break; |
| 1432 | } |
| 1433 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1434 | if (index_lower < index_higher) |
| 1435 | s.PutChar(','); |
| 1436 | } |
| 1437 | s.PutChar(']'); |
| 1438 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1439 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1440 | break; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1441 | case 'a': |
| 1442 | if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0) |
| 1443 | { |
| 1444 | if (addr && addr->IsValid()) |
| 1445 | { |
| 1446 | var_success = true; |
| 1447 | format_addr = *addr; |
| 1448 | } |
| 1449 | } |
Greg Clayton | 5a31471 | 2011-10-14 07:41:33 +0000 | [diff] [blame] | 1450 | else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0) |
| 1451 | { |
| 1452 | var_success = true; |
| 1453 | var_name_begin += strlen("ansi."); // Skip the "ansi." |
| 1454 | if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0) |
| 1455 | { |
| 1456 | var_name_begin += strlen("fg."); // Skip the "fg." |
| 1457 | if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0) |
| 1458 | { |
| 1459 | s.Printf ("%s%s%s", |
| 1460 | lldb_utility::ansi::k_escape_start, |
| 1461 | lldb_utility::ansi::k_fg_black, |
| 1462 | lldb_utility::ansi::k_escape_end); |
| 1463 | } |
| 1464 | else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0) |
| 1465 | { |
| 1466 | s.Printf ("%s%s%s", |
| 1467 | lldb_utility::ansi::k_escape_start, |
| 1468 | lldb_utility::ansi::k_fg_red, |
| 1469 | lldb_utility::ansi::k_escape_end); |
| 1470 | } |
| 1471 | else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0) |
| 1472 | { |
| 1473 | s.Printf ("%s%s%s", |
| 1474 | lldb_utility::ansi::k_escape_start, |
| 1475 | lldb_utility::ansi::k_fg_green, |
| 1476 | lldb_utility::ansi::k_escape_end); |
| 1477 | } |
| 1478 | else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0) |
| 1479 | { |
| 1480 | s.Printf ("%s%s%s", |
| 1481 | lldb_utility::ansi::k_escape_start, |
| 1482 | lldb_utility::ansi::k_fg_yellow, |
| 1483 | lldb_utility::ansi::k_escape_end); |
| 1484 | } |
| 1485 | else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0) |
| 1486 | { |
| 1487 | s.Printf ("%s%s%s", |
| 1488 | lldb_utility::ansi::k_escape_start, |
| 1489 | lldb_utility::ansi::k_fg_blue, |
| 1490 | lldb_utility::ansi::k_escape_end); |
| 1491 | } |
| 1492 | else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0) |
| 1493 | { |
| 1494 | s.Printf ("%s%s%s", |
| 1495 | lldb_utility::ansi::k_escape_start, |
| 1496 | lldb_utility::ansi::k_fg_purple, |
| 1497 | lldb_utility::ansi::k_escape_end); |
| 1498 | } |
| 1499 | else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0) |
| 1500 | { |
| 1501 | s.Printf ("%s%s%s", |
| 1502 | lldb_utility::ansi::k_escape_start, |
| 1503 | lldb_utility::ansi::k_fg_cyan, |
| 1504 | lldb_utility::ansi::k_escape_end); |
| 1505 | } |
| 1506 | else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0) |
| 1507 | { |
| 1508 | s.Printf ("%s%s%s", |
| 1509 | lldb_utility::ansi::k_escape_start, |
| 1510 | lldb_utility::ansi::k_fg_white, |
| 1511 | lldb_utility::ansi::k_escape_end); |
| 1512 | } |
| 1513 | else |
| 1514 | { |
| 1515 | var_success = false; |
| 1516 | } |
| 1517 | } |
| 1518 | else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0) |
| 1519 | { |
| 1520 | var_name_begin += strlen("bg."); // Skip the "bg." |
| 1521 | if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0) |
| 1522 | { |
| 1523 | s.Printf ("%s%s%s", |
| 1524 | lldb_utility::ansi::k_escape_start, |
| 1525 | lldb_utility::ansi::k_bg_black, |
| 1526 | lldb_utility::ansi::k_escape_end); |
| 1527 | } |
| 1528 | else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0) |
| 1529 | { |
| 1530 | s.Printf ("%s%s%s", |
| 1531 | lldb_utility::ansi::k_escape_start, |
| 1532 | lldb_utility::ansi::k_bg_red, |
| 1533 | lldb_utility::ansi::k_escape_end); |
| 1534 | } |
| 1535 | else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0) |
| 1536 | { |
| 1537 | s.Printf ("%s%s%s", |
| 1538 | lldb_utility::ansi::k_escape_start, |
| 1539 | lldb_utility::ansi::k_bg_green, |
| 1540 | lldb_utility::ansi::k_escape_end); |
| 1541 | } |
| 1542 | else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0) |
| 1543 | { |
| 1544 | s.Printf ("%s%s%s", |
| 1545 | lldb_utility::ansi::k_escape_start, |
| 1546 | lldb_utility::ansi::k_bg_yellow, |
| 1547 | lldb_utility::ansi::k_escape_end); |
| 1548 | } |
| 1549 | else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0) |
| 1550 | { |
| 1551 | s.Printf ("%s%s%s", |
| 1552 | lldb_utility::ansi::k_escape_start, |
| 1553 | lldb_utility::ansi::k_bg_blue, |
| 1554 | lldb_utility::ansi::k_escape_end); |
| 1555 | } |
| 1556 | else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0) |
| 1557 | { |
| 1558 | s.Printf ("%s%s%s", |
| 1559 | lldb_utility::ansi::k_escape_start, |
| 1560 | lldb_utility::ansi::k_bg_purple, |
| 1561 | lldb_utility::ansi::k_escape_end); |
| 1562 | } |
| 1563 | else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0) |
| 1564 | { |
| 1565 | s.Printf ("%s%s%s", |
| 1566 | lldb_utility::ansi::k_escape_start, |
| 1567 | lldb_utility::ansi::k_bg_cyan, |
| 1568 | lldb_utility::ansi::k_escape_end); |
| 1569 | } |
| 1570 | else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0) |
| 1571 | { |
| 1572 | s.Printf ("%s%s%s", |
| 1573 | lldb_utility::ansi::k_escape_start, |
| 1574 | lldb_utility::ansi::k_bg_white, |
| 1575 | lldb_utility::ansi::k_escape_end); |
| 1576 | } |
| 1577 | else |
| 1578 | { |
| 1579 | var_success = false; |
| 1580 | } |
| 1581 | } |
| 1582 | else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0) |
| 1583 | { |
| 1584 | s.Printf ("%s%s%s", |
| 1585 | lldb_utility::ansi::k_escape_start, |
| 1586 | lldb_utility::ansi::k_ctrl_normal, |
| 1587 | lldb_utility::ansi::k_escape_end); |
| 1588 | } |
| 1589 | else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0) |
| 1590 | { |
| 1591 | s.Printf ("%s%s%s", |
| 1592 | lldb_utility::ansi::k_escape_start, |
| 1593 | lldb_utility::ansi::k_ctrl_bold, |
| 1594 | lldb_utility::ansi::k_escape_end); |
| 1595 | } |
| 1596 | else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0) |
| 1597 | { |
| 1598 | s.Printf ("%s%s%s", |
| 1599 | lldb_utility::ansi::k_escape_start, |
| 1600 | lldb_utility::ansi::k_ctrl_faint, |
| 1601 | lldb_utility::ansi::k_escape_end); |
| 1602 | } |
| 1603 | else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0) |
| 1604 | { |
| 1605 | s.Printf ("%s%s%s", |
| 1606 | lldb_utility::ansi::k_escape_start, |
| 1607 | lldb_utility::ansi::k_ctrl_italic, |
| 1608 | lldb_utility::ansi::k_escape_end); |
| 1609 | } |
| 1610 | else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0) |
| 1611 | { |
| 1612 | s.Printf ("%s%s%s", |
| 1613 | lldb_utility::ansi::k_escape_start, |
| 1614 | lldb_utility::ansi::k_ctrl_underline, |
| 1615 | lldb_utility::ansi::k_escape_end); |
| 1616 | } |
| 1617 | else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0) |
| 1618 | { |
| 1619 | s.Printf ("%s%s%s", |
| 1620 | lldb_utility::ansi::k_escape_start, |
| 1621 | lldb_utility::ansi::k_ctrl_slow_blink, |
| 1622 | lldb_utility::ansi::k_escape_end); |
| 1623 | } |
| 1624 | else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0) |
| 1625 | { |
| 1626 | s.Printf ("%s%s%s", |
| 1627 | lldb_utility::ansi::k_escape_start, |
| 1628 | lldb_utility::ansi::k_ctrl_fast_blink, |
| 1629 | lldb_utility::ansi::k_escape_end); |
| 1630 | } |
| 1631 | else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0) |
| 1632 | { |
| 1633 | s.Printf ("%s%s%s", |
| 1634 | lldb_utility::ansi::k_escape_start, |
| 1635 | lldb_utility::ansi::k_ctrl_negative, |
| 1636 | lldb_utility::ansi::k_escape_end); |
| 1637 | } |
| 1638 | else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0) |
| 1639 | { |
| 1640 | s.Printf ("%s%s%s", |
| 1641 | lldb_utility::ansi::k_escape_start, |
| 1642 | lldb_utility::ansi::k_ctrl_conceal, |
| 1643 | lldb_utility::ansi::k_escape_end); |
| 1644 | |
| 1645 | } |
| 1646 | else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0) |
| 1647 | { |
| 1648 | s.Printf ("%s%s%s", |
| 1649 | lldb_utility::ansi::k_escape_start, |
| 1650 | lldb_utility::ansi::k_ctrl_crossed_out, |
| 1651 | lldb_utility::ansi::k_escape_end); |
| 1652 | } |
| 1653 | else |
| 1654 | { |
| 1655 | var_success = false; |
| 1656 | } |
| 1657 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1658 | break; |
| 1659 | |
| 1660 | case 'p': |
| 1661 | if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0) |
| 1662 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1663 | if (exe_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1664 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1665 | Process *process = exe_ctx->GetProcessPtr(); |
| 1666 | if (process) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1667 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1668 | var_name_begin += ::strlen ("process."); |
| 1669 | if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1670 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1671 | s.Printf("%llu", process->GetID()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1672 | var_success = true; |
| 1673 | } |
| 1674 | else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) || |
| 1675 | (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) || |
| 1676 | (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0)) |
| 1677 | { |
| 1678 | Module *exe_module = process->GetTarget().GetExecutableModulePointer(); |
| 1679 | if (exe_module) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1680 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1681 | if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f') |
| 1682 | { |
| 1683 | format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename(); |
| 1684 | var_success = format_file_spec; |
| 1685 | } |
| 1686 | else |
| 1687 | { |
| 1688 | format_file_spec = exe_module->GetFileSpec(); |
| 1689 | var_success = format_file_spec; |
| 1690 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | } |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1694 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1695 | } |
| 1696 | break; |
| 1697 | |
| 1698 | case 't': |
| 1699 | if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0) |
| 1700 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1701 | if (exe_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1702 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1703 | Thread *thread = exe_ctx->GetThreadPtr(); |
| 1704 | if (thread) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1705 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1706 | var_name_begin += ::strlen ("thread."); |
| 1707 | if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1708 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1709 | s.Printf("0x%4.4llx", thread->GetID()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1710 | var_success = true; |
| 1711 | } |
| 1712 | else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0) |
| 1713 | { |
| 1714 | s.Printf("%u", thread->GetIndexID()); |
| 1715 | var_success = true; |
| 1716 | } |
| 1717 | else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0) |
| 1718 | { |
| 1719 | cstr = thread->GetName(); |
| 1720 | var_success = cstr && cstr[0]; |
| 1721 | if (var_success) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1722 | s.PutCString(cstr); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1723 | } |
| 1724 | else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0) |
| 1725 | { |
| 1726 | cstr = thread->GetQueueName(); |
| 1727 | var_success = cstr && cstr[0]; |
| 1728 | if (var_success) |
| 1729 | s.PutCString(cstr); |
| 1730 | } |
| 1731 | else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0) |
| 1732 | { |
| 1733 | StopInfoSP stop_info_sp = thread->GetStopInfo (); |
| 1734 | if (stop_info_sp) |
| 1735 | { |
| 1736 | cstr = stop_info_sp->GetDescription(); |
| 1737 | if (cstr && cstr[0]) |
| 1738 | { |
| 1739 | s.PutCString(cstr); |
| 1740 | var_success = true; |
| 1741 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1742 | } |
| 1743 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1744 | else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0) |
| 1745 | { |
| 1746 | StopInfoSP stop_info_sp = thread->GetStopInfo (); |
| 1747 | if (stop_info_sp) |
| 1748 | { |
| 1749 | ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp); |
| 1750 | if (return_valobj_sp) |
| 1751 | { |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 1752 | ValueObject::DumpValueObjectOptions dump_options; |
| 1753 | ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options); |
| 1754 | var_success = true; |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1755 | } |
| 1756 | } |
| 1757 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0) |
| 1762 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1763 | Target *target = Target::GetTargetFromContexts (exe_ctx, sc); |
| 1764 | if (target) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1765 | { |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1766 | var_name_begin += ::strlen ("target."); |
| 1767 | if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0) |
| 1768 | { |
| 1769 | ArchSpec arch (target->GetArchitecture ()); |
| 1770 | if (arch.IsValid()) |
| 1771 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 1772 | s.PutCString (arch.GetArchitectureName()); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1773 | var_success = true; |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | break; |
| 1779 | |
| 1780 | |
| 1781 | case 'm': |
| 1782 | if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0) |
| 1783 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1784 | if (sc && sc->module_sp.get()) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1785 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1786 | Module *module = sc->module_sp.get(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1787 | var_name_begin += ::strlen ("module."); |
| 1788 | |
| 1789 | if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0) |
| 1790 | { |
| 1791 | if (module->GetFileSpec()) |
| 1792 | { |
| 1793 | var_name_begin += ::strlen ("file."); |
| 1794 | |
| 1795 | if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0) |
| 1796 | { |
| 1797 | format_file_spec.GetFilename() = module->GetFileSpec().GetFilename(); |
| 1798 | var_success = format_file_spec; |
| 1799 | } |
| 1800 | else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0) |
| 1801 | { |
| 1802 | format_file_spec = module->GetFileSpec(); |
| 1803 | var_success = format_file_spec; |
| 1804 | } |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | break; |
| 1810 | |
| 1811 | |
| 1812 | case 'f': |
| 1813 | if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0) |
| 1814 | { |
| 1815 | if (sc && sc->comp_unit != NULL) |
| 1816 | { |
| 1817 | var_name_begin += ::strlen ("file."); |
| 1818 | |
| 1819 | if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0) |
| 1820 | { |
| 1821 | format_file_spec.GetFilename() = sc->comp_unit->GetFilename(); |
| 1822 | var_success = format_file_spec; |
| 1823 | } |
| 1824 | else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0) |
| 1825 | { |
| 1826 | format_file_spec = *sc->comp_unit; |
| 1827 | var_success = format_file_spec; |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0) |
| 1832 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1833 | if (exe_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1834 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1835 | StackFrame *frame = exe_ctx->GetFramePtr(); |
| 1836 | if (frame) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1837 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1838 | var_name_begin += ::strlen ("frame."); |
| 1839 | if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1840 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1841 | s.Printf("%u", frame->GetFrameIndex()); |
| 1842 | var_success = true; |
| 1843 | } |
| 1844 | else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0) |
| 1845 | { |
| 1846 | reg_kind = eRegisterKindGeneric; |
| 1847 | reg_num = LLDB_REGNUM_GENERIC_PC; |
| 1848 | var_success = true; |
| 1849 | } |
| 1850 | else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0) |
| 1851 | { |
| 1852 | reg_kind = eRegisterKindGeneric; |
| 1853 | reg_num = LLDB_REGNUM_GENERIC_SP; |
| 1854 | var_success = true; |
| 1855 | } |
| 1856 | else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0) |
| 1857 | { |
| 1858 | reg_kind = eRegisterKindGeneric; |
| 1859 | reg_num = LLDB_REGNUM_GENERIC_FP; |
| 1860 | var_success = true; |
| 1861 | } |
| 1862 | else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0) |
| 1863 | { |
| 1864 | reg_kind = eRegisterKindGeneric; |
| 1865 | reg_num = LLDB_REGNUM_GENERIC_FLAGS; |
| 1866 | var_success = true; |
| 1867 | } |
| 1868 | else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0) |
| 1869 | { |
| 1870 | reg_ctx = frame->GetRegisterContext().get(); |
| 1871 | if (reg_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1872 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1873 | var_name_begin += ::strlen ("reg."); |
| 1874 | if (var_name_begin < var_name_end) |
| 1875 | { |
| 1876 | std::string reg_name (var_name_begin, var_name_end); |
| 1877 | reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str()); |
| 1878 | if (reg_info) |
| 1879 | var_success = true; |
| 1880 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1881 | } |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0) |
| 1887 | { |
| 1888 | if (sc && (sc->function != NULL || sc->symbol != NULL)) |
| 1889 | { |
| 1890 | var_name_begin += ::strlen ("function."); |
| 1891 | if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0) |
| 1892 | { |
| 1893 | if (sc->function) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1894 | s.Printf("function{0x%8.8llx}", sc->function->GetID()); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1895 | else |
| 1896 | s.Printf("symbol[%u]", sc->symbol->GetID()); |
| 1897 | |
| 1898 | var_success = true; |
| 1899 | } |
| 1900 | else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0) |
| 1901 | { |
| 1902 | if (sc->function) |
| 1903 | cstr = sc->function->GetName().AsCString (NULL); |
| 1904 | else if (sc->symbol) |
| 1905 | cstr = sc->symbol->GetName().AsCString (NULL); |
| 1906 | if (cstr) |
| 1907 | { |
| 1908 | s.PutCString(cstr); |
Greg Clayton | 0d9c993 | 2010-10-04 17:26:49 +0000 | [diff] [blame] | 1909 | |
| 1910 | if (sc->block) |
| 1911 | { |
| 1912 | Block *inline_block = sc->block->GetContainingInlinedBlock (); |
| 1913 | if (inline_block) |
| 1914 | { |
| 1915 | const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo(); |
| 1916 | if (inline_info) |
| 1917 | { |
| 1918 | s.PutCString(" [inlined] "); |
| 1919 | inline_info->GetName().Dump(&s); |
| 1920 | } |
| 1921 | } |
| 1922 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1923 | var_success = true; |
| 1924 | } |
| 1925 | } |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 1926 | else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0) |
| 1927 | { |
| 1928 | // Print the function name with arguments in it |
| 1929 | |
| 1930 | if (sc->function) |
| 1931 | { |
| 1932 | var_success = true; |
| 1933 | ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL; |
| 1934 | cstr = sc->function->GetName().AsCString (NULL); |
| 1935 | if (cstr) |
| 1936 | { |
| 1937 | const InlineFunctionInfo *inline_info = NULL; |
| 1938 | VariableListSP variable_list_sp; |
| 1939 | bool get_function_vars = true; |
| 1940 | if (sc->block) |
| 1941 | { |
| 1942 | Block *inline_block = sc->block->GetContainingInlinedBlock (); |
| 1943 | |
| 1944 | if (inline_block) |
| 1945 | { |
| 1946 | get_function_vars = false; |
| 1947 | inline_info = sc->block->GetInlinedFunctionInfo(); |
| 1948 | if (inline_info) |
| 1949 | variable_list_sp = inline_block->GetBlockVariableList (true); |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | if (get_function_vars) |
| 1954 | { |
| 1955 | variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true); |
| 1956 | } |
| 1957 | |
| 1958 | if (inline_info) |
| 1959 | { |
| 1960 | s.PutCString (cstr); |
| 1961 | s.PutCString (" [inlined] "); |
| 1962 | cstr = inline_info->GetName().GetCString(); |
| 1963 | } |
| 1964 | |
| 1965 | VariableList args; |
| 1966 | if (variable_list_sp) |
| 1967 | { |
| 1968 | const size_t num_variables = variable_list_sp->GetSize(); |
| 1969 | for (size_t var_idx = 0; var_idx < num_variables; ++var_idx) |
| 1970 | { |
| 1971 | VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx)); |
| 1972 | if (var_sp->GetScope() == eValueTypeVariableArgument) |
| 1973 | args.AddVariable (var_sp); |
| 1974 | } |
| 1975 | |
| 1976 | } |
| 1977 | if (args.GetSize() > 0) |
| 1978 | { |
| 1979 | const char *open_paren = strchr (cstr, '('); |
| 1980 | const char *close_paren = NULL; |
| 1981 | if (open_paren) |
| 1982 | close_paren = strchr (open_paren, ')'); |
| 1983 | |
| 1984 | if (open_paren) |
| 1985 | s.Write(cstr, open_paren - cstr + 1); |
| 1986 | else |
| 1987 | { |
| 1988 | s.PutCString (cstr); |
| 1989 | s.PutChar ('('); |
| 1990 | } |
Greg Clayton | 5b6889b | 2012-01-18 21:56:18 +0000 | [diff] [blame] | 1991 | const size_t num_args = args.GetSize(); |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 1992 | for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) |
| 1993 | { |
| 1994 | VariableSP var_sp (args.GetVariableAtIndex (arg_idx)); |
| 1995 | ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp)); |
| 1996 | const char *var_name = var_value_sp->GetName().GetCString(); |
| 1997 | const char *var_value = var_value_sp->GetValueAsCString(); |
| 1998 | if (var_value_sp->GetError().Success()) |
| 1999 | { |
| 2000 | if (arg_idx > 0) |
| 2001 | s.PutCString (", "); |
| 2002 | s.Printf ("%s=%s", var_name, var_value); |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | if (close_paren) |
| 2007 | s.PutCString (close_paren); |
| 2008 | else |
| 2009 | s.PutChar(')'); |
| 2010 | |
| 2011 | } |
| 2012 | else |
| 2013 | { |
| 2014 | s.PutCString(cstr); |
| 2015 | } |
| 2016 | } |
| 2017 | } |
| 2018 | else if (sc->symbol) |
| 2019 | { |
| 2020 | cstr = sc->symbol->GetName().AsCString (NULL); |
| 2021 | if (cstr) |
| 2022 | { |
| 2023 | s.PutCString(cstr); |
| 2024 | var_success = true; |
| 2025 | } |
| 2026 | } |
| 2027 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2028 | else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0) |
| 2029 | { |
| 2030 | var_success = addr != NULL; |
| 2031 | if (var_success) |
| 2032 | { |
| 2033 | format_addr = *addr; |
| 2034 | calculate_format_addr_function_offset = true; |
| 2035 | } |
| 2036 | } |
| 2037 | else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0) |
| 2038 | { |
| 2039 | var_success = sc->line_entry.range.GetBaseAddress().IsValid(); |
| 2040 | if (var_success) |
| 2041 | { |
| 2042 | format_addr = sc->line_entry.range.GetBaseAddress(); |
| 2043 | calculate_format_addr_function_offset = true; |
| 2044 | } |
| 2045 | } |
| 2046 | else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0) |
| 2047 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2048 | StackFrame *frame = exe_ctx->GetFramePtr(); |
| 2049 | var_success = frame != NULL; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2050 | if (var_success) |
| 2051 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2052 | format_addr = frame->GetFrameCodeAddress(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2053 | calculate_format_addr_function_offset = true; |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | } |
| 2058 | break; |
| 2059 | |
| 2060 | case 'l': |
| 2061 | if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0) |
| 2062 | { |
| 2063 | if (sc && sc->line_entry.IsValid()) |
| 2064 | { |
| 2065 | var_name_begin += ::strlen ("line."); |
| 2066 | if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0) |
| 2067 | { |
| 2068 | var_name_begin += ::strlen ("file."); |
| 2069 | |
| 2070 | if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0) |
| 2071 | { |
| 2072 | format_file_spec.GetFilename() = sc->line_entry.file.GetFilename(); |
| 2073 | var_success = format_file_spec; |
| 2074 | } |
| 2075 | else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0) |
| 2076 | { |
| 2077 | format_file_spec = sc->line_entry.file; |
| 2078 | var_success = format_file_spec; |
| 2079 | } |
| 2080 | } |
| 2081 | else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0) |
| 2082 | { |
| 2083 | var_success = true; |
| 2084 | s.Printf("%u", sc->line_entry.line); |
| 2085 | } |
| 2086 | else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) || |
| 2087 | (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0)) |
| 2088 | { |
| 2089 | var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid(); |
| 2090 | if (var_success) |
| 2091 | { |
| 2092 | format_addr = sc->line_entry.range.GetBaseAddress(); |
| 2093 | if (var_name_begin[0] == 'e') |
| 2094 | format_addr.Slide (sc->line_entry.range.GetByteSize()); |
| 2095 | } |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | break; |
| 2100 | } |
| 2101 | |
| 2102 | if (var_success) |
| 2103 | { |
| 2104 | // If format addr is valid, then we need to print an address |
| 2105 | if (reg_num != LLDB_INVALID_REGNUM) |
| 2106 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2107 | StackFrame *frame = exe_ctx->GetFramePtr(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2108 | // We have a register value to display... |
| 2109 | if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric) |
| 2110 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2111 | format_addr = frame->GetFrameCodeAddress(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2112 | } |
| 2113 | else |
| 2114 | { |
| 2115 | if (reg_ctx == NULL) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2116 | reg_ctx = frame->GetRegisterContext().get(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2117 | |
| 2118 | if (reg_ctx) |
| 2119 | { |
| 2120 | if (reg_kind != kNumRegisterKinds) |
| 2121 | reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num); |
| 2122 | reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num); |
| 2123 | var_success = reg_info != NULL; |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | if (reg_info != NULL) |
| 2129 | { |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 2130 | RegisterValue reg_value; |
| 2131 | var_success = reg_ctx->ReadRegister (reg_info, reg_value); |
| 2132 | if (var_success) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2133 | { |
Greg Clayton | 9a8fa91 | 2011-05-15 04:12:07 +0000 | [diff] [blame] | 2134 | reg_value.Dump(&s, reg_info, false, false, eFormatDefault); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | if (format_file_spec) |
| 2139 | { |
| 2140 | s << format_file_spec; |
| 2141 | } |
| 2142 | |
| 2143 | // If format addr is valid, then we need to print an address |
| 2144 | if (format_addr.IsValid()) |
| 2145 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2146 | var_success = false; |
| 2147 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2148 | if (calculate_format_addr_function_offset) |
| 2149 | { |
| 2150 | Address func_addr; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2151 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2152 | if (sc) |
| 2153 | { |
| 2154 | if (sc->function) |
Greg Clayton | 0d9c993 | 2010-10-04 17:26:49 +0000 | [diff] [blame] | 2155 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2156 | func_addr = sc->function->GetAddressRange().GetBaseAddress(); |
Greg Clayton | 0d9c993 | 2010-10-04 17:26:49 +0000 | [diff] [blame] | 2157 | if (sc->block) |
| 2158 | { |
| 2159 | // Check to make sure we aren't in an inline |
| 2160 | // function. If we are, use the inline block |
| 2161 | // range that contains "format_addr" since |
| 2162 | // blocks can be discontiguous. |
| 2163 | Block *inline_block = sc->block->GetContainingInlinedBlock (); |
| 2164 | AddressRange inline_range; |
| 2165 | if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range)) |
| 2166 | func_addr = inline_range.GetBaseAddress(); |
| 2167 | } |
| 2168 | } |
Greg Clayton | e761213 | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 2169 | else if (sc->symbol && sc->symbol->ValueIsAddress()) |
| 2170 | func_addr = sc->symbol->GetAddress(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | if (func_addr.IsValid()) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2174 | { |
| 2175 | if (func_addr.GetSection() == format_addr.GetSection()) |
| 2176 | { |
| 2177 | addr_t func_file_addr = func_addr.GetFileAddress(); |
| 2178 | addr_t addr_file_addr = format_addr.GetFileAddress(); |
| 2179 | if (addr_file_addr > func_file_addr) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2180 | s.Printf(" + %llu", addr_file_addr - func_file_addr); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2181 | else if (addr_file_addr < func_file_addr) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2182 | s.Printf(" - %llu", func_file_addr - addr_file_addr); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2183 | var_success = true; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2184 | } |
| 2185 | else |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2186 | { |
| 2187 | Target *target = Target::GetTargetFromContexts (exe_ctx, sc); |
| 2188 | if (target) |
| 2189 | { |
| 2190 | addr_t func_load_addr = func_addr.GetLoadAddress (target); |
| 2191 | addr_t addr_load_addr = format_addr.GetLoadAddress (target); |
| 2192 | if (addr_load_addr > func_load_addr) |
| 2193 | s.Printf(" + %llu", addr_load_addr - func_load_addr); |
| 2194 | else if (addr_load_addr < func_load_addr) |
| 2195 | s.Printf(" - %llu", func_load_addr - addr_load_addr); |
| 2196 | var_success = true; |
| 2197 | } |
| 2198 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | else |
| 2202 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2203 | Target *target = Target::GetTargetFromContexts (exe_ctx, sc); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2204 | addr_t vaddr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2205 | if (exe_ctx && !target->GetSectionLoadList().IsEmpty()) |
| 2206 | vaddr = format_addr.GetLoadAddress (target); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2207 | if (vaddr == LLDB_INVALID_ADDRESS) |
| 2208 | vaddr = format_addr.GetFileAddress (); |
| 2209 | |
| 2210 | if (vaddr != LLDB_INVALID_ADDRESS) |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2211 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 2212 | int addr_width = target->GetArchitecture().GetAddressByteSize() * 2; |
Greg Clayton | 35f1a0d | 2010-11-19 04:16:11 +0000 | [diff] [blame] | 2213 | if (addr_width == 0) |
| 2214 | addr_width = 16; |
| 2215 | s.Printf("0x%*.*llx", addr_width, addr_width, vaddr); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2216 | var_success = true; |
| 2217 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | if (var_success == false) |
| 2223 | success = false; |
| 2224 | } |
| 2225 | p = var_name_end; |
| 2226 | } |
| 2227 | else |
| 2228 | break; |
| 2229 | } |
| 2230 | else |
| 2231 | { |
| 2232 | // We got a dollar sign with no '{' after it, it must just be a dollar sign |
| 2233 | s.PutChar(*p); |
| 2234 | } |
| 2235 | } |
| 2236 | else if (*p == '\\') |
| 2237 | { |
| 2238 | ++p; // skip the slash |
| 2239 | switch (*p) |
| 2240 | { |
| 2241 | case 'a': s.PutChar ('\a'); break; |
| 2242 | case 'b': s.PutChar ('\b'); break; |
| 2243 | case 'f': s.PutChar ('\f'); break; |
| 2244 | case 'n': s.PutChar ('\n'); break; |
| 2245 | case 'r': s.PutChar ('\r'); break; |
| 2246 | case 't': s.PutChar ('\t'); break; |
| 2247 | case 'v': s.PutChar ('\v'); break; |
| 2248 | case '\'': s.PutChar ('\''); break; |
| 2249 | case '\\': s.PutChar ('\\'); break; |
| 2250 | case '0': |
| 2251 | // 1 to 3 octal chars |
| 2252 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2253 | // Make a string that can hold onto the initial zero char, |
| 2254 | // up to 3 octal digits, and a terminating NULL. |
| 2255 | char oct_str[5] = { 0, 0, 0, 0, 0 }; |
| 2256 | |
| 2257 | int i; |
| 2258 | for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i) |
| 2259 | oct_str[i] = p[i]; |
| 2260 | |
| 2261 | // We don't want to consume the last octal character since |
| 2262 | // the main for loop will do this for us, so we advance p by |
| 2263 | // one less than i (even if i is zero) |
| 2264 | p += i - 1; |
| 2265 | unsigned long octal_value = ::strtoul (oct_str, NULL, 8); |
| 2266 | if (octal_value <= UINT8_MAX) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2267 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2268 | char octal_char = octal_value; |
| 2269 | s.Write (&octal_char, 1); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2270 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2271 | } |
| 2272 | break; |
| 2273 | |
| 2274 | case 'x': |
| 2275 | // hex number in the format |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2276 | if (isxdigit(p[1])) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2277 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2278 | ++p; // Skip the 'x' |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2279 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2280 | // Make a string that can hold onto two hex chars plus a |
| 2281 | // NULL terminator |
| 2282 | char hex_str[3] = { 0,0,0 }; |
| 2283 | hex_str[0] = *p; |
| 2284 | if (isxdigit(p[1])) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2285 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2286 | ++p; // Skip the first of the two hex chars |
| 2287 | hex_str[1] = *p; |
| 2288 | } |
| 2289 | |
| 2290 | unsigned long hex_value = strtoul (hex_str, NULL, 16); |
| 2291 | if (hex_value <= UINT8_MAX) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2292 | s.PutChar (hex_value); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2293 | } |
| 2294 | else |
| 2295 | { |
| 2296 | s.PutChar('x'); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2297 | } |
| 2298 | break; |
| 2299 | |
| 2300 | default: |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2301 | // Just desensitize any other character by just printing what |
| 2302 | // came after the '\' |
| 2303 | s << *p; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2304 | break; |
| 2305 | |
| 2306 | } |
| 2307 | |
| 2308 | } |
| 2309 | } |
| 2310 | if (end) |
| 2311 | *end = p; |
| 2312 | return success; |
| 2313 | } |
| 2314 | |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2315 | void |
| 2316 | Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton) |
| 2317 | { |
Jim Ingham | 4f02b22 | 2012-02-22 22:49:20 +0000 | [diff] [blame] | 2318 | // For simplicity's sake, I am not going to deal with how to close down any |
| 2319 | // open logging streams, I just redirect everything from here on out to the |
| 2320 | // callback. |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2321 | m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton)); |
| 2322 | } |
| 2323 | |
| 2324 | bool |
| 2325 | Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream) |
| 2326 | { |
| 2327 | Log::Callbacks log_callbacks; |
| 2328 | |
| 2329 | StreamSP log_stream_sp; |
| 2330 | if (m_log_callback_stream_sp != NULL) |
| 2331 | { |
| 2332 | log_stream_sp = m_log_callback_stream_sp; |
| 2333 | // For now when using the callback mode you always get thread & timestamp. |
| 2334 | log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME; |
| 2335 | } |
| 2336 | else if (log_file == NULL || *log_file == '\0') |
| 2337 | { |
| 2338 | log_stream_sp.reset(new StreamFile(GetOutputFile().GetDescriptor(), false)); |
| 2339 | } |
| 2340 | else |
| 2341 | { |
| 2342 | LogStreamMap::iterator pos = m_log_streams.find(log_file); |
| 2343 | if (pos == m_log_streams.end()) |
| 2344 | { |
| 2345 | log_stream_sp.reset (new StreamFile (log_file)); |
| 2346 | m_log_streams[log_file] = log_stream_sp; |
| 2347 | } |
| 2348 | else |
| 2349 | log_stream_sp = pos->second; |
| 2350 | } |
| 2351 | assert (log_stream_sp.get()); |
| 2352 | |
| 2353 | if (log_options == 0) |
| 2354 | log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE; |
| 2355 | |
| 2356 | if (Log::GetLogChannelCallbacks (channel, log_callbacks)) |
| 2357 | { |
| 2358 | log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream); |
| 2359 | return true; |
| 2360 | } |
| 2361 | else |
| 2362 | { |
| 2363 | LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel)); |
| 2364 | if (log_channel_sp) |
| 2365 | { |
| 2366 | if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories)) |
| 2367 | { |
| 2368 | return true; |
| 2369 | } |
| 2370 | else |
| 2371 | { |
| 2372 | error_stream.Printf ("Invalid log channel '%s'.\n", channel); |
| 2373 | return false; |
| 2374 | } |
| 2375 | } |
| 2376 | else |
| 2377 | { |
| 2378 | error_stream.Printf ("Invalid log channel '%s'.\n", channel); |
| 2379 | return false; |
| 2380 | } |
| 2381 | } |
| 2382 | return false; |
| 2383 | } |
| 2384 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2385 | #pragma mark Debugger::SettingsController |
| 2386 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2387 | //-------------------------------------------------- |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2388 | // class Debugger::SettingsController |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2389 | //-------------------------------------------------- |
| 2390 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2391 | Debugger::SettingsController::SettingsController () : |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 2392 | UserSettingsController ("", UserSettingsControllerSP()) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2393 | { |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2396 | Debugger::SettingsController::~SettingsController () |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2397 | { |
| 2398 | } |
| 2399 | |
| 2400 | |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 2401 | InstanceSettingsSP |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2402 | Debugger::SettingsController::CreateInstanceSettings (const char *instance_name) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2403 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 2404 | InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(), |
| 2405 | false, |
| 2406 | instance_name)); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2407 | return new_settings_sp; |
| 2408 | } |
| 2409 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2410 | #pragma mark DebuggerInstanceSettings |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2411 | //-------------------------------------------------- |
| 2412 | // class DebuggerInstanceSettings |
| 2413 | //-------------------------------------------------- |
| 2414 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2415 | DebuggerInstanceSettings::DebuggerInstanceSettings |
| 2416 | ( |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 2417 | const UserSettingsControllerSP &m_owner_sp, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2418 | bool live_instance, |
| 2419 | const char *name |
| 2420 | ) : |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 2421 | InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2422 | m_term_width (80), |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 2423 | m_stop_source_before_count (3), |
| 2424 | m_stop_source_after_count (3), |
| 2425 | m_stop_disassembly_count (4), |
| 2426 | m_stop_disassembly_display (eStopDisassemblyTypeNoSource), |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2427 | m_prompt (), |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2428 | m_frame_format (), |
| 2429 | m_thread_format (), |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2430 | m_script_lang (), |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2431 | m_use_external_editor (false), |
| 2432 | m_auto_confirm_on (false) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2433 | { |
Caroline Tice | f20e823 | 2010-09-09 18:26:37 +0000 | [diff] [blame] | 2434 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 2435 | // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 2436 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
Caroline Tice | 9e41c15 | 2010-09-16 19:05:55 +0000 | [diff] [blame] | 2437 | // The same is true of CreateInstanceName(). |
| 2438 | |
| 2439 | if (GetInstanceName() == InstanceSettings::InvalidName()) |
| 2440 | { |
| 2441 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 2442 | m_owner_sp->RegisterInstanceSettings (this); |
Caroline Tice | 9e41c15 | 2010-09-16 19:05:55 +0000 | [diff] [blame] | 2443 | } |
Caroline Tice | f20e823 | 2010-09-09 18:26:37 +0000 | [diff] [blame] | 2444 | |
| 2445 | if (live_instance) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2446 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 2447 | const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2448 | CopyInstanceSettings (pending_settings, false); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) : |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 2453 | InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()), |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2454 | m_prompt (rhs.m_prompt), |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2455 | m_frame_format (rhs.m_frame_format), |
| 2456 | m_thread_format (rhs.m_thread_format), |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2457 | m_script_lang (rhs.m_script_lang), |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2458 | m_use_external_editor (rhs.m_use_external_editor), |
| 2459 | m_auto_confirm_on(rhs.m_auto_confirm_on) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2460 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 2461 | UserSettingsControllerSP owner_sp (m_owner_wp.lock()); |
| 2462 | if (owner_sp) |
| 2463 | { |
| 2464 | CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false); |
| 2465 | owner_sp->RemovePendingSettings (m_instance_name); |
| 2466 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | DebuggerInstanceSettings::~DebuggerInstanceSettings () |
| 2470 | { |
| 2471 | } |
| 2472 | |
| 2473 | DebuggerInstanceSettings& |
| 2474 | DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs) |
| 2475 | { |
| 2476 | if (this != &rhs) |
| 2477 | { |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2478 | m_term_width = rhs.m_term_width; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2479 | m_prompt = rhs.m_prompt; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2480 | m_frame_format = rhs.m_frame_format; |
| 2481 | m_thread_format = rhs.m_thread_format; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2482 | m_script_lang = rhs.m_script_lang; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2483 | m_use_external_editor = rhs.m_use_external_editor; |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2484 | m_auto_confirm_on = rhs.m_auto_confirm_on; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | return *this; |
| 2488 | } |
| 2489 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2490 | bool |
| 2491 | DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err) |
| 2492 | { |
| 2493 | bool valid = false; |
| 2494 | |
| 2495 | // Verify we have a value string. |
| 2496 | if (value == NULL || value[0] == '\0') |
| 2497 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 2498 | err.SetErrorString ("missing value, can't set terminal width without a value"); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2499 | } |
| 2500 | else |
| 2501 | { |
| 2502 | char *end = NULL; |
| 2503 | const uint32_t width = ::strtoul (value, &end, 0); |
| 2504 | |
Johnny Chen | ea9fc18 | 2010-09-20 16:36:43 +0000 | [diff] [blame] | 2505 | if (end && end[0] == '\0') |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2506 | { |
Johnny Chen | 433d774 | 2010-09-20 17:04:41 +0000 | [diff] [blame] | 2507 | if (width >= 10 && width <= 1024) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2508 | valid = true; |
| 2509 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 2510 | err.SetErrorString ("invalid term-width value; value must be between 10 and 1024"); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2511 | } |
| 2512 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 2513 | err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | return valid; |
| 2517 | } |
| 2518 | |
| 2519 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2520 | void |
| 2521 | DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 2522 | const char *index_value, |
| 2523 | const char *value, |
| 2524 | const ConstString &instance_name, |
| 2525 | const SettingEntry &entry, |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 2526 | VarSetOperationType op, |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2527 | Error &err, |
| 2528 | bool pending) |
| 2529 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2530 | |
| 2531 | if (var_name == TermWidthVarName()) |
| 2532 | { |
| 2533 | if (ValidTermWidthValue (value, err)) |
| 2534 | { |
| 2535 | m_term_width = ::strtoul (value, NULL, 0); |
| 2536 | } |
| 2537 | } |
| 2538 | else if (var_name == PromptVarName()) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2539 | { |
Caroline Tice | 101c7c2 | 2010-09-09 06:25:08 +0000 | [diff] [blame] | 2540 | UserSettingsController::UpdateStringVariable (op, m_prompt, value, err); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2541 | if (!pending) |
| 2542 | { |
Caroline Tice | 49e2737 | 2010-09-07 18:35:40 +0000 | [diff] [blame] | 2543 | // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to |
| 2544 | // strip off the brackets before passing it to BroadcastPromptChange. |
| 2545 | |
| 2546 | std::string tmp_instance_name (instance_name.AsCString()); |
| 2547 | if ((tmp_instance_name[0] == '[') |
| 2548 | && (tmp_instance_name[instance_name.GetLength() - 1] == ']')) |
| 2549 | tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2); |
| 2550 | ConstString new_name (tmp_instance_name.c_str()); |
| 2551 | |
| 2552 | BroadcastPromptChange (new_name, m_prompt.c_str()); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2553 | } |
| 2554 | } |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2555 | else if (var_name == GetFrameFormatName()) |
| 2556 | { |
| 2557 | UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err); |
| 2558 | } |
| 2559 | else if (var_name == GetThreadFormatName()) |
| 2560 | { |
| 2561 | UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err); |
| 2562 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2563 | else if (var_name == ScriptLangVarName()) |
| 2564 | { |
| 2565 | bool success; |
| 2566 | m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault, |
| 2567 | &success); |
| 2568 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2569 | else if (var_name == UseExternalEditorVarName ()) |
| 2570 | { |
Greg Clayton | 385aa28 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 2571 | UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2572 | } |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2573 | else if (var_name == AutoConfirmName ()) |
| 2574 | { |
Greg Clayton | 385aa28 | 2011-04-22 03:55:06 +0000 | [diff] [blame] | 2575 | UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err); |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2576 | } |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 2577 | else if (var_name == StopSourceContextBeforeName ()) |
| 2578 | { |
| 2579 | uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL); |
| 2580 | if (new_value != UINT32_MAX) |
| 2581 | m_stop_source_before_count = new_value; |
| 2582 | else |
| 2583 | err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString()); |
| 2584 | } |
| 2585 | else if (var_name == StopSourceContextAfterName ()) |
| 2586 | { |
| 2587 | uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL); |
| 2588 | if (new_value != UINT32_MAX) |
| 2589 | m_stop_source_after_count = new_value; |
| 2590 | else |
| 2591 | err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString()); |
| 2592 | } |
| 2593 | else if (var_name == StopDisassemblyCountName ()) |
| 2594 | { |
| 2595 | uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL); |
| 2596 | if (new_value != UINT32_MAX) |
| 2597 | m_stop_disassembly_count = new_value; |
| 2598 | else |
| 2599 | err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString()); |
| 2600 | } |
| 2601 | else if (var_name == StopDisassemblyDisplayName ()) |
| 2602 | { |
| 2603 | int new_value; |
| 2604 | UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err); |
| 2605 | if (err.Success()) |
| 2606 | m_stop_disassembly_display = (StopDisassemblyType)new_value; |
| 2607 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 2610 | bool |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2611 | DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 2612 | const ConstString &var_name, |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2613 | StringList &value, |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 2614 | Error *err) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2615 | { |
| 2616 | if (var_name == PromptVarName()) |
| 2617 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2618 | value.AppendString (m_prompt.c_str(), m_prompt.size()); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2619 | |
| 2620 | } |
| 2621 | else if (var_name == ScriptLangVarName()) |
| 2622 | { |
| 2623 | value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str()); |
| 2624 | } |
Caroline Tice | 101c7c2 | 2010-09-09 06:25:08 +0000 | [diff] [blame] | 2625 | else if (var_name == TermWidthVarName()) |
| 2626 | { |
| 2627 | StreamString width_str; |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 2628 | width_str.Printf ("%u", m_term_width); |
Caroline Tice | 101c7c2 | 2010-09-09 06:25:08 +0000 | [diff] [blame] | 2629 | value.AppendString (width_str.GetData()); |
| 2630 | } |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2631 | else if (var_name == GetFrameFormatName ()) |
| 2632 | { |
| 2633 | value.AppendString(m_frame_format.c_str(), m_frame_format.size()); |
| 2634 | } |
| 2635 | else if (var_name == GetThreadFormatName ()) |
| 2636 | { |
| 2637 | value.AppendString(m_thread_format.c_str(), m_thread_format.size()); |
| 2638 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2639 | else if (var_name == UseExternalEditorVarName()) |
| 2640 | { |
| 2641 | if (m_use_external_editor) |
| 2642 | value.AppendString ("true"); |
| 2643 | else |
| 2644 | value.AppendString ("false"); |
| 2645 | } |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2646 | else if (var_name == AutoConfirmName()) |
| 2647 | { |
| 2648 | if (m_auto_confirm_on) |
| 2649 | value.AppendString ("true"); |
| 2650 | else |
| 2651 | value.AppendString ("false"); |
| 2652 | } |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 2653 | else if (var_name == StopSourceContextAfterName ()) |
| 2654 | { |
| 2655 | StreamString strm; |
| 2656 | strm.Printf ("%u", m_stop_source_before_count); |
| 2657 | value.AppendString (strm.GetData()); |
| 2658 | } |
| 2659 | else if (var_name == StopSourceContextBeforeName ()) |
| 2660 | { |
| 2661 | StreamString strm; |
| 2662 | strm.Printf ("%u", m_stop_source_after_count); |
| 2663 | value.AppendString (strm.GetData()); |
| 2664 | } |
| 2665 | else if (var_name == StopDisassemblyCountName ()) |
| 2666 | { |
| 2667 | StreamString strm; |
| 2668 | strm.Printf ("%u", m_stop_disassembly_count); |
| 2669 | value.AppendString (strm.GetData()); |
| 2670 | } |
| 2671 | else if (var_name == StopDisassemblyDisplayName ()) |
| 2672 | { |
| 2673 | if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways) |
| 2674 | value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value); |
| 2675 | else |
| 2676 | value.AppendString ("<invalid>"); |
| 2677 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2678 | else |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 2679 | { |
| 2680 | if (err) |
| 2681 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 2682 | return false; |
| 2683 | } |
| 2684 | return true; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | void |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 2688 | DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings, |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2689 | bool pending) |
| 2690 | { |
| 2691 | if (new_settings.get() == NULL) |
| 2692 | return; |
| 2693 | |
| 2694 | DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get(); |
| 2695 | |
| 2696 | m_prompt = new_debugger_settings->m_prompt; |
| 2697 | if (!pending) |
Caroline Tice | 49e2737 | 2010-09-07 18:35:40 +0000 | [diff] [blame] | 2698 | { |
| 2699 | // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to |
| 2700 | // strip off the brackets before passing it to BroadcastPromptChange. |
| 2701 | |
| 2702 | std::string tmp_instance_name (m_instance_name.AsCString()); |
| 2703 | if ((tmp_instance_name[0] == '[') |
| 2704 | && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']')) |
| 2705 | tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2); |
| 2706 | ConstString new_name (tmp_instance_name.c_str()); |
| 2707 | |
| 2708 | BroadcastPromptChange (new_name, m_prompt.c_str()); |
| 2709 | } |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2710 | m_frame_format = new_debugger_settings->m_frame_format; |
| 2711 | m_thread_format = new_debugger_settings->m_thread_format; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2712 | m_term_width = new_debugger_settings->m_term_width; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2713 | m_script_lang = new_debugger_settings->m_script_lang; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2714 | m_use_external_editor = new_debugger_settings->m_use_external_editor; |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2715 | m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2718 | |
| 2719 | bool |
| 2720 | DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt) |
| 2721 | { |
| 2722 | std::string tmp_prompt; |
| 2723 | |
| 2724 | if (new_prompt != NULL) |
| 2725 | { |
| 2726 | tmp_prompt = new_prompt ; |
| 2727 | int len = tmp_prompt.size(); |
| 2728 | if (len > 1 |
| 2729 | && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"') |
| 2730 | && (tmp_prompt[len-1] == tmp_prompt[0])) |
| 2731 | { |
| 2732 | tmp_prompt = tmp_prompt.substr(1,len-2); |
| 2733 | } |
| 2734 | len = tmp_prompt.size(); |
| 2735 | if (tmp_prompt[len-1] != ' ') |
| 2736 | tmp_prompt.append(" "); |
| 2737 | } |
| 2738 | EventSP new_event_sp; |
| 2739 | new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt, |
| 2740 | new EventDataBytes (tmp_prompt.c_str()))); |
| 2741 | |
| 2742 | if (instance_name.GetLength() != 0) |
| 2743 | { |
| 2744 | // Set prompt for a particular instance. |
| 2745 | Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get(); |
| 2746 | if (dbg != NULL) |
| 2747 | { |
| 2748 | dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp); |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | return true; |
| 2753 | } |
| 2754 | |
| 2755 | const ConstString |
| 2756 | DebuggerInstanceSettings::CreateInstanceName () |
| 2757 | { |
| 2758 | static int instance_count = 1; |
| 2759 | StreamString sstr; |
| 2760 | |
| 2761 | sstr.Printf ("debugger_%d", instance_count); |
| 2762 | ++instance_count; |
| 2763 | |
| 2764 | const ConstString ret_val (sstr.GetData()); |
| 2765 | |
| 2766 | return ret_val; |
| 2767 | } |
| 2768 | |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2769 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2770 | //-------------------------------------------------- |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2771 | // SettingsController Variable Tables |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2772 | //-------------------------------------------------- |
| 2773 | |
| 2774 | |
| 2775 | SettingEntry |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2776 | Debugger::SettingsController::global_settings_table[] = |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2777 | { |
| 2778 | //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"}, |
Caroline Tice | 101c7c2 | 2010-09-09 06:25:08 +0000 | [diff] [blame] | 2779 | // The Debugger level global table should always be empty; all Debugger settable variables should be instance |
| 2780 | // variables. |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2781 | { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } |
| 2782 | }; |
| 2783 | |
Greg Clayton | bb562b1 | 2010-10-04 02:44:26 +0000 | [diff] [blame] | 2784 | #define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}" |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2785 | #define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2786 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2787 | #define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\ |
| 2788 | "{, ${frame.pc}}"\ |
| 2789 | MODULE_WITH_FUNC\ |
Greg Clayton | cf4b907 | 2010-10-04 17:04:23 +0000 | [diff] [blame] | 2790 | FILE_AND_LINE\ |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2791 | "{, stop reason = ${thread.stop-reason}}"\ |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 2792 | "{\\nReturn value: ${thread.return-value}}"\ |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2793 | "\\n" |
| 2794 | |
Greg Clayton | 315d2ca | 2010-11-02 01:53:21 +0000 | [diff] [blame] | 2795 | //#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\ |
| 2796 | // "{, ${frame.pc}}"\ |
| 2797 | // MODULE_WITH_FUNC\ |
| 2798 | // FILE_AND_LINE\ |
| 2799 | // "{, stop reason = ${thread.stop-reason}}"\ |
| 2800 | // "{, name = ${thread.name}}"\ |
| 2801 | // "{, queue = ${thread.queue}}"\ |
| 2802 | // "\\n" |
| 2803 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2804 | #define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\ |
| 2805 | MODULE_WITH_FUNC\ |
| 2806 | FILE_AND_LINE\ |
| 2807 | "\\n" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2808 | |
| 2809 | SettingEntry |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2810 | Debugger::SettingsController::instance_settings_table[] = |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2811 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2812 | // NAME Setting variable type Default Enum Init'd Hidden Help |
| 2813 | // ======================= ======================= ====================== ==== ====== ====== ====================== |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2814 | { "frame-format", eSetVarTypeString, DEFAULT_FRAME_FORMAT, NULL, false, false, "The default frame format string to use when displaying thread information." }, |
Greg Clayton | 5418039 | 2010-10-22 21:15:00 +0000 | [diff] [blame] | 2815 | { "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." }, |
Jim Ingham | 3bcdb29 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 2816 | { "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." }, |
| 2817 | { "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." }, |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2818 | { "thread-format", eSetVarTypeString, DEFAULT_THREAD_FORMAT, NULL, false, false, "The default thread format string to use when displaying thread information." }, |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 2819 | { "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." }, |
| 2820 | { "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." }, |
| 2821 | { "stop-line-count-before",eSetVarTypeInt, "3", NULL, false, false, "The number of sources lines to display that come before the current source line when displaying a stopped context." }, |
| 2822 | { "stop-line-count-after", eSetVarTypeInt, "3", NULL, false, false, "The number of sources lines to display that come after the current source line when displaying a stopped context." }, |
| 2823 | { "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." }, |
| 2824 | { "stop-disassembly-display", eSetVarTypeEnum, "no-source", g_show_disassembly_enum_values, false, false, "Control when to display disassembly when displaying a stopped context." }, |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2825 | { NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 2826 | }; |