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