Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Debugger.cpp --------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Greg Clayton | 4a33d31 | 2011-06-23 17:59:56 +0000 | [diff] [blame] | 10 | #include "lldb/Core/Debugger.h" |
| 11 | |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 12 | // C Includes |
| 13 | // C++ Includes |
Greg Clayton | 4a33d31 | 2011-06-23 17:59:56 +0000 | [diff] [blame] | 14 | #include <map> |
| 15 | |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 16 | // Other libraries and framework includes |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringRef.h" |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 18 | #include "llvm/Support/DynamicLibrary.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 19 | |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 20 | // Project includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/lldb-private.h" |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 22 | #include "lldb/Core/FormatEntity.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Module.h" |
Jim Ingham | 0d5a2bd | 2015-09-03 01:40:51 +0000 | [diff] [blame] | 24 | #include "lldb/Core/PluginInterface.h" |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 25 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 26 | #include "lldb/Core/RegisterValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/State.h" |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 28 | #include "lldb/Core/StreamAsynchronousIO.h" |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 29 | #include "lldb/Core/StreamCallback.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/StreamFile.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 31 | #include "lldb/Core/StreamString.h" |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 32 | #include "lldb/Core/StructuredData.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Core/Timer.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 34 | #include "lldb/Core/ValueObject.h" |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 35 | #include "lldb/Core/ValueObjectVariable.h" |
Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 36 | #include "lldb/DataFormatters/DataVisualization.h" |
| 37 | #include "lldb/DataFormatters/FormatManager.h" |
Enrico Granata | 894f735 | 2014-03-25 22:03:52 +0000 | [diff] [blame] | 38 | #include "lldb/DataFormatters/TypeSummary.h" |
Sean Callanan | 3e7e915 | 2015-10-20 00:23:46 +0000 | [diff] [blame] | 39 | #include "lldb/Expression/REPL.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 40 | #include "lldb/Host/ConnectionFileDescriptor.h" |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 41 | #include "lldb/Host/HostInfo.h" |
Greg Clayton | a340661 | 2011-02-07 23:24:47 +0000 | [diff] [blame] | 42 | #include "lldb/Host/Terminal.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 43 | #include "lldb/Host/ThreadLauncher.h" |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 44 | #include "lldb/Interpreter/CommandInterpreter.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 45 | #include "lldb/Interpreter/OptionValueProperties.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 46 | #include "lldb/Interpreter/OptionValueSInt64.h" |
| 47 | #include "lldb/Interpreter/OptionValueString.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 48 | #include "lldb/Symbol/CompileUnit.h" |
| 49 | #include "lldb/Symbol/Function.h" |
| 50 | #include "lldb/Symbol/Symbol.h" |
Greg Clayton | 6d3dbf5 | 2012-01-13 08:39:16 +0000 | [diff] [blame] | 51 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "lldb/Target/TargetList.h" |
Sean Callanan | 3e7e915 | 2015-10-20 00:23:46 +0000 | [diff] [blame] | 53 | #include "lldb/Target/Language.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | #include "lldb/Target/Process.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 55 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 56 | #include "lldb/Target/SectionLoadList.h" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 57 | #include "lldb/Target/StopInfo.h" |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 58 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | #include "lldb/Target/Thread.h" |
Greg Clayton | 5a31471 | 2011-10-14 07:41:33 +0000 | [diff] [blame] | 60 | #include "lldb/Utility/AnsiTerminal.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
| 62 | using namespace lldb; |
| 63 | using namespace lldb_private; |
| 64 | |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 65 | static lldb::user_id_t g_unique_id = 1; |
Zachary Turner | 7c2896a | 2014-10-24 22:06:29 +0000 | [diff] [blame] | 66 | static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024; |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 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 | { |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 91 | { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."}, |
| 92 | { Debugger::eStopDisassemblyTypeNoDebugInfo, "no-debuginfo", "Show disassembly when there is no debug information."}, |
| 93 | { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."}, |
| 94 | { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."}, |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 95 | { 0, nullptr, nullptr } |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 98 | OptionEnumValueElement |
| 99 | g_language_enumerators[] = |
| 100 | { |
| 101 | { eScriptLanguageNone, "none", "Disable scripting languages."}, |
| 102 | { eScriptLanguagePython, "python", "Select python as the default scripting language."}, |
| 103 | { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."}, |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 104 | { 0, nullptr, nullptr } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 105 | }; |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 106 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 107 | #define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}" |
| 108 | #define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}" |
Jason Molenda | 6ab659a | 2015-07-29 00:42:47 +0000 | [diff] [blame] | 109 | #define IS_OPTIMIZED "{${function.is-optimized} [opt]}" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 110 | |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 111 | #define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 112 | "{, ${frame.pc}}"\ |
| 113 | MODULE_WITH_FUNC\ |
| 114 | FILE_AND_LINE\ |
Michael Sartain | 0769b2b | 2013-07-30 16:44:36 +0000 | [diff] [blame] | 115 | "{, name = '${thread.name}'}"\ |
| 116 | "{, queue = '${thread.queue}'}"\ |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 117 | "{, activity = '${thread.info.activity.name}'}" \ |
| 118 | "{, ${thread.info.trace_messages} messages}" \ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 119 | "{, stop reason = ${thread.stop-reason}}"\ |
| 120 | "{\\nReturn value: ${thread.return-value}}"\ |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 121 | "{\\nCompleted expression: ${thread.completed-expression}}"\ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 122 | "\\n" |
| 123 | |
| 124 | #define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\ |
| 125 | MODULE_WITH_FUNC\ |
| 126 | FILE_AND_LINE\ |
Jason Molenda | 6ab659a | 2015-07-29 00:42:47 +0000 | [diff] [blame] | 127 | IS_OPTIMIZED\ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 128 | "\\n" |
| 129 | |
Jason Molenda | c980fa9 | 2015-02-13 23:24:21 +0000 | [diff] [blame] | 130 | // Three parts to this disassembly format specification: |
| 131 | // 1. If this is a new function/symbol (no previous symbol/function), print |
| 132 | // dylib`funcname:\n |
| 133 | // 2. If this is a symbol context change (different from previous symbol/function), print |
| 134 | // dylib`funcname:\n |
| 135 | // 3. print |
| 136 | // address <+offset>: |
| 137 | #define DEFAULT_DISASSEMBLY_FORMAT "{${function.initial-function}{${module.file.basename}`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name-without-args}}:\n}{${current-pc-arrow} }${addr-file-or-load}{ <${function.concrete-only-addr-offset-no-padding}>}: " |
| 138 | |
| 139 | // gdb's disassembly format can be emulated with |
| 140 | // ${current-pc-arrow}${addr-file-or-load}{ <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>}: |
| 141 | |
| 142 | // lldb's original format for disassembly would look like this format string - |
| 143 | // {${function.initial-function}{${module.file.basename}`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name-without-args}}:\n}{${current-pc-arrow} }{${addr-file-or-load}}: |
| 144 | |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 145 | static PropertyDefinition |
| 146 | g_properties[] = |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 147 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 148 | { "auto-confirm", OptionValue::eTypeBoolean , true, false, nullptr, nullptr, "If true all confirmation prompts will receive their default reply." }, |
| 149 | { "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, nullptr, "The default disassembly format string to use when disassembling instruction sequences." }, |
| 150 | { "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, nullptr, "The default frame format string to use when displaying stack frame information for threads." }, |
| 151 | { "notify-void", OptionValue::eTypeBoolean , true, false, nullptr, nullptr, "Notify the user explicitly if an expression returns void (default: false)." }, |
| 152 | { "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", nullptr, "The debugger command line prompt displayed for the user." }, |
| 153 | { "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, nullptr, g_language_enumerators, "The script language to be used for evaluating user-written scripts." }, |
| 154 | { "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , nullptr, nullptr, "The number of disassembly lines to show when displaying a stopped context." }, |
| 155 | { "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoDebugInfo, nullptr, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." }, |
| 156 | { "stop-line-count-after", OptionValue::eTypeSInt64 , true, 3 , nullptr, nullptr, "The number of sources lines to display that come after the current source line when displaying a stopped context." }, |
| 157 | { "stop-line-count-before", OptionValue::eTypeSInt64 , true, 3 , nullptr, nullptr, "The number of sources lines to display that come before the current source line when displaying a stopped context." }, |
| 158 | { "term-width", OptionValue::eTypeSInt64 , true, 80 , nullptr, nullptr, "The maximum number of columns to use for displaying text." }, |
| 159 | { "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, nullptr, "The default thread format string to use when displaying thread information." }, |
| 160 | { "use-external-editor", OptionValue::eTypeBoolean , true, false, nullptr, nullptr, "Whether to use an external editor or not." }, |
| 161 | { "use-color", OptionValue::eTypeBoolean , true, true , nullptr, nullptr, "Whether to use Ansi color codes or not." }, |
| 162 | { "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, nullptr, nullptr, "If true, LLDB will automatically display small structs in one-liner format (default: true)." }, |
| 163 | { "auto-indent", OptionValue::eTypeBoolean , true, true , nullptr, nullptr, "If true, LLDB will auto indent/outdent code. Currently only supported in the REPL (default: true)." }, |
| 164 | { "print-decls", OptionValue::eTypeBoolean , true, true , nullptr, nullptr, "If true, LLDB will print the values of variables declared in an expression. Currently only supported in the REPL (default: true)." }, |
| 165 | { "tab-size", OptionValue::eTypeUInt64 , true, 4 , nullptr, nullptr, "The tab size to use when indenting code in multi-line input mode (default: 4)." }, |
| 166 | { "escape-non-printables", OptionValue::eTypeBoolean , true, true, nullptr, nullptr, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." }, |
| 167 | { nullptr, OptionValue::eTypeInvalid , true, 0 , nullptr, nullptr, nullptr } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | enum |
| 171 | { |
| 172 | ePropertyAutoConfirm = 0, |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 173 | ePropertyDisassemblyFormat, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 174 | ePropertyFrameFormat, |
| 175 | ePropertyNotiftVoid, |
| 176 | ePropertyPrompt, |
| 177 | ePropertyScriptLanguage, |
| 178 | ePropertyStopDisassemblyCount, |
| 179 | ePropertyStopDisassemblyDisplay, |
| 180 | ePropertyStopLineCountAfter, |
| 181 | ePropertyStopLineCountBefore, |
| 182 | ePropertyTerminalWidth, |
| 183 | ePropertyThreadFormat, |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 184 | ePropertyUseExternalEditor, |
| 185 | ePropertyUseColor, |
Enrico Granata | ebdc1ac | 2014-11-05 21:20:48 +0000 | [diff] [blame] | 186 | ePropertyAutoOneLineSummaries, |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 187 | ePropertyAutoIndent, |
| 188 | ePropertyPrintDecls, |
| 189 | ePropertyTabSize, |
Enrico Granata | ebdc1ac | 2014-11-05 21:20:48 +0000 | [diff] [blame] | 190 | ePropertyEscapeNonPrintables |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 193 | LoadPluginCallbackType Debugger::g_load_plugin_callback = nullptr; |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 194 | |
| 195 | Error |
| 196 | Debugger::SetPropertyValue (const ExecutionContext *exe_ctx, |
| 197 | VarSetOperationType op, |
| 198 | const char *property_path, |
| 199 | const char *value) |
| 200 | { |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 201 | bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0; |
Enrico Granata | ebdc1ac | 2014-11-05 21:20:48 +0000 | [diff] [blame] | 202 | bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0; |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 203 | TargetSP target_sp; |
Enrico Granata | 397ddd5 | 2013-05-21 20:13:34 +0000 | [diff] [blame] | 204 | LoadScriptFromSymFile load_script_old_value; |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 205 | if (is_load_script && exe_ctx->GetTargetSP()) |
| 206 | { |
| 207 | target_sp = exe_ctx->GetTargetSP(); |
| 208 | load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile(); |
| 209 | } |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 210 | Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value)); |
| 211 | if (error.Success()) |
| 212 | { |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 213 | // FIXME it would be nice to have "on-change" callbacks for properties |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 214 | if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0) |
| 215 | { |
| 216 | const char *new_prompt = GetPrompt(); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 217 | std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor()); |
| 218 | if (str.length()) |
| 219 | new_prompt = str.c_str(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 220 | GetCommandInterpreter().UpdatePrompt(new_prompt); |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 221 | EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt))); |
| 222 | GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp); |
| 223 | } |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 224 | else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0) |
| 225 | { |
| 226 | // use-color changed. Ping the prompt so it can reset the ansi terminal codes. |
| 227 | SetPrompt (GetPrompt()); |
| 228 | } |
Enrico Granata | 397ddd5 | 2013-05-21 20:13:34 +0000 | [diff] [blame] | 229 | else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 230 | { |
Enrico Granata | 397ddd5 | 2013-05-21 20:13:34 +0000 | [diff] [blame] | 231 | if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 232 | { |
| 233 | std::list<Error> errors; |
Enrico Granata | 9730339 | 2013-05-21 00:00:30 +0000 | [diff] [blame] | 234 | StreamString feedback_stream; |
| 235 | if (!target_sp->LoadScriptingResources(errors,&feedback_stream)) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 236 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 237 | StreamFileSP stream_sp (GetErrorFile()); |
| 238 | if (stream_sp) |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 239 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 240 | for (auto error : errors) |
| 241 | { |
| 242 | stream_sp->Printf("%s\n",error.AsCString()); |
| 243 | } |
| 244 | if (feedback_stream.GetSize()) |
| 245 | stream_sp->Printf("%s",feedback_stream.GetData()); |
Enrico Granata | 84a53df | 2013-05-20 22:29:23 +0000 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
Enrico Granata | ebdc1ac | 2014-11-05 21:20:48 +0000 | [diff] [blame] | 250 | else if (is_escape_non_printables) |
| 251 | { |
| 252 | DataVisualization::ForceUpdate(); |
| 253 | } |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 254 | } |
| 255 | return error; |
| 256 | } |
| 257 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 258 | bool |
| 259 | Debugger::GetAutoConfirm () const |
| 260 | { |
| 261 | const uint32_t idx = ePropertyAutoConfirm; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 262 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 265 | const FormatEntity::Entry * |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 266 | Debugger::GetDisassemblyFormat() const |
| 267 | { |
| 268 | const uint32_t idx = ePropertyDisassemblyFormat; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 269 | return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx); |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 272 | const FormatEntity::Entry * |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 273 | Debugger::GetFrameFormat() const |
| 274 | { |
| 275 | const uint32_t idx = ePropertyFrameFormat; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 276 | return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | bool |
| 280 | Debugger::GetNotifyVoid () const |
| 281 | { |
| 282 | const uint32_t idx = ePropertyNotiftVoid; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 283 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | const char * |
| 287 | Debugger::GetPrompt() const |
| 288 | { |
| 289 | const uint32_t idx = ePropertyPrompt; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 290 | return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, g_properties[idx].default_cstr_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void |
| 294 | Debugger::SetPrompt(const char *p) |
| 295 | { |
| 296 | const uint32_t idx = ePropertyPrompt; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 297 | m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, p); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 298 | const char *new_prompt = GetPrompt(); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 299 | std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor()); |
| 300 | if (str.length()) |
| 301 | new_prompt = str.c_str(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 302 | GetCommandInterpreter().UpdatePrompt(new_prompt); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 305 | const FormatEntity::Entry * |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 306 | Debugger::GetThreadFormat() const |
| 307 | { |
| 308 | const uint32_t idx = ePropertyThreadFormat; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 309 | return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | lldb::ScriptLanguage |
| 313 | Debugger::GetScriptLanguage() const |
| 314 | { |
| 315 | const uint32_t idx = ePropertyScriptLanguage; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 316 | return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | bool |
| 320 | Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang) |
| 321 | { |
| 322 | const uint32_t idx = ePropertyScriptLanguage; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 323 | return m_collection_sp->SetPropertyAtIndexAsEnumeration(nullptr, idx, script_lang); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | uint32_t |
| 327 | Debugger::GetTerminalWidth () const |
| 328 | { |
| 329 | const uint32_t idx = ePropertyTerminalWidth; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 330 | return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | bool |
| 334 | Debugger::SetTerminalWidth (uint32_t term_width) |
| 335 | { |
| 336 | const uint32_t idx = ePropertyTerminalWidth; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 337 | return m_collection_sp->SetPropertyAtIndexAsSInt64(nullptr, idx, term_width); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | bool |
| 341 | Debugger::GetUseExternalEditor () const |
| 342 | { |
| 343 | const uint32_t idx = ePropertyUseExternalEditor; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 344 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | bool |
| 348 | Debugger::SetUseExternalEditor (bool b) |
| 349 | { |
| 350 | const uint32_t idx = ePropertyUseExternalEditor; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 351 | return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 354 | bool |
| 355 | Debugger::GetUseColor () const |
| 356 | { |
| 357 | const uint32_t idx = ePropertyUseColor; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 358 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | bool |
| 362 | Debugger::SetUseColor (bool b) |
| 363 | { |
| 364 | const uint32_t idx = ePropertyUseColor; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 365 | bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 366 | SetPrompt (GetPrompt()); |
| 367 | return ret; |
| 368 | } |
| 369 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 370 | uint32_t |
| 371 | Debugger::GetStopSourceLineCount (bool before) const |
| 372 | { |
| 373 | const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 374 | return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | Debugger::StopDisassemblyType |
| 378 | Debugger::GetStopDisassemblyDisplay () const |
| 379 | { |
| 380 | const uint32_t idx = ePropertyStopDisassemblyDisplay; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 381 | return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | uint32_t |
| 385 | Debugger::GetDisassemblyLineCount () const |
| 386 | { |
| 387 | const uint32_t idx = ePropertyStopDisassemblyCount; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 388 | return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 389 | } |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 390 | |
Enrico Granata | 553fad5 | 2013-10-25 23:09:40 +0000 | [diff] [blame] | 391 | bool |
Enrico Granata | 90a8db3 | 2013-10-31 21:01:07 +0000 | [diff] [blame] | 392 | Debugger::GetAutoOneLineSummaries () const |
Enrico Granata | 553fad5 | 2013-10-25 23:09:40 +0000 | [diff] [blame] | 393 | { |
Enrico Granata | 90a8db3 | 2013-10-31 21:01:07 +0000 | [diff] [blame] | 394 | const uint32_t idx = ePropertyAutoOneLineSummaries; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 395 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true); |
Enrico Granata | ebdc1ac | 2014-11-05 21:20:48 +0000 | [diff] [blame] | 396 | } |
Enrico Granata | 553fad5 | 2013-10-25 23:09:40 +0000 | [diff] [blame] | 397 | |
Enrico Granata | ebdc1ac | 2014-11-05 21:20:48 +0000 | [diff] [blame] | 398 | bool |
| 399 | Debugger::GetEscapeNonPrintables () const |
| 400 | { |
| 401 | const uint32_t idx = ePropertyEscapeNonPrintables; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 402 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true); |
Enrico Granata | 553fad5 | 2013-10-25 23:09:40 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 405 | bool |
| 406 | Debugger::GetAutoIndent () const |
| 407 | { |
| 408 | const uint32_t idx = ePropertyAutoIndent; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 409 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true); |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | bool |
| 413 | Debugger::SetAutoIndent (bool b) |
| 414 | { |
| 415 | const uint32_t idx = ePropertyAutoIndent; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 416 | return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | bool |
| 420 | Debugger::GetPrintDecls () const |
| 421 | { |
| 422 | const uint32_t idx = ePropertyPrintDecls; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 423 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true); |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | bool |
| 427 | Debugger::SetPrintDecls (bool b) |
| 428 | { |
| 429 | const uint32_t idx = ePropertyPrintDecls; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 430 | return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | uint32_t |
| 434 | Debugger::GetTabSize () const |
| 435 | { |
| 436 | const uint32_t idx = ePropertyTabSize; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 437 | return m_collection_sp->GetPropertyAtIndexAsUInt64(nullptr, idx, g_properties[idx].default_uint_value); |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | bool |
| 441 | Debugger::SetTabSize (uint32_t tab_size) |
| 442 | { |
| 443 | const uint32_t idx = ePropertyTabSize; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 444 | return m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, tab_size); |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 447 | #pragma mark Debugger |
| 448 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 449 | //const DebuggerPropertiesSP & |
| 450 | //Debugger::GetSettings() const |
| 451 | //{ |
| 452 | // return m_properties_sp; |
| 453 | //} |
| 454 | // |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 455 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 456 | static bool lldb_initialized = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | void |
Zachary Turner | 3a00691 | 2015-03-19 22:00:21 +0000 | [diff] [blame] | 458 | Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | { |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 460 | assert(!lldb_initialized && "Debugger::Initialize called more than once!"); |
| 461 | |
Robert Flack | f196c93 | 2015-03-10 18:07:47 +0000 | [diff] [blame] | 462 | lldb_initialized = true; |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 463 | g_load_plugin_callback = load_plugin_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 466 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 467 | Debugger::Terminate () |
| 468 | { |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 469 | assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!"); |
| 470 | |
| 471 | // Clear our master list of debugger objects |
| 472 | Mutex::Locker locker (GetDebuggerListMutex ()); |
Oleksiy Vyalov | f3cd181 | 2015-09-08 16:26:32 +0000 | [diff] [blame] | 473 | auto& debuggers = GetDebuggerList(); |
| 474 | for (const auto& debugger: debuggers) |
| 475 | debugger->Clear(); |
| 476 | |
| 477 | debuggers.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 480 | void |
| 481 | Debugger::SettingsInitialize () |
| 482 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 483 | Target::SettingsInitialize (); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void |
| 487 | Debugger::SettingsTerminate () |
| 488 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 489 | Target::SettingsTerminate (); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 492 | bool |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 493 | Debugger::LoadPlugin (const FileSpec& spec, Error& error) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 494 | { |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 495 | if (g_load_plugin_callback) |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 496 | { |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 497 | llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error); |
| 498 | if (dynlib.isValid()) |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 499 | { |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 500 | m_loaded_plugins.push_back(dynlib); |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 501 | return true; |
| 502 | } |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 503 | } |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 504 | else |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 505 | { |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 506 | // The g_load_plugin_callback is registered in SBDebugger::Initialize() |
| 507 | // and if the public API layer isn't available (code is linking against |
| 508 | // all of the internal LLDB static libraries), then we can't load plugins |
| 509 | error.SetErrorString("Public API layer is not available"); |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 510 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | |
| 514 | static FileSpec::EnumerateDirectoryResult |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 515 | LoadPluginCallback(void *baton, |
| 516 | FileSpec::FileType file_type, |
| 517 | const FileSpec &file_spec) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 518 | { |
| 519 | Error error; |
| 520 | |
| 521 | static ConstString g_dylibext("dylib"); |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 522 | static ConstString g_solibext("so"); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 523 | |
| 524 | if (!baton) |
| 525 | return FileSpec::eEnumerateDirectoryResultQuit; |
| 526 | |
| 527 | Debugger *debugger = (Debugger*)baton; |
| 528 | |
| 529 | // If we have a regular file, a symbolic link or unknown file type, try |
| 530 | // and process the file. We must handle unknown as sometimes the directory |
| 531 | // enumeration might be enumerating a file system that doesn't have correct |
| 532 | // file type information. |
| 533 | if (file_type == FileSpec::eFileTypeRegular || |
| 534 | file_type == FileSpec::eFileTypeSymbolicLink || |
| 535 | file_type == FileSpec::eFileTypeUnknown ) |
| 536 | { |
| 537 | FileSpec plugin_file_spec (file_spec); |
| 538 | plugin_file_spec.ResolvePath (); |
| 539 | |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 540 | if (plugin_file_spec.GetFileNameExtension() != g_dylibext && |
| 541 | plugin_file_spec.GetFileNameExtension() != g_solibext) |
| 542 | { |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 543 | return FileSpec::eEnumerateDirectoryResultNext; |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 544 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 545 | |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 546 | Error plugin_load_error; |
| 547 | debugger->LoadPlugin (plugin_file_spec, plugin_load_error); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 548 | |
| 549 | return FileSpec::eEnumerateDirectoryResultNext; |
| 550 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 551 | else if (file_type == FileSpec::eFileTypeUnknown || |
| 552 | file_type == FileSpec::eFileTypeDirectory || |
| 553 | file_type == FileSpec::eFileTypeSymbolicLink ) |
| 554 | { |
| 555 | // Try and recurse into anything that a directory or symbolic link. |
| 556 | // We must also do this for unknown as sometimes the directory enumeration |
Bruce Mitchener | 6a7f333 | 2014-06-27 02:42:12 +0000 | [diff] [blame] | 557 | // 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] | 558 | // information. |
| 559 | return FileSpec::eEnumerateDirectoryResultEnter; |
| 560 | } |
| 561 | |
| 562 | return FileSpec::eEnumerateDirectoryResultNext; |
| 563 | } |
| 564 | |
| 565 | void |
| 566 | Debugger::InstanceInitialize () |
| 567 | { |
| 568 | FileSpec dir_spec; |
| 569 | const bool find_directories = true; |
| 570 | const bool find_files = true; |
| 571 | const bool find_other = true; |
| 572 | char dir_path[PATH_MAX]; |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 573 | if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 574 | { |
| 575 | if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) |
| 576 | { |
| 577 | FileSpec::EnumerateDirectory (dir_path, |
| 578 | find_directories, |
| 579 | find_files, |
| 580 | find_other, |
| 581 | LoadPluginCallback, |
| 582 | this); |
| 583 | } |
| 584 | } |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 585 | |
| 586 | if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 587 | { |
| 588 | if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) |
| 589 | { |
| 590 | FileSpec::EnumerateDirectory (dir_path, |
| 591 | find_directories, |
| 592 | find_files, |
| 593 | find_other, |
| 594 | LoadPluginCallback, |
| 595 | this); |
| 596 | } |
| 597 | } |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 598 | |
| 599 | PluginManager::DebuggerInitialize (*this); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 600 | } |
| 601 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 602 | DebuggerSP |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 603 | Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 604 | { |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 605 | DebuggerSP debugger_sp (new Debugger(log_callback, baton)); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 606 | if (lldb_initialized) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 607 | { |
| 608 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 609 | GetDebuggerList().push_back(debugger_sp); |
| 610 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 611 | debugger_sp->InstanceInitialize (); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 612 | return debugger_sp; |
| 613 | } |
| 614 | |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 615 | void |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 616 | Debugger::Destroy (DebuggerSP &debugger_sp) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 617 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 618 | if (!debugger_sp) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 619 | return; |
| 620 | |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 621 | debugger_sp->Clear(); |
| 622 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 623 | if (lldb_initialized) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 624 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 625 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 626 | DebuggerList &debugger_list = GetDebuggerList (); |
| 627 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 628 | for (pos = debugger_list.begin (); pos != end; ++pos) |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 629 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 630 | if ((*pos).get() == debugger_sp.get()) |
| 631 | { |
| 632 | debugger_list.erase (pos); |
| 633 | return; |
| 634 | } |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 639 | DebuggerSP |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 640 | Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) |
| 641 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 642 | DebuggerSP debugger_sp; |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 643 | if (lldb_initialized) |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 644 | { |
| 645 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 646 | DebuggerList &debugger_list = GetDebuggerList(); |
| 647 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 648 | |
| 649 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 650 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 651 | if ((*pos)->m_instance_name == instance_name) |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 652 | { |
| 653 | debugger_sp = *pos; |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 658 | return debugger_sp; |
| 659 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 660 | |
| 661 | TargetSP |
| 662 | Debugger::FindTargetWithProcessID (lldb::pid_t pid) |
| 663 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 664 | TargetSP target_sp; |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 665 | if (lldb_initialized) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 666 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 667 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 668 | DebuggerList &debugger_list = GetDebuggerList(); |
| 669 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 670 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 671 | { |
| 672 | target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid); |
| 673 | if (target_sp) |
| 674 | break; |
| 675 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 676 | } |
| 677 | return target_sp; |
| 678 | } |
| 679 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 680 | TargetSP |
| 681 | Debugger::FindTargetWithProcess (Process *process) |
| 682 | { |
| 683 | TargetSP target_sp; |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 684 | if (lldb_initialized) |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 685 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 686 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 687 | DebuggerList &debugger_list = GetDebuggerList(); |
| 688 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 689 | for (pos = debugger_list.begin(); pos != end; ++pos) |
| 690 | { |
| 691 | target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process); |
| 692 | if (target_sp) |
| 693 | break; |
| 694 | } |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 695 | } |
| 696 | return target_sp; |
| 697 | } |
| 698 | |
Jason Molenda | e6481c7 | 2014-09-12 01:50:46 +0000 | [diff] [blame] | 699 | Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) : |
| 700 | UserID(g_unique_id++), |
| 701 | Properties(OptionValuePropertiesSP(new OptionValueProperties())), |
| 702 | m_input_file_sp(new StreamFile(stdin, false)), |
| 703 | m_output_file_sp(new StreamFile(stdout, false)), |
| 704 | m_error_file_sp(new StreamFile(stderr, false)), |
| 705 | m_terminal_state(), |
| 706 | m_target_list(*this), |
| 707 | m_platform_list(), |
| 708 | m_listener("lldb.Debugger"), |
| 709 | m_source_manager_ap(), |
| 710 | m_source_file_cache(), |
| 711 | m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)), |
| 712 | m_input_reader_stack(), |
| 713 | m_instance_name(), |
Greg Clayton | afa91e33 | 2014-12-01 22:41:27 +0000 | [diff] [blame] | 714 | m_loaded_plugins(), |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 715 | m_event_handler_thread(), |
| 716 | m_io_handler_thread(), |
| 717 | m_sync_broadcaster(nullptr, "lldb.debugger.sync") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 719 | char instance_cstr[256]; |
| 720 | snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID()); |
| 721 | m_instance_name.SetCString(instance_cstr); |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 722 | if (log_callback) |
| 723 | m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton)); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 724 | m_command_interpreter_ap->Initialize (); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 725 | // Always add our default platform to the platform list |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 726 | PlatformSP default_platform_sp (Platform::GetHostPlatform()); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 727 | assert(default_platform_sp); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 728 | m_platform_list.Append (default_platform_sp, true); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 729 | |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 730 | m_collection_sp->Initialize (g_properties); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 731 | m_collection_sp->AppendProperty (ConstString("target"), |
| 732 | ConstString("Settings specify to debugging targets."), |
| 733 | true, |
| 734 | Target::GetGlobalProperties()->GetValueProperties()); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 735 | m_collection_sp->AppendProperty (ConstString("platform"), |
| 736 | ConstString("Platform settings."), |
| 737 | true, |
| 738 | Platform::GetGlobalPlatformProperties()->GetValueProperties()); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 739 | if (m_command_interpreter_ap) |
Greg Clayton | 754a936 | 2012-08-23 00:22:02 +0000 | [diff] [blame] | 740 | { |
| 741 | m_collection_sp->AppendProperty (ConstString("interpreter"), |
| 742 | ConstString("Settings specify to the debugger's command interpreter."), |
| 743 | true, |
| 744 | m_command_interpreter_ap->GetValueProperties()); |
| 745 | } |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 746 | OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64(nullptr, ePropertyTerminalWidth); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 747 | term_width->SetMinimumValue(10); |
| 748 | term_width->SetMaximumValue(1024); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 749 | |
| 750 | // Turn off use-color if this is a dumb terminal. |
| 751 | const char *term = getenv ("TERM"); |
| 752 | if (term && !strcmp (term, "dumb")) |
| 753 | SetUseColor (false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | Debugger::~Debugger () |
| 757 | { |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 758 | Clear(); |
| 759 | } |
| 760 | |
| 761 | void |
| 762 | Debugger::Clear() |
| 763 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 764 | ClearIOHandlers(); |
| 765 | StopIOHandlerThread(); |
| 766 | StopEventHandlerThread(); |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 767 | m_listener.Clear(); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 768 | int num_targets = m_target_list.GetNumTargets(); |
| 769 | for (int i = 0; i < num_targets; i++) |
| 770 | { |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 771 | TargetSP target_sp (m_target_list.GetTargetAtIndex (i)); |
| 772 | if (target_sp) |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 773 | { |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 774 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 775 | if (process_sp) |
Jim Ingham | 1fd0705 | 2013-02-27 19:13:05 +0000 | [diff] [blame] | 776 | process_sp->Finalize(); |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 777 | target_sp->Destroy(); |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 778 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 779 | } |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 780 | BroadcasterManager::Clear (); |
Greg Clayton | 0d69a3a | 2012-05-16 00:11:54 +0000 | [diff] [blame] | 781 | |
| 782 | // Close the input file _before_ we close the input read communications class |
| 783 | // 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] | 784 | m_terminal_state.Clear(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 785 | if (m_input_file_sp) |
| 786 | m_input_file_sp->GetFile().Close (); |
Greg Clayton | 0c4129f | 2014-04-25 00:35:14 +0000 | [diff] [blame] | 787 | |
| 788 | m_command_interpreter_ap->Clear(); |
Jim Ingham | 8314c52 | 2011-09-15 21:36:42 +0000 | [diff] [blame] | 789 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | |
| 791 | bool |
Greg Clayton | fc3f027 | 2011-05-29 04:06:55 +0000 | [diff] [blame] | 792 | Debugger::GetCloseInputOnEOF () const |
| 793 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 794 | // return m_input_comm.GetCloseOnEOF(); |
| 795 | return false; |
Greg Clayton | fc3f027 | 2011-05-29 04:06:55 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | void |
| 799 | Debugger::SetCloseInputOnEOF (bool b) |
| 800 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 801 | // m_input_comm.SetCloseOnEOF(b); |
Greg Clayton | fc3f027 | 2011-05-29 04:06:55 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | Debugger::GetAsyncExecution () |
| 806 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 807 | return !m_command_interpreter_ap->GetSynchronous(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | void |
| 811 | Debugger::SetAsyncExecution (bool async_execution) |
| 812 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 813 | m_command_interpreter_ap->SetSynchronous (!async_execution); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 816 | void |
| 817 | Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership) |
| 818 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 819 | if (m_input_file_sp) |
| 820 | m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership); |
| 821 | else |
| 822 | m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership)); |
| 823 | |
| 824 | File &in_file = m_input_file_sp->GetFile(); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 825 | if (!in_file.IsValid()) |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 826 | in_file.SetStream (stdin, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 827 | |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 828 | // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState. |
| 829 | SaveInputTerminalState (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 830 | } |
| 831 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 832 | void |
| 833 | Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership) |
| 834 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 835 | if (m_output_file_sp) |
| 836 | m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership); |
| 837 | else |
| 838 | m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership)); |
| 839 | |
| 840 | File &out_file = m_output_file_sp->GetFile(); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 841 | if (!out_file.IsValid()) |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 842 | out_file.SetStream (stdout, false); |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 843 | |
Enrico Granata | b588726 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 844 | // do not create the ScriptInterpreter just for setting the output file handle |
| 845 | // as the constructor will know how to do the right thing on its own |
| 846 | const bool can_create = false; |
| 847 | ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create); |
| 848 | if (script_interpreter) |
| 849 | script_interpreter->ResetOutputFileHandle (fh); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 852 | void |
| 853 | Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership) |
| 854 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 855 | if (m_error_file_sp) |
| 856 | m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership); |
| 857 | else |
| 858 | m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership)); |
| 859 | |
| 860 | File &err_file = m_error_file_sp->GetFile(); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 861 | if (!err_file.IsValid()) |
Greg Clayton | 51b1e2d | 2011-02-09 01:08:52 +0000 | [diff] [blame] | 862 | err_file.SetStream (stderr, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 865 | void |
| 866 | Debugger::SaveInputTerminalState () |
| 867 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 868 | if (m_input_file_sp) |
| 869 | { |
| 870 | File &in_file = m_input_file_sp->GetFile(); |
| 871 | if (in_file.GetDescriptor() != File::kInvalidDescriptor) |
| 872 | m_terminal_state.Save(in_file.GetDescriptor(), true); |
| 873 | } |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | void |
| 877 | Debugger::RestoreInputTerminalState () |
| 878 | { |
| 879 | m_terminal_state.Restore(); |
| 880 | } |
| 881 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 882 | ExecutionContext |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 883 | Debugger::GetSelectedExecutionContext () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | { |
| 885 | ExecutionContext exe_ctx; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 886 | TargetSP target_sp(GetSelectedTarget()); |
| 887 | exe_ctx.SetTargetSP (target_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 888 | |
| 889 | if (target_sp) |
| 890 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 891 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 892 | exe_ctx.SetProcessSP (process_sp); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 893 | if (process_sp && !process_sp->IsRunning()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 894 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 895 | ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread()); |
| 896 | if (thread_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 897 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 898 | exe_ctx.SetThreadSP (thread_sp); |
| 899 | exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame()); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 900 | if (exe_ctx.GetFramePtr() == nullptr) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 901 | exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | } |
| 905 | return exe_ctx; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 908 | void |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 909 | Debugger::DispatchInputInterrupt () |
| 910 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 911 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
| 912 | IOHandlerSP reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 913 | if (reader_sp) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 914 | reader_sp->Interrupt(); |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | void |
| 918 | Debugger::DispatchInputEndOfFile () |
| 919 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 920 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
| 921 | IOHandlerSP reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 922 | if (reader_sp) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 923 | reader_sp->GotEOF(); |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 927 | Debugger::ClearIOHandlers () |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 928 | { |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 929 | // 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] | 930 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
Caroline Tice | d5a0a01b | 2011-06-02 19:18:55 +0000 | [diff] [blame] | 931 | while (m_input_reader_stack.GetSize() > 1) |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 932 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 933 | IOHandlerSP reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 934 | if (reader_sp) |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 935 | PopIOHandler (reader_sp); |
Caroline Tice | 3d6086f | 2010-12-20 18:35:50 +0000 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
| 939 | void |
Siva Chandra | 9aaab55 | 2015-02-26 19:26:36 +0000 | [diff] [blame] | 940 | Debugger::ExecuteIOHandlers() |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 941 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 942 | while (true) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 943 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 944 | IOHandlerSP reader_sp(m_input_reader_stack.Top()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 945 | if (!reader_sp) |
| 946 | break; |
| 947 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 948 | reader_sp->Run(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 949 | |
| 950 | // Remove all input readers that are done from the top of the stack |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 951 | while (true) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 952 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 953 | IOHandlerSP top_reader_sp = m_input_reader_stack.Top(); |
| 954 | if (top_reader_sp && top_reader_sp->GetIsDone()) |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 955 | PopIOHandler (top_reader_sp); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 956 | else |
| 957 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 960 | ClearIOHandlers(); |
| 961 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 962 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 963 | bool |
| 964 | Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp) |
| 965 | { |
| 966 | return m_input_reader_stack.IsTop (reader_sp); |
| 967 | } |
| 968 | |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 969 | bool |
| 970 | Debugger::CheckTopIOHandlerTypes (IOHandler::Type top_type, IOHandler::Type second_top_type) |
| 971 | { |
| 972 | return m_input_reader_stack.CheckTopIOHandlerTypes (top_type, second_top_type); |
| 973 | } |
| 974 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 975 | void |
| 976 | Debugger::PrintAsync (const char *s, size_t len, bool is_stdout) |
| 977 | { |
| 978 | lldb::StreamFileSP stream = is_stdout ? GetOutputFile() : GetErrorFile(); |
| 979 | m_input_reader_stack.PrintAsync(stream.get(), s, len); |
| 980 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 981 | |
| 982 | ConstString |
| 983 | Debugger::GetTopIOHandlerControlSequence(char ch) |
| 984 | { |
| 985 | return m_input_reader_stack.GetTopIOHandlerControlSequence (ch); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Kate Stone | a487aa4 | 2015-01-15 00:52:41 +0000 | [diff] [blame] | 988 | const char * |
| 989 | Debugger::GetIOHandlerCommandPrefix() |
| 990 | { |
| 991 | return m_input_reader_stack.GetTopIOHandlerCommandPrefix(); |
| 992 | } |
| 993 | |
| 994 | const char * |
| 995 | Debugger::GetIOHandlerHelpPrologue() |
| 996 | { |
| 997 | return m_input_reader_stack.GetTopIOHandlerHelpPrologue(); |
| 998 | } |
| 999 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1000 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1001 | Debugger::RunIOHandler (const IOHandlerSP& reader_sp) |
| 1002 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1003 | PushIOHandler (reader_sp); |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1004 | |
Greg Clayton | 577508d | 2014-06-20 00:23:57 +0000 | [diff] [blame] | 1005 | IOHandlerSP top_reader_sp = reader_sp; |
| 1006 | while (top_reader_sp) |
| 1007 | { |
Greg Clayton | 577508d | 2014-06-20 00:23:57 +0000 | [diff] [blame] | 1008 | top_reader_sp->Run(); |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1009 | |
Greg Clayton | 577508d | 2014-06-20 00:23:57 +0000 | [diff] [blame] | 1010 | if (top_reader_sp.get() == reader_sp.get()) |
| 1011 | { |
| 1012 | if (PopIOHandler (reader_sp)) |
| 1013 | break; |
| 1014 | } |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1015 | |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1016 | while (true) |
Greg Clayton | 577508d | 2014-06-20 00:23:57 +0000 | [diff] [blame] | 1017 | { |
| 1018 | top_reader_sp = m_input_reader_stack.Top(); |
| 1019 | if (top_reader_sp && top_reader_sp->GetIsDone()) |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1020 | PopIOHandler (top_reader_sp); |
Greg Clayton | 577508d | 2014-06-20 00:23:57 +0000 | [diff] [blame] | 1021 | else |
| 1022 | break; |
| 1023 | } |
| 1024 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | void |
| 1028 | Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err) |
| 1029 | { |
| 1030 | // Before an IOHandler runs, it must have in/out/err streams. |
| 1031 | // This function is called when one ore more of the streams |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1032 | // are nullptr. We use the top input reader's in/out/err streams, |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1033 | // or fall back to the debugger file handles, or we fall back |
| 1034 | // onto stdin/stdout/stderr as a last resort. |
| 1035 | |
| 1036 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
| 1037 | IOHandlerSP top_reader_sp (m_input_reader_stack.Top()); |
| 1038 | // If no STDIN has been set, then set it appropriately |
| 1039 | if (!in) |
| 1040 | { |
| 1041 | if (top_reader_sp) |
| 1042 | in = top_reader_sp->GetInputStreamFile(); |
| 1043 | else |
| 1044 | in = GetInputFile(); |
| 1045 | |
| 1046 | // If there is nothing, use stdin |
| 1047 | if (!in) |
| 1048 | in = StreamFileSP(new StreamFile(stdin, false)); |
| 1049 | } |
| 1050 | // If no STDOUT has been set, then set it appropriately |
| 1051 | if (!out) |
| 1052 | { |
| 1053 | if (top_reader_sp) |
| 1054 | out = top_reader_sp->GetOutputStreamFile(); |
| 1055 | else |
| 1056 | out = GetOutputFile(); |
| 1057 | |
| 1058 | // If there is nothing, use stdout |
| 1059 | if (!out) |
| 1060 | out = StreamFileSP(new StreamFile(stdout, false)); |
| 1061 | } |
| 1062 | // If no STDERR has been set, then set it appropriately |
| 1063 | if (!err) |
| 1064 | { |
| 1065 | if (top_reader_sp) |
| 1066 | err = top_reader_sp->GetErrorStreamFile(); |
| 1067 | else |
| 1068 | err = GetErrorFile(); |
| 1069 | |
| 1070 | // If there is nothing, use stderr |
| 1071 | if (!err) |
| 1072 | err = StreamFileSP(new StreamFile(stdout, false)); |
| 1073 | |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | void |
| 1078 | Debugger::PushIOHandler (const IOHandlerSP& reader_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1079 | { |
| 1080 | if (!reader_sp) |
| 1081 | return; |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 1082 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1083 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
| 1084 | |
| 1085 | // Get the current top input reader... |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1086 | IOHandlerSP top_reader_sp (m_input_reader_stack.Top()); |
Caroline Tice | b44880c | 2011-02-10 01:15:13 +0000 | [diff] [blame] | 1087 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1088 | // Don't push the same IO handler twice... |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1089 | if (reader_sp == top_reader_sp) |
| 1090 | return; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1091 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1092 | // Push our new input reader |
| 1093 | m_input_reader_stack.Push (reader_sp); |
| 1094 | reader_sp->Activate(); |
| 1095 | |
| 1096 | // Interrupt the top input reader to it will exit its Run() function |
| 1097 | // and let this new input reader take over |
| 1098 | if (top_reader_sp) |
| 1099 | { |
| 1100 | top_reader_sp->Deactivate(); |
| 1101 | top_reader_sp->Cancel(); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1102 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1106 | Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1107 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1108 | if (! pop_reader_sp) |
| 1109 | return false; |
| 1110 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1111 | Mutex::Locker locker (m_input_reader_stack.GetMutex()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1112 | |
| 1113 | // 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] | 1114 | // read on the stack refresh its prompt and if there is one... |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1115 | if (m_input_reader_stack.IsEmpty()) |
| 1116 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1117 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1118 | IOHandlerSP reader_sp(m_input_reader_stack.Top()); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1119 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1120 | if (pop_reader_sp != reader_sp) |
| 1121 | return false; |
| 1122 | |
| 1123 | reader_sp->Deactivate(); |
| 1124 | reader_sp->Cancel(); |
| 1125 | m_input_reader_stack.Pop (); |
| 1126 | |
| 1127 | reader_sp = m_input_reader_stack.Top(); |
| 1128 | if (reader_sp) |
| 1129 | reader_sp->Activate(); |
| 1130 | |
| 1131 | return true; |
| 1132 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1133 | |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 1134 | StreamSP |
| 1135 | Debugger::GetAsyncOutputStream () |
| 1136 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1137 | return StreamSP (new StreamAsynchronousIO (*this, true)); |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | StreamSP |
| 1141 | Debugger::GetAsyncErrorStream () |
| 1142 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1143 | return StreamSP (new StreamAsynchronousIO (*this, false)); |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1146 | size_t |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1147 | Debugger::GetNumDebuggers() |
| 1148 | { |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 1149 | if (lldb_initialized) |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1150 | { |
| 1151 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 1152 | return GetDebuggerList().size(); |
| 1153 | } |
| 1154 | return 0; |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | lldb::DebuggerSP |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1158 | Debugger::GetDebuggerAtIndex (size_t index) |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1159 | { |
| 1160 | DebuggerSP debugger_sp; |
| 1161 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 1162 | if (lldb_initialized) |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1163 | { |
| 1164 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 1165 | DebuggerList &debugger_list = GetDebuggerList(); |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1166 | |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1167 | if (index < debugger_list.size()) |
| 1168 | debugger_sp = debugger_list[index]; |
| 1169 | } |
| 1170 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1171 | return debugger_sp; |
| 1172 | } |
| 1173 | |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1174 | DebuggerSP |
| 1175 | Debugger::FindDebuggerWithID (lldb::user_id_t id) |
| 1176 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1177 | DebuggerSP debugger_sp; |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1178 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 1179 | if (lldb_initialized) |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1180 | { |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1181 | Mutex::Locker locker (GetDebuggerListMutex ()); |
| 1182 | DebuggerList &debugger_list = GetDebuggerList(); |
| 1183 | DebuggerList::iterator pos, end = debugger_list.end(); |
| 1184 | for (pos = debugger_list.begin(); pos != end; ++pos) |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1185 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1186 | if ((*pos)->GetID() == id) |
Greg Clayton | c15f55e | 2012-03-30 20:53:46 +0000 | [diff] [blame] | 1187 | { |
| 1188 | debugger_sp = *pos; |
| 1189 | break; |
| 1190 | } |
Caroline Tice | ebc1bb2 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | return debugger_sp; |
| 1194 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1195 | |
Saleem Abdulrasool | 2643b90 | 2014-03-20 06:08:21 +0000 | [diff] [blame] | 1196 | #if 0 |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1197 | static void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1198 | TestPromptFormats (StackFrame *frame) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1199 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1200 | if (frame == nullptr) |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1201 | return; |
| 1202 | |
| 1203 | StreamString s; |
| 1204 | const char *prompt_format = |
| 1205 | "{addr = '${addr}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1206 | "{addr-file-or-load = '${addr-file-or-load}'\n}" |
| 1207 | "{current-pc-arrow = '${current-pc-arrow}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1208 | "{process.id = '${process.id}'\n}" |
| 1209 | "{process.name = '${process.name}'\n}" |
| 1210 | "{process.file.basename = '${process.file.basename}'\n}" |
| 1211 | "{process.file.fullpath = '${process.file.fullpath}'\n}" |
| 1212 | "{thread.id = '${thread.id}'\n}" |
| 1213 | "{thread.index = '${thread.index}'\n}" |
| 1214 | "{thread.name = '${thread.name}'\n}" |
| 1215 | "{thread.queue = '${thread.queue}'\n}" |
| 1216 | "{thread.stop-reason = '${thread.stop-reason}'\n}" |
| 1217 | "{target.arch = '${target.arch}'\n}" |
| 1218 | "{module.file.basename = '${module.file.basename}'\n}" |
| 1219 | "{module.file.fullpath = '${module.file.fullpath}'\n}" |
| 1220 | "{file.basename = '${file.basename}'\n}" |
| 1221 | "{file.fullpath = '${file.fullpath}'\n}" |
| 1222 | "{frame.index = '${frame.index}'\n}" |
| 1223 | "{frame.pc = '${frame.pc}'\n}" |
| 1224 | "{frame.sp = '${frame.sp}'\n}" |
| 1225 | "{frame.fp = '${frame.fp}'\n}" |
| 1226 | "{frame.flags = '${frame.flags}'\n}" |
| 1227 | "{frame.reg.rdi = '${frame.reg.rdi}'\n}" |
| 1228 | "{frame.reg.rip = '${frame.reg.rip}'\n}" |
| 1229 | "{frame.reg.rsp = '${frame.reg.rsp}'\n}" |
| 1230 | "{frame.reg.rbp = '${frame.reg.rbp}'\n}" |
| 1231 | "{frame.reg.rflags = '${frame.reg.rflags}'\n}" |
| 1232 | "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}" |
| 1233 | "{frame.reg.carp = '${frame.reg.carp}'\n}" |
| 1234 | "{function.id = '${function.id}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1235 | "{function.changed = '${function.changed}'\n}" |
| 1236 | "{function.initial-function = '${function.initial-function}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1237 | "{function.name = '${function.name}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1238 | "{function.name-without-args = '${function.name-without-args}'\n}" |
Greg Clayton | ccbc08e | 2012-01-14 17:04:19 +0000 | [diff] [blame] | 1239 | "{function.name-with-args = '${function.name-with-args}'\n}" |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1240 | "{function.addr-offset = '${function.addr-offset}'\n}" |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1241 | "{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] | 1242 | "{function.line-offset = '${function.line-offset}'\n}" |
| 1243 | "{function.pc-offset = '${function.pc-offset}'\n}" |
| 1244 | "{line.file.basename = '${line.file.basename}'\n}" |
| 1245 | "{line.file.fullpath = '${line.file.fullpath}'\n}" |
| 1246 | "{line.number = '${line.number}'\n}" |
| 1247 | "{line.start-addr = '${line.start-addr}'\n}" |
| 1248 | "{line.end-addr = '${line.end-addr}'\n}" |
| 1249 | ; |
| 1250 | |
| 1251 | SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything)); |
| 1252 | ExecutionContext exe_ctx; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1253 | frame->CalculateExecutionContext(exe_ctx); |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1254 | 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] | 1255 | { |
| 1256 | printf("%s\n", s.GetData()); |
| 1257 | } |
| 1258 | else |
| 1259 | { |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1260 | printf ("what we got: %s\n", s.GetData()); |
| 1261 | } |
| 1262 | } |
Saleem Abdulrasool | 2643b90 | 2014-03-20 06:08:21 +0000 | [diff] [blame] | 1263 | #endif |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 1264 | |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1265 | bool |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 1266 | Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format, |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1267 | const SymbolContext *sc, |
| 1268 | const SymbolContext *prev_sc, |
| 1269 | const ExecutionContext *exe_ctx, |
| 1270 | const Address *addr, |
| 1271 | Stream &s) |
| 1272 | { |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 1273 | FormatEntity::Entry format_entry; |
| 1274 | |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1275 | if (format == nullptr) |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1276 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1277 | if (exe_ctx != nullptr && exe_ctx->HasTargetScope()) |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 1278 | format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat(); |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1279 | if (format == nullptr) |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 1280 | { |
| 1281 | FormatEntity::Parse("${addr}: ", format_entry); |
| 1282 | format = &format_entry; |
| 1283 | } |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1284 | } |
| 1285 | bool function_changed = false; |
| 1286 | bool initial_function = false; |
| 1287 | if (prev_sc && (prev_sc->function || prev_sc->symbol)) |
| 1288 | { |
| 1289 | if (sc && (sc->function || sc->symbol)) |
| 1290 | { |
| 1291 | if (prev_sc->symbol && sc->symbol) |
| 1292 | { |
| 1293 | if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType())) |
| 1294 | { |
| 1295 | function_changed = true; |
| 1296 | } |
| 1297 | } |
| 1298 | else if (prev_sc->function && sc->function) |
| 1299 | { |
| 1300 | if (prev_sc->function->GetMangled() != sc->function->GetMangled()) |
| 1301 | { |
| 1302 | function_changed = true; |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | // The first context on a list of instructions will have a prev_sc that |
| 1308 | // has no Function or Symbol -- if SymbolContext had an IsValid() method, it |
| 1309 | // would return false. But we do get a prev_sc pointer. |
| 1310 | if ((sc && (sc->function || sc->symbol)) |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1311 | && prev_sc && (prev_sc->function == nullptr && prev_sc->symbol == nullptr)) |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1312 | { |
| 1313 | initial_function = true; |
| 1314 | } |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1315 | return FormatEntity::Format(*format, s, sc, exe_ctx, addr, nullptr, function_changed, initial_function); |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1318 | void |
| 1319 | Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton) |
| 1320 | { |
Jim Ingham | 4f02b22 | 2012-02-22 22:49:20 +0000 | [diff] [blame] | 1321 | // For simplicity's sake, I am not going to deal with how to close down any |
| 1322 | // open logging streams, I just redirect everything from here on out to the |
| 1323 | // callback. |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1324 | m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton)); |
| 1325 | } |
| 1326 | |
| 1327 | bool |
| 1328 | Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream) |
| 1329 | { |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1330 | StreamSP log_stream_sp; |
Sean Callanan | 9a02851 | 2012-08-09 00:50:26 +0000 | [diff] [blame] | 1331 | if (m_log_callback_stream_sp) |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1332 | { |
| 1333 | log_stream_sp = m_log_callback_stream_sp; |
| 1334 | // For now when using the callback mode you always get thread & timestamp. |
| 1335 | log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME; |
| 1336 | } |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1337 | else if (log_file == nullptr || *log_file == '\0') |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1338 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1339 | log_stream_sp = GetOutputFile(); |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1340 | } |
| 1341 | else |
| 1342 | { |
| 1343 | LogStreamMap::iterator pos = m_log_streams.find(log_file); |
Greg Clayton | c1b2ccf | 2013-01-08 00:01:36 +0000 | [diff] [blame] | 1344 | if (pos != m_log_streams.end()) |
| 1345 | log_stream_sp = pos->second.lock(); |
| 1346 | if (!log_stream_sp) |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1347 | { |
Pavel Labath | 8ac0699 | 2015-03-20 09:43:20 +0000 | [diff] [blame] | 1348 | uint32_t options = File::eOpenOptionWrite | File::eOpenOptionCanCreate |
| 1349 | | File::eOpenOptionCloseOnExec | File::eOpenOptionAppend; |
| 1350 | if (! (log_options & LLDB_LOG_OPTION_APPEND)) |
| 1351 | options |= File::eOpenOptionTruncate; |
| 1352 | |
| 1353 | log_stream_sp.reset (new StreamFile (log_file, options)); |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1354 | m_log_streams[log_file] = log_stream_sp; |
| 1355 | } |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1356 | } |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1357 | assert(log_stream_sp); |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1358 | |
| 1359 | if (log_options == 0) |
| 1360 | log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE; |
| 1361 | |
Tamas Berghammer | 9c9ecce | 2015-05-27 13:34:04 +0000 | [diff] [blame] | 1362 | return Log::EnableLogChannel(log_stream_sp, log_options, channel, categories, error_stream); |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
Greg Clayton | 9585fbf | 2013-03-19 00:20:55 +0000 | [diff] [blame] | 1365 | SourceManager & |
| 1366 | Debugger::GetSourceManager () |
| 1367 | { |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1368 | if (!m_source_manager_ap) |
Greg Clayton | 9585fbf | 2013-03-19 00:20:55 +0000 | [diff] [blame] | 1369 | m_source_manager_ap.reset (new SourceManager (shared_from_this())); |
| 1370 | return *m_source_manager_ap; |
| 1371 | } |
| 1372 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1373 | // This function handles events that were broadcast by the process. |
| 1374 | void |
| 1375 | Debugger::HandleBreakpointEvent (const EventSP &event_sp) |
| 1376 | { |
| 1377 | using namespace lldb; |
| 1378 | const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp); |
| 1379 | |
| 1380 | // if (event_type & eBreakpointEventTypeAdded |
| 1381 | // || event_type & eBreakpointEventTypeRemoved |
| 1382 | // || event_type & eBreakpointEventTypeEnabled |
| 1383 | // || event_type & eBreakpointEventTypeDisabled |
| 1384 | // || event_type & eBreakpointEventTypeCommandChanged |
| 1385 | // || event_type & eBreakpointEventTypeConditionChanged |
| 1386 | // || event_type & eBreakpointEventTypeIgnoreChanged |
| 1387 | // || event_type & eBreakpointEventTypeLocationsResolved) |
| 1388 | // { |
| 1389 | // // Don't do anything about these events, since the breakpoint commands already echo these actions. |
| 1390 | // } |
| 1391 | // |
| 1392 | if (event_type & eBreakpointEventTypeLocationsAdded) |
| 1393 | { |
| 1394 | uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp); |
| 1395 | if (num_new_locations > 0) |
| 1396 | { |
| 1397 | BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp); |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1398 | StreamSP output_sp (GetAsyncOutputStream()); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1399 | if (output_sp) |
| 1400 | { |
| 1401 | output_sp->Printf("%d location%s added to breakpoint %d\n", |
| 1402 | num_new_locations, |
| 1403 | num_new_locations == 1 ? "" : "s", |
| 1404 | breakpoint->GetID()); |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1405 | output_sp->Flush(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | // else if (event_type & eBreakpointEventTypeLocationsRemoved) |
| 1410 | // { |
| 1411 | // // These locations just get disabled, not sure it is worth spamming folks about this on the command line. |
| 1412 | // } |
| 1413 | // else if (event_type & eBreakpointEventTypeLocationsResolved) |
| 1414 | // { |
| 1415 | // // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy. |
| 1416 | // } |
| 1417 | } |
| 1418 | |
| 1419 | size_t |
| 1420 | Debugger::GetProcessSTDOUT (Process *process, Stream *stream) |
| 1421 | { |
| 1422 | size_t total_bytes = 0; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1423 | if (stream == nullptr) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1424 | stream = GetOutputFile().get(); |
| 1425 | |
| 1426 | if (stream) |
| 1427 | { |
| 1428 | // The process has stuff waiting for stdout; get it and write it out to the appropriate place. |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1429 | if (process == nullptr) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1430 | { |
| 1431 | TargetSP target_sp = GetTargetList().GetSelectedTarget(); |
| 1432 | if (target_sp) |
| 1433 | process = target_sp->GetProcessSP().get(); |
| 1434 | } |
| 1435 | if (process) |
| 1436 | { |
| 1437 | Error error; |
| 1438 | size_t len; |
| 1439 | char stdio_buffer[1024]; |
| 1440 | while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0) |
| 1441 | { |
| 1442 | stream->Write(stdio_buffer, len); |
| 1443 | total_bytes += len; |
| 1444 | } |
| 1445 | } |
| 1446 | stream->Flush(); |
| 1447 | } |
| 1448 | return total_bytes; |
| 1449 | } |
| 1450 | |
| 1451 | size_t |
| 1452 | Debugger::GetProcessSTDERR (Process *process, Stream *stream) |
| 1453 | { |
| 1454 | size_t total_bytes = 0; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1455 | if (stream == nullptr) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1456 | stream = GetOutputFile().get(); |
| 1457 | |
| 1458 | if (stream) |
| 1459 | { |
| 1460 | // The process has stuff waiting for stderr; get it and write it out to the appropriate place. |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1461 | if (process == nullptr) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1462 | { |
| 1463 | TargetSP target_sp = GetTargetList().GetSelectedTarget(); |
| 1464 | if (target_sp) |
| 1465 | process = target_sp->GetProcessSP().get(); |
| 1466 | } |
| 1467 | if (process) |
| 1468 | { |
| 1469 | Error error; |
| 1470 | size_t len; |
| 1471 | char stdio_buffer[1024]; |
| 1472 | while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0) |
| 1473 | { |
| 1474 | stream->Write(stdio_buffer, len); |
| 1475 | total_bytes += len; |
| 1476 | } |
| 1477 | } |
| 1478 | stream->Flush(); |
| 1479 | } |
| 1480 | return total_bytes; |
| 1481 | } |
| 1482 | |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1483 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1484 | // This function handles events that were broadcast by the process. |
| 1485 | void |
| 1486 | Debugger::HandleProcessEvent (const EventSP &event_sp) |
| 1487 | { |
| 1488 | using namespace lldb; |
| 1489 | const uint32_t event_type = event_sp->GetType(); |
| 1490 | ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get()); |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1491 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1492 | StreamSP output_stream_sp = GetAsyncOutputStream(); |
| 1493 | StreamSP error_stream_sp = GetAsyncErrorStream(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1494 | const bool gui_enabled = IsForwardingEvents(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1495 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1496 | if (!gui_enabled) |
| 1497 | { |
| 1498 | bool pop_process_io_handler = false; |
| 1499 | assert (process_sp); |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1500 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1501 | bool state_is_stopped = false; |
| 1502 | const bool got_state_changed = (event_type & Process::eBroadcastBitStateChanged) != 0; |
| 1503 | const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0; |
| 1504 | const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0; |
| 1505 | if (got_state_changed) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1506 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1507 | StateType event_state = Process::ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 1508 | state_is_stopped = StateIsStoppedState(event_state, false); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1509 | } |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1510 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1511 | // Display running state changes first before any STDIO |
| 1512 | if (got_state_changed && !state_is_stopped) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1513 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1514 | Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1515 | } |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1516 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1517 | // Now display and STDOUT |
| 1518 | if (got_stdout || got_state_changed) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1519 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1520 | GetProcessSTDOUT (process_sp.get(), output_stream_sp.get()); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1521 | } |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1522 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1523 | // Now display and STDERR |
| 1524 | if (got_stderr || got_state_changed) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1525 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1526 | GetProcessSTDERR (process_sp.get(), error_stream_sp.get()); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1529 | // Now display any stopped state changes after any STDIO |
| 1530 | if (got_state_changed && state_is_stopped) |
| 1531 | { |
| 1532 | Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler); |
| 1533 | } |
| 1534 | |
| 1535 | output_stream_sp->Flush(); |
| 1536 | error_stream_sp->Flush(); |
| 1537 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 1538 | if (pop_process_io_handler) |
| 1539 | process_sp->PopProcessIOHandler(); |
| 1540 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | void |
| 1544 | Debugger::HandleThreadEvent (const EventSP &event_sp) |
| 1545 | { |
| 1546 | // At present the only thread event we handle is the Frame Changed event, |
| 1547 | // and all we do for that is just reprint the thread status for that thread. |
| 1548 | using namespace lldb; |
| 1549 | const uint32_t event_type = event_sp->GetType(); |
| 1550 | if (event_type == Thread::eBroadcastBitStackChanged || |
| 1551 | event_type == Thread::eBroadcastBitThreadSelected ) |
| 1552 | { |
| 1553 | ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get())); |
| 1554 | if (thread_sp) |
| 1555 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1556 | thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | bool |
| 1562 | Debugger::IsForwardingEvents () |
| 1563 | { |
| 1564 | return (bool)m_forward_listener_sp; |
| 1565 | } |
| 1566 | |
| 1567 | void |
| 1568 | Debugger::EnableForwardEvents (const ListenerSP &listener_sp) |
| 1569 | { |
| 1570 | m_forward_listener_sp = listener_sp; |
| 1571 | } |
| 1572 | |
| 1573 | void |
| 1574 | Debugger::CancelForwardEvents (const ListenerSP &listener_sp) |
| 1575 | { |
| 1576 | m_forward_listener_sp.reset(); |
| 1577 | } |
| 1578 | |
| 1579 | |
| 1580 | void |
| 1581 | Debugger::DefaultEventHandler() |
| 1582 | { |
| 1583 | Listener& listener(GetListener()); |
| 1584 | ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass()); |
| 1585 | ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass()); |
| 1586 | ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass()); |
| 1587 | BroadcastEventSpec target_event_spec (broadcaster_class_target, |
| 1588 | Target::eBroadcastBitBreakpointChanged); |
| 1589 | |
| 1590 | BroadcastEventSpec process_event_spec (broadcaster_class_process, |
| 1591 | Process::eBroadcastBitStateChanged | |
| 1592 | Process::eBroadcastBitSTDOUT | |
| 1593 | Process::eBroadcastBitSTDERR); |
| 1594 | |
| 1595 | BroadcastEventSpec thread_event_spec (broadcaster_class_thread, |
| 1596 | Thread::eBroadcastBitStackChanged | |
| 1597 | Thread::eBroadcastBitThreadSelected ); |
| 1598 | |
| 1599 | listener.StartListeningForEventSpec (*this, target_event_spec); |
| 1600 | listener.StartListeningForEventSpec (*this, process_event_spec); |
| 1601 | listener.StartListeningForEventSpec (*this, thread_event_spec); |
| 1602 | listener.StartListeningForEvents (m_command_interpreter_ap.get(), |
| 1603 | CommandInterpreter::eBroadcastBitQuitCommandReceived | |
| 1604 | CommandInterpreter::eBroadcastBitAsynchronousOutputData | |
| 1605 | CommandInterpreter::eBroadcastBitAsynchronousErrorData ); |
Greg Clayton | afa91e33 | 2014-12-01 22:41:27 +0000 | [diff] [blame] | 1606 | |
| 1607 | // Let the thread that spawned us know that we have started up and |
| 1608 | // that we are now listening to all required events so no events get missed |
| 1609 | m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening); |
| 1610 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1611 | bool done = false; |
| 1612 | while (!done) |
| 1613 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1614 | EventSP event_sp; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1615 | if (listener.WaitForEvent(nullptr, event_sp)) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1616 | { |
| 1617 | if (event_sp) |
| 1618 | { |
| 1619 | Broadcaster *broadcaster = event_sp->GetBroadcaster(); |
| 1620 | if (broadcaster) |
| 1621 | { |
| 1622 | uint32_t event_type = event_sp->GetType(); |
| 1623 | ConstString broadcaster_class (broadcaster->GetBroadcasterClass()); |
| 1624 | if (broadcaster_class == broadcaster_class_process) |
| 1625 | { |
| 1626 | HandleProcessEvent (event_sp); |
| 1627 | } |
| 1628 | else if (broadcaster_class == broadcaster_class_target) |
| 1629 | { |
| 1630 | if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get())) |
| 1631 | { |
| 1632 | HandleBreakpointEvent (event_sp); |
| 1633 | } |
| 1634 | } |
| 1635 | else if (broadcaster_class == broadcaster_class_thread) |
| 1636 | { |
| 1637 | HandleThreadEvent (event_sp); |
| 1638 | } |
| 1639 | else if (broadcaster == m_command_interpreter_ap.get()) |
| 1640 | { |
| 1641 | if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived) |
| 1642 | { |
| 1643 | done = true; |
| 1644 | } |
| 1645 | else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData) |
| 1646 | { |
| 1647 | const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get())); |
| 1648 | if (data && data[0]) |
| 1649 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1650 | StreamSP error_sp (GetAsyncErrorStream()); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1651 | if (error_sp) |
| 1652 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1653 | error_sp->PutCString(data); |
| 1654 | error_sp->Flush(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData) |
| 1659 | { |
| 1660 | const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get())); |
| 1661 | if (data && data[0]) |
| 1662 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 1663 | StreamSP output_sp (GetAsyncOutputStream()); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1664 | if (output_sp) |
| 1665 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1666 | output_sp->PutCString(data); |
| 1667 | output_sp->Flush(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | if (m_forward_listener_sp) |
| 1675 | m_forward_listener_sp->AddEvent(event_sp); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | lldb::thread_result_t |
| 1682 | Debugger::EventHandlerThread (lldb::thread_arg_t arg) |
| 1683 | { |
| 1684 | ((Debugger *)arg)->DefaultEventHandler(); |
| 1685 | return NULL; |
| 1686 | } |
| 1687 | |
| 1688 | bool |
| 1689 | Debugger::StartEventHandlerThread() |
| 1690 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1691 | if (!m_event_handler_thread.IsJoinable()) |
Greg Clayton | 807b6b3 | 2014-10-15 18:03:59 +0000 | [diff] [blame] | 1692 | { |
Greg Clayton | afa91e33 | 2014-12-01 22:41:27 +0000 | [diff] [blame] | 1693 | // We must synchronize with the DefaultEventHandler() thread to ensure |
| 1694 | // it is up and running and listening to events before we return from |
| 1695 | // this function. We do this by listening to events for the |
| 1696 | // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster |
| 1697 | Listener listener("lldb.debugger.event-handler"); |
| 1698 | listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening); |
| 1699 | |
Zachary Turner | 7c2896a | 2014-10-24 22:06:29 +0000 | [diff] [blame] | 1700 | // Use larger 8MB stack for this thread |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1701 | m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", |
| 1702 | EventHandlerThread, |
Greg Clayton | afa91e33 | 2014-12-01 22:41:27 +0000 | [diff] [blame] | 1703 | this, |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1704 | nullptr, |
Zachary Turner | 7c2896a | 2014-10-24 22:06:29 +0000 | [diff] [blame] | 1705 | g_debugger_event_thread_stack_bytes); |
Greg Clayton | afa91e33 | 2014-12-01 22:41:27 +0000 | [diff] [blame] | 1706 | |
| 1707 | // Make sure DefaultEventHandler() is running and listening to events before we return |
| 1708 | // from this function. We are only listening for events of type |
| 1709 | // eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1710 | // to wait an infinite amount of time for it (nullptr timeout as the first parameter) |
Greg Clayton | afa91e33 | 2014-12-01 22:41:27 +0000 | [diff] [blame] | 1711 | lldb::EventSP event_sp; |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1712 | listener.WaitForEvent(nullptr, event_sp); |
Greg Clayton | 807b6b3 | 2014-10-15 18:03:59 +0000 | [diff] [blame] | 1713 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1714 | return m_event_handler_thread.IsJoinable(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void |
| 1718 | Debugger::StopEventHandlerThread() |
| 1719 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1720 | if (m_event_handler_thread.IsJoinable()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1721 | { |
| 1722 | GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 1723 | m_event_handler_thread.Join(nullptr); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1727 | lldb::thread_result_t |
| 1728 | Debugger::IOHandlerThread (lldb::thread_arg_t arg) |
| 1729 | { |
| 1730 | Debugger *debugger = (Debugger *)arg; |
Siva Chandra | 9aaab55 | 2015-02-26 19:26:36 +0000 | [diff] [blame] | 1731 | debugger->ExecuteIOHandlers(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1732 | debugger->StopEventHandlerThread(); |
| 1733 | return NULL; |
| 1734 | } |
| 1735 | |
| 1736 | bool |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 1737 | Debugger::HasIOHandlerThread() |
| 1738 | { |
| 1739 | return m_io_handler_thread.IsJoinable(); |
| 1740 | } |
| 1741 | |
| 1742 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1743 | Debugger::StartIOHandlerThread() |
| 1744 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1745 | if (!m_io_handler_thread.IsJoinable()) |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1746 | m_io_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.io-handler", |
| 1747 | IOHandlerThread, |
| 1748 | this, |
| 1749 | nullptr, |
| 1750 | 8*1024*1024); // Use larger 8MB stack for this thread |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1751 | return m_io_handler_thread.IsJoinable(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | void |
| 1755 | Debugger::StopIOHandlerThread() |
| 1756 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 1757 | if (m_io_handler_thread.IsJoinable()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1758 | { |
| 1759 | if (m_input_file_sp) |
| 1760 | m_input_file_sp->GetFile().Close(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 1761 | m_io_handler_thread.Join(nullptr); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1762 | } |
| 1763 | } |
| 1764 | |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 1765 | void |
| 1766 | Debugger::JoinIOHandlerThread() |
| 1767 | { |
| 1768 | if (HasIOHandlerThread()) |
| 1769 | { |
| 1770 | thread_result_t result; |
| 1771 | m_io_handler_thread.Join(&result); |
| 1772 | m_io_handler_thread = LLDB_INVALID_HOST_THREAD; |
| 1773 | } |
| 1774 | } |
| 1775 | |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1776 | Target * |
| 1777 | Debugger::GetDummyTarget() |
| 1778 | { |
| 1779 | return m_target_list.GetDummyTarget (*this).get(); |
| 1780 | } |
| 1781 | |
| 1782 | Target * |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1783 | Debugger::GetSelectedOrDummyTarget(bool prefer_dummy) |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1784 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1785 | Target *target = nullptr; |
| 1786 | if (!prefer_dummy) |
| 1787 | { |
| 1788 | target = m_target_list.GetSelectedTarget().get(); |
| 1789 | if (target) |
| 1790 | return target; |
| 1791 | } |
| 1792 | |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1793 | return GetDummyTarget(); |
| 1794 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1795 | |
Sean Callanan | 3e7e915 | 2015-10-20 00:23:46 +0000 | [diff] [blame] | 1796 | Error |
| 1797 | Debugger::RunREPL (LanguageType language, const char *repl_options) |
| 1798 | { |
| 1799 | Error err; |
| 1800 | FileSpec repl_executable; |
Sean Callanan | 3e7e915 | 2015-10-20 00:23:46 +0000 | [diff] [blame] | 1801 | |
Sean Callanan | 97f84e8 | 2015-10-21 19:31:17 +0000 | [diff] [blame] | 1802 | if (language == eLanguageTypeUnknown) |
| 1803 | { |
| 1804 | std::set<LanguageType> repl_languages; |
| 1805 | |
| 1806 | Language::GetLanguagesSupportingREPLs(repl_languages); |
| 1807 | |
| 1808 | if (repl_languages.size() == 1) |
| 1809 | { |
| 1810 | language = *repl_languages.begin(); |
| 1811 | } |
Eugene Zelenko | df37055 | 2016-03-02 02:18:18 +0000 | [diff] [blame] | 1812 | else if (repl_languages.empty()) |
Sean Callanan | 97f84e8 | 2015-10-21 19:31:17 +0000 | [diff] [blame] | 1813 | { |
| 1814 | err.SetErrorStringWithFormat("LLDB isn't configured with support support for any REPLs."); |
| 1815 | return err; |
| 1816 | } |
| 1817 | else |
| 1818 | { |
| 1819 | err.SetErrorStringWithFormat("Multiple possible REPL languages. Please specify a language."); |
| 1820 | return err; |
| 1821 | } |
| 1822 | } |
| 1823 | |
Sean Callanan | 3e7e915 | 2015-10-20 00:23:46 +0000 | [diff] [blame] | 1824 | Target *const target = nullptr; // passing in an empty target means the REPL must create one |
| 1825 | |
Sean Callanan | 3b682de | 2015-10-21 00:28:44 +0000 | [diff] [blame] | 1826 | REPLSP repl_sp(REPL::Create(err, language, this, target, repl_options)); |
Sean Callanan | 3e7e915 | 2015-10-20 00:23:46 +0000 | [diff] [blame] | 1827 | |
| 1828 | if (!err.Success()) |
| 1829 | { |
| 1830 | return err; |
| 1831 | } |
| 1832 | |
| 1833 | if (!repl_sp) |
| 1834 | { |
| 1835 | err.SetErrorStringWithFormat("couldn't find a REPL for %s", Language::GetNameForLanguageType(language)); |
| 1836 | return err; |
| 1837 | } |
| 1838 | |
| 1839 | repl_sp->SetCompilerOptions(repl_options); |
| 1840 | repl_sp->RunLoop(); |
| 1841 | |
| 1842 | return err; |
| 1843 | } |