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 | |
Greg Clayton | 4a33d31 | 2011-06-23 17:59:56 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Debugger.h" |
| 13 | |
| 14 | #include <map> |
| 15 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
| 17 | #include "clang/AST/Type.h" |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringRef.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/lldb-private.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Module.h" |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 22 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 23 | #include "lldb/Core/RegisterValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Core/State.h" |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StreamAsynchronousIO.h" |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 26 | #include "lldb/Core/StreamCallback.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/StreamFile.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 28 | #include "lldb/Core/StreamString.h" |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 29 | #include "lldb/Core/StructuredData.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/Timer.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 31 | #include "lldb/Core/ValueObject.h" |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 32 | #include "lldb/Core/ValueObjectVariable.h" |
Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 33 | #include "lldb/DataFormatters/DataVisualization.h" |
| 34 | #include "lldb/DataFormatters/FormatManager.h" |
Enrico Granata | 894f735 | 2014-03-25 22:03:52 +0000 | [diff] [blame] | 35 | #include "lldb/DataFormatters/TypeSummary.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 36 | #include "lldb/Host/ConnectionFileDescriptor.h" |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 37 | #include "lldb/Host/HostInfo.h" |
Greg Clayton | a340661 | 2011-02-07 23:24:47 +0000 | [diff] [blame] | 38 | #include "lldb/Host/Terminal.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 39 | #include "lldb/Host/ThreadLauncher.h" |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 40 | #include "lldb/Interpreter/CommandInterpreter.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 41 | #include "lldb/Interpreter/OptionValueSInt64.h" |
| 42 | #include "lldb/Interpreter/OptionValueString.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/ClangASTContext.h" |
| 44 | #include "lldb/Symbol/CompileUnit.h" |
| 45 | #include "lldb/Symbol/Function.h" |
| 46 | #include "lldb/Symbol/Symbol.h" |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 47 | #include "lldb/Symbol/VariableList.h" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 48 | #include "lldb/Target/CPPLanguageRuntime.h" |
| 49 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | #include "lldb/Target/TargetList.h" |
| 51 | #include "lldb/Target/Process.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 52 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 53 | #include "lldb/Target/SectionLoadList.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 54 | #include "lldb/Target/StopInfo.h" |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 55 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | #include "lldb/Target/Thread.h" |
Greg Clayton | 5a31471 | 2011-10-14 07:41:33 +0000 | [diff] [blame] | 57 | #include "lldb/Utility/AnsiTerminal.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 59 | #include "llvm/Support/DynamicLibrary.h" |
| 60 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | using namespace lldb; |
| 62 | using namespace lldb_private; |
| 63 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 65 | static uint32_t g_shared_debugger_refcount = 0; |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 66 | static lldb::user_id_t g_unique_id = 1; |
| 67 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 68 | #pragma mark Static Functions |
| 69 | |
| 70 | static Mutex & |
| 71 | GetDebuggerListMutex () |
| 72 | { |
| 73 | static Mutex g_mutex(Mutex::eMutexTypeRecursive); |
| 74 | return g_mutex; |
| 75 | } |
| 76 | |
| 77 | typedef std::vector<DebuggerSP> DebuggerList; |
| 78 | |
| 79 | static DebuggerList & |
| 80 | GetDebuggerList() |
| 81 | { |
| 82 | // hide the static debugger list inside a singleton accessor to avoid |
Bruce Mitchener | 6a7f333 | 2014-06-27 02:42:12 +0000 | [diff] [blame] | 83 | // global init constructors |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 84 | static DebuggerList g_list; |
| 85 | return g_list; |
| 86 | } |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 87 | |
| 88 | OptionEnumValueElement |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 89 | g_show_disassembly_enum_values[] = |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 90 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 91 | { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."}, |
| 92 | { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."}, |
| 93 | { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."}, |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 94 | { 0, NULL, NULL } |
| 95 | }; |
| 96 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 97 | OptionEnumValueElement |
| 98 | g_language_enumerators[] = |
| 99 | { |
| 100 | { eScriptLanguageNone, "none", "Disable scripting languages."}, |
| 101 | { eScriptLanguagePython, "python", "Select python as the default scripting language."}, |
| 102 | { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."}, |
Greg Clayton | a12993c | 2012-09-13 23:03:20 +0000 | [diff] [blame] | 103 | { 0, NULL, NULL } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 104 | }; |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 105 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 106 | #define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}" |
| 107 | #define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}" |
| 108 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 109 | #define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 110 | "{, ${frame.pc}}"\ |
| 111 | MODULE_WITH_FUNC\ |
| 112 | FILE_AND_LINE\ |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 113 | "{, name = '${thread.name}'}"\ |
| 114 | "{, queue = '${thread.queue}'}"\ |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 115 | "{, activity = '${thread.info.activity.name}'}" \ |
| 116 | "{, ${thread.info.trace_messages} messages}" \ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 117 | "{, stop reason = ${thread.stop-reason}}"\ |
| 118 | "{\\nReturn value: ${thread.return-value}}"\ |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 119 | "{\\nCompleted expression: ${thread.completed-expression}}"\ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 120 | "\\n" |
| 121 | |
| 122 | #define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\ |
| 123 | MODULE_WITH_FUNC\ |
| 124 | FILE_AND_LINE\ |
| 125 | "\\n" |
| 126 | |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 127 | #define DEFAULT_DISASSEMBLY_FORMAT "${addr-file-or-load} <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>: " |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 128 | |
| 129 | |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 130 | static PropertyDefinition |
| 131 | g_properties[] = |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 132 | { |
| 133 | { "auto-confirm", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." }, |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 134 | { "disassembly-format", OptionValue::eTypeString , true, 0 , DEFAULT_DISASSEMBLY_FORMAT, NULL, "The default disassembly format string to use when disassembling instruction sequences." }, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 135 | { "frame-format", OptionValue::eTypeString , true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." }, |
| 136 | { "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] | 137 | { "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] | 138 | { "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." }, |
| 139 | { "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." }, |
| 140 | { "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." }, |
| 141 | { "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." }, |
| 142 | { "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." }, |
| 143 | { "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." }, |
| 144 | { "thread-format", OptionValue::eTypeString , true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." }, |
| 145 | { "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] | 146 | { "use-color", OptionValue::eTypeBoolean, true, true , NULL, NULL, "Whether to use Ansi color codes or not." }, |
Enrico Granata | 90a8db3 | 2013-10-31 21:01:07 +0000 | [diff] [blame] | 147 | { "auto-one-line-summaries", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." }, |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 148 | |
| 149 | { NULL, OptionValue::eTypeInvalid, true, 0 , NULL, NULL, NULL } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | enum |
| 153 | { |
| 154 | ePropertyAutoConfirm = 0, |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 155 | ePropertyDisassemblyFormat, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 156 | ePropertyFrameFormat, |
| 157 | ePropertyNotiftVoid, |
| 158 | ePropertyPrompt, |
| 159 | ePropertyScriptLanguage, |
| 160 | ePropertyStopDisassemblyCount, |
| 161 | ePropertyStopDisassemblyDisplay, |
| 162 | ePropertyStopLineCountAfter, |
| 163 | ePropertyStopLineCountBefore, |
| 164 | ePropertyTerminalWidth, |
| 165 | ePropertyThreadFormat, |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 166 | ePropertyUseExternalEditor, |
| 167 | ePropertyUseColor, |
Enrico Granata | 90a8db3 | 2013-10-31 21:01:07 +0000 | [diff] [blame] | 168 | ePropertyAutoOneLineSummaries |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 171 | Debugger::LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL; |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 172 | |
| 173 | Error |
| 174 | Debugger::SetPropertyValue (const ExecutionContext *exe_ctx, |
| 175 | VarSetOperationType op, |
| 176 | const char *property_path, |
| 177 | const char *value) |
| 178 | { |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 179 | bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0; |
| 180 | TargetSP target_sp; |
Enrico Granata | 397ddd5 | 2013-05-21 20:13:34 +0000 | [diff] [blame] | 181 | LoadScriptFromSymFile load_script_old_value; |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 182 | if (is_load_script && exe_ctx->GetTargetSP()) |
| 183 | { |
| 184 | target_sp = exe_ctx->GetTargetSP(); |
| 185 | load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile(); |
| 186 | } |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 187 | Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value)); |
| 188 | if (error.Success()) |
| 189 | { |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 190 | // FIXME it would be nice to have "on-change" callbacks for properties |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 191 | if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0) |
| 192 | { |
| 193 | const char *new_prompt = GetPrompt(); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 194 | std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor()); |
| 195 | if (str.length()) |
| 196 | new_prompt = str.c_str(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 197 | GetCommandInterpreter().UpdatePrompt(new_prompt); |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 198 | EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt))); |
| 199 | GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp); |
| 200 | } |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 201 | else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0) |
| 202 | { |
| 203 | // use-color changed. Ping the prompt so it can reset the ansi terminal codes. |
| 204 | SetPrompt (GetPrompt()); |
| 205 | } |
Enrico Granata | 397ddd5 | 2013-05-21 20:13:34 +0000 | [diff] [blame] | 206 | else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 207 | { |
Enrico Granata | 397ddd5 | 2013-05-21 20:13:34 +0000 | [diff] [blame] | 208 | if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 209 | { |
| 210 | std::list<Error> errors; |
Enrico Granata | 9730339 | 2013-05-21 00:00:30 +0000 | [diff] [blame] | 211 | StreamString feedback_stream; |
| 212 | if (!target_sp->LoadScriptingResources(errors,&feedback_stream)) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 213 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 214 | StreamFileSP stream_sp (GetErrorFile()); |
| 215 | if (stream_sp) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 216 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 217 | for (auto error : errors) |
| 218 | { |
| 219 | stream_sp->Printf("%s\n",error.AsCString()); |
| 220 | } |
| 221 | if (feedback_stream.GetSize()) |
| 222 | stream_sp->Printf("%s",feedback_stream.GetData()); |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 227 | } |
| 228 | return error; |
| 229 | } |
| 230 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 231 | bool |
| 232 | Debugger::GetAutoConfirm () const |
| 233 | { |
| 234 | const uint32_t idx = ePropertyAutoConfirm; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 235 | 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] | 236 | } |
| 237 | |
| 238 | const char * |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 239 | Debugger::GetDisassemblyFormat() const |
| 240 | { |
| 241 | const uint32_t idx = ePropertyDisassemblyFormat; |
| 242 | return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value); |
| 243 | } |
| 244 | |
| 245 | const char * |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 246 | Debugger::GetFrameFormat() const |
| 247 | { |
| 248 | const uint32_t idx = ePropertyFrameFormat; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 249 | 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] | 250 | } |
| 251 | |
| 252 | bool |
| 253 | Debugger::GetNotifyVoid () const |
| 254 | { |
| 255 | const uint32_t idx = ePropertyNotiftVoid; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 256 | 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] | 257 | } |
| 258 | |
| 259 | const char * |
| 260 | Debugger::GetPrompt() const |
| 261 | { |
| 262 | const uint32_t idx = ePropertyPrompt; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 263 | 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] | 264 | } |
| 265 | |
| 266 | void |
| 267 | Debugger::SetPrompt(const char *p) |
| 268 | { |
| 269 | const uint32_t idx = ePropertyPrompt; |
| 270 | m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p); |
| 271 | const char *new_prompt = GetPrompt(); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 272 | std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor()); |
| 273 | if (str.length()) |
| 274 | new_prompt = str.c_str(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 275 | GetCommandInterpreter().UpdatePrompt(new_prompt); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | const char * |
| 279 | Debugger::GetThreadFormat() const |
| 280 | { |
| 281 | const uint32_t idx = ePropertyThreadFormat; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 282 | 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] | 283 | } |
| 284 | |
| 285 | lldb::ScriptLanguage |
| 286 | Debugger::GetScriptLanguage() const |
| 287 | { |
| 288 | const uint32_t idx = ePropertyScriptLanguage; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 289 | 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] | 290 | } |
| 291 | |
| 292 | bool |
| 293 | Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang) |
| 294 | { |
| 295 | const uint32_t idx = ePropertyScriptLanguage; |
| 296 | return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang); |
| 297 | } |
| 298 | |
| 299 | uint32_t |
| 300 | Debugger::GetTerminalWidth () const |
| 301 | { |
| 302 | const uint32_t idx = ePropertyTerminalWidth; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 303 | 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] | 304 | } |
| 305 | |
| 306 | bool |
| 307 | Debugger::SetTerminalWidth (uint32_t term_width) |
| 308 | { |
| 309 | const uint32_t idx = ePropertyTerminalWidth; |
| 310 | return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width); |
| 311 | } |
| 312 | |
| 313 | bool |
| 314 | Debugger::GetUseExternalEditor () const |
| 315 | { |
| 316 | const uint32_t idx = ePropertyUseExternalEditor; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 317 | 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] | 318 | } |
| 319 | |
| 320 | bool |
| 321 | Debugger::SetUseExternalEditor (bool b) |
| 322 | { |
| 323 | const uint32_t idx = ePropertyUseExternalEditor; |
| 324 | return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b); |
| 325 | } |
| 326 | |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 327 | bool |
| 328 | Debugger::GetUseColor () const |
| 329 | { |
| 330 | const uint32_t idx = ePropertyUseColor; |
| 331 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 332 | } |
| 333 | |
| 334 | bool |
| 335 | Debugger::SetUseColor (bool b) |
| 336 | { |
| 337 | const uint32_t idx = ePropertyUseColor; |
| 338 | bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b); |
| 339 | SetPrompt (GetPrompt()); |
| 340 | return ret; |
| 341 | } |
| 342 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 343 | uint32_t |
| 344 | Debugger::GetStopSourceLineCount (bool before) const |
| 345 | { |
| 346 | const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter; |
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 | } |
| 349 | |
| 350 | Debugger::StopDisassemblyType |
| 351 | Debugger::GetStopDisassemblyDisplay () const |
| 352 | { |
| 353 | const uint32_t idx = ePropertyStopDisassemblyDisplay; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 354 | 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] | 355 | } |
| 356 | |
| 357 | uint32_t |
| 358 | Debugger::GetDisassemblyLineCount () const |
| 359 | { |
| 360 | const uint32_t idx = ePropertyStopDisassemblyCount; |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 361 | 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] | 362 | } |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 363 | |
Enrico Granata | 553fad5 | 2013-10-25 23:09:40 +0000 | [diff] [blame] | 364 | bool |
Enrico Granata | 90a8db3 | 2013-10-31 21:01:07 +0000 | [diff] [blame] | 365 | Debugger::GetAutoOneLineSummaries () const |
Enrico Granata | 553fad5 | 2013-10-25 23:09:40 +0000 | [diff] [blame] | 366 | { |
Enrico Granata | 90a8db3 | 2013-10-31 21:01:07 +0000 | [diff] [blame] | 367 | const uint32_t idx = ePropertyAutoOneLineSummaries; |
Enrico Granata | 553fad5 | 2013-10-25 23:09:40 +0000 | [diff] [blame] | 368 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true); |
| 369 | |
| 370 | } |
| 371 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 372 | #pragma mark Debugger |
| 373 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 374 | //const DebuggerPropertiesSP & |
| 375 | //Debugger::GetSettings() const |
| 376 | //{ |
| 377 | // return m_properties_sp; |
| 378 | //} |
| 379 | // |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 380 | |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 381 | int |
| 382 | Debugger::TestDebuggerRefCount () |
| 383 | { |
| 384 | return g_shared_debugger_refcount; |
| 385 | } |
| 386 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 387 | void |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 388 | Debugger::Initialize (LoadPluginCallbackType load_plugin_callback) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 389 | { |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 390 | g_load_plugin_callback = load_plugin_callback; |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 391 | if (g_shared_debugger_refcount++ == 0) |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 392 | lldb_private::Initialize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | void |
| 396 | Debugger::Terminate () |
| 397 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 398 | if (g_shared_debugger_refcount > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 399 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 400 | g_shared_debugger_refcount--; |
| 401 | if (g_shared_debugger_refcount == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 402 | { |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 403 | lldb_private::WillTerminate(); |
| 404 | lldb_private::Terminate(); |
Caroline Tice | 6760a51 | 2011-01-17 21:55:19 +0000 | [diff] [blame] | 405 | |
| 406 | // Clear our master list of debugger objects |
| 407 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 408 | GetDebuggerList().clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 413 | void |
| 414 | Debugger::SettingsInitialize () |
| 415 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 416 | Target::SettingsInitialize (); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void |
| 420 | Debugger::SettingsTerminate () |
| 421 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 422 | Target::SettingsTerminate (); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 425 | bool |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 426 | Debugger::LoadPlugin (const FileSpec& spec, Error& error) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 427 | { |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 428 | if (g_load_plugin_callback) |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 429 | { |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 430 | llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error); |
| 431 | if (dynlib.isValid()) |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 432 | { |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 433 | m_loaded_plugins.push_back(dynlib); |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 434 | return true; |
| 435 | } |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 436 | } |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 437 | else |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 438 | { |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 439 | // The g_load_plugin_callback is registered in SBDebugger::Initialize() |
| 440 | // and if the public API layer isn't available (code is linking against |
| 441 | // all of the internal LLDB static libraries), then we can't load plugins |
| 442 | error.SetErrorString("Public API layer is not available"); |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 443 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 444 | return false; |
| 445 | } |
| 446 | |
| 447 | static FileSpec::EnumerateDirectoryResult |
| 448 | LoadPluginCallback |
| 449 | ( |
| 450 | void *baton, |
| 451 | FileSpec::FileType file_type, |
| 452 | const FileSpec &file_spec |
| 453 | ) |
| 454 | { |
| 455 | Error error; |
| 456 | |
| 457 | static ConstString g_dylibext("dylib"); |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 458 | static ConstString g_solibext("so"); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 459 | |
| 460 | if (!baton) |
| 461 | return FileSpec::eEnumerateDirectoryResultQuit; |
| 462 | |
| 463 | Debugger *debugger = (Debugger*)baton; |
| 464 | |
| 465 | // If we have a regular file, a symbolic link or unknown file type, try |
| 466 | // and process the file. We must handle unknown as sometimes the directory |
| 467 | // enumeration might be enumerating a file system that doesn't have correct |
| 468 | // file type information. |
| 469 | if (file_type == FileSpec::eFileTypeRegular || |
| 470 | file_type == FileSpec::eFileTypeSymbolicLink || |
| 471 | file_type == FileSpec::eFileTypeUnknown ) |
| 472 | { |
| 473 | FileSpec plugin_file_spec (file_spec); |
| 474 | plugin_file_spec.ResolvePath (); |
| 475 | |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 476 | if (plugin_file_spec.GetFileNameExtension() != g_dylibext && |
| 477 | plugin_file_spec.GetFileNameExtension() != g_solibext) |
| 478 | { |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 479 | return FileSpec::eEnumerateDirectoryResultNext; |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 480 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 481 | |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 482 | Error plugin_load_error; |
| 483 | debugger->LoadPlugin (plugin_file_spec, plugin_load_error); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 484 | |
| 485 | return FileSpec::eEnumerateDirectoryResultNext; |
| 486 | } |
| 487 | |
| 488 | else if (file_type == FileSpec::eFileTypeUnknown || |
| 489 | file_type == FileSpec::eFileTypeDirectory || |
| 490 | file_type == FileSpec::eFileTypeSymbolicLink ) |
| 491 | { |
| 492 | // Try and recurse into anything that a directory or symbolic link. |
| 493 | // We must also do this for unknown as sometimes the directory enumeration |
Bruce Mitchener | 6a7f333 | 2014-06-27 02:42:12 +0000 | [diff] [blame] | 494 | // might be enumerating a file system that doesn't have correct file type |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 495 | // information. |
| 496 | return FileSpec::eEnumerateDirectoryResultEnter; |
| 497 | } |
| 498 | |
| 499 | return FileSpec::eEnumerateDirectoryResultNext; |
| 500 | } |
| 501 | |
| 502 | void |
| 503 | Debugger::InstanceInitialize () |
| 504 | { |
| 505 | FileSpec dir_spec; |
| 506 | const bool find_directories = true; |
| 507 | const bool find_files = true; |
| 508 | const bool find_other = true; |
| 509 | char dir_path[PATH_MAX]; |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 510 | if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 511 | { |
| 512 | if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) |
| 513 | { |
| 514 | FileSpec::EnumerateDirectory (dir_path, |
| 515 | find_directories, |
| 516 | find_files, |
| 517 | find_other, |
| 518 | LoadPluginCallback, |
| 519 | this); |
| 520 | } |
| 521 | } |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 522 | |
| 523 | if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 524 | { |
| 525 | if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) |
| 526 | { |
| 527 | FileSpec::EnumerateDirectory (dir_path, |
| 528 | find_directories, |
| 529 | find_files, |
| 530 | find_other, |
| 531 | LoadPluginCallback, |
| 532 | this); |
| 533 | } |
| 534 | } |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 535 | |
| 536 | PluginManager::DebuggerInitialize (*this); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 539 | DebuggerSP |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 540 | Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 541 | { |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 542 | DebuggerSP debugger_sp (new Debugger(log_callback, baton)); |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 543 | if (g_shared_debugger_refcount > 0) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 544 | { |
| 545 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 546 | GetDebuggerList().push_back(debugger_sp); |
| 547 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 548 | debugger_sp->InstanceInitialize (); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 549 | return debugger_sp; |
| 550 | } |
| 551 | |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 552 | void |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 553 | Debugger::Destroy (DebuggerSP &debugger_sp) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 554 | { |
| 555 | if (debugger_sp.get() == NULL) |
| 556 | return; |
| 557 | |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 558 | debugger_sp->Clear(); |
| 559 | |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 560 | if (g_shared_debugger_refcount > 0) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 561 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 562 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 563 | DebuggerList &debugger_list = GetDebuggerList (); |
| 564 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 565 | for (pos = debugger_list.begin (); pos != end; ++pos) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 566 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 567 | if ((*pos).get() == debugger_sp.get()) |
| 568 | { |
| 569 | debugger_list.erase (pos); |
| 570 | return; |
| 571 | } |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 576 | DebuggerSP |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 577 | Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) |
| 578 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 579 | DebuggerSP debugger_sp; |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 580 | if (g_shared_debugger_refcount > 0) |
| 581 | { |
| 582 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 583 | DebuggerList &debugger_list = GetDebuggerList(); |
| 584 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 585 | |
| 586 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 587 | { |
| 588 | if ((*pos).get()->m_instance_name == instance_name) |
| 589 | { |
| 590 | debugger_sp = *pos; |
| 591 | break; |
| 592 | } |
| 593 | } |
| 594 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 595 | return debugger_sp; |
| 596 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 597 | |
| 598 | TargetSP |
| 599 | Debugger::FindTargetWithProcessID (lldb::pid_t pid) |
| 600 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 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 | 6611103 | 2010-06-23 01:19:29 +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().FindTargetWithProcessID (pid); |
| 610 | if (target_sp) |
| 611 | break; |
| 612 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 613 | } |
| 614 | return target_sp; |
| 615 | } |
| 616 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 617 | TargetSP |
| 618 | Debugger::FindTargetWithProcess (Process *process) |
| 619 | { |
| 620 | TargetSP target_sp; |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 621 | if (g_shared_debugger_refcount > 0) |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 622 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 623 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 624 | DebuggerList &debugger_list = GetDebuggerList(); |
| 625 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 626 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 627 | { |
| 628 | target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process); |
| 629 | if (target_sp) |
| 630 | break; |
| 631 | } |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 632 | } |
| 633 | return target_sp; |
| 634 | } |
| 635 | |
Jason Molenda | e6481c7 | 2014-09-12 01:50:46 +0000 | [diff] [blame] | 636 | Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) : |
| 637 | UserID(g_unique_id++), |
| 638 | Properties(OptionValuePropertiesSP(new OptionValueProperties())), |
| 639 | m_input_file_sp(new StreamFile(stdin, false)), |
| 640 | m_output_file_sp(new StreamFile(stdout, false)), |
| 641 | m_error_file_sp(new StreamFile(stderr, false)), |
| 642 | m_terminal_state(), |
| 643 | m_target_list(*this), |
| 644 | m_platform_list(), |
| 645 | m_listener("lldb.Debugger"), |
| 646 | m_source_manager_ap(), |
| 647 | m_source_file_cache(), |
| 648 | m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)), |
| 649 | m_input_reader_stack(), |
| 650 | m_instance_name(), |
| 651 | m_loaded_plugins() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 652 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 653 | char instance_cstr[256]; |
| 654 | snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID()); |
| 655 | m_instance_name.SetCString(instance_cstr); |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 656 | if (log_callback) |
| 657 | m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton)); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 658 | m_command_interpreter_ap->Initialize (); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 659 | // Always add our default platform to the platform list |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 660 | PlatformSP default_platform_sp (Platform::GetHostPlatform()); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 661 | assert (default_platform_sp.get()); |
| 662 | m_platform_list.Append (default_platform_sp, true); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 663 | |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 664 | m_collection_sp->Initialize (g_properties); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 665 | m_collection_sp->AppendProperty (ConstString("target"), |
| 666 | ConstString("Settings specify to debugging targets."), |
| 667 | true, |
| 668 | Target::GetGlobalProperties()->GetValueProperties()); |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 669 | if (m_command_interpreter_ap.get()) |
| 670 | { |
| 671 | m_collection_sp->AppendProperty (ConstString("interpreter"), |
| 672 | ConstString("Settings specify to the debugger's command interpreter."), |
| 673 | true, |
| 674 | m_command_interpreter_ap->GetValueProperties()); |
| 675 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 676 | OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth); |
| 677 | term_width->SetMinimumValue(10); |
| 678 | term_width->SetMaximumValue(1024); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 679 | |
| 680 | // Turn off use-color if this is a dumb terminal. |
| 681 | const char *term = getenv ("TERM"); |
| 682 | if (term && !strcmp (term, "dumb")) |
| 683 | SetUseColor (false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | Debugger::~Debugger () |
| 687 | { |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 688 | Clear(); |
| 689 | } |
| 690 | |
| 691 | void |
| 692 | Debugger::Clear() |
| 693 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 694 | ClearIOHandlers(); |
| 695 | StopIOHandlerThread(); |
| 696 | StopEventHandlerThread(); |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 697 | m_listener.Clear(); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 698 | int num_targets = m_target_list.GetNumTargets(); |
| 699 | for (int i = 0; i < num_targets; i++) |
| 700 | { |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 701 | TargetSP target_sp (m_target_list.GetTargetAtIndex (i)); |
| 702 | if (target_sp) |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 703 | { |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 704 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 705 | if (process_sp) |
Jim Ingham | 1fd0705 | 2013-02-27 19:13:05 +0000 | [diff] [blame] | 706 | process_sp->Finalize(); |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 707 | target_sp->Destroy(); |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 708 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 709 | } |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 710 | BroadcasterManager::Clear (); |
Greg Clayton | 0d69a3a | 2012-05-16 00:11:54 +0000 | [diff] [blame] | 711 | |
| 712 | // Close the input file _before_ we close the input read communications class |
| 713 | // 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] | 714 | m_terminal_state.Clear(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 715 | if (m_input_file_sp) |
| 716 | m_input_file_sp->GetFile().Close (); |
Greg Clayton | 0c4129f | 2014-04-25 00:35:14 +0000 | [diff] [blame] | 717 | |
| 718 | m_command_interpreter_ap->Clear(); |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 719 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 720 | |
| 721 | bool |
Greg Clayton | fc3f027 | 2011-05-29 04:06:55 +0000 | [diff] [blame] | 722 | Debugger::GetCloseInputOnEOF () const |
| 723 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 724 | // return m_input_comm.GetCloseOnEOF(); |
| 725 | return false; |
Greg Clayton | fc3f027 | 2011-05-29 04:06:55 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | void |
| 729 | Debugger::SetCloseInputOnEOF (bool b) |
| 730 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 731 | // m_input_comm.SetCloseOnEOF(b); |
Greg Clayton | fc3f027 | 2011-05-29 04:06:55 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | Debugger::GetAsyncExecution () |
| 736 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 737 | return !m_command_interpreter_ap->GetSynchronous(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | void |
| 741 | Debugger::SetAsyncExecution (bool async_execution) |
| 742 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 743 | m_command_interpreter_ap->SetSynchronous (!async_execution); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 746 | |
| 747 | void |
| 748 | Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership) |
| 749 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 750 | if (m_input_file_sp) |
| 751 | m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership); |
| 752 | else |
| 753 | m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership)); |
| 754 | |
| 755 | File &in_file = m_input_file_sp->GetFile(); |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 756 | if (in_file.IsValid() == false) |
| 757 | in_file.SetStream (stdin, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 758 | |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 759 | // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState. |
| 760 | SaveInputTerminalState (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | void |
| 764 | Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership) |
| 765 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 766 | if (m_output_file_sp) |
| 767 | m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership); |
| 768 | else |
| 769 | m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership)); |
| 770 | |
| 771 | File &out_file = m_output_file_sp->GetFile(); |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 772 | if (out_file.IsValid() == false) |
| 773 | out_file.SetStream (stdout, false); |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 774 | |
Enrico Granata | b588726 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 775 | // do not create the ScriptInterpreter just for setting the output file handle |
| 776 | // as the constructor will know how to do the right thing on its own |
| 777 | const bool can_create = false; |
| 778 | ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create); |
| 779 | if (script_interpreter) |
| 780 | script_interpreter->ResetOutputFileHandle (fh); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | void |
| 784 | Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership) |
| 785 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 786 | if (m_error_file_sp) |
| 787 | m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership); |
| 788 | else |
| 789 | m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership)); |
| 790 | |
| 791 | File &err_file = m_error_file_sp->GetFile(); |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 792 | if (err_file.IsValid() == false) |
| 793 | err_file.SetStream (stderr, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 796 | void |
| 797 | Debugger::SaveInputTerminalState () |
| 798 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 799 | if (m_input_file_sp) |
| 800 | { |
| 801 | File &in_file = m_input_file_sp->GetFile(); |
| 802 | if (in_file.GetDescriptor() != File::kInvalidDescriptor) |
| 803 | m_terminal_state.Save(in_file.GetDescriptor(), true); |
| 804 | } |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | void |
| 808 | Debugger::RestoreInputTerminalState () |
| 809 | { |
| 810 | m_terminal_state.Restore(); |
| 811 | } |
| 812 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 813 | ExecutionContext |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 814 | Debugger::GetSelectedExecutionContext () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 815 | { |
| 816 | ExecutionContext exe_ctx; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 817 | TargetSP target_sp(GetSelectedTarget()); |
| 818 | exe_ctx.SetTargetSP (target_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 819 | |
| 820 | if (target_sp) |
| 821 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 822 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 823 | exe_ctx.SetProcessSP (process_sp); |
| 824 | if (process_sp && process_sp->IsRunning() == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 825 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 826 | ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread()); |
| 827 | if (thread_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 828 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 829 | exe_ctx.SetThreadSP (thread_sp); |
| 830 | exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame()); |
| 831 | if (exe_ctx.GetFramePtr() == NULL) |
| 832 | exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | } |
| 836 | return exe_ctx; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 839 | void |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 840 | Debugger::DispatchInputInterrupt () |
| 841 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 842 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
| 843 | IOHandlerSP reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 844 | if (reader_sp) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 845 | reader_sp->Interrupt(); |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | void |
| 849 | Debugger::DispatchInputEndOfFile () |
| 850 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 851 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
| 852 | IOHandlerSP reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 853 | if (reader_sp) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 854 | reader_sp->GotEOF(); |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 858 | Debugger::ClearIOHandlers () |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 859 | { |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 860 | // The bottom input reader should be the main debugger input reader. We do not want to close that one here. |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 861 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 862 | while (m_input_reader_stack.GetSize() > 1) |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 863 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 864 | IOHandlerSP reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 865 | if (reader_sp) |
| 866 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 867 | m_input_reader_stack.Pop(); |
| 868 | reader_sp->SetIsDone(true); |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 869 | reader_sp->Cancel(); |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 875 | Debugger::ExecuteIOHanders() |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 876 | { |
Caroline Tice | 9088b06 | 2011-05-09 23:06:58 +0000 | [diff] [blame] | 877 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 878 | while (1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 880 | IOHandlerSP reader_sp(m_input_reader_stack.Top()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 881 | if (!reader_sp) |
| 882 | break; |
| 883 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 884 | reader_sp->Activate(); |
| 885 | reader_sp->Run(); |
| 886 | reader_sp->Deactivate(); |
| 887 | |
| 888 | // Remove all input readers that are done from the top of the stack |
| 889 | while (1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 890 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 891 | IOHandlerSP top_reader_sp = m_input_reader_stack.Top(); |
| 892 | if (top_reader_sp && top_reader_sp->GetIsDone()) |
| 893 | m_input_reader_stack.Pop(); |
| 894 | else |
| 895 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 896 | } |
| 897 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 898 | ClearIOHandlers(); |
| 899 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 900 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 901 | bool |
| 902 | Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp) |
| 903 | { |
| 904 | return m_input_reader_stack.IsTop (reader_sp); |
| 905 | } |
| 906 | |
| 907 | |
| 908 | ConstString |
| 909 | Debugger::GetTopIOHandlerControlSequence(char ch) |
| 910 | { |
| 911 | return m_input_reader_stack.GetTopIOHandlerControlSequence (ch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 915 | Debugger::RunIOHandler (const IOHandlerSP& reader_sp) |
| 916 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 917 | PushIOHandler (reader_sp); |
Greg Clayton | 577508d | 2014-06-20 00:23:57 +0000 | [diff] [blame] | 918 | |
| 919 | IOHandlerSP top_reader_sp = reader_sp; |
| 920 | while (top_reader_sp) |
| 921 | { |
| 922 | top_reader_sp->Activate(); |
| 923 | top_reader_sp->Run(); |
| 924 | top_reader_sp->Deactivate(); |
| 925 | |
| 926 | if (top_reader_sp.get() == reader_sp.get()) |
| 927 | { |
| 928 | if (PopIOHandler (reader_sp)) |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | while (1) |
| 933 | { |
| 934 | top_reader_sp = m_input_reader_stack.Top(); |
| 935 | if (top_reader_sp && top_reader_sp->GetIsDone()) |
| 936 | m_input_reader_stack.Pop(); |
| 937 | else |
| 938 | break; |
| 939 | } |
| 940 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | void |
| 944 | Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err) |
| 945 | { |
| 946 | // Before an IOHandler runs, it must have in/out/err streams. |
| 947 | // This function is called when one ore more of the streams |
| 948 | // are NULL. We use the top input reader's in/out/err streams, |
| 949 | // or fall back to the debugger file handles, or we fall back |
| 950 | // onto stdin/stdout/stderr as a last resort. |
| 951 | |
| 952 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
| 953 | IOHandlerSP top_reader_sp (m_input_reader_stack.Top()); |
| 954 | // If no STDIN has been set, then set it appropriately |
| 955 | if (!in) |
| 956 | { |
| 957 | if (top_reader_sp) |
| 958 | in = top_reader_sp->GetInputStreamFile(); |
| 959 | else |
| 960 | in = GetInputFile(); |
| 961 | |
| 962 | // If there is nothing, use stdin |
| 963 | if (!in) |
| 964 | in = StreamFileSP(new StreamFile(stdin, false)); |
| 965 | } |
| 966 | // If no STDOUT has been set, then set it appropriately |
| 967 | if (!out) |
| 968 | { |
| 969 | if (top_reader_sp) |
| 970 | out = top_reader_sp->GetOutputStreamFile(); |
| 971 | else |
| 972 | out = GetOutputFile(); |
| 973 | |
| 974 | // If there is nothing, use stdout |
| 975 | if (!out) |
| 976 | out = StreamFileSP(new StreamFile(stdout, false)); |
| 977 | } |
| 978 | // If no STDERR has been set, then set it appropriately |
| 979 | if (!err) |
| 980 | { |
| 981 | if (top_reader_sp) |
| 982 | err = top_reader_sp->GetErrorStreamFile(); |
| 983 | else |
| 984 | err = GetErrorFile(); |
| 985 | |
| 986 | // If there is nothing, use stderr |
| 987 | if (!err) |
| 988 | err = StreamFileSP(new StreamFile(stdout, false)); |
| 989 | |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | void |
| 994 | Debugger::PushIOHandler (const IOHandlerSP& reader_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 995 | { |
| 996 | if (!reader_sp) |
| 997 | return; |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 998 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 999 | // Got the current top input reader... |
| 1000 | IOHandlerSP top_reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 1001 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1002 | // Don't push the same IO handler twice... |
| 1003 | if (reader_sp.get() != top_reader_sp.get()) |
| 1004 | { |
| 1005 | // Push our new input reader |
| 1006 | m_input_reader_stack.Push (reader_sp); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1007 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1008 | // Interrupt the top input reader to it will exit its Run() function |
| 1009 | // and let this new input reader take over |
| 1010 | if (top_reader_sp) |
| 1011 | top_reader_sp->Deactivate(); |
| 1012 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1016 | Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | { |
| 1018 | bool result = false; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1019 | |
| 1020 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1021 | |
| 1022 | // The reader on the stop of the stack is done, so let the next |
Bruce Mitchener | 6a7f333 | 2014-06-27 02:42:12 +0000 | [diff] [blame] | 1023 | // read on the stack refresh its prompt and if there is one... |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 1024 | if (!m_input_reader_stack.IsEmpty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1026 | IOHandlerSP reader_sp(m_input_reader_stack.Top()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1027 | |
| 1028 | if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get()) |
| 1029 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1030 | reader_sp->Deactivate(); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1031 | reader_sp->Cancel(); |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 1032 | m_input_reader_stack.Pop (); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1033 | |
| 1034 | reader_sp = m_input_reader_stack.Top(); |
| 1035 | if (reader_sp) |
| 1036 | reader_sp->Activate(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1037 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1038 | result = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | return result; |
| 1042 | } |
| 1043 | |
| 1044 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1045 | Debugger::HideTopIOHandler() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1046 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1047 | Mutex::Locker locker; |
| 1048 | |
| 1049 | if (locker.TryLock(m_input_reader_stack.GetMutex())) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1050 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1051 | IOHandlerSP reader_sp(m_input_reader_stack.Top()); |
| 1052 | if (reader_sp) |
| 1053 | reader_sp->Hide(); |
| 1054 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1055 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1056 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1060 | Debugger::RefreshTopIOHandler() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1061 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1062 | IOHandlerSP reader_sp(m_input_reader_stack.Top()); |
| 1063 | if (reader_sp) |
| 1064 | reader_sp->Refresh(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1065 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1066 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1067 | |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 1068 | StreamSP |
| 1069 | Debugger::GetAsyncOutputStream () |
| 1070 | { |
| 1071 | return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(), |
| 1072 | CommandInterpreter::eBroadcastBitAsynchronousOutputData)); |
| 1073 | } |
| 1074 | |
| 1075 | StreamSP |
| 1076 | Debugger::GetAsyncErrorStream () |
| 1077 | { |
| 1078 | return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(), |
| 1079 | CommandInterpreter::eBroadcastBitAsynchronousErrorData)); |
| 1080 | } |
| 1081 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1082 | size_t |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1083 | Debugger::GetNumDebuggers() |
| 1084 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1085 | if (g_shared_debugger_refcount > 0) |
| 1086 | { |
| 1087 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 1088 | return GetDebuggerList().size(); |
| 1089 | } |
| 1090 | return 0; |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | lldb::DebuggerSP |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1094 | Debugger::GetDebuggerAtIndex (size_t index) |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1095 | { |
| 1096 | DebuggerSP debugger_sp; |
| 1097 | |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1098 | if (g_shared_debugger_refcount > 0) |
| 1099 | { |
| 1100 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 1101 | DebuggerList &debugger_list = GetDebuggerList(); |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1102 | |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1103 | if (index < debugger_list.size()) |
| 1104 | debugger_sp = debugger_list[index]; |
| 1105 | } |
| 1106 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1107 | return debugger_sp; |
| 1108 | } |
| 1109 | |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1110 | DebuggerSP |
| 1111 | Debugger::FindDebuggerWithID (lldb::user_id_t id) |
| 1112 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1113 | DebuggerSP debugger_sp; |
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 (g_shared_debugger_refcount > 0) |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1116 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1117 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 1118 | DebuggerList &debugger_list = GetDebuggerList(); |
| 1119 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 1120 | for (pos = debugger_list.begin(); pos != end; ++pos) |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1121 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1122 | if ((*pos).get()->GetID() == id) |
| 1123 | { |
| 1124 | debugger_sp = *pos; |
| 1125 | break; |
| 1126 | } |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | return debugger_sp; |
| 1130 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1131 | |
Saleem Abdulrasool | 2643b90 | 2014-03-20 06:08:21 +0000 | [diff] [blame] | 1132 | #if 0 |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1133 | static void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1134 | TestPromptFormats (StackFrame *frame) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1135 | { |
| 1136 | if (frame == NULL) |
| 1137 | return; |
| 1138 | |
| 1139 | StreamString s; |
| 1140 | const char *prompt_format = |
| 1141 | "{addr = '${addr}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1142 | "{addr-file-or-load = '${addr-file-or-load}'\n}" |
| 1143 | "{current-pc-arrow = '${current-pc-arrow}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1144 | "{process.id = '${process.id}'\n}" |
| 1145 | "{process.name = '${process.name}'\n}" |
| 1146 | "{process.file.basename = '${process.file.basename}'\n}" |
| 1147 | "{process.file.fullpath = '${process.file.fullpath}'\n}" |
| 1148 | "{thread.id = '${thread.id}'\n}" |
| 1149 | "{thread.index = '${thread.index}'\n}" |
| 1150 | "{thread.name = '${thread.name}'\n}" |
| 1151 | "{thread.queue = '${thread.queue}'\n}" |
| 1152 | "{thread.stop-reason = '${thread.stop-reason}'\n}" |
| 1153 | "{target.arch = '${target.arch}'\n}" |
| 1154 | "{module.file.basename = '${module.file.basename}'\n}" |
| 1155 | "{module.file.fullpath = '${module.file.fullpath}'\n}" |
| 1156 | "{file.basename = '${file.basename}'\n}" |
| 1157 | "{file.fullpath = '${file.fullpath}'\n}" |
| 1158 | "{frame.index = '${frame.index}'\n}" |
| 1159 | "{frame.pc = '${frame.pc}'\n}" |
| 1160 | "{frame.sp = '${frame.sp}'\n}" |
| 1161 | "{frame.fp = '${frame.fp}'\n}" |
| 1162 | "{frame.flags = '${frame.flags}'\n}" |
| 1163 | "{frame.reg.rdi = '${frame.reg.rdi}'\n}" |
| 1164 | "{frame.reg.rip = '${frame.reg.rip}'\n}" |
| 1165 | "{frame.reg.rsp = '${frame.reg.rsp}'\n}" |
| 1166 | "{frame.reg.rbp = '${frame.reg.rbp}'\n}" |
| 1167 | "{frame.reg.rflags = '${frame.reg.rflags}'\n}" |
| 1168 | "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}" |
| 1169 | "{frame.reg.carp = '${frame.reg.carp}'\n}" |
| 1170 | "{function.id = '${function.id}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1171 | "{function.changed = '${function.changed}'\n}" |
| 1172 | "{function.initial-function = '${function.initial-function}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1173 | "{function.name = '${function.name}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1174 | "{function.name-without-args = '${function.name-without-args}'\n}" |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 1175 | "{function.name-with-args = '${function.name-with-args}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1176 | "{function.addr-offset = '${function.addr-offset}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1177 | "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1178 | "{function.line-offset = '${function.line-offset}'\n}" |
| 1179 | "{function.pc-offset = '${function.pc-offset}'\n}" |
| 1180 | "{line.file.basename = '${line.file.basename}'\n}" |
| 1181 | "{line.file.fullpath = '${line.file.fullpath}'\n}" |
| 1182 | "{line.number = '${line.number}'\n}" |
| 1183 | "{line.start-addr = '${line.start-addr}'\n}" |
| 1184 | "{line.end-addr = '${line.end-addr}'\n}" |
| 1185 | ; |
| 1186 | |
| 1187 | SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything)); |
| 1188 | ExecutionContext exe_ctx; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1189 | frame->CalculateExecutionContext(exe_ctx); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1190 | 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] | 1191 | { |
| 1192 | printf("%s\n", s.GetData()); |
| 1193 | } |
| 1194 | else |
| 1195 | { |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1196 | printf ("what we got: %s\n", s.GetData()); |
| 1197 | } |
| 1198 | } |
Saleem Abdulrasool | 2643b90 | 2014-03-20 06:08:21 +0000 | [diff] [blame] | 1199 | #endif |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1200 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1201 | static bool |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1202 | ScanFormatDescriptor (const char* var_name_begin, |
| 1203 | const char* var_name_end, |
| 1204 | const char** var_name_final, |
| 1205 | const char** percent_position, |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1206 | Format* custom_format, |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1207 | ValueObject::ValueObjectRepresentationStyle* val_obj_display) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1208 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1209 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1210 | *percent_position = ::strchr(var_name_begin,'%'); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1211 | if (!*percent_position || *percent_position > var_name_end) |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1212 | { |
| 1213 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1214 | log->Printf("[ScanFormatDescriptor] no format descriptor in string, skipping"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1215 | *var_name_final = var_name_end; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1216 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1217 | else |
| 1218 | { |
| 1219 | *var_name_final = *percent_position; |
Enrico Granata | 36aa5ae | 2013-05-06 17:18:22 +0000 | [diff] [blame] | 1220 | 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] | 1221 | if (log) |
Enrico Granata | 68ae411 | 2013-06-18 18:23:07 +0000 | [diff] [blame] | 1222 | 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] | 1223 | if ( !FormatManager::GetFormatFromCString(format_name.c_str(), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1224 | true, |
| 1225 | *custom_format) ) |
| 1226 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1227 | if (log) |
Enrico Granata | 68ae411 | 2013-06-18 18:23:07 +0000 | [diff] [blame] | 1228 | log->Printf("[ScanFormatDescriptor] %s is an unknown format", format_name.c_str()); |
Enrico Granata | 36aa5ae | 2013-05-06 17:18:22 +0000 | [diff] [blame] | 1229 | |
| 1230 | switch (format_name.front()) |
| 1231 | { |
| 1232 | case '@': // if this is an @ sign, print ObjC description |
| 1233 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleLanguageSpecific; |
| 1234 | break; |
| 1235 | case 'V': // if this is a V, print the value using the default format |
| 1236 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
| 1237 | break; |
| 1238 | case 'L': // if this is an L, print the location of the value |
| 1239 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleLocation; |
| 1240 | break; |
| 1241 | case 'S': // if this is an S, print the summary after all |
| 1242 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary; |
| 1243 | break; |
| 1244 | case '#': // if this is a '#', print the number of children |
| 1245 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleChildrenCount; |
| 1246 | break; |
| 1247 | case 'T': // if this is a 'T', print the type |
| 1248 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleType; |
| 1249 | break; |
Enrico Granata | 2c75f11 | 2013-06-21 00:04:51 +0000 | [diff] [blame] | 1250 | case 'N': // if this is a 'N', print the name |
| 1251 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleName; |
| 1252 | break; |
| 1253 | case '>': // if this is a '>', print the name |
| 1254 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleExpressionPath; |
| 1255 | break; |
Enrico Granata | 36aa5ae | 2013-05-06 17:18:22 +0000 | [diff] [blame] | 1256 | default: |
Jim Ingham | 5c42d8a | 2013-05-15 18:27:08 +0000 | [diff] [blame] | 1257 | if (log) |
| 1258 | 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] | 1259 | break; |
| 1260 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1261 | } |
| 1262 | // a good custom format tells us to print the value using it |
| 1263 | else |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1264 | { |
| 1265 | if (log) |
Enrico Granata | 68ae411 | 2013-06-18 18:23:07 +0000 | [diff] [blame] | 1266 | log->Printf("[ScanFormatDescriptor] will display value for this VO"); |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1267 | *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1268 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1269 | } |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1270 | if (log) |
Enrico Granata | 68ae411 | 2013-06-18 18:23:07 +0000 | [diff] [blame] | 1271 | 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] | 1272 | *custom_format, |
| 1273 | *val_obj_display); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1274 | return true; |
| 1275 | } |
| 1276 | |
| 1277 | static bool |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1278 | ScanBracketedRange (const char* var_name_begin, |
| 1279 | const char* var_name_end, |
| 1280 | const char* var_name_final, |
| 1281 | const char** open_bracket_position, |
| 1282 | const char** separator_position, |
| 1283 | const char** close_bracket_position, |
| 1284 | const char** var_name_final_if_array_range, |
| 1285 | int64_t* index_lower, |
| 1286 | int64_t* index_higher) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1287 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1288 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1289 | *open_bracket_position = ::strchr(var_name_begin,'['); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1290 | if (*open_bracket_position && *open_bracket_position < var_name_final) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1291 | { |
| 1292 | *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield |
| 1293 | *close_bracket_position = ::strchr(*open_bracket_position,']'); |
| 1294 | // as usual, we assume that [] will come before % |
| 1295 | //printf("trying to expand a []\n"); |
| 1296 | *var_name_final_if_array_range = *open_bracket_position; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1297 | if (*close_bracket_position - *open_bracket_position == 1) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1298 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1299 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1300 | log->Printf("[ScanBracketedRange] '[]' detected.. going from 0 to end of data"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1301 | *index_lower = 0; |
| 1302 | } |
| 1303 | else if (*separator_position == NULL || *separator_position > var_name_end) |
| 1304 | { |
| 1305 | char *end = NULL; |
| 1306 | *index_lower = ::strtoul (*open_bracket_position+1, &end, 0); |
| 1307 | *index_higher = *index_lower; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1308 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1309 | log->Printf("[ScanBracketedRange] [%" PRId64 "] detected, high index is same", *index_lower); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1310 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1311 | else if (*close_bracket_position && *close_bracket_position < var_name_end) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1312 | { |
| 1313 | char *end = NULL; |
| 1314 | *index_lower = ::strtoul (*open_bracket_position+1, &end, 0); |
| 1315 | *index_higher = ::strtoul (*separator_position+1, &end, 0); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1316 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1317 | log->Printf("[ScanBracketedRange] [%" PRId64 "-%" PRId64 "] detected", *index_lower, *index_higher); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1318 | } |
| 1319 | else |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1320 | { |
| 1321 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1322 | log->Printf("[ScanBracketedRange] expression is erroneous, cannot extract indices out of it"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1323 | return false; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1324 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1325 | if (*index_lower > *index_higher && *index_higher > 0) |
| 1326 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1327 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1328 | log->Printf("[ScanBracketedRange] swapping indices"); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1329 | int64_t temp = *index_lower; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1330 | *index_lower = *index_higher; |
| 1331 | *index_higher = temp; |
| 1332 | } |
| 1333 | } |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1334 | else if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1335 | log->Printf("[ScanBracketedRange] no bracketed range, skipping entirely"); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1336 | return true; |
| 1337 | } |
| 1338 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 1339 | template <typename T> |
| 1340 | static bool RunScriptFormatKeyword(Stream &s, ScriptInterpreter *script_interpreter, T t, const std::string& script_name) |
| 1341 | { |
| 1342 | if (script_interpreter) |
| 1343 | { |
| 1344 | Error script_error; |
| 1345 | std::string script_output; |
| 1346 | |
| 1347 | if (script_interpreter->RunScriptFormatKeyword(script_name.c_str(), t, script_output, script_error) && script_error.Success()) |
| 1348 | { |
| 1349 | s.Printf("%s", script_output.c_str()); |
| 1350 | return true; |
| 1351 | } |
| 1352 | else |
| 1353 | { |
| 1354 | s.Printf("<error: %s>",script_error.AsCString()); |
| 1355 | } |
| 1356 | } |
| 1357 | return false; |
| 1358 | } |
| 1359 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1360 | static ValueObjectSP |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1361 | ExpandIndexedExpression (ValueObject* valobj, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1362 | size_t index, |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1363 | StackFrame* frame, |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1364 | bool deref_pointer) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1365 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1366 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1367 | const char* ptr_deref_format = "[%d]"; |
Enrico Granata | 599171a | 2013-02-01 23:59:44 +0000 | [diff] [blame] | 1368 | std::string ptr_deref_buffer(10,0); |
| 1369 | ::sprintf(&ptr_deref_buffer[0], ptr_deref_format, index); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1370 | if (log) |
Enrico Granata | 599171a | 2013-02-01 23:59:44 +0000 | [diff] [blame] | 1371 | log->Printf("[ExpandIndexedExpression] name to deref: %s",ptr_deref_buffer.c_str()); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1372 | const char* first_unparsed; |
| 1373 | ValueObject::GetValueForExpressionPathOptions options; |
| 1374 | ValueObject::ExpressionPathEndResultType final_value_type; |
| 1375 | ValueObject::ExpressionPathScanEndReason reason_to_stop; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1376 | ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing); |
Enrico Granata | 599171a | 2013-02-01 23:59:44 +0000 | [diff] [blame] | 1377 | ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.c_str(), |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1378 | &first_unparsed, |
| 1379 | &reason_to_stop, |
| 1380 | &final_value_type, |
| 1381 | options, |
| 1382 | &what_next); |
| 1383 | if (!item) |
| 1384 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1385 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1386 | log->Printf("[ExpandIndexedExpression] ERROR: unparsed portion = %s, why stopping = %d," |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1387 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1388 | first_unparsed, reason_to_stop, final_value_type); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1389 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1390 | else |
| 1391 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1392 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1393 | log->Printf("[ExpandIndexedExpression] ALL RIGHT: unparsed portion = %s, why stopping = %d," |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1394 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1395 | first_unparsed, reason_to_stop, final_value_type); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1396 | } |
| 1397 | return item; |
| 1398 | } |
| 1399 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 1400 | static inline bool |
| 1401 | IsToken(const char *var_name_begin, const char *var) |
| 1402 | { |
| 1403 | return (::strncmp (var_name_begin, var, strlen(var)) == 0); |
| 1404 | } |
| 1405 | |
| 1406 | static bool |
| 1407 | IsTokenWithFormat(const char *var_name_begin, const char *var, std::string &format, const char *default_format, |
| 1408 | const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) |
| 1409 | { |
| 1410 | int var_len = strlen(var); |
| 1411 | if (::strncmp (var_name_begin, var, var_len) == 0) |
| 1412 | { |
| 1413 | var_name_begin += var_len; |
| 1414 | if (*var_name_begin == '}') |
| 1415 | { |
| 1416 | format = default_format; |
| 1417 | return true; |
| 1418 | } |
| 1419 | else if (*var_name_begin == '%') |
| 1420 | { |
| 1421 | // Allow format specifiers: x|X|u with optional width specifiers. |
| 1422 | // ${thread.id%x} ; hex |
| 1423 | // ${thread.id%X} ; uppercase hex |
| 1424 | // ${thread.id%u} ; unsigned decimal |
| 1425 | // ${thread.id%8.8X} ; width.precision + specifier |
| 1426 | // ${thread.id%tid} ; unsigned on FreeBSD/Linux, otherwise default_format (0x%4.4x for thread.id) |
| 1427 | int dot_count = 0; |
| 1428 | const char *specifier = NULL; |
| 1429 | int width_precision_length = 0; |
| 1430 | const char *width_precision = ++var_name_begin; |
| 1431 | while (isdigit(*var_name_begin) || *var_name_begin == '.') |
| 1432 | { |
| 1433 | dot_count += (*var_name_begin == '.'); |
| 1434 | if (dot_count > 1) |
| 1435 | break; |
| 1436 | var_name_begin++; |
| 1437 | width_precision_length++; |
| 1438 | } |
| 1439 | |
| 1440 | if (IsToken (var_name_begin, "tid}")) |
| 1441 | { |
| 1442 | Target *target = Target::GetTargetFromContexts (exe_ctx_ptr, sc_ptr); |
| 1443 | if (target) |
| 1444 | { |
| 1445 | ArchSpec arch (target->GetArchitecture ()); |
| 1446 | llvm::Triple::OSType ostype = arch.IsValid() ? arch.GetTriple().getOS() : llvm::Triple::UnknownOS; |
| 1447 | if ((ostype == llvm::Triple::FreeBSD) || (ostype == llvm::Triple::Linux)) |
| 1448 | specifier = PRIu64; |
| 1449 | } |
| 1450 | if (!specifier) |
| 1451 | { |
| 1452 | format = default_format; |
| 1453 | return true; |
| 1454 | } |
| 1455 | } |
| 1456 | else if (IsToken (var_name_begin, "x}")) |
| 1457 | specifier = PRIx64; |
| 1458 | else if (IsToken (var_name_begin, "X}")) |
| 1459 | specifier = PRIX64; |
| 1460 | else if (IsToken (var_name_begin, "u}")) |
| 1461 | specifier = PRIu64; |
| 1462 | |
| 1463 | if (specifier) |
| 1464 | { |
| 1465 | format = "%"; |
| 1466 | if (width_precision_length) |
| 1467 | format += std::string(width_precision, width_precision_length); |
| 1468 | format += specifier; |
| 1469 | return true; |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | return false; |
| 1474 | } |
| 1475 | |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 1476 | // Find information for the "thread.info.*" specifiers in a format string |
| 1477 | static bool |
| 1478 | FormatThreadExtendedInfoRecurse |
| 1479 | ( |
| 1480 | const char *var_name_begin, |
| 1481 | StructuredData::ObjectSP thread_info_dictionary, |
| 1482 | const SymbolContext *sc, |
| 1483 | const ExecutionContext *exe_ctx, |
| 1484 | Stream &s |
| 1485 | ) |
| 1486 | { |
| 1487 | bool var_success = false; |
| 1488 | std::string token_format; |
| 1489 | |
| 1490 | llvm::StringRef var_name(var_name_begin); |
| 1491 | size_t percent_idx = var_name.find('%'); |
| 1492 | size_t close_curly_idx = var_name.find('}'); |
| 1493 | llvm::StringRef path = var_name; |
| 1494 | llvm::StringRef formatter = var_name; |
| 1495 | |
| 1496 | // 'path' will be the dot separated list of objects to transverse up until we hit |
| 1497 | // a close curly brace, a percent sign, or an end of string. |
| 1498 | if (percent_idx != llvm::StringRef::npos || close_curly_idx != llvm::StringRef::npos) |
| 1499 | { |
| 1500 | if (percent_idx != llvm::StringRef::npos && close_curly_idx != llvm::StringRef::npos) |
| 1501 | { |
| 1502 | if (percent_idx < close_curly_idx) |
| 1503 | { |
| 1504 | path = var_name.slice(0, percent_idx); |
| 1505 | formatter = var_name.substr (percent_idx); |
| 1506 | } |
| 1507 | else |
| 1508 | { |
| 1509 | path = var_name.slice(0, close_curly_idx); |
| 1510 | formatter = var_name.substr (close_curly_idx); |
| 1511 | } |
| 1512 | } |
| 1513 | else if (percent_idx != llvm::StringRef::npos) |
| 1514 | { |
| 1515 | path = var_name.slice(0, percent_idx); |
| 1516 | formatter = var_name.substr (percent_idx); |
| 1517 | } |
| 1518 | else if (close_curly_idx != llvm::StringRef::npos) |
| 1519 | { |
| 1520 | path = var_name.slice(0, close_curly_idx); |
| 1521 | formatter = var_name.substr (close_curly_idx); |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | StructuredData::ObjectSP value = thread_info_dictionary->GetObjectForDotSeparatedPath (path); |
| 1526 | |
| 1527 | if (value.get()) |
| 1528 | { |
| 1529 | if (value->GetType() == StructuredData::Type::eTypeInteger) |
| 1530 | { |
| 1531 | if (IsTokenWithFormat (formatter.str().c_str(), "", token_format, "0x%4.4" PRIx64, exe_ctx, sc)) |
| 1532 | { |
| 1533 | s.Printf(token_format.c_str(), value->GetAsInteger()->GetValue()); |
| 1534 | var_success = true; |
| 1535 | } |
| 1536 | } |
| 1537 | else if (value->GetType() == StructuredData::Type::eTypeFloat) |
| 1538 | { |
| 1539 | s.Printf ("%f", value->GetAsFloat()->GetValue()); |
| 1540 | var_success = true; |
| 1541 | } |
| 1542 | else if (value->GetType() == StructuredData::Type::eTypeString) |
| 1543 | { |
| 1544 | s.Printf("%s", value->GetAsString()->GetValue().c_str()); |
| 1545 | var_success = true; |
| 1546 | } |
| 1547 | else if (value->GetType() == StructuredData::Type::eTypeArray) |
| 1548 | { |
| 1549 | if (value->GetAsArray()->GetSize() > 0) |
| 1550 | { |
| 1551 | s.Printf ("%zu", value->GetAsArray()->GetSize()); |
| 1552 | var_success = true; |
| 1553 | } |
| 1554 | } |
| 1555 | else if (value->GetType() == StructuredData::Type::eTypeDictionary) |
| 1556 | { |
| 1557 | s.Printf ("%zu", value->GetAsDictionary()->GetKeys()->GetAsArray()->GetSize()); |
| 1558 | var_success = true; |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | return var_success; |
| 1563 | } |
| 1564 | |
| 1565 | |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1566 | static bool |
| 1567 | FormatPromptRecurse |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1568 | ( |
| 1569 | const char *format, |
| 1570 | const SymbolContext *sc, |
| 1571 | const ExecutionContext *exe_ctx, |
| 1572 | const Address *addr, |
| 1573 | Stream &s, |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1574 | const char **end, |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1575 | ValueObject* valobj, |
| 1576 | bool function_changed, |
| 1577 | bool initial_function |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1578 | ) |
| 1579 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1580 | ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1581 | bool success = true; |
| 1582 | const char *p; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1583 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1584 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1585 | for (p = format; *p != '\0'; ++p) |
| 1586 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1587 | if (realvalobj) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1588 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1589 | valobj = realvalobj; |
| 1590 | realvalobj = NULL; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1591 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1592 | size_t non_special_chars = ::strcspn (p, "${}\\"); |
| 1593 | if (non_special_chars > 0) |
| 1594 | { |
| 1595 | if (success) |
| 1596 | s.Write (p, non_special_chars); |
| 1597 | p += non_special_chars; |
| 1598 | } |
| 1599 | |
| 1600 | if (*p == '\0') |
| 1601 | { |
| 1602 | break; |
| 1603 | } |
| 1604 | else if (*p == '{') |
| 1605 | { |
| 1606 | // Start a new scope that must have everything it needs if it is to |
| 1607 | // to make it into the final output stream "s". If you want to make |
| 1608 | // a format that only prints out the function or symbol name if there |
| 1609 | // is one in the symbol context you can use: |
| 1610 | // "{function =${function.name}}" |
| 1611 | // The first '{' starts a new scope that end with the matching '}' at |
| 1612 | // the end of the string. The contents "function =${function.name}" |
| 1613 | // will then be evaluated and only be output if there is a function |
| 1614 | // or symbol with a valid name. |
| 1615 | StreamString sub_strm; |
| 1616 | |
| 1617 | ++p; // Skip the '{' |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1618 | |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1619 | if (FormatPromptRecurse (p, sc, exe_ctx, addr, sub_strm, &p, valobj, function_changed, initial_function)) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1620 | { |
| 1621 | // The stream had all it needed |
| 1622 | s.Write(sub_strm.GetData(), sub_strm.GetSize()); |
| 1623 | } |
| 1624 | if (*p != '}') |
| 1625 | { |
| 1626 | success = false; |
| 1627 | break; |
| 1628 | } |
| 1629 | } |
| 1630 | else if (*p == '}') |
| 1631 | { |
| 1632 | // End of a enclosing scope |
| 1633 | break; |
| 1634 | } |
| 1635 | else if (*p == '$') |
| 1636 | { |
| 1637 | // We have a prompt variable to print |
| 1638 | ++p; |
| 1639 | if (*p == '{') |
| 1640 | { |
| 1641 | ++p; |
| 1642 | const char *var_name_begin = p; |
| 1643 | const char *var_name_end = ::strchr (p, '}'); |
| 1644 | |
| 1645 | if (var_name_end && var_name_begin < var_name_end) |
| 1646 | { |
| 1647 | // if we have already failed to parse, skip this variable |
| 1648 | if (success) |
| 1649 | { |
| 1650 | const char *cstr = NULL; |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 1651 | std::string token_format; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1652 | Address format_addr; |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1653 | |
| 1654 | // normally "addr" means print a raw address but |
| 1655 | // "file-addr-or-load-addr" means print a module + file addr if there's no load addr |
| 1656 | bool print_file_addr_or_load_addr = false; |
| 1657 | bool addr_offset_concrete_func_only = false; |
| 1658 | bool addr_offset_print_with_no_padding = false; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1659 | bool calculate_format_addr_function_offset = false; |
| 1660 | // Set reg_kind and reg_num to invalid values |
| 1661 | RegisterKind reg_kind = kNumRegisterKinds; |
| 1662 | uint32_t reg_num = LLDB_INVALID_REGNUM; |
| 1663 | FileSpec format_file_spec; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1664 | const RegisterInfo *reg_info = NULL; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1665 | RegisterContext *reg_ctx = NULL; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1666 | bool do_deref_pointer = false; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1667 | ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; |
| 1668 | ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1669 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1670 | // Each variable must set success to true below... |
| 1671 | bool var_success = false; |
| 1672 | switch (var_name_begin[0]) |
| 1673 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1674 | case '*': |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1675 | case 'v': |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1676 | case 's': |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1677 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1678 | if (!valobj) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1681 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1682 | log->Printf("[Debugger::FormatPrompt] initial string: %s",var_name_begin); |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1683 | |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1684 | // check for *var and *svar |
| 1685 | if (*var_name_begin == '*') |
| 1686 | { |
| 1687 | do_deref_pointer = true; |
| 1688 | var_name_begin++; |
Enrico Granata | 68ae411 | 2013-06-18 18:23:07 +0000 | [diff] [blame] | 1689 | if (log) |
| 1690 | 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] | 1691 | } |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1692 | |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1693 | if (*var_name_begin == 's') |
| 1694 | { |
Enrico Granata | c5bc412 | 2012-03-27 02:35:13 +0000 | [diff] [blame] | 1695 | if (!valobj->IsSynthetic()) |
| 1696 | valobj = valobj->GetSyntheticValue().get(); |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1697 | if (!valobj) |
| 1698 | break; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1699 | var_name_begin++; |
Enrico Granata | 68ae411 | 2013-06-18 18:23:07 +0000 | [diff] [blame] | 1700 | if (log) |
| 1701 | 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] | 1702 | } |
| 1703 | |
| 1704 | // should be a 'v' by now |
| 1705 | if (*var_name_begin != 'v') |
| 1706 | break; |
| 1707 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1708 | if (log) |
Enrico Granata | 68ae411 | 2013-06-18 18:23:07 +0000 | [diff] [blame] | 1709 | 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] | 1710 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1711 | ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ? |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1712 | ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1713 | ValueObject::GetValueForExpressionPathOptions options; |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 1714 | options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren(); |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1715 | ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1716 | ValueObject* target = NULL; |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1717 | Format custom_format = eFormatInvalid; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1718 | const char* var_name_final = NULL; |
| 1719 | const char* var_name_final_if_array_range = NULL; |
| 1720 | const char* close_bracket_position = NULL; |
| 1721 | int64_t index_lower = -1; |
| 1722 | int64_t index_higher = -1; |
| 1723 | bool is_array_range = false; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1724 | const char* first_unparsed; |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1725 | bool was_plain_var = false; |
| 1726 | bool was_var_format = false; |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 1727 | bool was_var_indexed = false; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1728 | |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1729 | if (!valobj) break; |
| 1730 | // simplest case ${var}, just print valobj's value |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 1731 | if (IsToken (var_name_begin, "var}")) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1732 | { |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1733 | was_plain_var = true; |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1734 | target = valobj; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1735 | val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1736 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 1737 | else if (IsToken (var_name_begin,"var%")) |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1738 | { |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1739 | was_var_format = true; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1740 | // this is a variable with some custom format applied to it |
| 1741 | const char* percent_position; |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1742 | target = valobj; |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1743 | val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1744 | ScanFormatDescriptor (var_name_begin, |
| 1745 | var_name_end, |
| 1746 | &var_name_final, |
| 1747 | &percent_position, |
| 1748 | &custom_format, |
| 1749 | &val_obj_display); |
| 1750 | } |
| 1751 | // this is ${var.something} or multiple .something nested |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 1752 | else if (IsToken (var_name_begin, "var")) |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1753 | { |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 1754 | if (IsToken (var_name_begin, "var[")) |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 1755 | was_var_indexed = true; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1756 | const char* percent_position; |
| 1757 | ScanFormatDescriptor (var_name_begin, |
| 1758 | var_name_end, |
| 1759 | &var_name_final, |
| 1760 | &percent_position, |
| 1761 | &custom_format, |
| 1762 | &val_obj_display); |
| 1763 | |
| 1764 | const char* open_bracket_position; |
| 1765 | const char* separator_position; |
| 1766 | ScanBracketedRange (var_name_begin, |
| 1767 | var_name_end, |
| 1768 | var_name_final, |
| 1769 | &open_bracket_position, |
| 1770 | &separator_position, |
| 1771 | &close_bracket_position, |
| 1772 | &var_name_final_if_array_range, |
| 1773 | &index_lower, |
| 1774 | &index_higher); |
| 1775 | |
| 1776 | Error error; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1777 | |
Enrico Granata | 599171a | 2013-02-01 23:59:44 +0000 | [diff] [blame] | 1778 | std::string expr_path(var_name_final-var_name_begin-1,0); |
| 1779 | memcpy(&expr_path[0], var_name_begin+3,var_name_final-var_name_begin-3); |
| 1780 | |
| 1781 | if (log) |
| 1782 | log->Printf("[Debugger::FormatPrompt] symbol to expand: %s",expr_path.c_str()); |
| 1783 | |
| 1784 | target = valobj->GetValueForExpressionPath(expr_path.c_str(), |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1785 | &first_unparsed, |
| 1786 | &reason_to_stop, |
| 1787 | &final_value_type, |
| 1788 | options, |
| 1789 | &what_next).get(); |
| 1790 | |
| 1791 | if (!target) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1792 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1793 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1794 | log->Printf("[Debugger::FormatPrompt] ERROR: unparsed portion = %s, why stopping = %d," |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1795 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1796 | first_unparsed, reason_to_stop, final_value_type); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1797 | break; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1798 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1799 | else |
| 1800 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1801 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1802 | log->Printf("[Debugger::FormatPrompt] ALL RIGHT: unparsed portion = %s, why stopping = %d," |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1803 | " final_value_type %d", |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1804 | first_unparsed, reason_to_stop, final_value_type); |
| 1805 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1806 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1807 | else |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1808 | break; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1809 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1810 | is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange || |
| 1811 | final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1812 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1813 | do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1814 | |
Enrico Granata | a7187d0 | 2011-07-06 19:27:11 +0000 | [diff] [blame] | 1815 | if (do_deref_pointer && !is_array_range) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1816 | { |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1817 | // I have not deref-ed yet, let's do it |
| 1818 | // this happens when we are not going through GetValueForVariableExpressionPath |
| 1819 | // to get to the target ValueObject |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1820 | Error error; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1821 | target = target->Dereference(error).get(); |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1822 | if (error.Fail()) |
| 1823 | { |
| 1824 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1825 | log->Printf("[Debugger::FormatPrompt] ERROR: %s\n", error.AsCString("unknown")); \ |
Enrico Granata | dc94073 | 2011-08-23 00:32:52 +0000 | [diff] [blame] | 1826 | break; |
| 1827 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1828 | do_deref_pointer = false; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1829 | } |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1830 | |
Jim Ingham | f164d94 | 2014-03-11 18:17:23 +0000 | [diff] [blame] | 1831 | if (!target) |
| 1832 | { |
| 1833 | if (log) |
| 1834 | log->Printf("[Debugger::FormatPrompt] could not calculate target for prompt expression"); |
| 1835 | break; |
| 1836 | } |
| 1837 | |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 1838 | // we do not want to use the summary for a bitfield of type T:n |
| 1839 | // if we were originally dealing with just a T - that would get |
| 1840 | // us into an endless recursion |
| 1841 | if (target->IsBitfield() && was_var_indexed) |
| 1842 | { |
| 1843 | // TODO: check for a (T:n)-specific summary - we should still obey that |
| 1844 | StreamString bitfield_name; |
| 1845 | bitfield_name.Printf("%s:%d", target->GetTypeName().AsCString(), target->GetBitfieldBitSize()); |
| 1846 | lldb::TypeNameSpecifierImplSP type_sp(new TypeNameSpecifierImpl(bitfield_name.GetData(),false)); |
| 1847 | if (!DataVisualization::GetSummaryForType(type_sp)) |
| 1848 | val_obj_display = ValueObject::eValueObjectRepresentationStyleValue; |
| 1849 | } |
| 1850 | |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1851 | // TODO use flags for these |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1852 | const uint32_t type_info_flags = target->GetClangType().GetTypeInfo(NULL); |
| 1853 | bool is_array = (type_info_flags & ClangASTType::eTypeIsArray) != 0; |
| 1854 | bool is_pointer = (type_info_flags & ClangASTType::eTypeIsPointer) != 0; |
| 1855 | bool is_aggregate = target->GetClangType().IsAggregateType(); |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1856 | |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1857 | 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] | 1858 | { |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1859 | StreamString str_temp; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1860 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1861 | log->Printf("[Debugger::FormatPrompt] I am into array || pointer && !range"); |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1862 | |
Greg Clayton | 5088c48 | 2013-03-25 21:06:13 +0000 | [diff] [blame] | 1863 | if (target->HasSpecialPrintableRepresentation(val_obj_display, custom_format)) |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1864 | { |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1865 | // try to use the special cases |
| 1866 | var_success = target->DumpPrintableRepresentation(str_temp, |
| 1867 | val_obj_display, |
| 1868 | custom_format); |
| 1869 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1870 | 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] | 1871 | |
| 1872 | // should not happen |
Greg Clayton | 5088c48 | 2013-03-25 21:06:13 +0000 | [diff] [blame] | 1873 | if (var_success) |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1874 | s << str_temp.GetData(); |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1875 | var_success = true; |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1876 | break; |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1877 | } |
| 1878 | else |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1879 | { |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1880 | if (was_plain_var) // if ${var} |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1881 | { |
| 1882 | s << target->GetTypeName() << " @ " << target->GetLocationAsCString(); |
| 1883 | } |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1884 | else if (is_pointer) // if pointer, value is the address stored |
| 1885 | { |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 1886 | target->DumpPrintableRepresentation (s, |
| 1887 | val_obj_display, |
| 1888 | custom_format, |
| 1889 | ValueObject::ePrintableRepresentationSpecialCasesDisable); |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1890 | } |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1891 | var_success = true; |
| 1892 | break; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | // if directly trying to print ${var}, and this is an aggregate, display a nice |
| 1897 | // type @ location message |
| 1898 | if (is_aggregate && was_plain_var) |
| 1899 | { |
| 1900 | s << target->GetTypeName() << " @ " << target->GetLocationAsCString(); |
| 1901 | var_success = true; |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1902 | break; |
| 1903 | } |
| 1904 | |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1905 | // 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] | 1906 | if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue))) |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1907 | { |
| 1908 | s << "<invalid use of aggregate type>"; |
| 1909 | var_success = true; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1910 | break; |
| 1911 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1912 | |
| 1913 | if (!is_array_range) |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1914 | { |
| 1915 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1916 | log->Printf("[Debugger::FormatPrompt] dumping ordinary printable output"); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1917 | var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format); |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1918 | } |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1919 | else |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1920 | { |
| 1921 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1922 | log->Printf("[Debugger::FormatPrompt] checking if I can handle as array"); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1923 | if (!is_array && !is_pointer) |
| 1924 | break; |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1925 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1926 | log->Printf("[Debugger::FormatPrompt] handle as array"); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1927 | const char* special_directions = NULL; |
| 1928 | StreamString special_directions_writer; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1929 | if (close_bracket_position && (var_name_end-close_bracket_position > 1)) |
| 1930 | { |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1931 | ConstString additional_data; |
| 1932 | additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1); |
| 1933 | special_directions_writer.Printf("${%svar%s}", |
| 1934 | do_deref_pointer ? "*" : "", |
| 1935 | additional_data.GetCString()); |
| 1936 | special_directions = special_directions_writer.GetData(); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | // let us display items index_lower thru index_higher of this array |
| 1940 | s.PutChar('['); |
| 1941 | var_success = true; |
| 1942 | |
| 1943 | if (index_higher < 0) |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 1944 | index_higher = valobj->GetNumChildren() - 1; |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1945 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1946 | uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 1947 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1948 | for (;index_lower<=index_higher;index_lower++) |
| 1949 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1950 | ValueObject* item = ExpandIndexedExpression (target, |
| 1951 | index_lower, |
| 1952 | exe_ctx->GetFramePtr(), |
| 1953 | false).get(); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1954 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1955 | if (!item) |
| 1956 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1957 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1958 | 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] | 1959 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1960 | else |
| 1961 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1962 | if (log) |
Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 1963 | log->Printf("[Debugger::FormatPrompt] special_directions for child item: %s",special_directions); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1964 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1965 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1966 | if (!special_directions) |
| 1967 | var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format); |
| 1968 | else |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1969 | var_success &= FormatPromptRecurse(special_directions, sc, exe_ctx, addr, s, NULL, item, function_changed, initial_function); |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1970 | |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 1971 | if (--max_num_children == 0) |
| 1972 | { |
| 1973 | s.PutCString(", ..."); |
| 1974 | break; |
| 1975 | } |
| 1976 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 1977 | if (index_lower < index_higher) |
| 1978 | s.PutChar(','); |
| 1979 | } |
| 1980 | s.PutChar(']'); |
| 1981 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1982 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1983 | break; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1984 | case 'a': |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1985 | if (IsToken (var_name_begin, "addr-file-or-load}")) |
| 1986 | { |
| 1987 | print_file_addr_or_load_addr = true; |
| 1988 | } |
| 1989 | if (IsToken (var_name_begin, "addr}") |
| 1990 | || IsToken (var_name_begin, "addr-file-or-load}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1991 | { |
| 1992 | if (addr && addr->IsValid()) |
| 1993 | { |
| 1994 | var_success = true; |
| 1995 | format_addr = *addr; |
| 1996 | } |
| 1997 | } |
| 1998 | break; |
| 1999 | |
| 2000 | case 'p': |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2001 | if (IsToken (var_name_begin, "process.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2002 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2003 | if (exe_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2004 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2005 | Process *process = exe_ctx->GetProcessPtr(); |
| 2006 | if (process) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2007 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2008 | var_name_begin += ::strlen ("process."); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2009 | if (IsTokenWithFormat (var_name_begin, "id", token_format, "%" PRIu64, exe_ctx, sc)) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2010 | { |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2011 | s.Printf(token_format.c_str(), process->GetID()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2012 | var_success = true; |
| 2013 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2014 | else if ((IsToken (var_name_begin, "name}")) || |
| 2015 | (IsToken (var_name_begin, "file.basename}")) || |
| 2016 | (IsToken (var_name_begin, "file.fullpath}"))) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2017 | { |
| 2018 | Module *exe_module = process->GetTarget().GetExecutableModulePointer(); |
| 2019 | if (exe_module) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2020 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2021 | if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f') |
| 2022 | { |
| 2023 | format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename(); |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2024 | var_success = (bool)format_file_spec; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2025 | } |
| 2026 | else |
| 2027 | { |
| 2028 | format_file_spec = exe_module->GetFileSpec(); |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2029 | var_success = (bool)format_file_spec; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2030 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2031 | } |
| 2032 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2033 | else if (IsToken (var_name_begin, "script:")) |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2034 | { |
| 2035 | var_name_begin += ::strlen("script:"); |
| 2036 | std::string script_name(var_name_begin,var_name_end); |
| 2037 | ScriptInterpreter* script_interpreter = process->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2038 | if (RunScriptFormatKeyword (s, script_interpreter, process, script_name)) |
| 2039 | var_success = true; |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2040 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2041 | } |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2042 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2043 | } |
| 2044 | break; |
| 2045 | |
| 2046 | case 't': |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2047 | if (IsToken (var_name_begin, "thread.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2048 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2049 | if (exe_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2050 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2051 | Thread *thread = exe_ctx->GetThreadPtr(); |
| 2052 | if (thread) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2053 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2054 | var_name_begin += ::strlen ("thread."); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2055 | if (IsTokenWithFormat (var_name_begin, "id", token_format, "0x%4.4" PRIx64, exe_ctx, sc)) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2056 | { |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2057 | s.Printf(token_format.c_str(), thread->GetID()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2058 | var_success = true; |
| 2059 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2060 | else if (IsTokenWithFormat (var_name_begin, "protocol_id", token_format, "0x%4.4" PRIx64, exe_ctx, sc)) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 2061 | { |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2062 | s.Printf(token_format.c_str(), thread->GetProtocolID()); |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 2063 | var_success = true; |
| 2064 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2065 | else if (IsTokenWithFormat (var_name_begin, "index", token_format, "%" PRIu64, exe_ctx, sc)) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2066 | { |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2067 | s.Printf(token_format.c_str(), (uint64_t)thread->GetIndexID()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2068 | var_success = true; |
| 2069 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2070 | else if (IsToken (var_name_begin, "name}")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2071 | { |
| 2072 | cstr = thread->GetName(); |
| 2073 | var_success = cstr && cstr[0]; |
| 2074 | if (var_success) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2075 | s.PutCString(cstr); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2076 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2077 | else if (IsToken (var_name_begin, "queue}")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2078 | { |
| 2079 | cstr = thread->GetQueueName(); |
| 2080 | var_success = cstr && cstr[0]; |
| 2081 | if (var_success) |
| 2082 | s.PutCString(cstr); |
| 2083 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2084 | else if (IsToken (var_name_begin, "stop-reason}")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2085 | { |
| 2086 | StopInfoSP stop_info_sp = thread->GetStopInfo (); |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 2087 | if (stop_info_sp && stop_info_sp->IsValid()) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2088 | { |
| 2089 | cstr = stop_info_sp->GetDescription(); |
| 2090 | if (cstr && cstr[0]) |
| 2091 | { |
| 2092 | s.PutCString(cstr); |
| 2093 | var_success = true; |
| 2094 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2095 | } |
| 2096 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2097 | else if (IsToken (var_name_begin, "return-value}")) |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 2098 | { |
| 2099 | StopInfoSP stop_info_sp = thread->GetStopInfo (); |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 2100 | if (stop_info_sp && stop_info_sp->IsValid()) |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 2101 | { |
| 2102 | ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp); |
| 2103 | if (return_valobj_sp) |
| 2104 | { |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 2105 | return_valobj_sp->Dump(s); |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 2106 | var_success = true; |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 2107 | } |
| 2108 | } |
| 2109 | } |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 2110 | else if (IsToken (var_name_begin, "completed-expression}")) |
| 2111 | { |
| 2112 | StopInfoSP stop_info_sp = thread->GetStopInfo (); |
| 2113 | if (stop_info_sp && stop_info_sp->IsValid()) |
| 2114 | { |
| 2115 | ClangExpressionVariableSP expression_var_sp = StopInfo::GetExpressionVariable (stop_info_sp); |
| 2116 | if (expression_var_sp && expression_var_sp->GetValueObject()) |
| 2117 | { |
| 2118 | expression_var_sp->GetValueObject()->Dump(s); |
| 2119 | var_success = true; |
| 2120 | } |
| 2121 | } |
| 2122 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2123 | else if (IsToken (var_name_begin, "script:")) |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2124 | { |
| 2125 | var_name_begin += ::strlen("script:"); |
| 2126 | std::string script_name(var_name_begin,var_name_end); |
| 2127 | ScriptInterpreter* script_interpreter = thread->GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2128 | if (RunScriptFormatKeyword (s, script_interpreter, thread, script_name)) |
| 2129 | var_success = true; |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2130 | } |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 2131 | else if (IsToken (var_name_begin, "info.")) |
| 2132 | { |
| 2133 | var_name_begin += ::strlen("info."); |
| 2134 | StructuredData::ObjectSP object_sp = thread->GetExtendedInfo(); |
| 2135 | if (object_sp && object_sp->GetType() == StructuredData::Type::eTypeDictionary) |
| 2136 | { |
| 2137 | var_success = FormatThreadExtendedInfoRecurse (var_name_begin, object_sp, sc, exe_ctx, s); |
| 2138 | } |
| 2139 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2140 | } |
| 2141 | } |
| 2142 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2143 | else if (IsToken (var_name_begin, "target.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2144 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2145 | // TODO: hookup properties |
| 2146 | // if (!target_properties_sp) |
| 2147 | // { |
| 2148 | // Target *target = Target::GetTargetFromContexts (exe_ctx, sc); |
| 2149 | // if (target) |
| 2150 | // target_properties_sp = target->GetProperties(); |
| 2151 | // } |
| 2152 | // |
| 2153 | // if (target_properties_sp) |
| 2154 | // { |
| 2155 | // var_name_begin += ::strlen ("target."); |
| 2156 | // const char *end_property = strchr(var_name_begin, '}'); |
| 2157 | // if (end_property) |
| 2158 | // { |
| 2159 | // ConstString property_name(var_name_begin, end_property - var_name_begin); |
| 2160 | // std::string property_value (target_properties_sp->GetPropertyValue(property_name)); |
| 2161 | // if (!property_value.empty()) |
| 2162 | // { |
| 2163 | // s.PutCString (property_value.c_str()); |
| 2164 | // var_success = true; |
| 2165 | // } |
| 2166 | // } |
| 2167 | // } |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2168 | Target *target = Target::GetTargetFromContexts (exe_ctx, sc); |
| 2169 | if (target) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2170 | { |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2171 | var_name_begin += ::strlen ("target."); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2172 | if (IsToken (var_name_begin, "arch}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2173 | { |
| 2174 | ArchSpec arch (target->GetArchitecture ()); |
| 2175 | if (arch.IsValid()) |
| 2176 | { |
Greg Clayton | 64195a2 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 2177 | s.PutCString (arch.GetArchitectureName()); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2178 | var_success = true; |
| 2179 | } |
| 2180 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2181 | else if (IsToken (var_name_begin, "script:")) |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2182 | { |
| 2183 | var_name_begin += ::strlen("script:"); |
| 2184 | std::string script_name(var_name_begin,var_name_end); |
| 2185 | ScriptInterpreter* script_interpreter = target->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2186 | if (RunScriptFormatKeyword (s, script_interpreter, target, script_name)) |
| 2187 | var_success = true; |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2188 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 2189 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2190 | } |
| 2191 | break; |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2192 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2193 | case 'm': |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2194 | if (IsToken (var_name_begin, "module.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2195 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2196 | if (sc && sc->module_sp.get()) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2197 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2198 | Module *module = sc->module_sp.get(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2199 | var_name_begin += ::strlen ("module."); |
| 2200 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2201 | if (IsToken (var_name_begin, "file.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2202 | { |
| 2203 | if (module->GetFileSpec()) |
| 2204 | { |
| 2205 | var_name_begin += ::strlen ("file."); |
| 2206 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2207 | if (IsToken (var_name_begin, "basename}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2208 | { |
| 2209 | format_file_spec.GetFilename() = module->GetFileSpec().GetFilename(); |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2210 | var_success = (bool)format_file_spec; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2211 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2212 | else if (IsToken (var_name_begin, "fullpath}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2213 | { |
| 2214 | format_file_spec = module->GetFileSpec(); |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2215 | var_success = (bool)format_file_spec; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2216 | } |
| 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | break; |
| 2222 | |
| 2223 | |
| 2224 | case 'f': |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2225 | if (IsToken (var_name_begin, "file.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2226 | { |
| 2227 | if (sc && sc->comp_unit != NULL) |
| 2228 | { |
| 2229 | var_name_begin += ::strlen ("file."); |
| 2230 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2231 | if (IsToken (var_name_begin, "basename}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2232 | { |
| 2233 | format_file_spec.GetFilename() = sc->comp_unit->GetFilename(); |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2234 | var_success = (bool)format_file_spec; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2235 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2236 | else if (IsToken (var_name_begin, "fullpath}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2237 | { |
| 2238 | format_file_spec = *sc->comp_unit; |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2239 | var_success = (bool)format_file_spec; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2243 | else if (IsToken (var_name_begin, "frame.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2244 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2245 | if (exe_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2246 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2247 | StackFrame *frame = exe_ctx->GetFramePtr(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2248 | if (frame) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2249 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2250 | var_name_begin += ::strlen ("frame."); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2251 | if (IsToken (var_name_begin, "index}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2252 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2253 | s.Printf("%u", frame->GetFrameIndex()); |
| 2254 | var_success = true; |
| 2255 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2256 | else if (IsToken (var_name_begin, "pc}")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2257 | { |
| 2258 | reg_kind = eRegisterKindGeneric; |
| 2259 | reg_num = LLDB_REGNUM_GENERIC_PC; |
| 2260 | var_success = true; |
| 2261 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2262 | else if (IsToken (var_name_begin, "sp}")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2263 | { |
| 2264 | reg_kind = eRegisterKindGeneric; |
| 2265 | reg_num = LLDB_REGNUM_GENERIC_SP; |
| 2266 | var_success = true; |
| 2267 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2268 | else if (IsToken (var_name_begin, "fp}")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2269 | { |
| 2270 | reg_kind = eRegisterKindGeneric; |
| 2271 | reg_num = LLDB_REGNUM_GENERIC_FP; |
| 2272 | var_success = true; |
| 2273 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2274 | else if (IsToken (var_name_begin, "flags}")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2275 | { |
| 2276 | reg_kind = eRegisterKindGeneric; |
| 2277 | reg_num = LLDB_REGNUM_GENERIC_FLAGS; |
| 2278 | var_success = true; |
| 2279 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2280 | else if (IsToken (var_name_begin, "reg.")) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2281 | { |
| 2282 | reg_ctx = frame->GetRegisterContext().get(); |
| 2283 | if (reg_ctx) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2284 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2285 | var_name_begin += ::strlen ("reg."); |
| 2286 | if (var_name_begin < var_name_end) |
| 2287 | { |
| 2288 | std::string reg_name (var_name_begin, var_name_end); |
| 2289 | reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str()); |
| 2290 | if (reg_info) |
| 2291 | var_success = true; |
| 2292 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2293 | } |
| 2294 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2295 | else if (IsToken (var_name_begin, "script:")) |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2296 | { |
| 2297 | var_name_begin += ::strlen("script:"); |
| 2298 | std::string script_name(var_name_begin,var_name_end); |
| 2299 | ScriptInterpreter* script_interpreter = frame->GetThread()->GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2300 | if (RunScriptFormatKeyword (s, script_interpreter, frame, script_name)) |
| 2301 | var_success = true; |
Enrico Granata | aad8e48 | 2013-06-20 23:40:21 +0000 | [diff] [blame] | 2302 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2306 | else if (IsToken (var_name_begin, "function.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2307 | { |
| 2308 | if (sc && (sc->function != NULL || sc->symbol != NULL)) |
| 2309 | { |
| 2310 | var_name_begin += ::strlen ("function."); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2311 | if (IsToken (var_name_begin, "id}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2312 | { |
| 2313 | if (sc->function) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2314 | s.Printf("function{0x%8.8" PRIx64 "}", sc->function->GetID()); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2315 | else |
| 2316 | s.Printf("symbol[%u]", sc->symbol->GetID()); |
| 2317 | |
| 2318 | var_success = true; |
| 2319 | } |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2320 | if (IsToken (var_name_begin, "changed}") && function_changed) |
| 2321 | { |
| 2322 | var_success = true; |
| 2323 | } |
| 2324 | if (IsToken (var_name_begin, "initial-function}") && initial_function) |
| 2325 | { |
| 2326 | var_success = true; |
| 2327 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2328 | else if (IsToken (var_name_begin, "name}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2329 | { |
| 2330 | if (sc->function) |
| 2331 | cstr = sc->function->GetName().AsCString (NULL); |
| 2332 | else if (sc->symbol) |
| 2333 | cstr = sc->symbol->GetName().AsCString (NULL); |
| 2334 | if (cstr) |
| 2335 | { |
| 2336 | s.PutCString(cstr); |
Greg Clayton | 0d9c993 | 2010-10-04 17:26:49 +0000 | [diff] [blame] | 2337 | |
| 2338 | if (sc->block) |
| 2339 | { |
| 2340 | Block *inline_block = sc->block->GetContainingInlinedBlock (); |
| 2341 | if (inline_block) |
| 2342 | { |
| 2343 | const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo(); |
| 2344 | if (inline_info) |
| 2345 | { |
| 2346 | s.PutCString(" [inlined] "); |
| 2347 | inline_info->GetName().Dump(&s); |
| 2348 | } |
| 2349 | } |
| 2350 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2351 | var_success = true; |
| 2352 | } |
| 2353 | } |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2354 | else if (IsToken (var_name_begin, "name-without-args}")) |
| 2355 | { |
| 2356 | ConstString name; |
| 2357 | if (sc->function) |
| 2358 | name = sc->function->GetMangled().GetName (Mangled::ePreferDemangledWithoutArguments); |
| 2359 | else if (sc->symbol) |
| 2360 | name = sc->symbol->GetMangled().GetName (Mangled::ePreferDemangledWithoutArguments); |
| 2361 | if (name) |
| 2362 | { |
| 2363 | s.PutCString(name.GetCString()); |
| 2364 | var_success = true; |
| 2365 | } |
| 2366 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2367 | else if (IsToken (var_name_begin, "name-with-args}")) |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2368 | { |
| 2369 | // Print the function name with arguments in it |
| 2370 | |
| 2371 | if (sc->function) |
| 2372 | { |
| 2373 | var_success = true; |
| 2374 | ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL; |
| 2375 | cstr = sc->function->GetName().AsCString (NULL); |
| 2376 | if (cstr) |
| 2377 | { |
| 2378 | const InlineFunctionInfo *inline_info = NULL; |
| 2379 | VariableListSP variable_list_sp; |
| 2380 | bool get_function_vars = true; |
| 2381 | if (sc->block) |
| 2382 | { |
| 2383 | Block *inline_block = sc->block->GetContainingInlinedBlock (); |
| 2384 | |
| 2385 | if (inline_block) |
| 2386 | { |
| 2387 | get_function_vars = false; |
| 2388 | inline_info = sc->block->GetInlinedFunctionInfo(); |
| 2389 | if (inline_info) |
| 2390 | variable_list_sp = inline_block->GetBlockVariableList (true); |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | if (get_function_vars) |
| 2395 | { |
| 2396 | variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true); |
| 2397 | } |
| 2398 | |
| 2399 | if (inline_info) |
| 2400 | { |
| 2401 | s.PutCString (cstr); |
| 2402 | s.PutCString (" [inlined] "); |
| 2403 | cstr = inline_info->GetName().GetCString(); |
| 2404 | } |
| 2405 | |
| 2406 | VariableList args; |
| 2407 | if (variable_list_sp) |
Enrico Granata | cc7f9bf | 2013-05-08 20:27:37 +0000 | [diff] [blame] | 2408 | variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument, args); |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2409 | if (args.GetSize() > 0) |
| 2410 | { |
| 2411 | const char *open_paren = strchr (cstr, '('); |
Enrico Granata | e4a4f5d | 2014-08-16 00:56:04 +0000 | [diff] [blame] | 2412 | const char *close_paren = nullptr; |
| 2413 | const char *generic = strchr(cstr, '<'); |
| 2414 | // if before the arguments list begins there is a template sign |
| 2415 | // then scan to the end of the generic args before you try to find |
| 2416 | // the arguments list |
| 2417 | if (generic && open_paren && generic < open_paren) |
| 2418 | { |
| 2419 | int generic_depth = 1; |
| 2420 | ++generic; |
| 2421 | for (; |
| 2422 | *generic && generic_depth > 0; |
| 2423 | generic++) |
| 2424 | { |
| 2425 | if (*generic == '<') |
| 2426 | generic_depth++; |
| 2427 | if (*generic == '>') |
| 2428 | generic_depth--; |
| 2429 | } |
| 2430 | if (*generic) |
| 2431 | open_paren = strchr(generic, '('); |
| 2432 | else |
| 2433 | open_paren = nullptr; |
| 2434 | } |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2435 | if (open_paren) |
Greg Clayton | 855958c | 2013-03-26 01:45:43 +0000 | [diff] [blame] | 2436 | { |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2437 | if (IsToken (open_paren, "(anonymous namespace)")) |
Greg Clayton | 855958c | 2013-03-26 01:45:43 +0000 | [diff] [blame] | 2438 | { |
| 2439 | open_paren = strchr (open_paren + strlen("(anonymous namespace)"), '('); |
| 2440 | if (open_paren) |
| 2441 | close_paren = strchr (open_paren, ')'); |
| 2442 | } |
| 2443 | else |
| 2444 | close_paren = strchr (open_paren, ')'); |
| 2445 | } |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2446 | |
| 2447 | if (open_paren) |
| 2448 | s.Write(cstr, open_paren - cstr + 1); |
| 2449 | else |
| 2450 | { |
| 2451 | s.PutCString (cstr); |
| 2452 | s.PutChar ('('); |
| 2453 | } |
Greg Clayton | 5b6889b | 2012-01-18 21:56:18 +0000 | [diff] [blame] | 2454 | const size_t num_args = args.GetSize(); |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2455 | for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) |
| 2456 | { |
Enrico Granata | 894f735 | 2014-03-25 22:03:52 +0000 | [diff] [blame] | 2457 | std::string buffer; |
| 2458 | |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2459 | VariableSP var_sp (args.GetVariableAtIndex (arg_idx)); |
| 2460 | ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp)); |
Enrico Granata | 894f735 | 2014-03-25 22:03:52 +0000 | [diff] [blame] | 2461 | const char *var_representation = nullptr; |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2462 | const char *var_name = var_value_sp->GetName().GetCString(); |
Enrico Granata | 894f735 | 2014-03-25 22:03:52 +0000 | [diff] [blame] | 2463 | if (var_value_sp->GetClangType().IsAggregateType() && |
| 2464 | DataVisualization::ShouldPrintAsOneLiner(*var_value_sp.get())) |
| 2465 | { |
| 2466 | static StringSummaryFormat format(TypeSummaryImpl::Flags() |
| 2467 | .SetHideItemNames(false) |
| 2468 | .SetShowMembersOneLiner(true), |
| 2469 | ""); |
| 2470 | format.FormatObject(var_value_sp.get(), buffer); |
| 2471 | var_representation = buffer.c_str(); |
| 2472 | } |
| 2473 | else |
| 2474 | var_representation = var_value_sp->GetValueAsCString(); |
Greg Clayton | 3b188b1 | 2012-12-10 22:26:34 +0000 | [diff] [blame] | 2475 | if (arg_idx > 0) |
| 2476 | s.PutCString (", "); |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2477 | if (var_value_sp->GetError().Success()) |
Enrico Granata | cc7f9bf | 2013-05-08 20:27:37 +0000 | [diff] [blame] | 2478 | { |
Enrico Granata | 894f735 | 2014-03-25 22:03:52 +0000 | [diff] [blame] | 2479 | if (var_representation) |
| 2480 | s.Printf ("%s=%s", var_name, var_representation); |
Enrico Granata | cc7f9bf | 2013-05-08 20:27:37 +0000 | [diff] [blame] | 2481 | else |
| 2482 | s.Printf ("%s=%s at %s", var_name, var_value_sp->GetTypeName().GetCString(), var_value_sp->GetLocationAsCString()); |
| 2483 | } |
Greg Clayton | 3b188b1 | 2012-12-10 22:26:34 +0000 | [diff] [blame] | 2484 | else |
| 2485 | s.Printf ("%s=<unavailable>", var_name); |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | if (close_paren) |
| 2489 | s.PutCString (close_paren); |
| 2490 | else |
| 2491 | s.PutChar(')'); |
| 2492 | |
| 2493 | } |
| 2494 | else |
| 2495 | { |
| 2496 | s.PutCString(cstr); |
| 2497 | } |
| 2498 | } |
| 2499 | } |
| 2500 | else if (sc->symbol) |
| 2501 | { |
| 2502 | cstr = sc->symbol->GetName().AsCString (NULL); |
| 2503 | if (cstr) |
| 2504 | { |
| 2505 | s.PutCString(cstr); |
| 2506 | var_success = true; |
| 2507 | } |
| 2508 | } |
| 2509 | } |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2510 | else if (IsToken (var_name_begin, "addr-offset}") |
| 2511 | || IsToken (var_name_begin, "concrete-only-addr-offset-no-padding}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2512 | { |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2513 | if (IsToken (var_name_begin, "concrete-only-addr-offset-no-padding}")) |
| 2514 | { |
| 2515 | addr_offset_print_with_no_padding = true; |
| 2516 | addr_offset_concrete_func_only = true; |
| 2517 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2518 | var_success = addr != NULL; |
| 2519 | if (var_success) |
| 2520 | { |
| 2521 | format_addr = *addr; |
| 2522 | calculate_format_addr_function_offset = true; |
| 2523 | } |
| 2524 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2525 | else if (IsToken (var_name_begin, "line-offset}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2526 | { |
| 2527 | var_success = sc->line_entry.range.GetBaseAddress().IsValid(); |
| 2528 | if (var_success) |
| 2529 | { |
| 2530 | format_addr = sc->line_entry.range.GetBaseAddress(); |
| 2531 | calculate_format_addr_function_offset = true; |
| 2532 | } |
| 2533 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2534 | else if (IsToken (var_name_begin, "pc-offset}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2535 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2536 | StackFrame *frame = exe_ctx->GetFramePtr(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2537 | var_success = frame != NULL; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2538 | if (var_success) |
| 2539 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2540 | format_addr = frame->GetFrameCodeAddress(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2541 | calculate_format_addr_function_offset = true; |
| 2542 | } |
| 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | break; |
| 2547 | |
| 2548 | case 'l': |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2549 | if (IsToken (var_name_begin, "line.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2550 | { |
| 2551 | if (sc && sc->line_entry.IsValid()) |
| 2552 | { |
| 2553 | var_name_begin += ::strlen ("line."); |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2554 | if (IsToken (var_name_begin, "file.")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2555 | { |
| 2556 | var_name_begin += ::strlen ("file."); |
| 2557 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2558 | if (IsToken (var_name_begin, "basename}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2559 | { |
| 2560 | format_file_spec.GetFilename() = sc->line_entry.file.GetFilename(); |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2561 | var_success = (bool)format_file_spec; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2562 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2563 | else if (IsToken (var_name_begin, "fullpath}")) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2564 | { |
| 2565 | format_file_spec = sc->line_entry.file; |
Sean Callanan | 9076c0f | 2013-10-04 21:35:29 +0000 | [diff] [blame] | 2566 | var_success = (bool)format_file_spec; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2567 | } |
| 2568 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2569 | else if (IsTokenWithFormat (var_name_begin, "number", token_format, "%" PRIu64, exe_ctx, sc)) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2570 | { |
| 2571 | var_success = true; |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2572 | s.Printf(token_format.c_str(), (uint64_t)sc->line_entry.line); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2573 | } |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 2574 | else if ((IsToken (var_name_begin, "start-addr}")) || |
| 2575 | (IsToken (var_name_begin, "end-addr}"))) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2576 | { |
| 2577 | var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid(); |
| 2578 | if (var_success) |
| 2579 | { |
| 2580 | format_addr = sc->line_entry.range.GetBaseAddress(); |
| 2581 | if (var_name_begin[0] == 'e') |
| 2582 | format_addr.Slide (sc->line_entry.range.GetByteSize()); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | } |
| 2587 | break; |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2588 | case 'c': |
| 2589 | if (IsToken (var_name_begin, "current-pc-arrow")) |
| 2590 | { |
| 2591 | if (addr && exe_ctx && exe_ctx->GetFramePtr()) |
| 2592 | { |
| 2593 | RegisterContextSP reg_ctx = exe_ctx->GetFramePtr()->GetRegisterContextSP(); |
| 2594 | if (reg_ctx.get()) |
| 2595 | { |
| 2596 | addr_t pc_loadaddr = reg_ctx->GetPC(); |
| 2597 | if (pc_loadaddr != LLDB_INVALID_ADDRESS) |
| 2598 | { |
| 2599 | Address pc; |
| 2600 | pc.SetLoadAddress (pc_loadaddr, exe_ctx->GetTargetPtr()); |
| 2601 | if (pc == *addr) |
| 2602 | { |
| 2603 | s.Printf ("->"); |
| 2604 | var_success = true; |
| 2605 | } |
| 2606 | else |
| 2607 | { |
| 2608 | s.Printf(" "); |
| 2609 | var_success = true; |
| 2610 | } |
| 2611 | } |
| 2612 | } |
| 2613 | } |
| 2614 | } |
| 2615 | break; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | if (var_success) |
| 2619 | { |
| 2620 | // If format addr is valid, then we need to print an address |
| 2621 | if (reg_num != LLDB_INVALID_REGNUM) |
| 2622 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2623 | StackFrame *frame = exe_ctx->GetFramePtr(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2624 | // We have a register value to display... |
| 2625 | if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric) |
| 2626 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2627 | format_addr = frame->GetFrameCodeAddress(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2628 | } |
| 2629 | else |
| 2630 | { |
| 2631 | if (reg_ctx == NULL) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2632 | reg_ctx = frame->GetRegisterContext().get(); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2633 | |
| 2634 | if (reg_ctx) |
| 2635 | { |
| 2636 | if (reg_kind != kNumRegisterKinds) |
| 2637 | reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num); |
| 2638 | reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num); |
| 2639 | var_success = reg_info != NULL; |
| 2640 | } |
| 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | if (reg_info != NULL) |
| 2645 | { |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 2646 | RegisterValue reg_value; |
| 2647 | var_success = reg_ctx->ReadRegister (reg_info, reg_value); |
| 2648 | if (var_success) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2649 | { |
Greg Clayton | 9a8fa91 | 2011-05-15 04:12:07 +0000 | [diff] [blame] | 2650 | reg_value.Dump(&s, reg_info, false, false, eFormatDefault); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | if (format_file_spec) |
| 2655 | { |
| 2656 | s << format_file_spec; |
| 2657 | } |
| 2658 | |
| 2659 | // If format addr is valid, then we need to print an address |
| 2660 | if (format_addr.IsValid()) |
| 2661 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2662 | var_success = false; |
| 2663 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2664 | if (calculate_format_addr_function_offset) |
| 2665 | { |
| 2666 | Address func_addr; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2667 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2668 | if (sc) |
| 2669 | { |
| 2670 | if (sc->function) |
Greg Clayton | 0d9c993 | 2010-10-04 17:26:49 +0000 | [diff] [blame] | 2671 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2672 | func_addr = sc->function->GetAddressRange().GetBaseAddress(); |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2673 | if (sc->block && addr_offset_concrete_func_only == false) |
Greg Clayton | 0d9c993 | 2010-10-04 17:26:49 +0000 | [diff] [blame] | 2674 | { |
| 2675 | // Check to make sure we aren't in an inline |
| 2676 | // function. If we are, use the inline block |
| 2677 | // range that contains "format_addr" since |
| 2678 | // blocks can be discontiguous. |
| 2679 | Block *inline_block = sc->block->GetContainingInlinedBlock (); |
| 2680 | AddressRange inline_range; |
| 2681 | if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range)) |
| 2682 | func_addr = inline_range.GetBaseAddress(); |
| 2683 | } |
| 2684 | } |
Greg Clayton | e761213 | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 2685 | else if (sc->symbol && sc->symbol->ValueIsAddress()) |
| 2686 | func_addr = sc->symbol->GetAddress(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | if (func_addr.IsValid()) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2690 | { |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2691 | const char *addr_offset_padding = " "; |
| 2692 | if (addr_offset_print_with_no_padding) |
| 2693 | { |
| 2694 | addr_offset_padding = ""; |
| 2695 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2696 | if (func_addr.GetSection() == format_addr.GetSection()) |
| 2697 | { |
| 2698 | addr_t func_file_addr = func_addr.GetFileAddress(); |
| 2699 | addr_t addr_file_addr = format_addr.GetFileAddress(); |
| 2700 | if (addr_file_addr > func_file_addr) |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2701 | s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding, addr_file_addr - func_file_addr); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2702 | else if (addr_file_addr < func_file_addr) |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2703 | s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding, func_file_addr - addr_file_addr); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2704 | var_success = true; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2705 | } |
| 2706 | else |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2707 | { |
| 2708 | Target *target = Target::GetTargetFromContexts (exe_ctx, sc); |
| 2709 | if (target) |
| 2710 | { |
| 2711 | addr_t func_load_addr = func_addr.GetLoadAddress (target); |
| 2712 | addr_t addr_load_addr = format_addr.GetLoadAddress (target); |
| 2713 | if (addr_load_addr > func_load_addr) |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2714 | s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding, addr_load_addr - func_load_addr); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2715 | else if (addr_load_addr < func_load_addr) |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2716 | s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding, func_load_addr - addr_load_addr); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2717 | var_success = true; |
| 2718 | } |
| 2719 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | else |
| 2723 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2724 | Target *target = Target::GetTargetFromContexts (exe_ctx, sc); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2725 | addr_t vaddr = LLDB_INVALID_ADDRESS; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2726 | if (exe_ctx && !target->GetSectionLoadList().IsEmpty()) |
| 2727 | vaddr = format_addr.GetLoadAddress (target); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2728 | if (vaddr == LLDB_INVALID_ADDRESS) |
| 2729 | vaddr = format_addr.GetFileAddress (); |
| 2730 | |
| 2731 | if (vaddr != LLDB_INVALID_ADDRESS) |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2732 | { |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2733 | int addr_width = 0; |
| 2734 | if (exe_ctx && target) |
| 2735 | { |
Eric Christopher | fd1a936 | 2014-10-11 00:04:42 +0000 | [diff] [blame] | 2736 | addr_width = target->GetArchitecture().GetAddressByteSize() * 2; |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2737 | } |
Greg Clayton | 35f1a0d | 2010-11-19 04:16:11 +0000 | [diff] [blame] | 2738 | if (addr_width == 0) |
| 2739 | addr_width = 16; |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2740 | if (print_file_addr_or_load_addr) |
| 2741 | { |
| 2742 | format_addr.Dump (&s, exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, 0); |
| 2743 | } |
| 2744 | else |
| 2745 | { |
| 2746 | s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr); |
| 2747 | } |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2748 | var_success = true; |
| 2749 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | if (var_success == false) |
| 2755 | success = false; |
| 2756 | } |
| 2757 | p = var_name_end; |
| 2758 | } |
| 2759 | else |
| 2760 | break; |
| 2761 | } |
| 2762 | else |
| 2763 | { |
| 2764 | // We got a dollar sign with no '{' after it, it must just be a dollar sign |
| 2765 | s.PutChar(*p); |
| 2766 | } |
| 2767 | } |
| 2768 | else if (*p == '\\') |
| 2769 | { |
| 2770 | ++p; // skip the slash |
| 2771 | switch (*p) |
| 2772 | { |
| 2773 | case 'a': s.PutChar ('\a'); break; |
| 2774 | case 'b': s.PutChar ('\b'); break; |
| 2775 | case 'f': s.PutChar ('\f'); break; |
| 2776 | case 'n': s.PutChar ('\n'); break; |
| 2777 | case 'r': s.PutChar ('\r'); break; |
| 2778 | case 't': s.PutChar ('\t'); break; |
| 2779 | case 'v': s.PutChar ('\v'); break; |
| 2780 | case '\'': s.PutChar ('\''); break; |
| 2781 | case '\\': s.PutChar ('\\'); break; |
| 2782 | case '0': |
| 2783 | // 1 to 3 octal chars |
| 2784 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2785 | // Make a string that can hold onto the initial zero char, |
| 2786 | // up to 3 octal digits, and a terminating NULL. |
| 2787 | char oct_str[5] = { 0, 0, 0, 0, 0 }; |
| 2788 | |
| 2789 | int i; |
| 2790 | for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i) |
| 2791 | oct_str[i] = p[i]; |
| 2792 | |
| 2793 | // We don't want to consume the last octal character since |
| 2794 | // the main for loop will do this for us, so we advance p by |
| 2795 | // one less than i (even if i is zero) |
| 2796 | p += i - 1; |
| 2797 | unsigned long octal_value = ::strtoul (oct_str, NULL, 8); |
| 2798 | if (octal_value <= UINT8_MAX) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2799 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2800 | s.PutChar((char)octal_value); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2801 | } |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2802 | } |
| 2803 | break; |
| 2804 | |
| 2805 | case 'x': |
| 2806 | // hex number in the format |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2807 | if (isxdigit(p[1])) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2808 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2809 | ++p; // Skip the 'x' |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2810 | |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2811 | // Make a string that can hold onto two hex chars plus a |
| 2812 | // NULL terminator |
| 2813 | char hex_str[3] = { 0,0,0 }; |
| 2814 | hex_str[0] = *p; |
| 2815 | if (isxdigit(p[1])) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2816 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2817 | ++p; // Skip the first of the two hex chars |
| 2818 | hex_str[1] = *p; |
| 2819 | } |
| 2820 | |
| 2821 | unsigned long hex_value = strtoul (hex_str, NULL, 16); |
| 2822 | if (hex_value <= UINT8_MAX) |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2823 | s.PutChar ((char)hex_value); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2824 | } |
| 2825 | else |
| 2826 | { |
| 2827 | s.PutChar('x'); |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2828 | } |
| 2829 | break; |
| 2830 | |
| 2831 | default: |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2832 | // Just desensitize any other character by just printing what |
| 2833 | // came after the '\' |
| 2834 | s << *p; |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | |
| 2837 | } |
| 2838 | |
| 2839 | } |
| 2840 | } |
| 2841 | if (end) |
| 2842 | *end = p; |
| 2843 | return success; |
| 2844 | } |
| 2845 | |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 2846 | bool |
| 2847 | Debugger::FormatPrompt |
| 2848 | ( |
| 2849 | const char *format, |
| 2850 | const SymbolContext *sc, |
| 2851 | const ExecutionContext *exe_ctx, |
| 2852 | const Address *addr, |
| 2853 | Stream &s, |
| 2854 | ValueObject* valobj |
| 2855 | ) |
| 2856 | { |
| 2857 | bool use_color = exe_ctx ? exe_ctx->GetTargetRef().GetDebugger().GetUseColor() : true; |
| 2858 | std::string format_str = lldb_utility::ansi::FormatAnsiTerminalCodes (format, use_color); |
| 2859 | if (format_str.length()) |
| 2860 | format = format_str.c_str(); |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2861 | return FormatPromptRecurse (format, sc, exe_ctx, addr, s, NULL, valobj, false, false); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 2864 | bool |
| 2865 | Debugger::FormatDisassemblerAddress (const char *format, |
| 2866 | const SymbolContext *sc, |
| 2867 | const SymbolContext *prev_sc, |
| 2868 | const ExecutionContext *exe_ctx, |
| 2869 | const Address *addr, |
| 2870 | Stream &s) |
| 2871 | { |
| 2872 | if (format == NULL && exe_ctx != NULL && exe_ctx->HasTargetScope()) |
| 2873 | { |
| 2874 | format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat(); |
| 2875 | } |
| 2876 | bool function_changed = false; |
| 2877 | bool initial_function = false; |
| 2878 | if (prev_sc && (prev_sc->function || prev_sc->symbol)) |
| 2879 | { |
| 2880 | if (sc && (sc->function || sc->symbol)) |
| 2881 | { |
| 2882 | if (prev_sc->symbol && sc->symbol) |
| 2883 | { |
| 2884 | if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType())) |
| 2885 | { |
| 2886 | function_changed = true; |
| 2887 | } |
| 2888 | } |
| 2889 | else if (prev_sc->function && sc->function) |
| 2890 | { |
| 2891 | if (prev_sc->function->GetMangled() != sc->function->GetMangled()) |
| 2892 | { |
| 2893 | function_changed = true; |
| 2894 | } |
| 2895 | } |
| 2896 | } |
| 2897 | } |
| 2898 | // The first context on a list of instructions will have a prev_sc that |
| 2899 | // has no Function or Symbol -- if SymbolContext had an IsValid() method, it |
| 2900 | // would return false. But we do get a prev_sc pointer. |
| 2901 | if ((sc && (sc->function || sc->symbol)) |
| 2902 | && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL)) |
| 2903 | { |
| 2904 | initial_function = true; |
| 2905 | } |
| 2906 | return FormatPromptRecurse (format, sc, exe_ctx, addr, s, NULL, NULL, function_changed, initial_function); |
| 2907 | } |
| 2908 | |
| 2909 | |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2910 | void |
| 2911 | Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton) |
| 2912 | { |
Jim Ingham | 4f02b22 | 2012-02-22 22:49:20 +0000 | [diff] [blame] | 2913 | // For simplicity's sake, I am not going to deal with how to close down any |
| 2914 | // open logging streams, I just redirect everything from here on out to the |
| 2915 | // callback. |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2916 | m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton)); |
| 2917 | } |
| 2918 | |
| 2919 | bool |
| 2920 | Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream) |
| 2921 | { |
| 2922 | Log::Callbacks log_callbacks; |
| 2923 | |
| 2924 | StreamSP log_stream_sp; |
Sean Callanan | 9a02851 | 2012-08-09 00:50:26 +0000 | [diff] [blame] | 2925 | if (m_log_callback_stream_sp) |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2926 | { |
| 2927 | log_stream_sp = m_log_callback_stream_sp; |
| 2928 | // For now when using the callback mode you always get thread & timestamp. |
| 2929 | log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME; |
| 2930 | } |
| 2931 | else if (log_file == NULL || *log_file == '\0') |
| 2932 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2933 | log_stream_sp = GetOutputFile(); |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2934 | } |
| 2935 | else |
| 2936 | { |
| 2937 | LogStreamMap::iterator pos = m_log_streams.find(log_file); |
Greg Clayton | c1b2ccf | 2013-01-08 00:01:36 +0000 | [diff] [blame] | 2938 | if (pos != m_log_streams.end()) |
| 2939 | log_stream_sp = pos->second.lock(); |
| 2940 | if (!log_stream_sp) |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2941 | { |
| 2942 | log_stream_sp.reset (new StreamFile (log_file)); |
| 2943 | m_log_streams[log_file] = log_stream_sp; |
| 2944 | } |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2945 | } |
| 2946 | assert (log_stream_sp.get()); |
| 2947 | |
| 2948 | if (log_options == 0) |
| 2949 | log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE; |
| 2950 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 2951 | if (Log::GetLogChannelCallbacks (ConstString(channel), log_callbacks)) |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 2952 | { |
| 2953 | log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream); |
| 2954 | return true; |
| 2955 | } |
| 2956 | else |
| 2957 | { |
| 2958 | LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel)); |
| 2959 | if (log_channel_sp) |
| 2960 | { |
| 2961 | if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories)) |
| 2962 | { |
| 2963 | return true; |
| 2964 | } |
| 2965 | else |
| 2966 | { |
| 2967 | error_stream.Printf ("Invalid log channel '%s'.\n", channel); |
| 2968 | return false; |
| 2969 | } |
| 2970 | } |
| 2971 | else |
| 2972 | { |
| 2973 | error_stream.Printf ("Invalid log channel '%s'.\n", channel); |
| 2974 | return false; |
| 2975 | } |
| 2976 | } |
| 2977 | return false; |
| 2978 | } |
| 2979 | |
Greg Clayton | 9585fbf | 2013-03-19 00:20:55 +0000 | [diff] [blame] | 2980 | SourceManager & |
| 2981 | Debugger::GetSourceManager () |
| 2982 | { |
| 2983 | if (m_source_manager_ap.get() == NULL) |
| 2984 | m_source_manager_ap.reset (new SourceManager (shared_from_this())); |
| 2985 | return *m_source_manager_ap; |
| 2986 | } |
| 2987 | |
| 2988 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2989 | |
| 2990 | // This function handles events that were broadcast by the process. |
| 2991 | void |
| 2992 | Debugger::HandleBreakpointEvent (const EventSP &event_sp) |
| 2993 | { |
| 2994 | using namespace lldb; |
| 2995 | const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp); |
| 2996 | |
| 2997 | // if (event_type & eBreakpointEventTypeAdded |
| 2998 | // || event_type & eBreakpointEventTypeRemoved |
| 2999 | // || event_type & eBreakpointEventTypeEnabled |
| 3000 | // || event_type & eBreakpointEventTypeDisabled |
| 3001 | // || event_type & eBreakpointEventTypeCommandChanged |
| 3002 | // || event_type & eBreakpointEventTypeConditionChanged |
| 3003 | // || event_type & eBreakpointEventTypeIgnoreChanged |
| 3004 | // || event_type & eBreakpointEventTypeLocationsResolved) |
| 3005 | // { |
| 3006 | // // Don't do anything about these events, since the breakpoint commands already echo these actions. |
| 3007 | // } |
| 3008 | // |
| 3009 | if (event_type & eBreakpointEventTypeLocationsAdded) |
| 3010 | { |
| 3011 | uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp); |
| 3012 | if (num_new_locations > 0) |
| 3013 | { |
| 3014 | BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp); |
| 3015 | StreamFileSP output_sp (GetOutputFile()); |
| 3016 | if (output_sp) |
| 3017 | { |
| 3018 | output_sp->Printf("%d location%s added to breakpoint %d\n", |
| 3019 | num_new_locations, |
| 3020 | num_new_locations == 1 ? "" : "s", |
| 3021 | breakpoint->GetID()); |
| 3022 | RefreshTopIOHandler(); |
| 3023 | } |
| 3024 | } |
| 3025 | } |
| 3026 | // else if (event_type & eBreakpointEventTypeLocationsRemoved) |
| 3027 | // { |
| 3028 | // // These locations just get disabled, not sure it is worth spamming folks about this on the command line. |
| 3029 | // } |
| 3030 | // else if (event_type & eBreakpointEventTypeLocationsResolved) |
| 3031 | // { |
| 3032 | // // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy. |
| 3033 | // } |
| 3034 | } |
| 3035 | |
| 3036 | size_t |
| 3037 | Debugger::GetProcessSTDOUT (Process *process, Stream *stream) |
| 3038 | { |
| 3039 | size_t total_bytes = 0; |
| 3040 | if (stream == NULL) |
| 3041 | stream = GetOutputFile().get(); |
| 3042 | |
| 3043 | if (stream) |
| 3044 | { |
| 3045 | // The process has stuff waiting for stdout; get it and write it out to the appropriate place. |
| 3046 | if (process == NULL) |
| 3047 | { |
| 3048 | TargetSP target_sp = GetTargetList().GetSelectedTarget(); |
| 3049 | if (target_sp) |
| 3050 | process = target_sp->GetProcessSP().get(); |
| 3051 | } |
| 3052 | if (process) |
| 3053 | { |
| 3054 | Error error; |
| 3055 | size_t len; |
| 3056 | char stdio_buffer[1024]; |
| 3057 | while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0) |
| 3058 | { |
| 3059 | stream->Write(stdio_buffer, len); |
| 3060 | total_bytes += len; |
| 3061 | } |
| 3062 | } |
| 3063 | stream->Flush(); |
| 3064 | } |
| 3065 | return total_bytes; |
| 3066 | } |
| 3067 | |
| 3068 | size_t |
| 3069 | Debugger::GetProcessSTDERR (Process *process, Stream *stream) |
| 3070 | { |
| 3071 | size_t total_bytes = 0; |
| 3072 | if (stream == NULL) |
| 3073 | stream = GetOutputFile().get(); |
| 3074 | |
| 3075 | if (stream) |
| 3076 | { |
| 3077 | // The process has stuff waiting for stderr; get it and write it out to the appropriate place. |
| 3078 | if (process == NULL) |
| 3079 | { |
| 3080 | TargetSP target_sp = GetTargetList().GetSelectedTarget(); |
| 3081 | if (target_sp) |
| 3082 | process = target_sp->GetProcessSP().get(); |
| 3083 | } |
| 3084 | if (process) |
| 3085 | { |
| 3086 | Error error; |
| 3087 | size_t len; |
| 3088 | char stdio_buffer[1024]; |
| 3089 | while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0) |
| 3090 | { |
| 3091 | stream->Write(stdio_buffer, len); |
| 3092 | total_bytes += len; |
| 3093 | } |
| 3094 | } |
| 3095 | stream->Flush(); |
| 3096 | } |
| 3097 | return total_bytes; |
| 3098 | } |
| 3099 | |
| 3100 | // This function handles events that were broadcast by the process. |
| 3101 | void |
| 3102 | Debugger::HandleProcessEvent (const EventSP &event_sp) |
| 3103 | { |
| 3104 | using namespace lldb; |
| 3105 | const uint32_t event_type = event_sp->GetType(); |
| 3106 | ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get()); |
| 3107 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3108 | StreamString output_stream; |
| 3109 | StreamString error_stream; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3110 | const bool gui_enabled = IsForwardingEvents(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3111 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3112 | if (!gui_enabled) |
| 3113 | { |
| 3114 | bool pop_process_io_handler = false; |
| 3115 | assert (process_sp); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3116 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3117 | if (event_type & Process::eBroadcastBitSTDOUT || event_type & Process::eBroadcastBitStateChanged) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3118 | { |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3119 | GetProcessSTDOUT (process_sp.get(), &output_stream); |
| 3120 | } |
| 3121 | |
| 3122 | if (event_type & Process::eBroadcastBitSTDERR || event_type & Process::eBroadcastBitStateChanged) |
| 3123 | { |
| 3124 | GetProcessSTDERR (process_sp.get(), &error_stream); |
| 3125 | } |
| 3126 | |
| 3127 | if (event_type & Process::eBroadcastBitStateChanged) |
| 3128 | { |
| 3129 | |
| 3130 | // Drain all stout and stderr so we don't see any output come after |
| 3131 | // we print our prompts |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3132 | // Something changed in the process; get the event and report the process's current status and location to |
| 3133 | // the user. |
| 3134 | StateType event_state = Process::ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 3135 | if (event_state == eStateInvalid) |
| 3136 | return; |
| 3137 | |
| 3138 | switch (event_state) |
| 3139 | { |
| 3140 | case eStateInvalid: |
| 3141 | case eStateUnloaded: |
| 3142 | case eStateConnected: |
| 3143 | case eStateAttaching: |
| 3144 | case eStateLaunching: |
| 3145 | case eStateStepping: |
| 3146 | case eStateDetached: |
| 3147 | { |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3148 | output_stream.Printf("Process %" PRIu64 " %s\n", |
| 3149 | process_sp->GetID(), |
| 3150 | StateAsCString (event_state)); |
| 3151 | |
| 3152 | if (event_state == eStateDetached) |
| 3153 | pop_process_io_handler = true; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3154 | } |
| 3155 | break; |
| 3156 | |
| 3157 | case eStateRunning: |
| 3158 | // Don't be chatty when we run... |
| 3159 | break; |
| 3160 | |
| 3161 | case eStateExited: |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3162 | process_sp->GetStatus(output_stream); |
| 3163 | pop_process_io_handler = true; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3164 | break; |
| 3165 | |
| 3166 | case eStateStopped: |
| 3167 | case eStateCrashed: |
| 3168 | case eStateSuspended: |
| 3169 | // Make sure the program hasn't been auto-restarted: |
| 3170 | if (Process::ProcessEventData::GetRestartedFromEvent (event_sp.get())) |
| 3171 | { |
| 3172 | size_t num_reasons = Process::ProcessEventData::GetNumRestartedReasons(event_sp.get()); |
| 3173 | if (num_reasons > 0) |
| 3174 | { |
| 3175 | // FIXME: Do we want to report this, or would that just be annoyingly chatty? |
| 3176 | if (num_reasons == 1) |
| 3177 | { |
| 3178 | const char *reason = Process::ProcessEventData::GetRestartedReasonAtIndex (event_sp.get(), 0); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3179 | output_stream.Printf("Process %" PRIu64 " stopped and restarted: %s\n", |
| 3180 | process_sp->GetID(), |
| 3181 | reason ? reason : "<UNKNOWN REASON>"); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3182 | } |
| 3183 | else |
| 3184 | { |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3185 | output_stream.Printf("Process %" PRIu64 " stopped and restarted, reasons:\n", |
| 3186 | process_sp->GetID()); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3187 | |
| 3188 | |
| 3189 | for (size_t i = 0; i < num_reasons; i++) |
| 3190 | { |
| 3191 | const char *reason = Process::ProcessEventData::GetRestartedReasonAtIndex (event_sp.get(), i); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3192 | output_stream.Printf("\t%s\n", reason ? reason : "<UNKNOWN REASON>"); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3193 | } |
| 3194 | } |
| 3195 | } |
| 3196 | } |
| 3197 | else |
| 3198 | { |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 3199 | // Lock the thread list so it doesn't change on us, this is the scope for the locker: |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3200 | { |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 3201 | ThreadList &thread_list = process_sp->GetThreadList(); |
| 3202 | Mutex::Locker locker (thread_list.GetMutex()); |
| 3203 | |
| 3204 | ThreadSP curr_thread (thread_list.GetSelectedThread()); |
| 3205 | ThreadSP thread; |
| 3206 | StopReason curr_thread_stop_reason = eStopReasonInvalid; |
| 3207 | if (curr_thread) |
| 3208 | curr_thread_stop_reason = curr_thread->GetStopReason(); |
| 3209 | if (!curr_thread || |
| 3210 | !curr_thread->IsValid() || |
| 3211 | curr_thread_stop_reason == eStopReasonInvalid || |
| 3212 | curr_thread_stop_reason == eStopReasonNone) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3213 | { |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 3214 | // Prefer a thread that has just completed its plan over another thread as current thread. |
| 3215 | ThreadSP plan_thread; |
| 3216 | ThreadSP other_thread; |
| 3217 | const size_t num_threads = thread_list.GetSize(); |
| 3218 | size_t i; |
| 3219 | for (i = 0; i < num_threads; ++i) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3220 | { |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 3221 | thread = thread_list.GetThreadAtIndex(i); |
| 3222 | StopReason thread_stop_reason = thread->GetStopReason(); |
| 3223 | switch (thread_stop_reason) |
| 3224 | { |
| 3225 | case eStopReasonInvalid: |
| 3226 | case eStopReasonNone: |
| 3227 | break; |
| 3228 | |
| 3229 | case eStopReasonTrace: |
| 3230 | case eStopReasonBreakpoint: |
| 3231 | case eStopReasonWatchpoint: |
| 3232 | case eStopReasonSignal: |
| 3233 | case eStopReasonException: |
| 3234 | case eStopReasonExec: |
| 3235 | case eStopReasonThreadExiting: |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 3236 | case eStopReasonInstrumentation: |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 3237 | if (!other_thread) |
| 3238 | other_thread = thread; |
| 3239 | break; |
| 3240 | case eStopReasonPlanComplete: |
| 3241 | if (!plan_thread) |
| 3242 | plan_thread = thread; |
| 3243 | break; |
| 3244 | } |
| 3245 | } |
| 3246 | if (plan_thread) |
| 3247 | thread_list.SetSelectedThreadByID (plan_thread->GetID()); |
| 3248 | else if (other_thread) |
| 3249 | thread_list.SetSelectedThreadByID (other_thread->GetID()); |
| 3250 | else |
| 3251 | { |
| 3252 | if (curr_thread && curr_thread->IsValid()) |
| 3253 | thread = curr_thread; |
| 3254 | else |
| 3255 | thread = thread_list.GetThreadAtIndex(0); |
| 3256 | |
| 3257 | if (thread) |
| 3258 | thread_list.SetSelectedThreadByID (thread->GetID()); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3259 | } |
| 3260 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3261 | } |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 3262 | // Drop the ThreadList mutex by here, since GetThreadStatus below might have to run code, |
| 3263 | // e.g. for Data formatters, and if we hold the ThreadList mutex, then the process is going to |
| 3264 | // have a hard time restarting the process. |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3265 | |
| 3266 | if (GetTargetList().GetSelectedTarget().get() == &process_sp->GetTarget()) |
| 3267 | { |
| 3268 | const bool only_threads_with_stop_reason = true; |
| 3269 | const uint32_t start_frame = 0; |
| 3270 | const uint32_t num_frames = 1; |
| 3271 | const uint32_t num_frames_with_source = 1; |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3272 | process_sp->GetStatus(output_stream); |
| 3273 | process_sp->GetThreadStatus (output_stream, |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3274 | only_threads_with_stop_reason, |
| 3275 | start_frame, |
| 3276 | num_frames, |
| 3277 | num_frames_with_source); |
| 3278 | } |
| 3279 | else |
| 3280 | { |
| 3281 | uint32_t target_idx = GetTargetList().GetIndexOfTarget(process_sp->GetTarget().shared_from_this()); |
| 3282 | if (target_idx != UINT32_MAX) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3283 | output_stream.Printf ("Target %d: (", target_idx); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3284 | else |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3285 | output_stream.Printf ("Target <unknown index>: ("); |
| 3286 | process_sp->GetTarget().Dump (&output_stream, eDescriptionLevelBrief); |
| 3287 | output_stream.Printf (") stopped.\n"); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3288 | } |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3289 | |
| 3290 | // Pop the process IO handler |
| 3291 | pop_process_io_handler = true; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3292 | } |
| 3293 | break; |
| 3294 | } |
| 3295 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3296 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3297 | if (output_stream.GetSize() || error_stream.GetSize()) |
| 3298 | { |
| 3299 | StreamFileSP error_stream_sp (GetOutputFile()); |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 3300 | bool top_io_handler_hid = false; |
| 3301 | |
| 3302 | if (process_sp->ProcessIOHandlerIsActive() == false) |
| 3303 | top_io_handler_hid = HideTopIOHandler(); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3304 | |
| 3305 | if (output_stream.GetSize()) |
| 3306 | { |
| 3307 | StreamFileSP output_stream_sp (GetOutputFile()); |
| 3308 | if (output_stream_sp) |
| 3309 | output_stream_sp->Write (output_stream.GetData(), output_stream.GetSize()); |
| 3310 | } |
| 3311 | |
| 3312 | if (error_stream.GetSize()) |
| 3313 | { |
| 3314 | StreamFileSP error_stream_sp (GetErrorFile()); |
| 3315 | if (error_stream_sp) |
| 3316 | error_stream_sp->Write (error_stream.GetData(), error_stream.GetSize()); |
| 3317 | } |
| 3318 | |
| 3319 | if (top_io_handler_hid) |
| 3320 | RefreshTopIOHandler(); |
| 3321 | } |
| 3322 | |
| 3323 | if (pop_process_io_handler) |
| 3324 | process_sp->PopProcessIOHandler(); |
| 3325 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | void |
| 3329 | Debugger::HandleThreadEvent (const EventSP &event_sp) |
| 3330 | { |
| 3331 | // At present the only thread event we handle is the Frame Changed event, |
| 3332 | // and all we do for that is just reprint the thread status for that thread. |
| 3333 | using namespace lldb; |
| 3334 | const uint32_t event_type = event_sp->GetType(); |
| 3335 | if (event_type == Thread::eBroadcastBitStackChanged || |
| 3336 | event_type == Thread::eBroadcastBitThreadSelected ) |
| 3337 | { |
| 3338 | ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get())); |
| 3339 | if (thread_sp) |
| 3340 | { |
| 3341 | HideTopIOHandler(); |
| 3342 | StreamFileSP stream_sp (GetOutputFile()); |
| 3343 | thread_sp->GetStatus(*stream_sp, 0, 1, 1); |
| 3344 | RefreshTopIOHandler(); |
| 3345 | } |
| 3346 | } |
| 3347 | } |
| 3348 | |
| 3349 | bool |
| 3350 | Debugger::IsForwardingEvents () |
| 3351 | { |
| 3352 | return (bool)m_forward_listener_sp; |
| 3353 | } |
| 3354 | |
| 3355 | void |
| 3356 | Debugger::EnableForwardEvents (const ListenerSP &listener_sp) |
| 3357 | { |
| 3358 | m_forward_listener_sp = listener_sp; |
| 3359 | } |
| 3360 | |
| 3361 | void |
| 3362 | Debugger::CancelForwardEvents (const ListenerSP &listener_sp) |
| 3363 | { |
| 3364 | m_forward_listener_sp.reset(); |
| 3365 | } |
| 3366 | |
| 3367 | |
| 3368 | void |
| 3369 | Debugger::DefaultEventHandler() |
| 3370 | { |
| 3371 | Listener& listener(GetListener()); |
| 3372 | ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass()); |
| 3373 | ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass()); |
| 3374 | ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass()); |
| 3375 | BroadcastEventSpec target_event_spec (broadcaster_class_target, |
| 3376 | Target::eBroadcastBitBreakpointChanged); |
| 3377 | |
| 3378 | BroadcastEventSpec process_event_spec (broadcaster_class_process, |
| 3379 | Process::eBroadcastBitStateChanged | |
| 3380 | Process::eBroadcastBitSTDOUT | |
| 3381 | Process::eBroadcastBitSTDERR); |
| 3382 | |
| 3383 | BroadcastEventSpec thread_event_spec (broadcaster_class_thread, |
| 3384 | Thread::eBroadcastBitStackChanged | |
| 3385 | Thread::eBroadcastBitThreadSelected ); |
| 3386 | |
| 3387 | listener.StartListeningForEventSpec (*this, target_event_spec); |
| 3388 | listener.StartListeningForEventSpec (*this, process_event_spec); |
| 3389 | listener.StartListeningForEventSpec (*this, thread_event_spec); |
| 3390 | listener.StartListeningForEvents (m_command_interpreter_ap.get(), |
| 3391 | CommandInterpreter::eBroadcastBitQuitCommandReceived | |
| 3392 | CommandInterpreter::eBroadcastBitAsynchronousOutputData | |
| 3393 | CommandInterpreter::eBroadcastBitAsynchronousErrorData ); |
| 3394 | |
| 3395 | bool done = false; |
| 3396 | while (!done) |
| 3397 | { |
| 3398 | // Mutex::Locker locker; |
| 3399 | // if (locker.TryLock(m_input_reader_stack.GetMutex())) |
| 3400 | // { |
| 3401 | // if (m_input_reader_stack.IsEmpty()) |
| 3402 | // break; |
| 3403 | // } |
| 3404 | // |
| 3405 | EventSP event_sp; |
| 3406 | if (listener.WaitForEvent(NULL, event_sp)) |
| 3407 | { |
| 3408 | if (event_sp) |
| 3409 | { |
| 3410 | Broadcaster *broadcaster = event_sp->GetBroadcaster(); |
| 3411 | if (broadcaster) |
| 3412 | { |
| 3413 | uint32_t event_type = event_sp->GetType(); |
| 3414 | ConstString broadcaster_class (broadcaster->GetBroadcasterClass()); |
| 3415 | if (broadcaster_class == broadcaster_class_process) |
| 3416 | { |
| 3417 | HandleProcessEvent (event_sp); |
| 3418 | } |
| 3419 | else if (broadcaster_class == broadcaster_class_target) |
| 3420 | { |
| 3421 | if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get())) |
| 3422 | { |
| 3423 | HandleBreakpointEvent (event_sp); |
| 3424 | } |
| 3425 | } |
| 3426 | else if (broadcaster_class == broadcaster_class_thread) |
| 3427 | { |
| 3428 | HandleThreadEvent (event_sp); |
| 3429 | } |
| 3430 | else if (broadcaster == m_command_interpreter_ap.get()) |
| 3431 | { |
| 3432 | if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived) |
| 3433 | { |
| 3434 | done = true; |
| 3435 | } |
| 3436 | else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData) |
| 3437 | { |
| 3438 | const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get())); |
| 3439 | if (data && data[0]) |
| 3440 | { |
| 3441 | StreamFileSP error_sp (GetErrorFile()); |
| 3442 | if (error_sp) |
| 3443 | { |
| 3444 | HideTopIOHandler(); |
| 3445 | error_sp->PutCString(data); |
| 3446 | error_sp->Flush(); |
| 3447 | RefreshTopIOHandler(); |
| 3448 | } |
| 3449 | } |
| 3450 | } |
| 3451 | else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData) |
| 3452 | { |
| 3453 | const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get())); |
| 3454 | if (data && data[0]) |
| 3455 | { |
| 3456 | StreamFileSP output_sp (GetOutputFile()); |
| 3457 | if (output_sp) |
| 3458 | { |
| 3459 | HideTopIOHandler(); |
| 3460 | output_sp->PutCString(data); |
| 3461 | output_sp->Flush(); |
| 3462 | RefreshTopIOHandler(); |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | if (m_forward_listener_sp) |
| 3470 | m_forward_listener_sp->AddEvent(event_sp); |
| 3471 | } |
| 3472 | } |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | lldb::thread_result_t |
| 3477 | Debugger::EventHandlerThread (lldb::thread_arg_t arg) |
| 3478 | { |
| 3479 | ((Debugger *)arg)->DefaultEventHandler(); |
| 3480 | return NULL; |
| 3481 | } |
| 3482 | |
| 3483 | bool |
| 3484 | Debugger::StartEventHandlerThread() |
| 3485 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3486 | if (!m_event_handler_thread.IsJoinable()) |
Greg Clayton | 807b6b3 | 2014-10-15 18:03:59 +0000 | [diff] [blame^] | 3487 | { |
| 3488 | m_event_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.event-handler", |
| 3489 | EventHandlerThread, |
| 3490 | this, |
| 3491 | NULL, |
| 3492 | 8*1024*1024); // Use larger 8MB stack for this thread |
| 3493 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3494 | return m_event_handler_thread.IsJoinable(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | void |
| 3498 | Debugger::StopEventHandlerThread() |
| 3499 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3500 | if (m_event_handler_thread.IsJoinable()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3501 | { |
| 3502 | GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3503 | m_event_handler_thread.Join(nullptr); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | |
| 3508 | lldb::thread_result_t |
| 3509 | Debugger::IOHandlerThread (lldb::thread_arg_t arg) |
| 3510 | { |
| 3511 | Debugger *debugger = (Debugger *)arg; |
| 3512 | debugger->ExecuteIOHanders(); |
| 3513 | debugger->StopEventHandlerThread(); |
| 3514 | return NULL; |
| 3515 | } |
| 3516 | |
| 3517 | bool |
| 3518 | Debugger::StartIOHandlerThread() |
| 3519 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3520 | if (!m_io_handler_thread.IsJoinable()) |
Greg Clayton | 807b6b3 | 2014-10-15 18:03:59 +0000 | [diff] [blame^] | 3521 | m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler", |
| 3522 | IOHandlerThread, |
| 3523 | this, |
| 3524 | NULL, |
| 3525 | 8*1024*1024); // Use larger 8MB stack for this thread |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3526 | return m_io_handler_thread.IsJoinable(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | void |
| 3530 | Debugger::StopIOHandlerThread() |
| 3531 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 3532 | if (m_io_handler_thread.IsJoinable()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3533 | { |
| 3534 | if (m_input_file_sp) |
| 3535 | m_input_file_sp->GetFile().Close(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 3536 | m_io_handler_thread.Join(nullptr); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3537 | } |
| 3538 | } |
| 3539 | |
| 3540 | |