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