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