blob: 9591fc9843d8ca207987cfb380619f2aa545bbc1 [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
Greg Clayton4a33d312011-06-23 17:59:56 +000010#include "lldb/Core/Debugger.h"
11
12#include <map>
13
Enrico Granata4becb372011-06-29 22:27:15 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Type.h"
Jason Molenda705b1802014-06-13 02:37:02 +000016#include "llvm/ADT/StringRef.h"
Enrico Granata4becb372011-06-29 22:27:15 +000017
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/lldb-private.h"
Greg Clayton554f68d2015-02-04 22:00:53 +000019#include "lldb/Core/FormatEntity.h"
Greg Clayton1f746072012-08-29 21:13:06 +000020#include "lldb/Core/Module.h"
Jim Ingham0d5a2bd2015-09-03 01:40:51 +000021#include "lldb/Core/PluginInterface.h"
Greg Claytone8cd0c92012-10-19 18:02:49 +000022#include "lldb/Core/PluginManager.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000023#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000025#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000026#include "lldb/Core/StreamCallback.h"
Greg Clayton44d93782014-01-27 23:43:24 +000027#include "lldb/Core/StreamFile.h"
Greg Clayton1b654882010-09-19 02:33:57 +000028#include "lldb/Core/StreamString.h"
Jason Molenda705b1802014-06-13 02:37:02 +000029#include "lldb/Core/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000031#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000032#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000033#include "lldb/DataFormatters/DataVisualization.h"
34#include "lldb/DataFormatters/FormatManager.h"
Enrico Granata894f7352014-03-25 22:03:52 +000035#include "lldb/DataFormatters/TypeSummary.h"
Zachary Turner93a66fc2014-10-06 21:22:36 +000036#include "lldb/Host/ConnectionFileDescriptor.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000037#include "lldb/Host/HostInfo.h"
Greg Claytona3406612011-02-07 23:24:47 +000038#include "lldb/Host/Terminal.h"
Zachary Turner39de3112014-09-09 20:54:56 +000039#include "lldb/Host/ThreadLauncher.h"
Greg Clayton66111032010-06-23 01:19:29 +000040#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turner633a29c2015-03-04 01:58:01 +000041#include "lldb/Interpreter/OptionValueProperties.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000042#include "lldb/Interpreter/OptionValueSInt64.h"
43#include "lldb/Interpreter/OptionValueString.h"
Greg Clayton1f746072012-08-29 21:13:06 +000044#include "lldb/Symbol/ClangASTContext.h"
45#include "lldb/Symbol/CompileUnit.h"
46#include "lldb/Symbol/Function.h"
47#include "lldb/Symbol/Symbol.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000048#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Target/TargetList.h"
50#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000051#include "lldb/Target/RegisterContext.h"
Greg Clayton5fb8f792013-12-02 19:35:49 +000052#include "lldb/Target/SectionLoadList.h"
Greg Clayton1b654882010-09-19 02:33:57 +000053#include "lldb/Target/StopInfo.h"
Enrico Granata84a53df2013-05-20 22:29:23 +000054#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000056#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
Zachary Turner58a559c2014-08-27 20:15:09 +000058#include "llvm/Support/DynamicLibrary.h"
59
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060using namespace lldb;
61using namespace lldb_private;
62
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
Caroline Ticeebc1bb22010-06-30 16:22:25 +000064static lldb::user_id_t g_unique_id = 1;
Zachary Turner7c2896a2014-10-24 22:06:29 +000065static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000066
Greg Clayton1b654882010-09-19 02:33:57 +000067#pragma mark Static Functions
68
69static Mutex &
70GetDebuggerListMutex ()
71{
72 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
73 return g_mutex;
74}
75
76typedef std::vector<DebuggerSP> DebuggerList;
77
78static DebuggerList &
79GetDebuggerList()
80{
81 // hide the static debugger list inside a singleton accessor to avoid
Bruce Mitchener6a7f3332014-06-27 02:42:12 +000082 // global init constructors
Greg Clayton1b654882010-09-19 02:33:57 +000083 static DebuggerList g_list;
84 return g_list;
85}
Greg Claytone372b982011-11-21 21:44:34 +000086
87OptionEnumValueElement
Greg Clayton67cc0632012-08-22 17:17:09 +000088g_show_disassembly_enum_values[] =
Greg Claytone372b982011-11-21 21:44:34 +000089{
Greg Clayton67cc0632012-08-22 17:17:09 +000090 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
91 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
92 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
Greg Claytone372b982011-11-21 21:44:34 +000093 { 0, NULL, NULL }
94};
95
Greg Clayton67cc0632012-08-22 17:17:09 +000096OptionEnumValueElement
97g_language_enumerators[] =
98{
99 { eScriptLanguageNone, "none", "Disable scripting languages."},
100 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
101 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
Greg Claytona12993c2012-09-13 23:03:20 +0000102 { 0, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000103};
Greg Claytone372b982011-11-21 21:44:34 +0000104
Greg Clayton67cc0632012-08-22 17:17:09 +0000105#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
106#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Jason Molenda6ab659a2015-07-29 00:42:47 +0000107#define IS_OPTIMIZED "{${function.is-optimized} [opt]}"
Greg Clayton67cc0632012-08-22 17:17:09 +0000108
Michael Sartain0769b2b2013-07-30 16:44:36 +0000109#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000110 "{, ${frame.pc}}"\
111 MODULE_WITH_FUNC\
112 FILE_AND_LINE\
Michael Sartain0769b2b2013-07-30 16:44:36 +0000113 "{, name = '${thread.name}'}"\
114 "{, queue = '${thread.queue}'}"\
Jason Molenda705b1802014-06-13 02:37:02 +0000115 "{, activity = '${thread.info.activity.name}'}" \
116 "{, ${thread.info.trace_messages} messages}" \
Greg Clayton67cc0632012-08-22 17:17:09 +0000117 "{, stop reason = ${thread.stop-reason}}"\
118 "{\\nReturn value: ${thread.return-value}}"\
Jim Ingham30fadaf2014-07-08 01:07:32 +0000119 "{\\nCompleted expression: ${thread.completed-expression}}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000120 "\\n"
121
122#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
123 MODULE_WITH_FUNC\
124 FILE_AND_LINE\
Jason Molenda6ab659a2015-07-29 00:42:47 +0000125 IS_OPTIMIZED\
Greg Clayton67cc0632012-08-22 17:17:09 +0000126 "\\n"
127
Jason Molendac980fa92015-02-13 23:24:21 +0000128// Three parts to this disassembly format specification:
129// 1. If this is a new function/symbol (no previous symbol/function), print
130// dylib`funcname:\n
131// 2. If this is a symbol context change (different from previous symbol/function), print
132// dylib`funcname:\n
133// 3. print
134// address <+offset>:
135#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}>}: "
136
137// gdb's disassembly format can be emulated with
138// ${current-pc-arrow}${addr-file-or-load}{ <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>}:
139
140// lldb's original format for disassembly would look like this format string -
141// {${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}}:
142
Greg Clayton67cc0632012-08-22 17:17:09 +0000143
Greg Clayton754a9362012-08-23 00:22:02 +0000144static PropertyDefinition
145g_properties[] =
Greg Clayton67cc0632012-08-22 17:17:09 +0000146{
Greg Clayton554f68d2015-02-04 22:00:53 +0000147{ "auto-confirm", OptionValue::eTypeBoolean , true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
148{ "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, NULL, "The default disassembly format string to use when disassembling instruction sequences." },
149{ "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
150{ "notify-void", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
151{ "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
152{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
153{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
154{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
155{ "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." },
156{ "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." },
157{ "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
158{ "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
159{ "use-external-editor", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Whether to use an external editor or not." },
160{ "use-color", OptionValue::eTypeBoolean , true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
161{ "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
162{ "escape-non-printables", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
163{ NULL, OptionValue::eTypeInvalid , true, 0 , NULL, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000164};
165
166enum
167{
168 ePropertyAutoConfirm = 0,
Jason Molendaaff1b352014-10-10 23:07:36 +0000169 ePropertyDisassemblyFormat,
Greg Clayton67cc0632012-08-22 17:17:09 +0000170 ePropertyFrameFormat,
171 ePropertyNotiftVoid,
172 ePropertyPrompt,
173 ePropertyScriptLanguage,
174 ePropertyStopDisassemblyCount,
175 ePropertyStopDisassemblyDisplay,
176 ePropertyStopLineCountAfter,
177 ePropertyStopLineCountBefore,
178 ePropertyTerminalWidth,
179 ePropertyThreadFormat,
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000180 ePropertyUseExternalEditor,
181 ePropertyUseColor,
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000182 ePropertyAutoOneLineSummaries,
183 ePropertyEscapeNonPrintables
Greg Clayton67cc0632012-08-22 17:17:09 +0000184};
185
Zachary Turner3a006912015-03-19 22:00:21 +0000186LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
Greg Clayton4c054102012-09-01 00:38:36 +0000187
188Error
189Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
190 VarSetOperationType op,
191 const char *property_path,
192 const char *value)
193{
Enrico Granata84a53df2013-05-20 22:29:23 +0000194 bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000195 bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0;
Enrico Granata84a53df2013-05-20 22:29:23 +0000196 TargetSP target_sp;
Enrico Granata397ddd52013-05-21 20:13:34 +0000197 LoadScriptFromSymFile load_script_old_value;
Enrico Granata84a53df2013-05-20 22:29:23 +0000198 if (is_load_script && exe_ctx->GetTargetSP())
199 {
200 target_sp = exe_ctx->GetTargetSP();
201 load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
202 }
Greg Clayton4c054102012-09-01 00:38:36 +0000203 Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value));
204 if (error.Success())
205 {
Enrico Granata84a53df2013-05-20 22:29:23 +0000206 // FIXME it would be nice to have "on-change" callbacks for properties
Greg Clayton4c054102012-09-01 00:38:36 +0000207 if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0)
208 {
209 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000210 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
211 if (str.length())
212 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000213 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton4c054102012-09-01 00:38:36 +0000214 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
215 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
216 }
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000217 else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0)
218 {
219 // use-color changed. Ping the prompt so it can reset the ansi terminal codes.
220 SetPrompt (GetPrompt());
221 }
Enrico Granata397ddd52013-05-21 20:13:34 +0000222 else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn)
Enrico Granata84a53df2013-05-20 22:29:23 +0000223 {
Enrico Granata397ddd52013-05-21 20:13:34 +0000224 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue)
Enrico Granata84a53df2013-05-20 22:29:23 +0000225 {
226 std::list<Error> errors;
Enrico Granata97303392013-05-21 00:00:30 +0000227 StreamString feedback_stream;
228 if (!target_sp->LoadScriptingResources(errors,&feedback_stream))
Enrico Granata84a53df2013-05-20 22:29:23 +0000229 {
Greg Clayton44d93782014-01-27 23:43:24 +0000230 StreamFileSP stream_sp (GetErrorFile());
231 if (stream_sp)
Enrico Granata84a53df2013-05-20 22:29:23 +0000232 {
Greg Clayton44d93782014-01-27 23:43:24 +0000233 for (auto error : errors)
234 {
235 stream_sp->Printf("%s\n",error.AsCString());
236 }
237 if (feedback_stream.GetSize())
238 stream_sp->Printf("%s",feedback_stream.GetData());
Enrico Granata84a53df2013-05-20 22:29:23 +0000239 }
240 }
241 }
242 }
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000243 else if (is_escape_non_printables)
244 {
245 DataVisualization::ForceUpdate();
246 }
Greg Clayton4c054102012-09-01 00:38:36 +0000247 }
248 return error;
249}
250
Greg Clayton67cc0632012-08-22 17:17:09 +0000251bool
252Debugger::GetAutoConfirm () const
253{
254 const uint32_t idx = ePropertyAutoConfirm;
Greg Clayton754a9362012-08-23 00:22:02 +0000255 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000256}
257
Greg Clayton554f68d2015-02-04 22:00:53 +0000258const FormatEntity::Entry *
Jason Molendaaff1b352014-10-10 23:07:36 +0000259Debugger::GetDisassemblyFormat() const
260{
261 const uint32_t idx = ePropertyDisassemblyFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000262 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Jason Molendaaff1b352014-10-10 23:07:36 +0000263}
264
Greg Clayton554f68d2015-02-04 22:00:53 +0000265const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000266Debugger::GetFrameFormat() const
267{
268 const uint32_t idx = ePropertyFrameFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000269 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000270}
271
272bool
273Debugger::GetNotifyVoid () const
274{
275 const uint32_t idx = ePropertyNotiftVoid;
Greg Clayton754a9362012-08-23 00:22:02 +0000276 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000277}
278
279const char *
280Debugger::GetPrompt() const
281{
282 const uint32_t idx = ePropertyPrompt;
Greg Clayton754a9362012-08-23 00:22:02 +0000283 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000284}
285
286void
287Debugger::SetPrompt(const char *p)
288{
289 const uint32_t idx = ePropertyPrompt;
290 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
291 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000292 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
293 if (str.length())
294 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000295 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton67cc0632012-08-22 17:17:09 +0000296}
297
Greg Clayton554f68d2015-02-04 22:00:53 +0000298const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000299Debugger::GetThreadFormat() const
300{
301 const uint32_t idx = ePropertyThreadFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000302 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000303}
304
305lldb::ScriptLanguage
306Debugger::GetScriptLanguage() const
307{
308 const uint32_t idx = ePropertyScriptLanguage;
Greg Clayton754a9362012-08-23 00:22:02 +0000309 return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000310}
311
312bool
313Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
314{
315 const uint32_t idx = ePropertyScriptLanguage;
316 return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
317}
318
319uint32_t
320Debugger::GetTerminalWidth () const
321{
322 const uint32_t idx = ePropertyTerminalWidth;
Greg Clayton754a9362012-08-23 00:22:02 +0000323 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000324}
325
326bool
327Debugger::SetTerminalWidth (uint32_t term_width)
328{
329 const uint32_t idx = ePropertyTerminalWidth;
330 return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
331}
332
333bool
334Debugger::GetUseExternalEditor () const
335{
336 const uint32_t idx = ePropertyUseExternalEditor;
Greg Clayton754a9362012-08-23 00:22:02 +0000337 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000338}
339
340bool
341Debugger::SetUseExternalEditor (bool b)
342{
343 const uint32_t idx = ePropertyUseExternalEditor;
344 return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
345}
346
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000347bool
348Debugger::GetUseColor () const
349{
350 const uint32_t idx = ePropertyUseColor;
351 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
352}
353
354bool
355Debugger::SetUseColor (bool b)
356{
357 const uint32_t idx = ePropertyUseColor;
358 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
359 SetPrompt (GetPrompt());
360 return ret;
361}
362
Greg Clayton67cc0632012-08-22 17:17:09 +0000363uint32_t
364Debugger::GetStopSourceLineCount (bool before) const
365{
366 const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
Greg Clayton754a9362012-08-23 00:22:02 +0000367 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000368}
369
370Debugger::StopDisassemblyType
371Debugger::GetStopDisassemblyDisplay () const
372{
373 const uint32_t idx = ePropertyStopDisassemblyDisplay;
Greg Clayton754a9362012-08-23 00:22:02 +0000374 return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000375}
376
377uint32_t
378Debugger::GetDisassemblyLineCount () const
379{
380 const uint32_t idx = ePropertyStopDisassemblyCount;
Greg Clayton754a9362012-08-23 00:22:02 +0000381 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000382}
Greg Claytone372b982011-11-21 21:44:34 +0000383
Enrico Granata553fad52013-10-25 23:09:40 +0000384bool
Enrico Granata90a8db32013-10-31 21:01:07 +0000385Debugger::GetAutoOneLineSummaries () const
Enrico Granata553fad52013-10-25 23:09:40 +0000386{
Enrico Granata90a8db32013-10-31 21:01:07 +0000387 const uint32_t idx = ePropertyAutoOneLineSummaries;
Enrico Granata553fad52013-10-25 23:09:40 +0000388 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000389}
Enrico Granata553fad52013-10-25 23:09:40 +0000390
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000391bool
392Debugger::GetEscapeNonPrintables () const
393{
394 const uint32_t idx = ePropertyEscapeNonPrintables;
395 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granata553fad52013-10-25 23:09:40 +0000396}
397
Greg Clayton1b654882010-09-19 02:33:57 +0000398#pragma mark Debugger
399
Greg Clayton67cc0632012-08-22 17:17:09 +0000400//const DebuggerPropertiesSP &
401//Debugger::GetSettings() const
402//{
403// return m_properties_sp;
404//}
405//
Greg Clayton99d0faf2010-11-18 23:32:35 +0000406
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000407static bool lldb_initialized = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408void
Zachary Turner3a006912015-03-19 22:00:21 +0000409Debugger::Initialize(LoadPluginCallbackType load_plugin_callback)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000411 assert(!lldb_initialized && "Debugger::Initialize called more than once!");
412
Robert Flackf196c932015-03-10 18:07:47 +0000413 lldb_initialized = true;
Greg Clayton5fb8f792013-12-02 19:35:49 +0000414 g_load_plugin_callback = load_plugin_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415}
416
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000417void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418Debugger::Terminate ()
419{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000420 assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!");
421
422 // Clear our master list of debugger objects
423 Mutex::Locker locker (GetDebuggerListMutex ());
424 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425}
426
Caroline Tice20bd37f2011-03-10 22:14:10 +0000427void
428Debugger::SettingsInitialize ()
429{
Greg Clayton6920b522012-08-22 18:39:03 +0000430 Target::SettingsInitialize ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000431}
432
433void
434Debugger::SettingsTerminate ()
435{
Greg Clayton6920b522012-08-22 18:39:03 +0000436 Target::SettingsTerminate ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000437}
438
Enrico Granata21dfcd92012-09-28 23:57:51 +0000439bool
Enrico Granatae743c782013-04-24 21:29:08 +0000440Debugger::LoadPlugin (const FileSpec& spec, Error& error)
Enrico Granata21dfcd92012-09-28 23:57:51 +0000441{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000442 if (g_load_plugin_callback)
Enrico Granatae743c782013-04-24 21:29:08 +0000443 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000444 llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error);
445 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +0000446 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000447 m_loaded_plugins.push_back(dynlib);
Greg Clayton5fb8f792013-12-02 19:35:49 +0000448 return true;
449 }
Enrico Granatae743c782013-04-24 21:29:08 +0000450 }
Greg Clayton5fb8f792013-12-02 19:35:49 +0000451 else
Enrico Granatae743c782013-04-24 21:29:08 +0000452 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000453 // The g_load_plugin_callback is registered in SBDebugger::Initialize()
454 // and if the public API layer isn't available (code is linking against
455 // all of the internal LLDB static libraries), then we can't load plugins
456 error.SetErrorString("Public API layer is not available");
Enrico Granatae743c782013-04-24 21:29:08 +0000457 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000458 return false;
459}
460
461static FileSpec::EnumerateDirectoryResult
462LoadPluginCallback
463(
464 void *baton,
465 FileSpec::FileType file_type,
466 const FileSpec &file_spec
467 )
468{
469 Error error;
470
471 static ConstString g_dylibext("dylib");
Michael Sartain3cf443d2013-07-17 00:26:30 +0000472 static ConstString g_solibext("so");
Enrico Granata21dfcd92012-09-28 23:57:51 +0000473
474 if (!baton)
475 return FileSpec::eEnumerateDirectoryResultQuit;
476
477 Debugger *debugger = (Debugger*)baton;
478
479 // If we have a regular file, a symbolic link or unknown file type, try
480 // and process the file. We must handle unknown as sometimes the directory
481 // enumeration might be enumerating a file system that doesn't have correct
482 // file type information.
483 if (file_type == FileSpec::eFileTypeRegular ||
484 file_type == FileSpec::eFileTypeSymbolicLink ||
485 file_type == FileSpec::eFileTypeUnknown )
486 {
487 FileSpec plugin_file_spec (file_spec);
488 plugin_file_spec.ResolvePath ();
489
Michael Sartain3cf443d2013-07-17 00:26:30 +0000490 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
491 plugin_file_spec.GetFileNameExtension() != g_solibext)
492 {
Enrico Granata21dfcd92012-09-28 23:57:51 +0000493 return FileSpec::eEnumerateDirectoryResultNext;
Michael Sartain3cf443d2013-07-17 00:26:30 +0000494 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000495
Enrico Granatae743c782013-04-24 21:29:08 +0000496 Error plugin_load_error;
497 debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000498
499 return FileSpec::eEnumerateDirectoryResultNext;
500 }
501
502 else if (file_type == FileSpec::eFileTypeUnknown ||
503 file_type == FileSpec::eFileTypeDirectory ||
504 file_type == FileSpec::eFileTypeSymbolicLink )
505 {
506 // Try and recurse into anything that a directory or symbolic link.
507 // We must also do this for unknown as sometimes the directory enumeration
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000508 // might be enumerating a file system that doesn't have correct file type
Enrico Granata21dfcd92012-09-28 23:57:51 +0000509 // information.
510 return FileSpec::eEnumerateDirectoryResultEnter;
511 }
512
513 return FileSpec::eEnumerateDirectoryResultNext;
514}
515
516void
517Debugger::InstanceInitialize ()
518{
519 FileSpec dir_spec;
520 const bool find_directories = true;
521 const bool find_files = true;
522 const bool find_other = true;
523 char dir_path[PATH_MAX];
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000524 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000525 {
526 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
527 {
528 FileSpec::EnumerateDirectory (dir_path,
529 find_directories,
530 find_files,
531 find_other,
532 LoadPluginCallback,
533 this);
534 }
535 }
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000536
537 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000538 {
539 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
540 {
541 FileSpec::EnumerateDirectory (dir_path,
542 find_directories,
543 find_files,
544 find_other,
545 LoadPluginCallback,
546 this);
547 }
548 }
Greg Claytone8cd0c92012-10-19 18:02:49 +0000549
550 PluginManager::DebuggerInitialize (*this);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000551}
552
Greg Clayton66111032010-06-23 01:19:29 +0000553DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000554Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000555{
Jim Ingham228063c2012-02-21 02:23:08 +0000556 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000557 if (lldb_initialized)
Greg Clayton66111032010-06-23 01:19:29 +0000558 {
559 Mutex::Locker locker (GetDebuggerListMutex ());
560 GetDebuggerList().push_back(debugger_sp);
561 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000562 debugger_sp->InstanceInitialize ();
Greg Clayton66111032010-06-23 01:19:29 +0000563 return debugger_sp;
564}
565
Caroline Ticee02657b2011-01-22 01:02:07 +0000566void
Greg Clayton4d122c42011-09-17 08:33:22 +0000567Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000568{
569 if (debugger_sp.get() == NULL)
570 return;
571
Jim Ingham8314c522011-09-15 21:36:42 +0000572 debugger_sp->Clear();
573
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000574 if (lldb_initialized)
Caroline Ticee02657b2011-01-22 01:02:07 +0000575 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000576 Mutex::Locker locker (GetDebuggerListMutex ());
577 DebuggerList &debugger_list = GetDebuggerList ();
578 DebuggerList::iterator pos, end = debugger_list.end();
579 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000580 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000581 if ((*pos).get() == debugger_sp.get())
582 {
583 debugger_list.erase (pos);
584 return;
585 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000586 }
587 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000588}
589
Greg Clayton4d122c42011-09-17 08:33:22 +0000590DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000591Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
592{
Greg Clayton4d122c42011-09-17 08:33:22 +0000593 DebuggerSP debugger_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000594 if (lldb_initialized)
Greg Clayton6920b522012-08-22 18:39:03 +0000595 {
596 Mutex::Locker locker (GetDebuggerListMutex ());
597 DebuggerList &debugger_list = GetDebuggerList();
598 DebuggerList::iterator pos, end = debugger_list.end();
599
600 for (pos = debugger_list.begin(); pos != end; ++pos)
601 {
602 if ((*pos).get()->m_instance_name == instance_name)
603 {
604 debugger_sp = *pos;
605 break;
606 }
607 }
608 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000609 return debugger_sp;
610}
Greg Clayton66111032010-06-23 01:19:29 +0000611
612TargetSP
613Debugger::FindTargetWithProcessID (lldb::pid_t pid)
614{
Greg Clayton4d122c42011-09-17 08:33:22 +0000615 TargetSP target_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000616 if (lldb_initialized)
Greg Clayton66111032010-06-23 01:19:29 +0000617 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000618 Mutex::Locker locker (GetDebuggerListMutex ());
619 DebuggerList &debugger_list = GetDebuggerList();
620 DebuggerList::iterator pos, end = debugger_list.end();
621 for (pos = debugger_list.begin(); pos != end; ++pos)
622 {
623 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
624 if (target_sp)
625 break;
626 }
Greg Clayton66111032010-06-23 01:19:29 +0000627 }
628 return target_sp;
629}
630
Greg Claytone4e45922011-11-16 05:37:56 +0000631TargetSP
632Debugger::FindTargetWithProcess (Process *process)
633{
634 TargetSP target_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000635 if (lldb_initialized)
Greg Claytone4e45922011-11-16 05:37:56 +0000636 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000637 Mutex::Locker locker (GetDebuggerListMutex ());
638 DebuggerList &debugger_list = GetDebuggerList();
639 DebuggerList::iterator pos, end = debugger_list.end();
640 for (pos = debugger_list.begin(); pos != end; ++pos)
641 {
642 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
643 if (target_sp)
644 break;
645 }
Greg Claytone4e45922011-11-16 05:37:56 +0000646 }
647 return target_sp;
648}
649
Jason Molendae6481c72014-09-12 01:50:46 +0000650Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
651 UserID(g_unique_id++),
652 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
653 m_input_file_sp(new StreamFile(stdin, false)),
654 m_output_file_sp(new StreamFile(stdout, false)),
655 m_error_file_sp(new StreamFile(stderr, false)),
656 m_terminal_state(),
657 m_target_list(*this),
658 m_platform_list(),
659 m_listener("lldb.Debugger"),
660 m_source_manager_ap(),
661 m_source_file_cache(),
662 m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)),
663 m_input_reader_stack(),
664 m_instance_name(),
Greg Claytonafa91e332014-12-01 22:41:27 +0000665 m_loaded_plugins(),
666 m_event_handler_thread (),
667 m_io_handler_thread (),
668 m_sync_broadcaster (NULL, "lldb.debugger.sync")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669{
Greg Clayton67cc0632012-08-22 17:17:09 +0000670 char instance_cstr[256];
671 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
672 m_instance_name.SetCString(instance_cstr);
Jim Ingham228063c2012-02-21 02:23:08 +0000673 if (log_callback)
674 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000675 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000676 // Always add our default platform to the platform list
Greg Clayton615eb7e2014-09-19 20:11:50 +0000677 PlatformSP default_platform_sp (Platform::GetHostPlatform());
Greg Claytonded470d2011-03-19 01:12:21 +0000678 assert (default_platform_sp.get());
679 m_platform_list.Append (default_platform_sp, true);
Greg Clayton67cc0632012-08-22 17:17:09 +0000680
Greg Clayton754a9362012-08-23 00:22:02 +0000681 m_collection_sp->Initialize (g_properties);
Greg Clayton67cc0632012-08-22 17:17:09 +0000682 m_collection_sp->AppendProperty (ConstString("target"),
683 ConstString("Settings specify to debugging targets."),
684 true,
685 Target::GetGlobalProperties()->GetValueProperties());
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000686 m_collection_sp->AppendProperty (ConstString("platform"),
687 ConstString("Platform settings."),
688 true,
689 Platform::GetGlobalPlatformProperties()->GetValueProperties());
Greg Clayton754a9362012-08-23 00:22:02 +0000690 if (m_command_interpreter_ap.get())
691 {
692 m_collection_sp->AppendProperty (ConstString("interpreter"),
693 ConstString("Settings specify to the debugger's command interpreter."),
694 true,
695 m_command_interpreter_ap->GetValueProperties());
696 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000697 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
698 term_width->SetMinimumValue(10);
699 term_width->SetMaximumValue(1024);
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000700
701 // Turn off use-color if this is a dumb terminal.
702 const char *term = getenv ("TERM");
703 if (term && !strcmp (term, "dumb"))
704 SetUseColor (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705}
706
707Debugger::~Debugger ()
708{
Jim Ingham8314c522011-09-15 21:36:42 +0000709 Clear();
710}
711
712void
713Debugger::Clear()
714{
Greg Clayton44d93782014-01-27 23:43:24 +0000715 ClearIOHandlers();
716 StopIOHandlerThread();
717 StopEventHandlerThread();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000718 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000719 int num_targets = m_target_list.GetNumTargets();
720 for (int i = 0; i < num_targets; i++)
721 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000722 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
723 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000724 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000725 ProcessSP process_sp (target_sp->GetProcessSP());
726 if (process_sp)
Jim Ingham1fd07052013-02-27 19:13:05 +0000727 process_sp->Finalize();
Greg Claytonccbc08e2012-01-14 17:04:19 +0000728 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000729 }
Greg Clayton66111032010-06-23 01:19:29 +0000730 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000731 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000732
733 // Close the input file _before_ we close the input read communications class
734 // as it does NOT own the input file, our m_input_file does.
Jim Inghamc5917d92012-11-30 20:23:19 +0000735 m_terminal_state.Clear();
Greg Clayton44d93782014-01-27 23:43:24 +0000736 if (m_input_file_sp)
737 m_input_file_sp->GetFile().Close ();
Greg Clayton0c4129f2014-04-25 00:35:14 +0000738
739 m_command_interpreter_ap->Clear();
Jim Ingham8314c522011-09-15 21:36:42 +0000740}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741
742bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000743Debugger::GetCloseInputOnEOF () const
744{
Greg Clayton44d93782014-01-27 23:43:24 +0000745// return m_input_comm.GetCloseOnEOF();
746 return false;
Greg Claytonfc3f0272011-05-29 04:06:55 +0000747}
748
749void
750Debugger::SetCloseInputOnEOF (bool b)
751{
Greg Clayton44d93782014-01-27 23:43:24 +0000752// m_input_comm.SetCloseOnEOF(b);
Greg Claytonfc3f0272011-05-29 04:06:55 +0000753}
754
755bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756Debugger::GetAsyncExecution ()
757{
Greg Clayton66111032010-06-23 01:19:29 +0000758 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759}
760
761void
762Debugger::SetAsyncExecution (bool async_execution)
763{
Greg Clayton66111032010-06-23 01:19:29 +0000764 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765}
766
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767
768void
769Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
770{
Greg Clayton44d93782014-01-27 23:43:24 +0000771 if (m_input_file_sp)
772 m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership);
773 else
774 m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
775
776 File &in_file = m_input_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000777 if (in_file.IsValid() == false)
778 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779
Jim Inghamc5917d92012-11-30 20:23:19 +0000780 // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
781 SaveInputTerminalState ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000782}
783
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784void
785Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
786{
Greg Clayton44d93782014-01-27 23:43:24 +0000787 if (m_output_file_sp)
788 m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership);
789 else
790 m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
791
792 File &out_file = m_output_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000793 if (out_file.IsValid() == false)
794 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000795
Enrico Granatab5887262012-10-29 21:18:03 +0000796 // do not create the ScriptInterpreter just for setting the output file handle
797 // as the constructor will know how to do the right thing on its own
798 const bool can_create = false;
799 ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create);
800 if (script_interpreter)
801 script_interpreter->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802}
803
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804void
805Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
806{
Greg Clayton44d93782014-01-27 23:43:24 +0000807 if (m_error_file_sp)
808 m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership);
809 else
810 m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
811
812 File &err_file = m_error_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000813 if (err_file.IsValid() == false)
814 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815}
816
Jim Inghamc5917d92012-11-30 20:23:19 +0000817void
818Debugger::SaveInputTerminalState ()
819{
Greg Clayton44d93782014-01-27 23:43:24 +0000820 if (m_input_file_sp)
821 {
822 File &in_file = m_input_file_sp->GetFile();
823 if (in_file.GetDescriptor() != File::kInvalidDescriptor)
824 m_terminal_state.Save(in_file.GetDescriptor(), true);
825 }
Jim Inghamc5917d92012-11-30 20:23:19 +0000826}
827
828void
829Debugger::RestoreInputTerminalState ()
830{
831 m_terminal_state.Restore();
832}
833
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000835Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000836{
837 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000838 TargetSP target_sp(GetSelectedTarget());
839 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840
841 if (target_sp)
842 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000843 ProcessSP process_sp (target_sp->GetProcessSP());
844 exe_ctx.SetProcessSP (process_sp);
845 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000847 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
848 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000850 exe_ctx.SetThreadSP (thread_sp);
851 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
852 if (exe_ctx.GetFramePtr() == NULL)
853 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854 }
855 }
856 }
857 return exe_ctx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858}
859
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860void
Caroline Ticeefed6132010-11-19 20:47:54 +0000861Debugger::DispatchInputInterrupt ()
862{
Greg Clayton44d93782014-01-27 23:43:24 +0000863 Mutex::Locker locker (m_input_reader_stack.GetMutex());
864 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000865 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000866 reader_sp->Interrupt();
Caroline Ticeefed6132010-11-19 20:47:54 +0000867}
868
869void
870Debugger::DispatchInputEndOfFile ()
871{
Greg Clayton44d93782014-01-27 23:43:24 +0000872 Mutex::Locker locker (m_input_reader_stack.GetMutex());
873 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000874 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000875 reader_sp->GotEOF();
Caroline Ticeefed6132010-11-19 20:47:54 +0000876}
877
878void
Greg Clayton44d93782014-01-27 23:43:24 +0000879Debugger::ClearIOHandlers ()
Caroline Tice3d6086f2010-12-20 18:35:50 +0000880{
Caroline Ticeb44880c2011-02-10 01:15:13 +0000881 // 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 +0000882 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000883 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000884 {
Greg Clayton44d93782014-01-27 23:43:24 +0000885 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000886 if (reader_sp)
Pavel Labath44464872015-05-27 12:40:32 +0000887 PopIOHandler (reader_sp);
Caroline Tice3d6086f2010-12-20 18:35:50 +0000888 }
889}
890
891void
Siva Chandra9aaab552015-02-26 19:26:36 +0000892Debugger::ExecuteIOHandlers()
Caroline Tice969ed3d2011-05-02 20:41:46 +0000893{
Greg Clayton44d93782014-01-27 23:43:24 +0000894 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000895 {
Greg Clayton44d93782014-01-27 23:43:24 +0000896 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 if (!reader_sp)
898 break;
899
Greg Clayton44d93782014-01-27 23:43:24 +0000900 reader_sp->Run();
Greg Clayton44d93782014-01-27 23:43:24 +0000901
902 // Remove all input readers that are done from the top of the stack
903 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000904 {
Greg Clayton44d93782014-01-27 23:43:24 +0000905 IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
906 if (top_reader_sp && top_reader_sp->GetIsDone())
Pavel Labath44464872015-05-27 12:40:32 +0000907 PopIOHandler (top_reader_sp);
Greg Clayton44d93782014-01-27 23:43:24 +0000908 else
909 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000910 }
911 }
Greg Clayton44d93782014-01-27 23:43:24 +0000912 ClearIOHandlers();
913}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000914
Greg Clayton44d93782014-01-27 23:43:24 +0000915bool
916Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
917{
918 return m_input_reader_stack.IsTop (reader_sp);
919}
920
Pavel Labath44464872015-05-27 12:40:32 +0000921void
922Debugger::PrintAsync (const char *s, size_t len, bool is_stdout)
923{
924 lldb::StreamFileSP stream = is_stdout ? GetOutputFile() : GetErrorFile();
925 m_input_reader_stack.PrintAsync(stream.get(), s, len);
926}
Greg Clayton44d93782014-01-27 23:43:24 +0000927
928ConstString
929Debugger::GetTopIOHandlerControlSequence(char ch)
930{
931 return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000932}
933
Kate Stonea487aa42015-01-15 00:52:41 +0000934const char *
935Debugger::GetIOHandlerCommandPrefix()
936{
937 return m_input_reader_stack.GetTopIOHandlerCommandPrefix();
938}
939
940const char *
941Debugger::GetIOHandlerHelpPrologue()
942{
943 return m_input_reader_stack.GetTopIOHandlerHelpPrologue();
944}
945
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946void
Greg Clayton44d93782014-01-27 23:43:24 +0000947Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
948{
Greg Clayton44d93782014-01-27 23:43:24 +0000949 PushIOHandler (reader_sp);
Pavel Labath44464872015-05-27 12:40:32 +0000950
Greg Clayton577508d2014-06-20 00:23:57 +0000951 IOHandlerSP top_reader_sp = reader_sp;
952 while (top_reader_sp)
953 {
Greg Clayton577508d2014-06-20 00:23:57 +0000954 top_reader_sp->Run();
Pavel Labath44464872015-05-27 12:40:32 +0000955
Greg Clayton577508d2014-06-20 00:23:57 +0000956 if (top_reader_sp.get() == reader_sp.get())
957 {
958 if (PopIOHandler (reader_sp))
959 break;
960 }
Pavel Labath44464872015-05-27 12:40:32 +0000961
Greg Clayton577508d2014-06-20 00:23:57 +0000962 while (1)
963 {
964 top_reader_sp = m_input_reader_stack.Top();
965 if (top_reader_sp && top_reader_sp->GetIsDone())
Pavel Labath44464872015-05-27 12:40:32 +0000966 PopIOHandler (top_reader_sp);
Greg Clayton577508d2014-06-20 00:23:57 +0000967 else
968 break;
969 }
970 }
Greg Clayton44d93782014-01-27 23:43:24 +0000971}
972
973void
974Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
975{
976 // Before an IOHandler runs, it must have in/out/err streams.
977 // This function is called when one ore more of the streams
978 // are NULL. We use the top input reader's in/out/err streams,
979 // or fall back to the debugger file handles, or we fall back
980 // onto stdin/stdout/stderr as a last resort.
981
982 Mutex::Locker locker (m_input_reader_stack.GetMutex());
983 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
984 // If no STDIN has been set, then set it appropriately
985 if (!in)
986 {
987 if (top_reader_sp)
988 in = top_reader_sp->GetInputStreamFile();
989 else
990 in = GetInputFile();
991
992 // If there is nothing, use stdin
993 if (!in)
994 in = StreamFileSP(new StreamFile(stdin, false));
995 }
996 // If no STDOUT has been set, then set it appropriately
997 if (!out)
998 {
999 if (top_reader_sp)
1000 out = top_reader_sp->GetOutputStreamFile();
1001 else
1002 out = GetOutputFile();
1003
1004 // If there is nothing, use stdout
1005 if (!out)
1006 out = StreamFileSP(new StreamFile(stdout, false));
1007 }
1008 // If no STDERR has been set, then set it appropriately
1009 if (!err)
1010 {
1011 if (top_reader_sp)
1012 err = top_reader_sp->GetErrorStreamFile();
1013 else
1014 err = GetErrorFile();
1015
1016 // If there is nothing, use stderr
1017 if (!err)
1018 err = StreamFileSP(new StreamFile(stdout, false));
1019
1020 }
1021}
1022
1023void
1024Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025{
1026 if (!reader_sp)
1027 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +00001028
Pavel Labath44464872015-05-27 12:40:32 +00001029 Mutex::Locker locker (m_input_reader_stack.GetMutex());
1030
1031 // Get the current top input reader...
Greg Clayton44d93782014-01-27 23:43:24 +00001032 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +00001033
Greg Claytonb4874f12014-02-28 18:22:24 +00001034 // Don't push the same IO handler twice...
Pavel Labath44464872015-05-27 12:40:32 +00001035 if (reader_sp == top_reader_sp)
1036 return;
Greg Clayton44d93782014-01-27 23:43:24 +00001037
Pavel Labath44464872015-05-27 12:40:32 +00001038 // Push our new input reader
1039 m_input_reader_stack.Push (reader_sp);
1040 reader_sp->Activate();
1041
1042 // Interrupt the top input reader to it will exit its Run() function
1043 // and let this new input reader take over
1044 if (top_reader_sp)
1045 {
1046 top_reader_sp->Deactivate();
1047 top_reader_sp->Cancel();
Greg Claytonb4874f12014-02-28 18:22:24 +00001048 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001049}
1050
1051bool
Greg Clayton44d93782014-01-27 23:43:24 +00001052Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053{
Pavel Labath44464872015-05-27 12:40:32 +00001054 if (! pop_reader_sp)
1055 return false;
1056
Greg Clayton44d93782014-01-27 23:43:24 +00001057 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001058
1059 // The reader on the stop of the stack is done, so let the next
Bruce Mitchener6a7f3332014-06-27 02:42:12 +00001060 // read on the stack refresh its prompt and if there is one...
Pavel Labath44464872015-05-27 12:40:32 +00001061 if (m_input_reader_stack.IsEmpty())
1062 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063
Greg Clayton44d93782014-01-27 23:43:24 +00001064 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Greg Clayton66111032010-06-23 01:19:29 +00001065
Pavel Labath44464872015-05-27 12:40:32 +00001066 if (pop_reader_sp != reader_sp)
1067 return false;
1068
1069 reader_sp->Deactivate();
1070 reader_sp->Cancel();
1071 m_input_reader_stack.Pop ();
1072
1073 reader_sp = m_input_reader_stack.Top();
1074 if (reader_sp)
1075 reader_sp->Activate();
1076
1077 return true;
1078}
Greg Clayton44d93782014-01-27 23:43:24 +00001079
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001080StreamSP
1081Debugger::GetAsyncOutputStream ()
1082{
Pavel Labath44464872015-05-27 12:40:32 +00001083 return StreamSP (new StreamAsynchronousIO (*this, true));
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001084}
1085
1086StreamSP
1087Debugger::GetAsyncErrorStream ()
1088{
Pavel Labath44464872015-05-27 12:40:32 +00001089 return StreamSP (new StreamAsynchronousIO (*this, false));
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001090}
1091
Greg Claytonc7bece562013-01-25 18:06:21 +00001092size_t
Enrico Granata061858c2012-02-15 02:34:21 +00001093Debugger::GetNumDebuggers()
1094{
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001095 if (lldb_initialized)
Greg Claytonc15f55e2012-03-30 20:53:46 +00001096 {
1097 Mutex::Locker locker (GetDebuggerListMutex ());
1098 return GetDebuggerList().size();
1099 }
1100 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +00001101}
1102
1103lldb::DebuggerSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001104Debugger::GetDebuggerAtIndex (size_t index)
Enrico Granata061858c2012-02-15 02:34:21 +00001105{
1106 DebuggerSP debugger_sp;
1107
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001108 if (lldb_initialized)
Greg Claytonc15f55e2012-03-30 20:53:46 +00001109 {
1110 Mutex::Locker locker (GetDebuggerListMutex ());
1111 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +00001112
Greg Claytonc15f55e2012-03-30 20:53:46 +00001113 if (index < debugger_list.size())
1114 debugger_sp = debugger_list[index];
1115 }
1116
Enrico Granata061858c2012-02-15 02:34:21 +00001117 return debugger_sp;
1118}
1119
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001120DebuggerSP
1121Debugger::FindDebuggerWithID (lldb::user_id_t id)
1122{
Greg Clayton4d122c42011-09-17 08:33:22 +00001123 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001124
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001125 if (lldb_initialized)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001126 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001127 Mutex::Locker locker (GetDebuggerListMutex ());
1128 DebuggerList &debugger_list = GetDebuggerList();
1129 DebuggerList::iterator pos, end = debugger_list.end();
1130 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001131 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001132 if ((*pos).get()->GetID() == id)
1133 {
1134 debugger_sp = *pos;
1135 break;
1136 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001137 }
1138 }
1139 return debugger_sp;
1140}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001141
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001142#if 0
Greg Clayton1b654882010-09-19 02:33:57 +00001143static void
Jason Molendab57e4a12013-11-04 09:33:30 +00001144TestPromptFormats (StackFrame *frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001145{
1146 if (frame == NULL)
1147 return;
1148
1149 StreamString s;
1150 const char *prompt_format =
1151 "{addr = '${addr}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001152 "{addr-file-or-load = '${addr-file-or-load}'\n}"
1153 "{current-pc-arrow = '${current-pc-arrow}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001154 "{process.id = '${process.id}'\n}"
1155 "{process.name = '${process.name}'\n}"
1156 "{process.file.basename = '${process.file.basename}'\n}"
1157 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1158 "{thread.id = '${thread.id}'\n}"
1159 "{thread.index = '${thread.index}'\n}"
1160 "{thread.name = '${thread.name}'\n}"
1161 "{thread.queue = '${thread.queue}'\n}"
1162 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1163 "{target.arch = '${target.arch}'\n}"
1164 "{module.file.basename = '${module.file.basename}'\n}"
1165 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1166 "{file.basename = '${file.basename}'\n}"
1167 "{file.fullpath = '${file.fullpath}'\n}"
1168 "{frame.index = '${frame.index}'\n}"
1169 "{frame.pc = '${frame.pc}'\n}"
1170 "{frame.sp = '${frame.sp}'\n}"
1171 "{frame.fp = '${frame.fp}'\n}"
1172 "{frame.flags = '${frame.flags}'\n}"
1173 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1174 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1175 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1176 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1177 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1178 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1179 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1180 "{function.id = '${function.id}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001181 "{function.changed = '${function.changed}'\n}"
1182 "{function.initial-function = '${function.initial-function}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001183 "{function.name = '${function.name}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001184 "{function.name-without-args = '${function.name-without-args}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +00001185 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001186 "{function.addr-offset = '${function.addr-offset}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001187 "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001188 "{function.line-offset = '${function.line-offset}'\n}"
1189 "{function.pc-offset = '${function.pc-offset}'\n}"
1190 "{line.file.basename = '${line.file.basename}'\n}"
1191 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1192 "{line.number = '${line.number}'\n}"
1193 "{line.start-addr = '${line.start-addr}'\n}"
1194 "{line.end-addr = '${line.end-addr}'\n}"
1195;
1196
1197 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1198 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +00001199 frame->CalculateExecutionContext(exe_ctx);
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001200 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
Greg Clayton1b654882010-09-19 02:33:57 +00001201 {
1202 printf("%s\n", s.GetData());
1203 }
1204 else
1205 {
Greg Clayton1b654882010-09-19 02:33:57 +00001206 printf ("what we got: %s\n", s.GetData());
1207 }
1208}
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001209#endif
Greg Clayton1b654882010-09-19 02:33:57 +00001210
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001211bool
Greg Clayton554f68d2015-02-04 22:00:53 +00001212Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
Jason Molendaaff1b352014-10-10 23:07:36 +00001213 const SymbolContext *sc,
1214 const SymbolContext *prev_sc,
1215 const ExecutionContext *exe_ctx,
1216 const Address *addr,
1217 Stream &s)
1218{
Greg Clayton554f68d2015-02-04 22:00:53 +00001219 FormatEntity::Entry format_entry;
1220
1221 if (format == NULL)
Jason Molendaaff1b352014-10-10 23:07:36 +00001222 {
Greg Clayton554f68d2015-02-04 22:00:53 +00001223 if (exe_ctx != NULL && exe_ctx->HasTargetScope())
1224 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1225 if (format == NULL)
1226 {
1227 FormatEntity::Parse("${addr}: ", format_entry);
1228 format = &format_entry;
1229 }
Jason Molendaaff1b352014-10-10 23:07:36 +00001230 }
1231 bool function_changed = false;
1232 bool initial_function = false;
1233 if (prev_sc && (prev_sc->function || prev_sc->symbol))
1234 {
1235 if (sc && (sc->function || sc->symbol))
1236 {
1237 if (prev_sc->symbol && sc->symbol)
1238 {
1239 if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType()))
1240 {
1241 function_changed = true;
1242 }
1243 }
1244 else if (prev_sc->function && sc->function)
1245 {
1246 if (prev_sc->function->GetMangled() != sc->function->GetMangled())
1247 {
1248 function_changed = true;
1249 }
1250 }
1251 }
1252 }
1253 // The first context on a list of instructions will have a prev_sc that
1254 // has no Function or Symbol -- if SymbolContext had an IsValid() method, it
1255 // would return false. But we do get a prev_sc pointer.
1256 if ((sc && (sc->function || sc->symbol))
1257 && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL))
1258 {
1259 initial_function = true;
1260 }
Greg Clayton554f68d2015-02-04 22:00:53 +00001261 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, NULL, function_changed, initial_function);
Jason Molendaaff1b352014-10-10 23:07:36 +00001262}
1263
1264
Jim Ingham228063c2012-02-21 02:23:08 +00001265void
1266Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1267{
Jim Ingham4f02b222012-02-22 22:49:20 +00001268 // For simplicity's sake, I am not going to deal with how to close down any
1269 // open logging streams, I just redirect everything from here on out to the
1270 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00001271 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
1272}
1273
1274bool
1275Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
1276{
Jim Ingham228063c2012-02-21 02:23:08 +00001277 StreamSP log_stream_sp;
Sean Callanan9a028512012-08-09 00:50:26 +00001278 if (m_log_callback_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001279 {
1280 log_stream_sp = m_log_callback_stream_sp;
1281 // For now when using the callback mode you always get thread & timestamp.
1282 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1283 }
1284 else if (log_file == NULL || *log_file == '\0')
1285 {
Greg Clayton44d93782014-01-27 23:43:24 +00001286 log_stream_sp = GetOutputFile();
Jim Ingham228063c2012-02-21 02:23:08 +00001287 }
1288 else
1289 {
1290 LogStreamMap::iterator pos = m_log_streams.find(log_file);
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001291 if (pos != m_log_streams.end())
1292 log_stream_sp = pos->second.lock();
1293 if (!log_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001294 {
Pavel Labath8ac06992015-03-20 09:43:20 +00001295 uint32_t options = File::eOpenOptionWrite | File::eOpenOptionCanCreate
1296 | File::eOpenOptionCloseOnExec | File::eOpenOptionAppend;
1297 if (! (log_options & LLDB_LOG_OPTION_APPEND))
1298 options |= File::eOpenOptionTruncate;
1299
1300 log_stream_sp.reset (new StreamFile (log_file, options));
Jim Ingham228063c2012-02-21 02:23:08 +00001301 m_log_streams[log_file] = log_stream_sp;
1302 }
Jim Ingham228063c2012-02-21 02:23:08 +00001303 }
1304 assert (log_stream_sp.get());
1305
1306 if (log_options == 0)
1307 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
1308
Tamas Berghammer9c9ecce2015-05-27 13:34:04 +00001309 return Log::EnableLogChannel(log_stream_sp, log_options, channel, categories, error_stream);
Jim Ingham228063c2012-02-21 02:23:08 +00001310}
1311
Greg Clayton9585fbf2013-03-19 00:20:55 +00001312SourceManager &
1313Debugger::GetSourceManager ()
1314{
1315 if (m_source_manager_ap.get() == NULL)
1316 m_source_manager_ap.reset (new SourceManager (shared_from_this()));
1317 return *m_source_manager_ap;
1318}
1319
1320
Greg Clayton44d93782014-01-27 23:43:24 +00001321
1322// This function handles events that were broadcast by the process.
1323void
1324Debugger::HandleBreakpointEvent (const EventSP &event_sp)
1325{
1326 using namespace lldb;
1327 const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp);
1328
1329// if (event_type & eBreakpointEventTypeAdded
1330// || event_type & eBreakpointEventTypeRemoved
1331// || event_type & eBreakpointEventTypeEnabled
1332// || event_type & eBreakpointEventTypeDisabled
1333// || event_type & eBreakpointEventTypeCommandChanged
1334// || event_type & eBreakpointEventTypeConditionChanged
1335// || event_type & eBreakpointEventTypeIgnoreChanged
1336// || event_type & eBreakpointEventTypeLocationsResolved)
1337// {
1338// // Don't do anything about these events, since the breakpoint commands already echo these actions.
1339// }
1340//
1341 if (event_type & eBreakpointEventTypeLocationsAdded)
1342 {
1343 uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp);
1344 if (num_new_locations > 0)
1345 {
1346 BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
Pavel Labath44464872015-05-27 12:40:32 +00001347 StreamSP output_sp (GetAsyncOutputStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001348 if (output_sp)
1349 {
1350 output_sp->Printf("%d location%s added to breakpoint %d\n",
1351 num_new_locations,
1352 num_new_locations == 1 ? "" : "s",
1353 breakpoint->GetID());
Pavel Labath44464872015-05-27 12:40:32 +00001354 output_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001355 }
1356 }
1357 }
1358// else if (event_type & eBreakpointEventTypeLocationsRemoved)
1359// {
1360// // These locations just get disabled, not sure it is worth spamming folks about this on the command line.
1361// }
1362// else if (event_type & eBreakpointEventTypeLocationsResolved)
1363// {
1364// // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy.
1365// }
1366}
1367
1368size_t
1369Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
1370{
1371 size_t total_bytes = 0;
1372 if (stream == NULL)
1373 stream = GetOutputFile().get();
1374
1375 if (stream)
1376 {
1377 // The process has stuff waiting for stdout; get it and write it out to the appropriate place.
1378 if (process == NULL)
1379 {
1380 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1381 if (target_sp)
1382 process = target_sp->GetProcessSP().get();
1383 }
1384 if (process)
1385 {
1386 Error error;
1387 size_t len;
1388 char stdio_buffer[1024];
1389 while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1390 {
1391 stream->Write(stdio_buffer, len);
1392 total_bytes += len;
1393 }
1394 }
1395 stream->Flush();
1396 }
1397 return total_bytes;
1398}
1399
1400size_t
1401Debugger::GetProcessSTDERR (Process *process, Stream *stream)
1402{
1403 size_t total_bytes = 0;
1404 if (stream == NULL)
1405 stream = GetOutputFile().get();
1406
1407 if (stream)
1408 {
1409 // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
1410 if (process == NULL)
1411 {
1412 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1413 if (target_sp)
1414 process = target_sp->GetProcessSP().get();
1415 }
1416 if (process)
1417 {
1418 Error error;
1419 size_t len;
1420 char stdio_buffer[1024];
1421 while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1422 {
1423 stream->Write(stdio_buffer, len);
1424 total_bytes += len;
1425 }
1426 }
1427 stream->Flush();
1428 }
1429 return total_bytes;
1430}
1431
Greg Claytondc6224e2014-10-21 01:00:42 +00001432
Greg Clayton44d93782014-01-27 23:43:24 +00001433// This function handles events that were broadcast by the process.
1434void
1435Debugger::HandleProcessEvent (const EventSP &event_sp)
1436{
1437 using namespace lldb;
1438 const uint32_t event_type = event_sp->GetType();
1439 ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
Greg Claytondc6224e2014-10-21 01:00:42 +00001440
Pavel Labath44464872015-05-27 12:40:32 +00001441 StreamSP output_stream_sp = GetAsyncOutputStream();
1442 StreamSP error_stream_sp = GetAsyncErrorStream();
Greg Clayton44d93782014-01-27 23:43:24 +00001443 const bool gui_enabled = IsForwardingEvents();
Greg Clayton44d93782014-01-27 23:43:24 +00001444
Greg Claytonb4874f12014-02-28 18:22:24 +00001445 if (!gui_enabled)
1446 {
1447 bool pop_process_io_handler = false;
1448 assert (process_sp);
Greg Claytondc6224e2014-10-21 01:00:42 +00001449
Pavel Labath44464872015-05-27 12:40:32 +00001450 bool state_is_stopped = false;
1451 const bool got_state_changed = (event_type & Process::eBroadcastBitStateChanged) != 0;
1452 const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0;
1453 const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0;
1454 if (got_state_changed)
Greg Clayton44d93782014-01-27 23:43:24 +00001455 {
Pavel Labath44464872015-05-27 12:40:32 +00001456 StateType event_state = Process::ProcessEventData::GetStateFromEvent (event_sp.get());
1457 state_is_stopped = StateIsStoppedState(event_state, false);
Greg Claytonb4874f12014-02-28 18:22:24 +00001458 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001459
Pavel Labath44464872015-05-27 12:40:32 +00001460 // Display running state changes first before any STDIO
1461 if (got_state_changed && !state_is_stopped)
Greg Claytonb4874f12014-02-28 18:22:24 +00001462 {
Pavel Labath44464872015-05-27 12:40:32 +00001463 Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler);
Greg Claytonb4874f12014-02-28 18:22:24 +00001464 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001465
Pavel Labath44464872015-05-27 12:40:32 +00001466 // Now display and STDOUT
1467 if (got_stdout || got_state_changed)
Greg Claytonb4874f12014-02-28 18:22:24 +00001468 {
Pavel Labath44464872015-05-27 12:40:32 +00001469 GetProcessSTDOUT (process_sp.get(), output_stream_sp.get());
Greg Clayton44d93782014-01-27 23:43:24 +00001470 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001471
Pavel Labath44464872015-05-27 12:40:32 +00001472 // Now display and STDERR
1473 if (got_stderr || got_state_changed)
Greg Claytonb4874f12014-02-28 18:22:24 +00001474 {
Pavel Labath44464872015-05-27 12:40:32 +00001475 GetProcessSTDERR (process_sp.get(), error_stream_sp.get());
Greg Claytonb4874f12014-02-28 18:22:24 +00001476 }
1477
Pavel Labath44464872015-05-27 12:40:32 +00001478 // Now display any stopped state changes after any STDIO
1479 if (got_state_changed && state_is_stopped)
1480 {
1481 Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler);
1482 }
1483
1484 output_stream_sp->Flush();
1485 error_stream_sp->Flush();
1486
Greg Claytonb4874f12014-02-28 18:22:24 +00001487 if (pop_process_io_handler)
1488 process_sp->PopProcessIOHandler();
1489 }
Greg Clayton44d93782014-01-27 23:43:24 +00001490}
1491
1492void
1493Debugger::HandleThreadEvent (const EventSP &event_sp)
1494{
1495 // At present the only thread event we handle is the Frame Changed event,
1496 // and all we do for that is just reprint the thread status for that thread.
1497 using namespace lldb;
1498 const uint32_t event_type = event_sp->GetType();
1499 if (event_type == Thread::eBroadcastBitStackChanged ||
1500 event_type == Thread::eBroadcastBitThreadSelected )
1501 {
1502 ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get()));
1503 if (thread_sp)
1504 {
Pavel Labath44464872015-05-27 12:40:32 +00001505 thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1);
Greg Clayton44d93782014-01-27 23:43:24 +00001506 }
1507 }
1508}
1509
1510bool
1511Debugger::IsForwardingEvents ()
1512{
1513 return (bool)m_forward_listener_sp;
1514}
1515
1516void
1517Debugger::EnableForwardEvents (const ListenerSP &listener_sp)
1518{
1519 m_forward_listener_sp = listener_sp;
1520}
1521
1522void
1523Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
1524{
1525 m_forward_listener_sp.reset();
1526}
1527
1528
1529void
1530Debugger::DefaultEventHandler()
1531{
1532 Listener& listener(GetListener());
1533 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1534 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1535 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1536 BroadcastEventSpec target_event_spec (broadcaster_class_target,
1537 Target::eBroadcastBitBreakpointChanged);
1538
1539 BroadcastEventSpec process_event_spec (broadcaster_class_process,
1540 Process::eBroadcastBitStateChanged |
1541 Process::eBroadcastBitSTDOUT |
1542 Process::eBroadcastBitSTDERR);
1543
1544 BroadcastEventSpec thread_event_spec (broadcaster_class_thread,
1545 Thread::eBroadcastBitStackChanged |
1546 Thread::eBroadcastBitThreadSelected );
1547
1548 listener.StartListeningForEventSpec (*this, target_event_spec);
1549 listener.StartListeningForEventSpec (*this, process_event_spec);
1550 listener.StartListeningForEventSpec (*this, thread_event_spec);
1551 listener.StartListeningForEvents (m_command_interpreter_ap.get(),
1552 CommandInterpreter::eBroadcastBitQuitCommandReceived |
1553 CommandInterpreter::eBroadcastBitAsynchronousOutputData |
1554 CommandInterpreter::eBroadcastBitAsynchronousErrorData );
Greg Claytonafa91e332014-12-01 22:41:27 +00001555
1556 // Let the thread that spawned us know that we have started up and
1557 // that we are now listening to all required events so no events get missed
1558 m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
1559
Greg Clayton44d93782014-01-27 23:43:24 +00001560 bool done = false;
1561 while (!done)
1562 {
Greg Clayton44d93782014-01-27 23:43:24 +00001563 EventSP event_sp;
1564 if (listener.WaitForEvent(NULL, event_sp))
1565 {
1566 if (event_sp)
1567 {
1568 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1569 if (broadcaster)
1570 {
1571 uint32_t event_type = event_sp->GetType();
1572 ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
1573 if (broadcaster_class == broadcaster_class_process)
1574 {
1575 HandleProcessEvent (event_sp);
1576 }
1577 else if (broadcaster_class == broadcaster_class_target)
1578 {
1579 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get()))
1580 {
1581 HandleBreakpointEvent (event_sp);
1582 }
1583 }
1584 else if (broadcaster_class == broadcaster_class_thread)
1585 {
1586 HandleThreadEvent (event_sp);
1587 }
1588 else if (broadcaster == m_command_interpreter_ap.get())
1589 {
1590 if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived)
1591 {
1592 done = true;
1593 }
1594 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData)
1595 {
1596 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1597 if (data && data[0])
1598 {
Pavel Labath44464872015-05-27 12:40:32 +00001599 StreamSP error_sp (GetAsyncErrorStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001600 if (error_sp)
1601 {
Greg Clayton44d93782014-01-27 23:43:24 +00001602 error_sp->PutCString(data);
1603 error_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001604 }
1605 }
1606 }
1607 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData)
1608 {
1609 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1610 if (data && data[0])
1611 {
Pavel Labath44464872015-05-27 12:40:32 +00001612 StreamSP output_sp (GetAsyncOutputStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001613 if (output_sp)
1614 {
Greg Clayton44d93782014-01-27 23:43:24 +00001615 output_sp->PutCString(data);
1616 output_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001617 }
1618 }
1619 }
1620 }
1621 }
1622
1623 if (m_forward_listener_sp)
1624 m_forward_listener_sp->AddEvent(event_sp);
1625 }
1626 }
1627 }
1628}
1629
1630lldb::thread_result_t
1631Debugger::EventHandlerThread (lldb::thread_arg_t arg)
1632{
1633 ((Debugger *)arg)->DefaultEventHandler();
1634 return NULL;
1635}
1636
1637bool
1638Debugger::StartEventHandlerThread()
1639{
Zachary Turneracee96a2014-09-23 18:32:09 +00001640 if (!m_event_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001641 {
Greg Claytonafa91e332014-12-01 22:41:27 +00001642 // We must synchronize with the DefaultEventHandler() thread to ensure
1643 // it is up and running and listening to events before we return from
1644 // this function. We do this by listening to events for the
1645 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1646 Listener listener("lldb.debugger.event-handler");
1647 listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
1648
Zachary Turner7c2896a2014-10-24 22:06:29 +00001649 // Use larger 8MB stack for this thread
Greg Claytonafa91e332014-12-01 22:41:27 +00001650 m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread,
1651 this,
1652 NULL,
Zachary Turner7c2896a2014-10-24 22:06:29 +00001653 g_debugger_event_thread_stack_bytes);
Greg Claytonafa91e332014-12-01 22:41:27 +00001654
1655 // Make sure DefaultEventHandler() is running and listening to events before we return
1656 // from this function. We are only listening for events of type
1657 // eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
1658 // to wait an infinite amount of time for it (NULL timeout as the first parameter)
1659 lldb::EventSP event_sp;
1660 listener.WaitForEvent(NULL, event_sp);
Greg Clayton807b6b32014-10-15 18:03:59 +00001661 }
Zachary Turneracee96a2014-09-23 18:32:09 +00001662 return m_event_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001663}
1664
1665void
1666Debugger::StopEventHandlerThread()
1667{
Zachary Turneracee96a2014-09-23 18:32:09 +00001668 if (m_event_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001669 {
1670 GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
Zachary Turner39de3112014-09-09 20:54:56 +00001671 m_event_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001672 }
1673}
1674
1675
1676lldb::thread_result_t
1677Debugger::IOHandlerThread (lldb::thread_arg_t arg)
1678{
1679 Debugger *debugger = (Debugger *)arg;
Siva Chandra9aaab552015-02-26 19:26:36 +00001680 debugger->ExecuteIOHandlers();
Greg Clayton44d93782014-01-27 23:43:24 +00001681 debugger->StopEventHandlerThread();
1682 return NULL;
1683}
1684
1685bool
1686Debugger::StartIOHandlerThread()
1687{
Zachary Turneracee96a2014-09-23 18:32:09 +00001688 if (!m_io_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001689 m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
1690 IOHandlerThread,
1691 this,
1692 NULL,
1693 8*1024*1024); // Use larger 8MB stack for this thread
Zachary Turneracee96a2014-09-23 18:32:09 +00001694 return m_io_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001695}
1696
1697void
1698Debugger::StopIOHandlerThread()
1699{
Zachary Turneracee96a2014-09-23 18:32:09 +00001700 if (m_io_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001701 {
1702 if (m_input_file_sp)
1703 m_input_file_sp->GetFile().Close();
Zachary Turner39de3112014-09-09 20:54:56 +00001704 m_io_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001705 }
1706}
1707
Jim Ingham893c9322014-11-22 01:42:44 +00001708Target *
1709Debugger::GetDummyTarget()
1710{
1711 return m_target_list.GetDummyTarget (*this).get();
1712}
1713
1714Target *
Jim Ingham33df7cd2014-12-06 01:28:03 +00001715Debugger::GetSelectedOrDummyTarget(bool prefer_dummy)
Jim Ingham893c9322014-11-22 01:42:44 +00001716{
Jim Ingham33df7cd2014-12-06 01:28:03 +00001717 Target *target = nullptr;
1718 if (!prefer_dummy)
1719 {
1720 target = m_target_list.GetSelectedTarget().get();
1721 if (target)
1722 return target;
1723 }
1724
Jim Ingham893c9322014-11-22 01:42:44 +00001725 return GetDummyTarget();
1726}
Greg Clayton44d93782014-01-27 23:43:24 +00001727