blob: f93da0eb5cd63edf5ac8bb2576e512ccfeb50b35 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton4a33d312011-06-23 17:59:56 +000012#include "lldb/Core/Debugger.h"
13
14#include <map>
15
Enrico Granata4becb372011-06-29 22:27:15 +000016#include "clang/AST/DeclCXX.h"
17#include "clang/AST/Type.h"
Jason Molenda705b1802014-06-13 02:37:02 +000018#include "llvm/ADT/StringRef.h"
Enrico Granata4becb372011-06-29 22:27:15 +000019
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/lldb-private.h"
Greg Clayton554f68d2015-02-04 22:00:53 +000021#include "lldb/Core/FormatEntity.h"
Greg Clayton1f746072012-08-29 21:13:06 +000022#include "lldb/Core/Module.h"
Greg Claytone8cd0c92012-10-19 18:02:49 +000023#include "lldb/Core/PluginManager.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000024#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000026#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000027#include "lldb/Core/StreamCallback.h"
Greg Clayton44d93782014-01-27 23:43:24 +000028#include "lldb/Core/StreamFile.h"
Greg Clayton1b654882010-09-19 02:33:57 +000029#include "lldb/Core/StreamString.h"
Jason Molenda705b1802014-06-13 02:37:02 +000030#include "lldb/Core/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000032#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000033#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000034#include "lldb/DataFormatters/DataVisualization.h"
35#include "lldb/DataFormatters/FormatManager.h"
Enrico Granata894f7352014-03-25 22:03:52 +000036#include "lldb/DataFormatters/TypeSummary.h"
Zachary Turner93a66fc2014-10-06 21:22:36 +000037#include "lldb/Host/ConnectionFileDescriptor.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000038#include "lldb/Host/HostInfo.h"
Greg Claytona3406612011-02-07 23:24:47 +000039#include "lldb/Host/Terminal.h"
Zachary Turner39de3112014-09-09 20:54:56 +000040#include "lldb/Host/ThreadLauncher.h"
Zachary Turner3a006912015-03-19 22:00:21 +000041#include "lldb/Initialization/InitializeLLDB.h"
Greg Clayton66111032010-06-23 01:19:29 +000042#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turner633a29c2015-03-04 01:58:01 +000043#include "lldb/Interpreter/OptionValueProperties.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000044#include "lldb/Interpreter/OptionValueSInt64.h"
45#include "lldb/Interpreter/OptionValueString.h"
Greg Clayton1f746072012-08-29 21:13:06 +000046#include "lldb/Symbol/ClangASTContext.h"
47#include "lldb/Symbol/CompileUnit.h"
48#include "lldb/Symbol/Function.h"
49#include "lldb/Symbol/Symbol.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000050#include "lldb/Symbol/VariableList.h"
Jason Molendaaff1b352014-10-10 23:07:36 +000051#include "lldb/Target/CPPLanguageRuntime.h"
52#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/TargetList.h"
54#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000055#include "lldb/Target/RegisterContext.h"
Greg Clayton5fb8f792013-12-02 19:35:49 +000056#include "lldb/Target/SectionLoadList.h"
Greg Clayton1b654882010-09-19 02:33:57 +000057#include "lldb/Target/StopInfo.h"
Enrico Granata84a53df2013-05-20 22:29:23 +000058#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000060#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
Zachary Turner58a559c2014-08-27 20:15:09 +000062#include "llvm/Support/DynamicLibrary.h"
63
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064using namespace lldb;
65using namespace lldb_private;
66
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
Greg Clayton1b654882010-09-19 02:33:57 +000068static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000069static lldb::user_id_t g_unique_id = 1;
Zachary Turner7c2896a2014-10-24 22:06:29 +000070static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000071
Greg Clayton1b654882010-09-19 02:33:57 +000072#pragma mark Static Functions
73
74static Mutex &
75GetDebuggerListMutex ()
76{
77 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
78 return g_mutex;
79}
80
81typedef std::vector<DebuggerSP> DebuggerList;
82
83static DebuggerList &
84GetDebuggerList()
85{
86 // hide the static debugger list inside a singleton accessor to avoid
Bruce Mitchener6a7f3332014-06-27 02:42:12 +000087 // global init constructors
Greg Clayton1b654882010-09-19 02:33:57 +000088 static DebuggerList g_list;
89 return g_list;
90}
Greg Claytone372b982011-11-21 21:44:34 +000091
92OptionEnumValueElement
Greg Clayton67cc0632012-08-22 17:17:09 +000093g_show_disassembly_enum_values[] =
Greg Claytone372b982011-11-21 21:44:34 +000094{
Greg Clayton67cc0632012-08-22 17:17:09 +000095 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
96 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
97 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
Greg Claytone372b982011-11-21 21:44:34 +000098 { 0, NULL, NULL }
99};
100
Greg Clayton67cc0632012-08-22 17:17:09 +0000101OptionEnumValueElement
102g_language_enumerators[] =
103{
104 { eScriptLanguageNone, "none", "Disable scripting languages."},
105 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
106 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
Greg Claytona12993c2012-09-13 23:03:20 +0000107 { 0, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000108};
Greg Claytone372b982011-11-21 21:44:34 +0000109
Greg Clayton67cc0632012-08-22 17:17:09 +0000110#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
111#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
112
Michael Sartain0769b2b2013-07-30 16:44:36 +0000113#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000114 "{, ${frame.pc}}"\
115 MODULE_WITH_FUNC\
116 FILE_AND_LINE\
Michael Sartain0769b2b2013-07-30 16:44:36 +0000117 "{, name = '${thread.name}'}"\
118 "{, queue = '${thread.queue}'}"\
Jason Molenda705b1802014-06-13 02:37:02 +0000119 "{, activity = '${thread.info.activity.name}'}" \
120 "{, ${thread.info.trace_messages} messages}" \
Greg Clayton67cc0632012-08-22 17:17:09 +0000121 "{, stop reason = ${thread.stop-reason}}"\
122 "{\\nReturn value: ${thread.return-value}}"\
Jim Ingham30fadaf2014-07-08 01:07:32 +0000123 "{\\nCompleted expression: ${thread.completed-expression}}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000124 "\\n"
125
126#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
127 MODULE_WITH_FUNC\
128 FILE_AND_LINE\
129 "\\n"
130
Jason Molendac980fa92015-02-13 23:24:21 +0000131// Three parts to this disassembly format specification:
132// 1. If this is a new function/symbol (no previous symbol/function), print
133// dylib`funcname:\n
134// 2. If this is a symbol context change (different from previous symbol/function), print
135// dylib`funcname:\n
136// 3. print
137// address <+offset>:
138#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}>}: "
139
140// gdb's disassembly format can be emulated with
141// ${current-pc-arrow}${addr-file-or-load}{ <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>}:
142
143// lldb's original format for disassembly would look like this format string -
144// {${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}}:
145
Greg Clayton67cc0632012-08-22 17:17:09 +0000146
Greg Clayton754a9362012-08-23 00:22:02 +0000147static PropertyDefinition
148g_properties[] =
Greg Clayton67cc0632012-08-22 17:17:09 +0000149{
Greg Clayton554f68d2015-02-04 22:00:53 +0000150{ "auto-confirm", OptionValue::eTypeBoolean , true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
151{ "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, NULL, "The default disassembly format string to use when disassembling instruction sequences." },
152{ "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
153{ "notify-void", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
154{ "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
155{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
156{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
157{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
158{ "stop-line-count-after", OptionValue::eTypeSInt64 , true, 3 , NULL, NULL, "The number of sources lines to display that come after the current source line when displaying a stopped context." },
159{ "stop-line-count-before", OptionValue::eTypeSInt64 , true, 3 , NULL, NULL, "The number of sources lines to display that come before the current source line when displaying a stopped context." },
160{ "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
161{ "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
162{ "use-external-editor", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Whether to use an external editor or not." },
163{ "use-color", OptionValue::eTypeBoolean , true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
164{ "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
165{ "escape-non-printables", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
166{ NULL, OptionValue::eTypeInvalid , true, 0 , NULL, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000167};
168
169enum
170{
171 ePropertyAutoConfirm = 0,
Jason Molendaaff1b352014-10-10 23:07:36 +0000172 ePropertyDisassemblyFormat,
Greg Clayton67cc0632012-08-22 17:17:09 +0000173 ePropertyFrameFormat,
174 ePropertyNotiftVoid,
175 ePropertyPrompt,
176 ePropertyScriptLanguage,
177 ePropertyStopDisassemblyCount,
178 ePropertyStopDisassemblyDisplay,
179 ePropertyStopLineCountAfter,
180 ePropertyStopLineCountBefore,
181 ePropertyTerminalWidth,
182 ePropertyThreadFormat,
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000183 ePropertyUseExternalEditor,
184 ePropertyUseColor,
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000185 ePropertyAutoOneLineSummaries,
186 ePropertyEscapeNonPrintables
Greg Clayton67cc0632012-08-22 17:17:09 +0000187};
188
Zachary Turner3a006912015-03-19 22:00:21 +0000189LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
Greg Clayton4c054102012-09-01 00:38:36 +0000190
191Error
192Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
193 VarSetOperationType op,
194 const char *property_path,
195 const char *value)
196{
Enrico Granata84a53df2013-05-20 22:29:23 +0000197 bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000198 bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0;
Enrico Granata84a53df2013-05-20 22:29:23 +0000199 TargetSP target_sp;
Enrico Granata397ddd52013-05-21 20:13:34 +0000200 LoadScriptFromSymFile load_script_old_value;
Enrico Granata84a53df2013-05-20 22:29:23 +0000201 if (is_load_script && exe_ctx->GetTargetSP())
202 {
203 target_sp = exe_ctx->GetTargetSP();
204 load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
205 }
Greg Clayton4c054102012-09-01 00:38:36 +0000206 Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value));
207 if (error.Success())
208 {
Enrico Granata84a53df2013-05-20 22:29:23 +0000209 // FIXME it would be nice to have "on-change" callbacks for properties
Greg Clayton4c054102012-09-01 00:38:36 +0000210 if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0)
211 {
212 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000213 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
214 if (str.length())
215 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000216 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton4c054102012-09-01 00:38:36 +0000217 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
218 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
219 }
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000220 else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0)
221 {
222 // use-color changed. Ping the prompt so it can reset the ansi terminal codes.
223 SetPrompt (GetPrompt());
224 }
Enrico Granata397ddd52013-05-21 20:13:34 +0000225 else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn)
Enrico Granata84a53df2013-05-20 22:29:23 +0000226 {
Enrico Granata397ddd52013-05-21 20:13:34 +0000227 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue)
Enrico Granata84a53df2013-05-20 22:29:23 +0000228 {
229 std::list<Error> errors;
Enrico Granata97303392013-05-21 00:00:30 +0000230 StreamString feedback_stream;
231 if (!target_sp->LoadScriptingResources(errors,&feedback_stream))
Enrico Granata84a53df2013-05-20 22:29:23 +0000232 {
Greg Clayton44d93782014-01-27 23:43:24 +0000233 StreamFileSP stream_sp (GetErrorFile());
234 if (stream_sp)
Enrico Granata84a53df2013-05-20 22:29:23 +0000235 {
Greg Clayton44d93782014-01-27 23:43:24 +0000236 for (auto error : errors)
237 {
238 stream_sp->Printf("%s\n",error.AsCString());
239 }
240 if (feedback_stream.GetSize())
241 stream_sp->Printf("%s",feedback_stream.GetData());
Enrico Granata84a53df2013-05-20 22:29:23 +0000242 }
243 }
244 }
245 }
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000246 else if (is_escape_non_printables)
247 {
248 DataVisualization::ForceUpdate();
249 }
Greg Clayton4c054102012-09-01 00:38:36 +0000250 }
251 return error;
252}
253
Greg Clayton67cc0632012-08-22 17:17:09 +0000254bool
255Debugger::GetAutoConfirm () const
256{
257 const uint32_t idx = ePropertyAutoConfirm;
Greg Clayton754a9362012-08-23 00:22:02 +0000258 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000259}
260
Greg Clayton554f68d2015-02-04 22:00:53 +0000261const FormatEntity::Entry *
Jason Molendaaff1b352014-10-10 23:07:36 +0000262Debugger::GetDisassemblyFormat() const
263{
264 const uint32_t idx = ePropertyDisassemblyFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000265 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Jason Molendaaff1b352014-10-10 23:07:36 +0000266}
267
Greg Clayton554f68d2015-02-04 22:00:53 +0000268const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000269Debugger::GetFrameFormat() const
270{
271 const uint32_t idx = ePropertyFrameFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000272 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000273}
274
275bool
276Debugger::GetNotifyVoid () const
277{
278 const uint32_t idx = ePropertyNotiftVoid;
Greg Clayton754a9362012-08-23 00:22:02 +0000279 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000280}
281
282const char *
283Debugger::GetPrompt() const
284{
285 const uint32_t idx = ePropertyPrompt;
Greg Clayton754a9362012-08-23 00:22:02 +0000286 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000287}
288
289void
290Debugger::SetPrompt(const char *p)
291{
292 const uint32_t idx = ePropertyPrompt;
293 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
294 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000295 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
296 if (str.length())
297 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000298 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton67cc0632012-08-22 17:17:09 +0000299}
300
Greg Clayton554f68d2015-02-04 22:00:53 +0000301const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000302Debugger::GetThreadFormat() const
303{
304 const uint32_t idx = ePropertyThreadFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000305 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000306}
307
308lldb::ScriptLanguage
309Debugger::GetScriptLanguage() const
310{
311 const uint32_t idx = ePropertyScriptLanguage;
Greg Clayton754a9362012-08-23 00:22:02 +0000312 return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000313}
314
315bool
316Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
317{
318 const uint32_t idx = ePropertyScriptLanguage;
319 return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
320}
321
322uint32_t
323Debugger::GetTerminalWidth () const
324{
325 const uint32_t idx = ePropertyTerminalWidth;
Greg Clayton754a9362012-08-23 00:22:02 +0000326 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000327}
328
329bool
330Debugger::SetTerminalWidth (uint32_t term_width)
331{
332 const uint32_t idx = ePropertyTerminalWidth;
333 return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
334}
335
336bool
337Debugger::GetUseExternalEditor () const
338{
339 const uint32_t idx = ePropertyUseExternalEditor;
Greg Clayton754a9362012-08-23 00:22:02 +0000340 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000341}
342
343bool
344Debugger::SetUseExternalEditor (bool b)
345{
346 const uint32_t idx = ePropertyUseExternalEditor;
347 return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
348}
349
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000350bool
351Debugger::GetUseColor () const
352{
353 const uint32_t idx = ePropertyUseColor;
354 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
355}
356
357bool
358Debugger::SetUseColor (bool b)
359{
360 const uint32_t idx = ePropertyUseColor;
361 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
362 SetPrompt (GetPrompt());
363 return ret;
364}
365
Greg Clayton67cc0632012-08-22 17:17:09 +0000366uint32_t
367Debugger::GetStopSourceLineCount (bool before) const
368{
369 const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
Greg Clayton754a9362012-08-23 00:22:02 +0000370 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000371}
372
373Debugger::StopDisassemblyType
374Debugger::GetStopDisassemblyDisplay () const
375{
376 const uint32_t idx = ePropertyStopDisassemblyDisplay;
Greg Clayton754a9362012-08-23 00:22:02 +0000377 return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000378}
379
380uint32_t
381Debugger::GetDisassemblyLineCount () const
382{
383 const uint32_t idx = ePropertyStopDisassemblyCount;
Greg Clayton754a9362012-08-23 00:22:02 +0000384 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000385}
Greg Claytone372b982011-11-21 21:44:34 +0000386
Enrico Granata553fad52013-10-25 23:09:40 +0000387bool
Enrico Granata90a8db32013-10-31 21:01:07 +0000388Debugger::GetAutoOneLineSummaries () const
Enrico Granata553fad52013-10-25 23:09:40 +0000389{
Enrico Granata90a8db32013-10-31 21:01:07 +0000390 const uint32_t idx = ePropertyAutoOneLineSummaries;
Enrico Granata553fad52013-10-25 23:09:40 +0000391 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000392}
Enrico Granata553fad52013-10-25 23:09:40 +0000393
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000394bool
395Debugger::GetEscapeNonPrintables () const
396{
397 const uint32_t idx = ePropertyEscapeNonPrintables;
398 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granata553fad52013-10-25 23:09:40 +0000399}
400
Greg Clayton1b654882010-09-19 02:33:57 +0000401#pragma mark Debugger
402
Greg Clayton67cc0632012-08-22 17:17:09 +0000403//const DebuggerPropertiesSP &
404//Debugger::GetSettings() const
405//{
406// return m_properties_sp;
407//}
408//
Greg Clayton99d0faf2010-11-18 23:32:35 +0000409
Caroline Tice2f88aad2011-01-14 00:29:16 +0000410int
411Debugger::TestDebuggerRefCount ()
412{
413 return g_shared_debugger_refcount;
414}
415
Robert Flackf196c932015-03-10 18:07:47 +0000416static bool lldb_initialized = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417void
Zachary Turner3a006912015-03-19 22:00:21 +0000418Debugger::Initialize(LoadPluginCallbackType load_plugin_callback)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419{
Robert Flackf196c932015-03-10 18:07:47 +0000420 lldb_initialized = true;
421 g_shared_debugger_refcount++;
Greg Clayton5fb8f792013-12-02 19:35:49 +0000422 g_load_plugin_callback = load_plugin_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423}
424
Zachary Turner3a006912015-03-19 22:00:21 +0000425int
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426Debugger::Terminate ()
427{
Greg Clayton66111032010-06-23 01:19:29 +0000428 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 {
Greg Clayton66111032010-06-23 01:19:29 +0000430 g_shared_debugger_refcount--;
431 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432 {
Caroline Tice6760a512011-01-17 21:55:19 +0000433 // Clear our master list of debugger objects
434 Mutex::Locker locker (GetDebuggerListMutex ());
435 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 }
Zachary Turner3a006912015-03-19 22:00:21 +0000438 return g_shared_debugger_refcount;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439}
440
Caroline Tice20bd37f2011-03-10 22:14:10 +0000441void
442Debugger::SettingsInitialize ()
443{
Greg Clayton6920b522012-08-22 18:39:03 +0000444 Target::SettingsInitialize ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000445}
446
447void
448Debugger::SettingsTerminate ()
449{
Greg Clayton6920b522012-08-22 18:39:03 +0000450 Target::SettingsTerminate ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000451}
452
Enrico Granata21dfcd92012-09-28 23:57:51 +0000453bool
Enrico Granatae743c782013-04-24 21:29:08 +0000454Debugger::LoadPlugin (const FileSpec& spec, Error& error)
Enrico Granata21dfcd92012-09-28 23:57:51 +0000455{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000456 if (g_load_plugin_callback)
Enrico Granatae743c782013-04-24 21:29:08 +0000457 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000458 llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error);
459 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +0000460 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000461 m_loaded_plugins.push_back(dynlib);
Greg Clayton5fb8f792013-12-02 19:35:49 +0000462 return true;
463 }
Enrico Granatae743c782013-04-24 21:29:08 +0000464 }
Greg Clayton5fb8f792013-12-02 19:35:49 +0000465 else
Enrico Granatae743c782013-04-24 21:29:08 +0000466 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000467 // The g_load_plugin_callback is registered in SBDebugger::Initialize()
468 // and if the public API layer isn't available (code is linking against
469 // all of the internal LLDB static libraries), then we can't load plugins
470 error.SetErrorString("Public API layer is not available");
Enrico Granatae743c782013-04-24 21:29:08 +0000471 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000472 return false;
473}
474
475static FileSpec::EnumerateDirectoryResult
476LoadPluginCallback
477(
478 void *baton,
479 FileSpec::FileType file_type,
480 const FileSpec &file_spec
481 )
482{
483 Error error;
484
485 static ConstString g_dylibext("dylib");
Michael Sartain3cf443d2013-07-17 00:26:30 +0000486 static ConstString g_solibext("so");
Enrico Granata21dfcd92012-09-28 23:57:51 +0000487
488 if (!baton)
489 return FileSpec::eEnumerateDirectoryResultQuit;
490
491 Debugger *debugger = (Debugger*)baton;
492
493 // If we have a regular file, a symbolic link or unknown file type, try
494 // and process the file. We must handle unknown as sometimes the directory
495 // enumeration might be enumerating a file system that doesn't have correct
496 // file type information.
497 if (file_type == FileSpec::eFileTypeRegular ||
498 file_type == FileSpec::eFileTypeSymbolicLink ||
499 file_type == FileSpec::eFileTypeUnknown )
500 {
501 FileSpec plugin_file_spec (file_spec);
502 plugin_file_spec.ResolvePath ();
503
Michael Sartain3cf443d2013-07-17 00:26:30 +0000504 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
505 plugin_file_spec.GetFileNameExtension() != g_solibext)
506 {
Enrico Granata21dfcd92012-09-28 23:57:51 +0000507 return FileSpec::eEnumerateDirectoryResultNext;
Michael Sartain3cf443d2013-07-17 00:26:30 +0000508 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000509
Enrico Granatae743c782013-04-24 21:29:08 +0000510 Error plugin_load_error;
511 debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000512
513 return FileSpec::eEnumerateDirectoryResultNext;
514 }
515
516 else if (file_type == FileSpec::eFileTypeUnknown ||
517 file_type == FileSpec::eFileTypeDirectory ||
518 file_type == FileSpec::eFileTypeSymbolicLink )
519 {
520 // Try and recurse into anything that a directory or symbolic link.
521 // We must also do this for unknown as sometimes the directory enumeration
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000522 // might be enumerating a file system that doesn't have correct file type
Enrico Granata21dfcd92012-09-28 23:57:51 +0000523 // information.
524 return FileSpec::eEnumerateDirectoryResultEnter;
525 }
526
527 return FileSpec::eEnumerateDirectoryResultNext;
528}
529
530void
531Debugger::InstanceInitialize ()
532{
533 FileSpec dir_spec;
534 const bool find_directories = true;
535 const bool find_files = true;
536 const bool find_other = true;
537 char dir_path[PATH_MAX];
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000538 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000539 {
540 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
541 {
542 FileSpec::EnumerateDirectory (dir_path,
543 find_directories,
544 find_files,
545 find_other,
546 LoadPluginCallback,
547 this);
548 }
549 }
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000550
551 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000552 {
553 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
554 {
555 FileSpec::EnumerateDirectory (dir_path,
556 find_directories,
557 find_files,
558 find_other,
559 LoadPluginCallback,
560 this);
561 }
562 }
Greg Claytone8cd0c92012-10-19 18:02:49 +0000563
564 PluginManager::DebuggerInitialize (*this);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000565}
566
Greg Clayton66111032010-06-23 01:19:29 +0000567DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000568Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000569{
Jim Ingham228063c2012-02-21 02:23:08 +0000570 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Greg Claytonc15f55e2012-03-30 20:53:46 +0000571 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000572 {
573 Mutex::Locker locker (GetDebuggerListMutex ());
574 GetDebuggerList().push_back(debugger_sp);
575 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000576 debugger_sp->InstanceInitialize ();
Greg Clayton66111032010-06-23 01:19:29 +0000577 return debugger_sp;
578}
579
Caroline Ticee02657b2011-01-22 01:02:07 +0000580void
Greg Clayton4d122c42011-09-17 08:33:22 +0000581Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000582{
583 if (debugger_sp.get() == NULL)
584 return;
585
Jim Ingham8314c522011-09-15 21:36:42 +0000586 debugger_sp->Clear();
587
Greg Claytonc15f55e2012-03-30 20:53:46 +0000588 if (g_shared_debugger_refcount > 0)
Caroline Ticee02657b2011-01-22 01:02:07 +0000589 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000590 Mutex::Locker locker (GetDebuggerListMutex ());
591 DebuggerList &debugger_list = GetDebuggerList ();
592 DebuggerList::iterator pos, end = debugger_list.end();
593 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000594 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000595 if ((*pos).get() == debugger_sp.get())
596 {
597 debugger_list.erase (pos);
598 return;
599 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000600 }
601 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000602}
603
Greg Clayton4d122c42011-09-17 08:33:22 +0000604DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000605Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
606{
Greg Clayton4d122c42011-09-17 08:33:22 +0000607 DebuggerSP debugger_sp;
Greg Clayton6920b522012-08-22 18:39:03 +0000608 if (g_shared_debugger_refcount > 0)
609 {
610 Mutex::Locker locker (GetDebuggerListMutex ());
611 DebuggerList &debugger_list = GetDebuggerList();
612 DebuggerList::iterator pos, end = debugger_list.end();
613
614 for (pos = debugger_list.begin(); pos != end; ++pos)
615 {
616 if ((*pos).get()->m_instance_name == instance_name)
617 {
618 debugger_sp = *pos;
619 break;
620 }
621 }
622 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000623 return debugger_sp;
624}
Greg Clayton66111032010-06-23 01:19:29 +0000625
626TargetSP
627Debugger::FindTargetWithProcessID (lldb::pid_t pid)
628{
Greg Clayton4d122c42011-09-17 08:33:22 +0000629 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000630 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000631 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000632 Mutex::Locker locker (GetDebuggerListMutex ());
633 DebuggerList &debugger_list = GetDebuggerList();
634 DebuggerList::iterator pos, end = debugger_list.end();
635 for (pos = debugger_list.begin(); pos != end; ++pos)
636 {
637 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
638 if (target_sp)
639 break;
640 }
Greg Clayton66111032010-06-23 01:19:29 +0000641 }
642 return target_sp;
643}
644
Greg Claytone4e45922011-11-16 05:37:56 +0000645TargetSP
646Debugger::FindTargetWithProcess (Process *process)
647{
648 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000649 if (g_shared_debugger_refcount > 0)
Greg Claytone4e45922011-11-16 05:37:56 +0000650 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000651 Mutex::Locker locker (GetDebuggerListMutex ());
652 DebuggerList &debugger_list = GetDebuggerList();
653 DebuggerList::iterator pos, end = debugger_list.end();
654 for (pos = debugger_list.begin(); pos != end; ++pos)
655 {
656 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
657 if (target_sp)
658 break;
659 }
Greg Claytone4e45922011-11-16 05:37:56 +0000660 }
661 return target_sp;
662}
663
Jason Molendae6481c72014-09-12 01:50:46 +0000664Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
665 UserID(g_unique_id++),
666 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
667 m_input_file_sp(new StreamFile(stdin, false)),
668 m_output_file_sp(new StreamFile(stdout, false)),
669 m_error_file_sp(new StreamFile(stderr, false)),
670 m_terminal_state(),
671 m_target_list(*this),
672 m_platform_list(),
673 m_listener("lldb.Debugger"),
674 m_source_manager_ap(),
675 m_source_file_cache(),
676 m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)),
677 m_input_reader_stack(),
678 m_instance_name(),
Greg Claytonafa91e332014-12-01 22:41:27 +0000679 m_loaded_plugins(),
680 m_event_handler_thread (),
681 m_io_handler_thread (),
682 m_sync_broadcaster (NULL, "lldb.debugger.sync")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683{
Greg Clayton67cc0632012-08-22 17:17:09 +0000684 char instance_cstr[256];
685 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
686 m_instance_name.SetCString(instance_cstr);
Jim Ingham228063c2012-02-21 02:23:08 +0000687 if (log_callback)
688 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000689 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000690 // Always add our default platform to the platform list
Greg Clayton615eb7e2014-09-19 20:11:50 +0000691 PlatformSP default_platform_sp (Platform::GetHostPlatform());
Greg Claytonded470d2011-03-19 01:12:21 +0000692 assert (default_platform_sp.get());
693 m_platform_list.Append (default_platform_sp, true);
Greg Clayton67cc0632012-08-22 17:17:09 +0000694
Greg Clayton754a9362012-08-23 00:22:02 +0000695 m_collection_sp->Initialize (g_properties);
Greg Clayton67cc0632012-08-22 17:17:09 +0000696 m_collection_sp->AppendProperty (ConstString("target"),
697 ConstString("Settings specify to debugging targets."),
698 true,
699 Target::GetGlobalProperties()->GetValueProperties());
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000700 m_collection_sp->AppendProperty (ConstString("platform"),
701 ConstString("Platform settings."),
702 true,
703 Platform::GetGlobalPlatformProperties()->GetValueProperties());
Greg Clayton754a9362012-08-23 00:22:02 +0000704 if (m_command_interpreter_ap.get())
705 {
706 m_collection_sp->AppendProperty (ConstString("interpreter"),
707 ConstString("Settings specify to the debugger's command interpreter."),
708 true,
709 m_command_interpreter_ap->GetValueProperties());
710 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000711 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
712 term_width->SetMinimumValue(10);
713 term_width->SetMaximumValue(1024);
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000714
715 // Turn off use-color if this is a dumb terminal.
716 const char *term = getenv ("TERM");
717 if (term && !strcmp (term, "dumb"))
718 SetUseColor (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719}
720
721Debugger::~Debugger ()
722{
Jim Ingham8314c522011-09-15 21:36:42 +0000723 Clear();
724}
725
726void
727Debugger::Clear()
728{
Greg Clayton44d93782014-01-27 23:43:24 +0000729 ClearIOHandlers();
730 StopIOHandlerThread();
731 StopEventHandlerThread();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000732 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000733 int num_targets = m_target_list.GetNumTargets();
734 for (int i = 0; i < num_targets; i++)
735 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000736 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
737 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000738 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000739 ProcessSP process_sp (target_sp->GetProcessSP());
740 if (process_sp)
Jim Ingham1fd07052013-02-27 19:13:05 +0000741 process_sp->Finalize();
Greg Claytonccbc08e2012-01-14 17:04:19 +0000742 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000743 }
Greg Clayton66111032010-06-23 01:19:29 +0000744 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000745 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000746
747 // Close the input file _before_ we close the input read communications class
748 // as it does NOT own the input file, our m_input_file does.
Jim Inghamc5917d92012-11-30 20:23:19 +0000749 m_terminal_state.Clear();
Greg Clayton44d93782014-01-27 23:43:24 +0000750 if (m_input_file_sp)
751 m_input_file_sp->GetFile().Close ();
Greg Clayton0c4129f2014-04-25 00:35:14 +0000752
753 m_command_interpreter_ap->Clear();
Jim Ingham8314c522011-09-15 21:36:42 +0000754}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755
756bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000757Debugger::GetCloseInputOnEOF () const
758{
Greg Clayton44d93782014-01-27 23:43:24 +0000759// return m_input_comm.GetCloseOnEOF();
760 return false;
Greg Claytonfc3f0272011-05-29 04:06:55 +0000761}
762
763void
764Debugger::SetCloseInputOnEOF (bool b)
765{
Greg Clayton44d93782014-01-27 23:43:24 +0000766// m_input_comm.SetCloseOnEOF(b);
Greg Claytonfc3f0272011-05-29 04:06:55 +0000767}
768
769bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770Debugger::GetAsyncExecution ()
771{
Greg Clayton66111032010-06-23 01:19:29 +0000772 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773}
774
775void
776Debugger::SetAsyncExecution (bool async_execution)
777{
Greg Clayton66111032010-06-23 01:19:29 +0000778 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779}
780
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781
782void
783Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
784{
Greg Clayton44d93782014-01-27 23:43:24 +0000785 if (m_input_file_sp)
786 m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership);
787 else
788 m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
789
790 File &in_file = m_input_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000791 if (in_file.IsValid() == false)
792 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793
Jim Inghamc5917d92012-11-30 20:23:19 +0000794 // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
795 SaveInputTerminalState ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796}
797
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798void
799Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
800{
Greg Clayton44d93782014-01-27 23:43:24 +0000801 if (m_output_file_sp)
802 m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership);
803 else
804 m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
805
806 File &out_file = m_output_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000807 if (out_file.IsValid() == false)
808 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000809
Enrico Granatab5887262012-10-29 21:18:03 +0000810 // do not create the ScriptInterpreter just for setting the output file handle
811 // as the constructor will know how to do the right thing on its own
812 const bool can_create = false;
813 ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create);
814 if (script_interpreter)
815 script_interpreter->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816}
817
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818void
819Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
820{
Greg Clayton44d93782014-01-27 23:43:24 +0000821 if (m_error_file_sp)
822 m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership);
823 else
824 m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
825
826 File &err_file = m_error_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000827 if (err_file.IsValid() == false)
828 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829}
830
Jim Inghamc5917d92012-11-30 20:23:19 +0000831void
832Debugger::SaveInputTerminalState ()
833{
Greg Clayton44d93782014-01-27 23:43:24 +0000834 if (m_input_file_sp)
835 {
836 File &in_file = m_input_file_sp->GetFile();
837 if (in_file.GetDescriptor() != File::kInvalidDescriptor)
838 m_terminal_state.Save(in_file.GetDescriptor(), true);
839 }
Jim Inghamc5917d92012-11-30 20:23:19 +0000840}
841
842void
843Debugger::RestoreInputTerminalState ()
844{
845 m_terminal_state.Restore();
846}
847
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000849Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850{
851 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000852 TargetSP target_sp(GetSelectedTarget());
853 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854
855 if (target_sp)
856 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000857 ProcessSP process_sp (target_sp->GetProcessSP());
858 exe_ctx.SetProcessSP (process_sp);
859 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000861 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
862 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000864 exe_ctx.SetThreadSP (thread_sp);
865 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
866 if (exe_ctx.GetFramePtr() == NULL)
867 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868 }
869 }
870 }
871 return exe_ctx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000872}
873
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874void
Caroline Ticeefed6132010-11-19 20:47:54 +0000875Debugger::DispatchInputInterrupt ()
876{
Greg Clayton44d93782014-01-27 23:43:24 +0000877 Mutex::Locker locker (m_input_reader_stack.GetMutex());
878 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000879 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000880 reader_sp->Interrupt();
Caroline Ticeefed6132010-11-19 20:47:54 +0000881}
882
883void
884Debugger::DispatchInputEndOfFile ()
885{
Greg Clayton44d93782014-01-27 23:43:24 +0000886 Mutex::Locker locker (m_input_reader_stack.GetMutex());
887 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000888 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000889 reader_sp->GotEOF();
Caroline Ticeefed6132010-11-19 20:47:54 +0000890}
891
892void
Greg Clayton44d93782014-01-27 23:43:24 +0000893Debugger::ClearIOHandlers ()
Caroline Tice3d6086f2010-12-20 18:35:50 +0000894{
Caroline Ticeb44880c2011-02-10 01:15:13 +0000895 // The bottom input reader should be the main debugger input reader. We do not want to close that one here.
Greg Clayton44d93782014-01-27 23:43:24 +0000896 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000897 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000898 {
Greg Clayton44d93782014-01-27 23:43:24 +0000899 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000900 if (reader_sp)
901 {
Greg Clayton44d93782014-01-27 23:43:24 +0000902 m_input_reader_stack.Pop();
903 reader_sp->SetIsDone(true);
Greg Claytone68f5d62014-02-24 22:50:57 +0000904 reader_sp->Cancel();
Caroline Tice3d6086f2010-12-20 18:35:50 +0000905 }
906 }
907}
908
909void
Siva Chandra9aaab552015-02-26 19:26:36 +0000910Debugger::ExecuteIOHandlers()
Caroline Tice969ed3d2011-05-02 20:41:46 +0000911{
Caroline Tice9088b062011-05-09 23:06:58 +0000912
Greg Clayton44d93782014-01-27 23:43:24 +0000913 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000914 {
Greg Clayton44d93782014-01-27 23:43:24 +0000915 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000916 if (!reader_sp)
917 break;
918
Greg Clayton44d93782014-01-27 23:43:24 +0000919 reader_sp->Activate();
920 reader_sp->Run();
921 reader_sp->Deactivate();
922
923 // Remove all input readers that are done from the top of the stack
924 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000925 {
Greg Clayton44d93782014-01-27 23:43:24 +0000926 IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
927 if (top_reader_sp && top_reader_sp->GetIsDone())
928 m_input_reader_stack.Pop();
929 else
930 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931 }
932 }
Greg Clayton44d93782014-01-27 23:43:24 +0000933 ClearIOHandlers();
934}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000935
Greg Clayton44d93782014-01-27 23:43:24 +0000936bool
937Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
938{
939 return m_input_reader_stack.IsTop (reader_sp);
940}
941
942
943ConstString
944Debugger::GetTopIOHandlerControlSequence(char ch)
945{
946 return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000947}
948
Kate Stonea487aa42015-01-15 00:52:41 +0000949const char *
950Debugger::GetIOHandlerCommandPrefix()
951{
952 return m_input_reader_stack.GetTopIOHandlerCommandPrefix();
953}
954
955const char *
956Debugger::GetIOHandlerHelpPrologue()
957{
958 return m_input_reader_stack.GetTopIOHandlerHelpPrologue();
959}
960
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961void
Greg Clayton44d93782014-01-27 23:43:24 +0000962Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
963{
Greg Clayton44d93782014-01-27 23:43:24 +0000964 PushIOHandler (reader_sp);
Greg Clayton577508d2014-06-20 00:23:57 +0000965
966 IOHandlerSP top_reader_sp = reader_sp;
967 while (top_reader_sp)
968 {
969 top_reader_sp->Activate();
970 top_reader_sp->Run();
971 top_reader_sp->Deactivate();
972
973 if (top_reader_sp.get() == reader_sp.get())
974 {
975 if (PopIOHandler (reader_sp))
976 break;
977 }
978
979 while (1)
980 {
981 top_reader_sp = m_input_reader_stack.Top();
982 if (top_reader_sp && top_reader_sp->GetIsDone())
983 m_input_reader_stack.Pop();
984 else
985 break;
986 }
987 }
Greg Clayton44d93782014-01-27 23:43:24 +0000988}
989
990void
991Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
992{
993 // Before an IOHandler runs, it must have in/out/err streams.
994 // This function is called when one ore more of the streams
995 // are NULL. We use the top input reader's in/out/err streams,
996 // or fall back to the debugger file handles, or we fall back
997 // onto stdin/stdout/stderr as a last resort.
998
999 Mutex::Locker locker (m_input_reader_stack.GetMutex());
1000 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
1001 // If no STDIN has been set, then set it appropriately
1002 if (!in)
1003 {
1004 if (top_reader_sp)
1005 in = top_reader_sp->GetInputStreamFile();
1006 else
1007 in = GetInputFile();
1008
1009 // If there is nothing, use stdin
1010 if (!in)
1011 in = StreamFileSP(new StreamFile(stdin, false));
1012 }
1013 // If no STDOUT has been set, then set it appropriately
1014 if (!out)
1015 {
1016 if (top_reader_sp)
1017 out = top_reader_sp->GetOutputStreamFile();
1018 else
1019 out = GetOutputFile();
1020
1021 // If there is nothing, use stdout
1022 if (!out)
1023 out = StreamFileSP(new StreamFile(stdout, false));
1024 }
1025 // If no STDERR has been set, then set it appropriately
1026 if (!err)
1027 {
1028 if (top_reader_sp)
1029 err = top_reader_sp->GetErrorStreamFile();
1030 else
1031 err = GetErrorFile();
1032
1033 // If there is nothing, use stderr
1034 if (!err)
1035 err = StreamFileSP(new StreamFile(stdout, false));
1036
1037 }
1038}
1039
1040void
1041Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001042{
1043 if (!reader_sp)
1044 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +00001045
Greg Clayton44d93782014-01-27 23:43:24 +00001046 // Got the current top input reader...
1047 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +00001048
Greg Claytonb4874f12014-02-28 18:22:24 +00001049 // Don't push the same IO handler twice...
1050 if (reader_sp.get() != top_reader_sp.get())
1051 {
1052 // Push our new input reader
1053 m_input_reader_stack.Push (reader_sp);
Greg Clayton44d93782014-01-27 23:43:24 +00001054
Greg Claytonb4874f12014-02-28 18:22:24 +00001055 // Interrupt the top input reader to it will exit its Run() function
1056 // and let this new input reader take over
1057 if (top_reader_sp)
1058 top_reader_sp->Deactivate();
1059 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060}
1061
1062bool
Greg Clayton44d93782014-01-27 23:43:24 +00001063Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064{
1065 bool result = false;
Greg Clayton44d93782014-01-27 23:43:24 +00001066
1067 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068
1069 // The reader on the stop of the stack is done, so let the next
Bruce Mitchener6a7f3332014-06-27 02:42:12 +00001070 // read on the stack refresh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +00001071 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001072 {
Greg Clayton44d93782014-01-27 23:43:24 +00001073 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001074
1075 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
1076 {
Greg Clayton44d93782014-01-27 23:43:24 +00001077 reader_sp->Deactivate();
Greg Claytonb4874f12014-02-28 18:22:24 +00001078 reader_sp->Cancel();
Caroline Ticed5a0a01b2011-06-02 19:18:55 +00001079 m_input_reader_stack.Pop ();
Greg Clayton44d93782014-01-27 23:43:24 +00001080
1081 reader_sp = m_input_reader_stack.Top();
1082 if (reader_sp)
1083 reader_sp->Activate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084
Greg Clayton44d93782014-01-27 23:43:24 +00001085 result = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001086 }
1087 }
1088 return result;
1089}
1090
1091bool
Greg Clayton44d93782014-01-27 23:43:24 +00001092Debugger::HideTopIOHandler()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001093{
Greg Clayton44d93782014-01-27 23:43:24 +00001094 Mutex::Locker locker;
1095
1096 if (locker.TryLock(m_input_reader_stack.GetMutex()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097 {
Greg Clayton44d93782014-01-27 23:43:24 +00001098 IOHandlerSP reader_sp(m_input_reader_stack.Top());
1099 if (reader_sp)
1100 reader_sp->Hide();
1101 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001102 }
Greg Clayton44d93782014-01-27 23:43:24 +00001103 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001104}
1105
1106void
Greg Clayton44d93782014-01-27 23:43:24 +00001107Debugger::RefreshTopIOHandler()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001108{
Greg Clayton44d93782014-01-27 23:43:24 +00001109 IOHandlerSP reader_sp(m_input_reader_stack.Top());
1110 if (reader_sp)
1111 reader_sp->Refresh();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112}
Greg Clayton66111032010-06-23 01:19:29 +00001113
Greg Clayton44d93782014-01-27 23:43:24 +00001114
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001115StreamSP
1116Debugger::GetAsyncOutputStream ()
1117{
1118 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1119 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
1120}
1121
1122StreamSP
1123Debugger::GetAsyncErrorStream ()
1124{
1125 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1126 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
1127}
1128
Greg Claytonc7bece562013-01-25 18:06:21 +00001129size_t
Enrico Granata061858c2012-02-15 02:34:21 +00001130Debugger::GetNumDebuggers()
1131{
Greg Claytonc15f55e2012-03-30 20:53:46 +00001132 if (g_shared_debugger_refcount > 0)
1133 {
1134 Mutex::Locker locker (GetDebuggerListMutex ());
1135 return GetDebuggerList().size();
1136 }
1137 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +00001138}
1139
1140lldb::DebuggerSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001141Debugger::GetDebuggerAtIndex (size_t index)
Enrico Granata061858c2012-02-15 02:34:21 +00001142{
1143 DebuggerSP debugger_sp;
1144
Greg Claytonc15f55e2012-03-30 20:53:46 +00001145 if (g_shared_debugger_refcount > 0)
1146 {
1147 Mutex::Locker locker (GetDebuggerListMutex ());
1148 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +00001149
Greg Claytonc15f55e2012-03-30 20:53:46 +00001150 if (index < debugger_list.size())
1151 debugger_sp = debugger_list[index];
1152 }
1153
Enrico Granata061858c2012-02-15 02:34:21 +00001154 return debugger_sp;
1155}
1156
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001157DebuggerSP
1158Debugger::FindDebuggerWithID (lldb::user_id_t id)
1159{
Greg Clayton4d122c42011-09-17 08:33:22 +00001160 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001161
Greg Claytonc15f55e2012-03-30 20:53:46 +00001162 if (g_shared_debugger_refcount > 0)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001163 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001164 Mutex::Locker locker (GetDebuggerListMutex ());
1165 DebuggerList &debugger_list = GetDebuggerList();
1166 DebuggerList::iterator pos, end = debugger_list.end();
1167 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001168 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001169 if ((*pos).get()->GetID() == id)
1170 {
1171 debugger_sp = *pos;
1172 break;
1173 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001174 }
1175 }
1176 return debugger_sp;
1177}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001178
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001179#if 0
Greg Clayton1b654882010-09-19 02:33:57 +00001180static void
Jason Molendab57e4a12013-11-04 09:33:30 +00001181TestPromptFormats (StackFrame *frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001182{
1183 if (frame == NULL)
1184 return;
1185
1186 StreamString s;
1187 const char *prompt_format =
1188 "{addr = '${addr}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001189 "{addr-file-or-load = '${addr-file-or-load}'\n}"
1190 "{current-pc-arrow = '${current-pc-arrow}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001191 "{process.id = '${process.id}'\n}"
1192 "{process.name = '${process.name}'\n}"
1193 "{process.file.basename = '${process.file.basename}'\n}"
1194 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1195 "{thread.id = '${thread.id}'\n}"
1196 "{thread.index = '${thread.index}'\n}"
1197 "{thread.name = '${thread.name}'\n}"
1198 "{thread.queue = '${thread.queue}'\n}"
1199 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1200 "{target.arch = '${target.arch}'\n}"
1201 "{module.file.basename = '${module.file.basename}'\n}"
1202 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1203 "{file.basename = '${file.basename}'\n}"
1204 "{file.fullpath = '${file.fullpath}'\n}"
1205 "{frame.index = '${frame.index}'\n}"
1206 "{frame.pc = '${frame.pc}'\n}"
1207 "{frame.sp = '${frame.sp}'\n}"
1208 "{frame.fp = '${frame.fp}'\n}"
1209 "{frame.flags = '${frame.flags}'\n}"
1210 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1211 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1212 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1213 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1214 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1215 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1216 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1217 "{function.id = '${function.id}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001218 "{function.changed = '${function.changed}'\n}"
1219 "{function.initial-function = '${function.initial-function}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001220 "{function.name = '${function.name}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001221 "{function.name-without-args = '${function.name-without-args}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +00001222 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001223 "{function.addr-offset = '${function.addr-offset}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001224 "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001225 "{function.line-offset = '${function.line-offset}'\n}"
1226 "{function.pc-offset = '${function.pc-offset}'\n}"
1227 "{line.file.basename = '${line.file.basename}'\n}"
1228 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1229 "{line.number = '${line.number}'\n}"
1230 "{line.start-addr = '${line.start-addr}'\n}"
1231 "{line.end-addr = '${line.end-addr}'\n}"
1232;
1233
1234 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1235 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +00001236 frame->CalculateExecutionContext(exe_ctx);
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001237 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
Greg Clayton1b654882010-09-19 02:33:57 +00001238 {
1239 printf("%s\n", s.GetData());
1240 }
1241 else
1242 {
Greg Clayton1b654882010-09-19 02:33:57 +00001243 printf ("what we got: %s\n", s.GetData());
1244 }
1245}
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001246#endif
Greg Clayton1b654882010-09-19 02:33:57 +00001247
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001248bool
Greg Clayton554f68d2015-02-04 22:00:53 +00001249Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
Jason Molendaaff1b352014-10-10 23:07:36 +00001250 const SymbolContext *sc,
1251 const SymbolContext *prev_sc,
1252 const ExecutionContext *exe_ctx,
1253 const Address *addr,
1254 Stream &s)
1255{
Greg Clayton554f68d2015-02-04 22:00:53 +00001256 FormatEntity::Entry format_entry;
1257
1258 if (format == NULL)
Jason Molendaaff1b352014-10-10 23:07:36 +00001259 {
Greg Clayton554f68d2015-02-04 22:00:53 +00001260 if (exe_ctx != NULL && exe_ctx->HasTargetScope())
1261 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1262 if (format == NULL)
1263 {
1264 FormatEntity::Parse("${addr}: ", format_entry);
1265 format = &format_entry;
1266 }
Jason Molendaaff1b352014-10-10 23:07:36 +00001267 }
1268 bool function_changed = false;
1269 bool initial_function = false;
1270 if (prev_sc && (prev_sc->function || prev_sc->symbol))
1271 {
1272 if (sc && (sc->function || sc->symbol))
1273 {
1274 if (prev_sc->symbol && sc->symbol)
1275 {
1276 if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType()))
1277 {
1278 function_changed = true;
1279 }
1280 }
1281 else if (prev_sc->function && sc->function)
1282 {
1283 if (prev_sc->function->GetMangled() != sc->function->GetMangled())
1284 {
1285 function_changed = true;
1286 }
1287 }
1288 }
1289 }
1290 // The first context on a list of instructions will have a prev_sc that
1291 // has no Function or Symbol -- if SymbolContext had an IsValid() method, it
1292 // would return false. But we do get a prev_sc pointer.
1293 if ((sc && (sc->function || sc->symbol))
1294 && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL))
1295 {
1296 initial_function = true;
1297 }
Greg Clayton554f68d2015-02-04 22:00:53 +00001298 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, NULL, function_changed, initial_function);
Jason Molendaaff1b352014-10-10 23:07:36 +00001299}
1300
1301
Jim Ingham228063c2012-02-21 02:23:08 +00001302void
1303Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1304{
Jim Ingham4f02b222012-02-22 22:49:20 +00001305 // For simplicity's sake, I am not going to deal with how to close down any
1306 // open logging streams, I just redirect everything from here on out to the
1307 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00001308 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
1309}
1310
1311bool
1312Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
1313{
1314 Log::Callbacks log_callbacks;
1315
1316 StreamSP log_stream_sp;
Sean Callanan9a028512012-08-09 00:50:26 +00001317 if (m_log_callback_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001318 {
1319 log_stream_sp = m_log_callback_stream_sp;
1320 // For now when using the callback mode you always get thread & timestamp.
1321 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1322 }
1323 else if (log_file == NULL || *log_file == '\0')
1324 {
Greg Clayton44d93782014-01-27 23:43:24 +00001325 log_stream_sp = GetOutputFile();
Jim Ingham228063c2012-02-21 02:23:08 +00001326 }
1327 else
1328 {
1329 LogStreamMap::iterator pos = m_log_streams.find(log_file);
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001330 if (pos != m_log_streams.end())
1331 log_stream_sp = pos->second.lock();
1332 if (!log_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001333 {
1334 log_stream_sp.reset (new StreamFile (log_file));
1335 m_log_streams[log_file] = log_stream_sp;
1336 }
Jim Ingham228063c2012-02-21 02:23:08 +00001337 }
1338 assert (log_stream_sp.get());
1339
1340 if (log_options == 0)
1341 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
1342
Greg Clayton57abc5d2013-05-10 21:47:16 +00001343 if (Log::GetLogChannelCallbacks (ConstString(channel), log_callbacks))
Jim Ingham228063c2012-02-21 02:23:08 +00001344 {
1345 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
1346 return true;
1347 }
1348 else
1349 {
1350 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
1351 if (log_channel_sp)
1352 {
1353 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
1354 {
1355 return true;
1356 }
1357 else
1358 {
1359 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
1360 return false;
1361 }
1362 }
1363 else
1364 {
1365 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
1366 return false;
1367 }
1368 }
1369 return false;
1370}
1371
Greg Clayton9585fbf2013-03-19 00:20:55 +00001372SourceManager &
1373Debugger::GetSourceManager ()
1374{
1375 if (m_source_manager_ap.get() == NULL)
1376 m_source_manager_ap.reset (new SourceManager (shared_from_this()));
1377 return *m_source_manager_ap;
1378}
1379
1380
Greg Clayton44d93782014-01-27 23:43:24 +00001381
1382// This function handles events that were broadcast by the process.
1383void
1384Debugger::HandleBreakpointEvent (const EventSP &event_sp)
1385{
1386 using namespace lldb;
1387 const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp);
1388
1389// if (event_type & eBreakpointEventTypeAdded
1390// || event_type & eBreakpointEventTypeRemoved
1391// || event_type & eBreakpointEventTypeEnabled
1392// || event_type & eBreakpointEventTypeDisabled
1393// || event_type & eBreakpointEventTypeCommandChanged
1394// || event_type & eBreakpointEventTypeConditionChanged
1395// || event_type & eBreakpointEventTypeIgnoreChanged
1396// || event_type & eBreakpointEventTypeLocationsResolved)
1397// {
1398// // Don't do anything about these events, since the breakpoint commands already echo these actions.
1399// }
1400//
1401 if (event_type & eBreakpointEventTypeLocationsAdded)
1402 {
1403 uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp);
1404 if (num_new_locations > 0)
1405 {
1406 BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
1407 StreamFileSP output_sp (GetOutputFile());
1408 if (output_sp)
1409 {
1410 output_sp->Printf("%d location%s added to breakpoint %d\n",
1411 num_new_locations,
1412 num_new_locations == 1 ? "" : "s",
1413 breakpoint->GetID());
1414 RefreshTopIOHandler();
1415 }
1416 }
1417 }
1418// else if (event_type & eBreakpointEventTypeLocationsRemoved)
1419// {
1420// // These locations just get disabled, not sure it is worth spamming folks about this on the command line.
1421// }
1422// else if (event_type & eBreakpointEventTypeLocationsResolved)
1423// {
1424// // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy.
1425// }
1426}
1427
1428size_t
1429Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
1430{
1431 size_t total_bytes = 0;
1432 if (stream == NULL)
1433 stream = GetOutputFile().get();
1434
1435 if (stream)
1436 {
1437 // The process has stuff waiting for stdout; get it and write it out to the appropriate place.
1438 if (process == NULL)
1439 {
1440 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1441 if (target_sp)
1442 process = target_sp->GetProcessSP().get();
1443 }
1444 if (process)
1445 {
1446 Error error;
1447 size_t len;
1448 char stdio_buffer[1024];
1449 while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1450 {
1451 stream->Write(stdio_buffer, len);
1452 total_bytes += len;
1453 }
1454 }
1455 stream->Flush();
1456 }
1457 return total_bytes;
1458}
1459
1460size_t
1461Debugger::GetProcessSTDERR (Process *process, Stream *stream)
1462{
1463 size_t total_bytes = 0;
1464 if (stream == NULL)
1465 stream = GetOutputFile().get();
1466
1467 if (stream)
1468 {
1469 // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
1470 if (process == NULL)
1471 {
1472 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1473 if (target_sp)
1474 process = target_sp->GetProcessSP().get();
1475 }
1476 if (process)
1477 {
1478 Error error;
1479 size_t len;
1480 char stdio_buffer[1024];
1481 while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1482 {
1483 stream->Write(stdio_buffer, len);
1484 total_bytes += len;
1485 }
1486 }
1487 stream->Flush();
1488 }
1489 return total_bytes;
1490}
1491
Greg Claytondc6224e2014-10-21 01:00:42 +00001492
Greg Clayton44d93782014-01-27 23:43:24 +00001493// This function handles events that were broadcast by the process.
1494void
1495Debugger::HandleProcessEvent (const EventSP &event_sp)
1496{
1497 using namespace lldb;
1498 const uint32_t event_type = event_sp->GetType();
1499 ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
Greg Claytondc6224e2014-10-21 01:00:42 +00001500
Greg Claytonb4874f12014-02-28 18:22:24 +00001501 StreamString output_stream;
1502 StreamString error_stream;
Greg Clayton44d93782014-01-27 23:43:24 +00001503 const bool gui_enabled = IsForwardingEvents();
Greg Clayton44d93782014-01-27 23:43:24 +00001504
Greg Claytonb4874f12014-02-28 18:22:24 +00001505 if (!gui_enabled)
1506 {
1507 bool pop_process_io_handler = false;
1508 assert (process_sp);
Greg Claytondc6224e2014-10-21 01:00:42 +00001509
Greg Claytonb4874f12014-02-28 18:22:24 +00001510 if (event_type & Process::eBroadcastBitSTDOUT || event_type & Process::eBroadcastBitStateChanged)
Greg Clayton44d93782014-01-27 23:43:24 +00001511 {
Greg Claytonb4874f12014-02-28 18:22:24 +00001512 GetProcessSTDOUT (process_sp.get(), &output_stream);
1513 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001514
Greg Claytonb4874f12014-02-28 18:22:24 +00001515 if (event_type & Process::eBroadcastBitSTDERR || event_type & Process::eBroadcastBitStateChanged)
1516 {
1517 GetProcessSTDERR (process_sp.get(), &error_stream);
1518 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001519
Greg Claytonb4874f12014-02-28 18:22:24 +00001520 if (event_type & Process::eBroadcastBitStateChanged)
1521 {
Greg Claytondc6224e2014-10-21 01:00:42 +00001522 Process::HandleProcessStateChangedEvent (event_sp, &output_stream, pop_process_io_handler);
Greg Clayton44d93782014-01-27 23:43:24 +00001523 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001524
Greg Claytonb4874f12014-02-28 18:22:24 +00001525 if (output_stream.GetSize() || error_stream.GetSize())
1526 {
1527 StreamFileSP error_stream_sp (GetOutputFile());
Greg Clayton6fea17e2014-03-03 19:15:20 +00001528 bool top_io_handler_hid = false;
Greg Claytondc6224e2014-10-21 01:00:42 +00001529
Greg Clayton6fea17e2014-03-03 19:15:20 +00001530 if (process_sp->ProcessIOHandlerIsActive() == false)
1531 top_io_handler_hid = HideTopIOHandler();
Greg Claytonb4874f12014-02-28 18:22:24 +00001532
1533 if (output_stream.GetSize())
1534 {
1535 StreamFileSP output_stream_sp (GetOutputFile());
1536 if (output_stream_sp)
1537 output_stream_sp->Write (output_stream.GetData(), output_stream.GetSize());
1538 }
1539
1540 if (error_stream.GetSize())
1541 {
1542 StreamFileSP error_stream_sp (GetErrorFile());
1543 if (error_stream_sp)
1544 error_stream_sp->Write (error_stream.GetData(), error_stream.GetSize());
1545 }
1546
1547 if (top_io_handler_hid)
1548 RefreshTopIOHandler();
1549 }
1550
1551 if (pop_process_io_handler)
1552 process_sp->PopProcessIOHandler();
1553 }
Greg Clayton44d93782014-01-27 23:43:24 +00001554}
1555
1556void
1557Debugger::HandleThreadEvent (const EventSP &event_sp)
1558{
1559 // At present the only thread event we handle is the Frame Changed event,
1560 // and all we do for that is just reprint the thread status for that thread.
1561 using namespace lldb;
1562 const uint32_t event_type = event_sp->GetType();
1563 if (event_type == Thread::eBroadcastBitStackChanged ||
1564 event_type == Thread::eBroadcastBitThreadSelected )
1565 {
1566 ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get()));
1567 if (thread_sp)
1568 {
1569 HideTopIOHandler();
1570 StreamFileSP stream_sp (GetOutputFile());
1571 thread_sp->GetStatus(*stream_sp, 0, 1, 1);
1572 RefreshTopIOHandler();
1573 }
1574 }
1575}
1576
1577bool
1578Debugger::IsForwardingEvents ()
1579{
1580 return (bool)m_forward_listener_sp;
1581}
1582
1583void
1584Debugger::EnableForwardEvents (const ListenerSP &listener_sp)
1585{
1586 m_forward_listener_sp = listener_sp;
1587}
1588
1589void
1590Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
1591{
1592 m_forward_listener_sp.reset();
1593}
1594
1595
1596void
1597Debugger::DefaultEventHandler()
1598{
1599 Listener& listener(GetListener());
1600 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1601 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1602 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1603 BroadcastEventSpec target_event_spec (broadcaster_class_target,
1604 Target::eBroadcastBitBreakpointChanged);
1605
1606 BroadcastEventSpec process_event_spec (broadcaster_class_process,
1607 Process::eBroadcastBitStateChanged |
1608 Process::eBroadcastBitSTDOUT |
1609 Process::eBroadcastBitSTDERR);
1610
1611 BroadcastEventSpec thread_event_spec (broadcaster_class_thread,
1612 Thread::eBroadcastBitStackChanged |
1613 Thread::eBroadcastBitThreadSelected );
1614
1615 listener.StartListeningForEventSpec (*this, target_event_spec);
1616 listener.StartListeningForEventSpec (*this, process_event_spec);
1617 listener.StartListeningForEventSpec (*this, thread_event_spec);
1618 listener.StartListeningForEvents (m_command_interpreter_ap.get(),
1619 CommandInterpreter::eBroadcastBitQuitCommandReceived |
1620 CommandInterpreter::eBroadcastBitAsynchronousOutputData |
1621 CommandInterpreter::eBroadcastBitAsynchronousErrorData );
Greg Claytonafa91e332014-12-01 22:41:27 +00001622
1623 // Let the thread that spawned us know that we have started up and
1624 // that we are now listening to all required events so no events get missed
1625 m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
1626
Greg Clayton44d93782014-01-27 23:43:24 +00001627 bool done = false;
1628 while (!done)
1629 {
Greg Clayton44d93782014-01-27 23:43:24 +00001630 EventSP event_sp;
1631 if (listener.WaitForEvent(NULL, event_sp))
1632 {
1633 if (event_sp)
1634 {
1635 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1636 if (broadcaster)
1637 {
1638 uint32_t event_type = event_sp->GetType();
1639 ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
1640 if (broadcaster_class == broadcaster_class_process)
1641 {
1642 HandleProcessEvent (event_sp);
1643 }
1644 else if (broadcaster_class == broadcaster_class_target)
1645 {
1646 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get()))
1647 {
1648 HandleBreakpointEvent (event_sp);
1649 }
1650 }
1651 else if (broadcaster_class == broadcaster_class_thread)
1652 {
1653 HandleThreadEvent (event_sp);
1654 }
1655 else if (broadcaster == m_command_interpreter_ap.get())
1656 {
1657 if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived)
1658 {
1659 done = true;
1660 }
1661 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData)
1662 {
1663 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1664 if (data && data[0])
1665 {
1666 StreamFileSP error_sp (GetErrorFile());
1667 if (error_sp)
1668 {
1669 HideTopIOHandler();
1670 error_sp->PutCString(data);
1671 error_sp->Flush();
1672 RefreshTopIOHandler();
1673 }
1674 }
1675 }
1676 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData)
1677 {
1678 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1679 if (data && data[0])
1680 {
1681 StreamFileSP output_sp (GetOutputFile());
1682 if (output_sp)
1683 {
1684 HideTopIOHandler();
1685 output_sp->PutCString(data);
1686 output_sp->Flush();
1687 RefreshTopIOHandler();
1688 }
1689 }
1690 }
1691 }
1692 }
1693
1694 if (m_forward_listener_sp)
1695 m_forward_listener_sp->AddEvent(event_sp);
1696 }
1697 }
1698 }
1699}
1700
1701lldb::thread_result_t
1702Debugger::EventHandlerThread (lldb::thread_arg_t arg)
1703{
1704 ((Debugger *)arg)->DefaultEventHandler();
1705 return NULL;
1706}
1707
1708bool
1709Debugger::StartEventHandlerThread()
1710{
Zachary Turneracee96a2014-09-23 18:32:09 +00001711 if (!m_event_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001712 {
Greg Claytonafa91e332014-12-01 22:41:27 +00001713 // We must synchronize with the DefaultEventHandler() thread to ensure
1714 // it is up and running and listening to events before we return from
1715 // this function. We do this by listening to events for the
1716 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1717 Listener listener("lldb.debugger.event-handler");
1718 listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
1719
Zachary Turner7c2896a2014-10-24 22:06:29 +00001720 // Use larger 8MB stack for this thread
Greg Claytonafa91e332014-12-01 22:41:27 +00001721 m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread,
1722 this,
1723 NULL,
Zachary Turner7c2896a2014-10-24 22:06:29 +00001724 g_debugger_event_thread_stack_bytes);
Greg Claytonafa91e332014-12-01 22:41:27 +00001725
1726 // Make sure DefaultEventHandler() is running and listening to events before we return
1727 // from this function. We are only listening for events of type
1728 // eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
1729 // to wait an infinite amount of time for it (NULL timeout as the first parameter)
1730 lldb::EventSP event_sp;
1731 listener.WaitForEvent(NULL, event_sp);
Greg Clayton807b6b32014-10-15 18:03:59 +00001732 }
Zachary Turneracee96a2014-09-23 18:32:09 +00001733 return m_event_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001734}
1735
1736void
1737Debugger::StopEventHandlerThread()
1738{
Zachary Turneracee96a2014-09-23 18:32:09 +00001739 if (m_event_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001740 {
1741 GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
Zachary Turner39de3112014-09-09 20:54:56 +00001742 m_event_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001743 }
1744}
1745
1746
1747lldb::thread_result_t
1748Debugger::IOHandlerThread (lldb::thread_arg_t arg)
1749{
1750 Debugger *debugger = (Debugger *)arg;
Siva Chandra9aaab552015-02-26 19:26:36 +00001751 debugger->ExecuteIOHandlers();
Greg Clayton44d93782014-01-27 23:43:24 +00001752 debugger->StopEventHandlerThread();
1753 return NULL;
1754}
1755
1756bool
1757Debugger::StartIOHandlerThread()
1758{
Zachary Turneracee96a2014-09-23 18:32:09 +00001759 if (!m_io_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001760 m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
1761 IOHandlerThread,
1762 this,
1763 NULL,
1764 8*1024*1024); // Use larger 8MB stack for this thread
Zachary Turneracee96a2014-09-23 18:32:09 +00001765 return m_io_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001766}
1767
1768void
1769Debugger::StopIOHandlerThread()
1770{
Zachary Turneracee96a2014-09-23 18:32:09 +00001771 if (m_io_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001772 {
1773 if (m_input_file_sp)
1774 m_input_file_sp->GetFile().Close();
Zachary Turner39de3112014-09-09 20:54:56 +00001775 m_io_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001776 }
1777}
1778
Jim Ingham893c9322014-11-22 01:42:44 +00001779Target *
1780Debugger::GetDummyTarget()
1781{
1782 return m_target_list.GetDummyTarget (*this).get();
1783}
1784
1785Target *
Jim Ingham33df7cd2014-12-06 01:28:03 +00001786Debugger::GetSelectedOrDummyTarget(bool prefer_dummy)
Jim Ingham893c9322014-11-22 01:42:44 +00001787{
Jim Ingham33df7cd2014-12-06 01:28:03 +00001788 Target *target = nullptr;
1789 if (!prefer_dummy)
1790 {
1791 target = m_target_list.GetSelectedTarget().get();
1792 if (target)
1793 return target;
1794 }
1795
Jim Ingham893c9322014-11-22 01:42:44 +00001796 return GetDummyTarget();
1797}
Greg Clayton44d93782014-01-27 23:43:24 +00001798