blob: 55324f15c5e7dc49d07d9d4a8c770ef7bdb459d4 [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"
Greg Claytone8cd0c92012-10-19 18:02:49 +000021#include "lldb/Core/PluginManager.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000022#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000024#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000025#include "lldb/Core/StreamCallback.h"
Greg Clayton44d93782014-01-27 23:43:24 +000026#include "lldb/Core/StreamFile.h"
Greg Clayton1b654882010-09-19 02:33:57 +000027#include "lldb/Core/StreamString.h"
Jason Molenda705b1802014-06-13 02:37:02 +000028#include "lldb/Core/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000030#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000031#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000032#include "lldb/DataFormatters/DataVisualization.h"
33#include "lldb/DataFormatters/FormatManager.h"
Enrico Granata894f7352014-03-25 22:03:52 +000034#include "lldb/DataFormatters/TypeSummary.h"
Zachary Turner93a66fc2014-10-06 21:22:36 +000035#include "lldb/Host/ConnectionFileDescriptor.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000036#include "lldb/Host/HostInfo.h"
Greg Claytona3406612011-02-07 23:24:47 +000037#include "lldb/Host/Terminal.h"
Zachary Turner39de3112014-09-09 20:54:56 +000038#include "lldb/Host/ThreadLauncher.h"
Greg Clayton66111032010-06-23 01:19:29 +000039#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turner633a29c2015-03-04 01:58:01 +000040#include "lldb/Interpreter/OptionValueProperties.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000041#include "lldb/Interpreter/OptionValueSInt64.h"
42#include "lldb/Interpreter/OptionValueString.h"
Greg Clayton1f746072012-08-29 21:13:06 +000043#include "lldb/Symbol/ClangASTContext.h"
44#include "lldb/Symbol/CompileUnit.h"
45#include "lldb/Symbol/Function.h"
46#include "lldb/Symbol/Symbol.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000047#include "lldb/Symbol/VariableList.h"
Jason Molendaaff1b352014-10-10 23:07:36 +000048#include "lldb/Target/CPPLanguageRuntime.h"
49#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/TargetList.h"
51#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000052#include "lldb/Target/RegisterContext.h"
Greg Clayton5fb8f792013-12-02 19:35:49 +000053#include "lldb/Target/SectionLoadList.h"
Greg Clayton1b654882010-09-19 02:33:57 +000054#include "lldb/Target/StopInfo.h"
Enrico Granata84a53df2013-05-20 22:29:23 +000055#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000057#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Zachary Turner58a559c2014-08-27 20:15:09 +000059#include "llvm/Support/DynamicLibrary.h"
60
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061using namespace lldb;
62using namespace lldb_private;
63
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
Caroline Ticeebc1bb22010-06-30 16:22:25 +000065static lldb::user_id_t g_unique_id = 1;
Zachary Turner7c2896a2014-10-24 22:06:29 +000066static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000067
Greg Clayton1b654882010-09-19 02:33:57 +000068#pragma mark Static Functions
69
70static Mutex &
71GetDebuggerListMutex ()
72{
73 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
74 return g_mutex;
75}
76
77typedef std::vector<DebuggerSP> DebuggerList;
78
79static DebuggerList &
80GetDebuggerList()
81{
82 // hide the static debugger list inside a singleton accessor to avoid
Bruce Mitchener6a7f3332014-06-27 02:42:12 +000083 // global init constructors
Greg Clayton1b654882010-09-19 02:33:57 +000084 static DebuggerList g_list;
85 return g_list;
86}
Greg Claytone372b982011-11-21 21:44:34 +000087
88OptionEnumValueElement
Greg Clayton67cc0632012-08-22 17:17:09 +000089g_show_disassembly_enum_values[] =
Greg Claytone372b982011-11-21 21:44:34 +000090{
Greg Clayton67cc0632012-08-22 17:17:09 +000091 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
92 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
93 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
Greg Claytone372b982011-11-21 21:44:34 +000094 { 0, NULL, NULL }
95};
96
Greg Clayton67cc0632012-08-22 17:17:09 +000097OptionEnumValueElement
98g_language_enumerators[] =
99{
100 { eScriptLanguageNone, "none", "Disable scripting languages."},
101 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
102 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
Greg Claytona12993c2012-09-13 23:03:20 +0000103 { 0, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000104};
Greg Claytone372b982011-11-21 21:44:34 +0000105
Greg Clayton67cc0632012-08-22 17:17:09 +0000106#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
107#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Jason Molenda6ab659a2015-07-29 00:42:47 +0000108#define IS_OPTIMIZED "{${function.is-optimized} [opt]}"
Greg Clayton67cc0632012-08-22 17:17:09 +0000109
Michael Sartain0769b2b2013-07-30 16:44:36 +0000110#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000111 "{, ${frame.pc}}"\
112 MODULE_WITH_FUNC\
113 FILE_AND_LINE\
Michael Sartain0769b2b2013-07-30 16:44:36 +0000114 "{, name = '${thread.name}'}"\
115 "{, queue = '${thread.queue}'}"\
Jason Molenda705b1802014-06-13 02:37:02 +0000116 "{, activity = '${thread.info.activity.name}'}" \
117 "{, ${thread.info.trace_messages} messages}" \
Greg Clayton67cc0632012-08-22 17:17:09 +0000118 "{, stop reason = ${thread.stop-reason}}"\
119 "{\\nReturn value: ${thread.return-value}}"\
Jim Ingham30fadaf2014-07-08 01:07:32 +0000120 "{\\nCompleted expression: ${thread.completed-expression}}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000121 "\\n"
122
123#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
124 MODULE_WITH_FUNC\
125 FILE_AND_LINE\
Jason Molenda6ab659a2015-07-29 00:42:47 +0000126 IS_OPTIMIZED\
Greg Clayton67cc0632012-08-22 17:17:09 +0000127 "\\n"
128
Jason Molendac980fa92015-02-13 23:24:21 +0000129// Three parts to this disassembly format specification:
130// 1. If this is a new function/symbol (no previous symbol/function), print
131// dylib`funcname:\n
132// 2. If this is a symbol context change (different from previous symbol/function), print
133// dylib`funcname:\n
134// 3. print
135// address <+offset>:
136#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}>}: "
137
138// gdb's disassembly format can be emulated with
139// ${current-pc-arrow}${addr-file-or-load}{ <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>}:
140
141// lldb's original format for disassembly would look like this format string -
142// {${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}}:
143
Greg Clayton67cc0632012-08-22 17:17:09 +0000144
Greg Clayton754a9362012-08-23 00:22:02 +0000145static PropertyDefinition
146g_properties[] =
Greg Clayton67cc0632012-08-22 17:17:09 +0000147{
Greg Clayton554f68d2015-02-04 22:00:53 +0000148{ "auto-confirm", OptionValue::eTypeBoolean , true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
149{ "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, NULL, "The default disassembly format string to use when disassembling instruction sequences." },
150{ "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
151{ "notify-void", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
152{ "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
153{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
154{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
155{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
156{ "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." },
157{ "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." },
158{ "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
159{ "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
160{ "use-external-editor", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Whether to use an external editor or not." },
161{ "use-color", OptionValue::eTypeBoolean , true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
162{ "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
163{ "escape-non-printables", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
164{ NULL, OptionValue::eTypeInvalid , true, 0 , NULL, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000165};
166
167enum
168{
169 ePropertyAutoConfirm = 0,
Jason Molendaaff1b352014-10-10 23:07:36 +0000170 ePropertyDisassemblyFormat,
Greg Clayton67cc0632012-08-22 17:17:09 +0000171 ePropertyFrameFormat,
172 ePropertyNotiftVoid,
173 ePropertyPrompt,
174 ePropertyScriptLanguage,
175 ePropertyStopDisassemblyCount,
176 ePropertyStopDisassemblyDisplay,
177 ePropertyStopLineCountAfter,
178 ePropertyStopLineCountBefore,
179 ePropertyTerminalWidth,
180 ePropertyThreadFormat,
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000181 ePropertyUseExternalEditor,
182 ePropertyUseColor,
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000183 ePropertyAutoOneLineSummaries,
184 ePropertyEscapeNonPrintables
Greg Clayton67cc0632012-08-22 17:17:09 +0000185};
186
Zachary Turner3a006912015-03-19 22:00:21 +0000187LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
Greg Clayton4c054102012-09-01 00:38:36 +0000188
189Error
190Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
191 VarSetOperationType op,
192 const char *property_path,
193 const char *value)
194{
Enrico Granata84a53df2013-05-20 22:29:23 +0000195 bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000196 bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0;
Enrico Granata84a53df2013-05-20 22:29:23 +0000197 TargetSP target_sp;
Enrico Granata397ddd52013-05-21 20:13:34 +0000198 LoadScriptFromSymFile load_script_old_value;
Enrico Granata84a53df2013-05-20 22:29:23 +0000199 if (is_load_script && exe_ctx->GetTargetSP())
200 {
201 target_sp = exe_ctx->GetTargetSP();
202 load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
203 }
Greg Clayton4c054102012-09-01 00:38:36 +0000204 Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value));
205 if (error.Success())
206 {
Enrico Granata84a53df2013-05-20 22:29:23 +0000207 // FIXME it would be nice to have "on-change" callbacks for properties
Greg Clayton4c054102012-09-01 00:38:36 +0000208 if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0)
209 {
210 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000211 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
212 if (str.length())
213 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000214 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton4c054102012-09-01 00:38:36 +0000215 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
216 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
217 }
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000218 else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0)
219 {
220 // use-color changed. Ping the prompt so it can reset the ansi terminal codes.
221 SetPrompt (GetPrompt());
222 }
Enrico Granata397ddd52013-05-21 20:13:34 +0000223 else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn)
Enrico Granata84a53df2013-05-20 22:29:23 +0000224 {
Enrico Granata397ddd52013-05-21 20:13:34 +0000225 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue)
Enrico Granata84a53df2013-05-20 22:29:23 +0000226 {
227 std::list<Error> errors;
Enrico Granata97303392013-05-21 00:00:30 +0000228 StreamString feedback_stream;
229 if (!target_sp->LoadScriptingResources(errors,&feedback_stream))
Enrico Granata84a53df2013-05-20 22:29:23 +0000230 {
Greg Clayton44d93782014-01-27 23:43:24 +0000231 StreamFileSP stream_sp (GetErrorFile());
232 if (stream_sp)
Enrico Granata84a53df2013-05-20 22:29:23 +0000233 {
Greg Clayton44d93782014-01-27 23:43:24 +0000234 for (auto error : errors)
235 {
236 stream_sp->Printf("%s\n",error.AsCString());
237 }
238 if (feedback_stream.GetSize())
239 stream_sp->Printf("%s",feedback_stream.GetData());
Enrico Granata84a53df2013-05-20 22:29:23 +0000240 }
241 }
242 }
243 }
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000244 else if (is_escape_non_printables)
245 {
246 DataVisualization::ForceUpdate();
247 }
Greg Clayton4c054102012-09-01 00:38:36 +0000248 }
249 return error;
250}
251
Greg Clayton67cc0632012-08-22 17:17:09 +0000252bool
253Debugger::GetAutoConfirm () const
254{
255 const uint32_t idx = ePropertyAutoConfirm;
Greg Clayton754a9362012-08-23 00:22:02 +0000256 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000257}
258
Greg Clayton554f68d2015-02-04 22:00:53 +0000259const FormatEntity::Entry *
Jason Molendaaff1b352014-10-10 23:07:36 +0000260Debugger::GetDisassemblyFormat() const
261{
262 const uint32_t idx = ePropertyDisassemblyFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000263 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Jason Molendaaff1b352014-10-10 23:07:36 +0000264}
265
Greg Clayton554f68d2015-02-04 22:00:53 +0000266const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000267Debugger::GetFrameFormat() const
268{
269 const uint32_t idx = ePropertyFrameFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000270 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000271}
272
273bool
274Debugger::GetNotifyVoid () const
275{
276 const uint32_t idx = ePropertyNotiftVoid;
Greg Clayton754a9362012-08-23 00:22:02 +0000277 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000278}
279
280const char *
281Debugger::GetPrompt() const
282{
283 const uint32_t idx = ePropertyPrompt;
Greg Clayton754a9362012-08-23 00:22:02 +0000284 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000285}
286
287void
288Debugger::SetPrompt(const char *p)
289{
290 const uint32_t idx = ePropertyPrompt;
291 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
292 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000293 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
294 if (str.length())
295 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000296 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton67cc0632012-08-22 17:17:09 +0000297}
298
Greg Clayton554f68d2015-02-04 22:00:53 +0000299const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000300Debugger::GetThreadFormat() const
301{
302 const uint32_t idx = ePropertyThreadFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000303 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000304}
305
306lldb::ScriptLanguage
307Debugger::GetScriptLanguage() const
308{
309 const uint32_t idx = ePropertyScriptLanguage;
Greg Clayton754a9362012-08-23 00:22:02 +0000310 return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000311}
312
313bool
314Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
315{
316 const uint32_t idx = ePropertyScriptLanguage;
317 return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
318}
319
320uint32_t
321Debugger::GetTerminalWidth () const
322{
323 const uint32_t idx = ePropertyTerminalWidth;
Greg Clayton754a9362012-08-23 00:22:02 +0000324 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000325}
326
327bool
328Debugger::SetTerminalWidth (uint32_t term_width)
329{
330 const uint32_t idx = ePropertyTerminalWidth;
331 return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
332}
333
334bool
335Debugger::GetUseExternalEditor () const
336{
337 const uint32_t idx = ePropertyUseExternalEditor;
Greg Clayton754a9362012-08-23 00:22:02 +0000338 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000339}
340
341bool
342Debugger::SetUseExternalEditor (bool b)
343{
344 const uint32_t idx = ePropertyUseExternalEditor;
345 return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
346}
347
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000348bool
349Debugger::GetUseColor () const
350{
351 const uint32_t idx = ePropertyUseColor;
352 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
353}
354
355bool
356Debugger::SetUseColor (bool b)
357{
358 const uint32_t idx = ePropertyUseColor;
359 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
360 SetPrompt (GetPrompt());
361 return ret;
362}
363
Greg Clayton67cc0632012-08-22 17:17:09 +0000364uint32_t
365Debugger::GetStopSourceLineCount (bool before) const
366{
367 const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
Greg Clayton754a9362012-08-23 00:22:02 +0000368 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000369}
370
371Debugger::StopDisassemblyType
372Debugger::GetStopDisassemblyDisplay () const
373{
374 const uint32_t idx = ePropertyStopDisassemblyDisplay;
Greg Clayton754a9362012-08-23 00:22:02 +0000375 return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000376}
377
378uint32_t
379Debugger::GetDisassemblyLineCount () const
380{
381 const uint32_t idx = ePropertyStopDisassemblyCount;
Greg Clayton754a9362012-08-23 00:22:02 +0000382 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000383}
Greg Claytone372b982011-11-21 21:44:34 +0000384
Enrico Granata553fad52013-10-25 23:09:40 +0000385bool
Enrico Granata90a8db32013-10-31 21:01:07 +0000386Debugger::GetAutoOneLineSummaries () const
Enrico Granata553fad52013-10-25 23:09:40 +0000387{
Enrico Granata90a8db32013-10-31 21:01:07 +0000388 const uint32_t idx = ePropertyAutoOneLineSummaries;
Enrico Granata553fad52013-10-25 23:09:40 +0000389 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000390}
Enrico Granata553fad52013-10-25 23:09:40 +0000391
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000392bool
393Debugger::GetEscapeNonPrintables () const
394{
395 const uint32_t idx = ePropertyEscapeNonPrintables;
396 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granata553fad52013-10-25 23:09:40 +0000397}
398
Greg Clayton1b654882010-09-19 02:33:57 +0000399#pragma mark Debugger
400
Greg Clayton67cc0632012-08-22 17:17:09 +0000401//const DebuggerPropertiesSP &
402//Debugger::GetSettings() const
403//{
404// return m_properties_sp;
405//}
406//
Greg Clayton99d0faf2010-11-18 23:32:35 +0000407
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000408static bool lldb_initialized = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409void
Zachary Turner3a006912015-03-19 22:00:21 +0000410Debugger::Initialize(LoadPluginCallbackType load_plugin_callback)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000412 assert(!lldb_initialized && "Debugger::Initialize called more than once!");
413
Robert Flackf196c932015-03-10 18:07:47 +0000414 lldb_initialized = true;
Greg Clayton5fb8f792013-12-02 19:35:49 +0000415 g_load_plugin_callback = load_plugin_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416}
417
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000418void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419Debugger::Terminate ()
420{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000421 assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!");
422
423 // Clear our master list of debugger objects
424 Mutex::Locker locker (GetDebuggerListMutex ());
425 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426}
427
Caroline Tice20bd37f2011-03-10 22:14:10 +0000428void
429Debugger::SettingsInitialize ()
430{
Greg Clayton6920b522012-08-22 18:39:03 +0000431 Target::SettingsInitialize ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000432}
433
434void
435Debugger::SettingsTerminate ()
436{
Greg Clayton6920b522012-08-22 18:39:03 +0000437 Target::SettingsTerminate ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000438}
439
Enrico Granata21dfcd92012-09-28 23:57:51 +0000440bool
Enrico Granatae743c782013-04-24 21:29:08 +0000441Debugger::LoadPlugin (const FileSpec& spec, Error& error)
Enrico Granata21dfcd92012-09-28 23:57:51 +0000442{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000443 if (g_load_plugin_callback)
Enrico Granatae743c782013-04-24 21:29:08 +0000444 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000445 llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error);
446 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +0000447 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000448 m_loaded_plugins.push_back(dynlib);
Greg Clayton5fb8f792013-12-02 19:35:49 +0000449 return true;
450 }
Enrico Granatae743c782013-04-24 21:29:08 +0000451 }
Greg Clayton5fb8f792013-12-02 19:35:49 +0000452 else
Enrico Granatae743c782013-04-24 21:29:08 +0000453 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000454 // The g_load_plugin_callback is registered in SBDebugger::Initialize()
455 // and if the public API layer isn't available (code is linking against
456 // all of the internal LLDB static libraries), then we can't load plugins
457 error.SetErrorString("Public API layer is not available");
Enrico Granatae743c782013-04-24 21:29:08 +0000458 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000459 return false;
460}
461
462static FileSpec::EnumerateDirectoryResult
463LoadPluginCallback
464(
465 void *baton,
466 FileSpec::FileType file_type,
467 const FileSpec &file_spec
468 )
469{
470 Error error;
471
472 static ConstString g_dylibext("dylib");
Michael Sartain3cf443d2013-07-17 00:26:30 +0000473 static ConstString g_solibext("so");
Enrico Granata21dfcd92012-09-28 23:57:51 +0000474
475 if (!baton)
476 return FileSpec::eEnumerateDirectoryResultQuit;
477
478 Debugger *debugger = (Debugger*)baton;
479
480 // If we have a regular file, a symbolic link or unknown file type, try
481 // and process the file. We must handle unknown as sometimes the directory
482 // enumeration might be enumerating a file system that doesn't have correct
483 // file type information.
484 if (file_type == FileSpec::eFileTypeRegular ||
485 file_type == FileSpec::eFileTypeSymbolicLink ||
486 file_type == FileSpec::eFileTypeUnknown )
487 {
488 FileSpec plugin_file_spec (file_spec);
489 plugin_file_spec.ResolvePath ();
490
Michael Sartain3cf443d2013-07-17 00:26:30 +0000491 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
492 plugin_file_spec.GetFileNameExtension() != g_solibext)
493 {
Enrico Granata21dfcd92012-09-28 23:57:51 +0000494 return FileSpec::eEnumerateDirectoryResultNext;
Michael Sartain3cf443d2013-07-17 00:26:30 +0000495 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000496
Enrico Granatae743c782013-04-24 21:29:08 +0000497 Error plugin_load_error;
498 debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000499
500 return FileSpec::eEnumerateDirectoryResultNext;
501 }
502
503 else if (file_type == FileSpec::eFileTypeUnknown ||
504 file_type == FileSpec::eFileTypeDirectory ||
505 file_type == FileSpec::eFileTypeSymbolicLink )
506 {
507 // Try and recurse into anything that a directory or symbolic link.
508 // We must also do this for unknown as sometimes the directory enumeration
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000509 // might be enumerating a file system that doesn't have correct file type
Enrico Granata21dfcd92012-09-28 23:57:51 +0000510 // information.
511 return FileSpec::eEnumerateDirectoryResultEnter;
512 }
513
514 return FileSpec::eEnumerateDirectoryResultNext;
515}
516
517void
518Debugger::InstanceInitialize ()
519{
520 FileSpec dir_spec;
521 const bool find_directories = true;
522 const bool find_files = true;
523 const bool find_other = true;
524 char dir_path[PATH_MAX];
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000525 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000526 {
527 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
528 {
529 FileSpec::EnumerateDirectory (dir_path,
530 find_directories,
531 find_files,
532 find_other,
533 LoadPluginCallback,
534 this);
535 }
536 }
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000537
538 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, 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 }
Greg Claytone8cd0c92012-10-19 18:02:49 +0000550
551 PluginManager::DebuggerInitialize (*this);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000552}
553
Greg Clayton66111032010-06-23 01:19:29 +0000554DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000555Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000556{
Jim Ingham228063c2012-02-21 02:23:08 +0000557 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000558 if (lldb_initialized)
Greg Clayton66111032010-06-23 01:19:29 +0000559 {
560 Mutex::Locker locker (GetDebuggerListMutex ());
561 GetDebuggerList().push_back(debugger_sp);
562 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000563 debugger_sp->InstanceInitialize ();
Greg Clayton66111032010-06-23 01:19:29 +0000564 return debugger_sp;
565}
566
Caroline Ticee02657b2011-01-22 01:02:07 +0000567void
Greg Clayton4d122c42011-09-17 08:33:22 +0000568Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000569{
570 if (debugger_sp.get() == NULL)
571 return;
572
Jim Ingham8314c522011-09-15 21:36:42 +0000573 debugger_sp->Clear();
574
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000575 if (lldb_initialized)
Caroline Ticee02657b2011-01-22 01:02:07 +0000576 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000577 Mutex::Locker locker (GetDebuggerListMutex ());
578 DebuggerList &debugger_list = GetDebuggerList ();
579 DebuggerList::iterator pos, end = debugger_list.end();
580 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000581 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000582 if ((*pos).get() == debugger_sp.get())
583 {
584 debugger_list.erase (pos);
585 return;
586 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000587 }
588 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000589}
590
Greg Clayton4d122c42011-09-17 08:33:22 +0000591DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000592Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
593{
Greg Clayton4d122c42011-09-17 08:33:22 +0000594 DebuggerSP debugger_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000595 if (lldb_initialized)
Greg Clayton6920b522012-08-22 18:39:03 +0000596 {
597 Mutex::Locker locker (GetDebuggerListMutex ());
598 DebuggerList &debugger_list = GetDebuggerList();
599 DebuggerList::iterator pos, end = debugger_list.end();
600
601 for (pos = debugger_list.begin(); pos != end; ++pos)
602 {
603 if ((*pos).get()->m_instance_name == instance_name)
604 {
605 debugger_sp = *pos;
606 break;
607 }
608 }
609 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000610 return debugger_sp;
611}
Greg Clayton66111032010-06-23 01:19:29 +0000612
613TargetSP
614Debugger::FindTargetWithProcessID (lldb::pid_t pid)
615{
Greg Clayton4d122c42011-09-17 08:33:22 +0000616 TargetSP target_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000617 if (lldb_initialized)
Greg Clayton66111032010-06-23 01:19:29 +0000618 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000619 Mutex::Locker locker (GetDebuggerListMutex ());
620 DebuggerList &debugger_list = GetDebuggerList();
621 DebuggerList::iterator pos, end = debugger_list.end();
622 for (pos = debugger_list.begin(); pos != end; ++pos)
623 {
624 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
625 if (target_sp)
626 break;
627 }
Greg Clayton66111032010-06-23 01:19:29 +0000628 }
629 return target_sp;
630}
631
Greg Claytone4e45922011-11-16 05:37:56 +0000632TargetSP
633Debugger::FindTargetWithProcess (Process *process)
634{
635 TargetSP target_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000636 if (lldb_initialized)
Greg Claytone4e45922011-11-16 05:37:56 +0000637 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000638 Mutex::Locker locker (GetDebuggerListMutex ());
639 DebuggerList &debugger_list = GetDebuggerList();
640 DebuggerList::iterator pos, end = debugger_list.end();
641 for (pos = debugger_list.begin(); pos != end; ++pos)
642 {
643 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
644 if (target_sp)
645 break;
646 }
Greg Claytone4e45922011-11-16 05:37:56 +0000647 }
648 return target_sp;
649}
650
Jason Molendae6481c72014-09-12 01:50:46 +0000651Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
652 UserID(g_unique_id++),
653 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
654 m_input_file_sp(new StreamFile(stdin, false)),
655 m_output_file_sp(new StreamFile(stdout, false)),
656 m_error_file_sp(new StreamFile(stderr, false)),
657 m_terminal_state(),
658 m_target_list(*this),
659 m_platform_list(),
660 m_listener("lldb.Debugger"),
661 m_source_manager_ap(),
662 m_source_file_cache(),
663 m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)),
664 m_input_reader_stack(),
665 m_instance_name(),
Greg Claytonafa91e332014-12-01 22:41:27 +0000666 m_loaded_plugins(),
667 m_event_handler_thread (),
668 m_io_handler_thread (),
669 m_sync_broadcaster (NULL, "lldb.debugger.sync")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670{
Greg Clayton67cc0632012-08-22 17:17:09 +0000671 char instance_cstr[256];
672 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
673 m_instance_name.SetCString(instance_cstr);
Jim Ingham228063c2012-02-21 02:23:08 +0000674 if (log_callback)
675 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000676 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000677 // Always add our default platform to the platform list
Greg Clayton615eb7e2014-09-19 20:11:50 +0000678 PlatformSP default_platform_sp (Platform::GetHostPlatform());
Greg Claytonded470d2011-03-19 01:12:21 +0000679 assert (default_platform_sp.get());
680 m_platform_list.Append (default_platform_sp, true);
Greg Clayton67cc0632012-08-22 17:17:09 +0000681
Greg Clayton754a9362012-08-23 00:22:02 +0000682 m_collection_sp->Initialize (g_properties);
Greg Clayton67cc0632012-08-22 17:17:09 +0000683 m_collection_sp->AppendProperty (ConstString("target"),
684 ConstString("Settings specify to debugging targets."),
685 true,
686 Target::GetGlobalProperties()->GetValueProperties());
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000687 m_collection_sp->AppendProperty (ConstString("platform"),
688 ConstString("Platform settings."),
689 true,
690 Platform::GetGlobalPlatformProperties()->GetValueProperties());
Greg Clayton754a9362012-08-23 00:22:02 +0000691 if (m_command_interpreter_ap.get())
692 {
693 m_collection_sp->AppendProperty (ConstString("interpreter"),
694 ConstString("Settings specify to the debugger's command interpreter."),
695 true,
696 m_command_interpreter_ap->GetValueProperties());
697 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000698 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
699 term_width->SetMinimumValue(10);
700 term_width->SetMaximumValue(1024);
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000701
702 // Turn off use-color if this is a dumb terminal.
703 const char *term = getenv ("TERM");
704 if (term && !strcmp (term, "dumb"))
705 SetUseColor (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706}
707
708Debugger::~Debugger ()
709{
Jim Ingham8314c522011-09-15 21:36:42 +0000710 Clear();
711}
712
713void
714Debugger::Clear()
715{
Greg Clayton44d93782014-01-27 23:43:24 +0000716 ClearIOHandlers();
717 StopIOHandlerThread();
718 StopEventHandlerThread();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000719 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000720 int num_targets = m_target_list.GetNumTargets();
721 for (int i = 0; i < num_targets; i++)
722 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000723 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
724 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000725 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000726 ProcessSP process_sp (target_sp->GetProcessSP());
727 if (process_sp)
Jim Ingham1fd07052013-02-27 19:13:05 +0000728 process_sp->Finalize();
Greg Claytonccbc08e2012-01-14 17:04:19 +0000729 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000730 }
Greg Clayton66111032010-06-23 01:19:29 +0000731 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000732 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000733
734 // Close the input file _before_ we close the input read communications class
735 // as it does NOT own the input file, our m_input_file does.
Jim Inghamc5917d92012-11-30 20:23:19 +0000736 m_terminal_state.Clear();
Greg Clayton44d93782014-01-27 23:43:24 +0000737 if (m_input_file_sp)
738 m_input_file_sp->GetFile().Close ();
Greg Clayton0c4129f2014-04-25 00:35:14 +0000739
740 m_command_interpreter_ap->Clear();
Jim Ingham8314c522011-09-15 21:36:42 +0000741}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000742
743bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000744Debugger::GetCloseInputOnEOF () const
745{
Greg Clayton44d93782014-01-27 23:43:24 +0000746// return m_input_comm.GetCloseOnEOF();
747 return false;
Greg Claytonfc3f0272011-05-29 04:06:55 +0000748}
749
750void
751Debugger::SetCloseInputOnEOF (bool b)
752{
Greg Clayton44d93782014-01-27 23:43:24 +0000753// m_input_comm.SetCloseOnEOF(b);
Greg Claytonfc3f0272011-05-29 04:06:55 +0000754}
755
756bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757Debugger::GetAsyncExecution ()
758{
Greg Clayton66111032010-06-23 01:19:29 +0000759 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760}
761
762void
763Debugger::SetAsyncExecution (bool async_execution)
764{
Greg Clayton66111032010-06-23 01:19:29 +0000765 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766}
767
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768
769void
770Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
771{
Greg Clayton44d93782014-01-27 23:43:24 +0000772 if (m_input_file_sp)
773 m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership);
774 else
775 m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
776
777 File &in_file = m_input_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000778 if (in_file.IsValid() == false)
779 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780
Jim Inghamc5917d92012-11-30 20:23:19 +0000781 // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
782 SaveInputTerminalState ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783}
784
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785void
786Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
787{
Greg Clayton44d93782014-01-27 23:43:24 +0000788 if (m_output_file_sp)
789 m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership);
790 else
791 m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
792
793 File &out_file = m_output_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000794 if (out_file.IsValid() == false)
795 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000796
Enrico Granatab5887262012-10-29 21:18:03 +0000797 // do not create the ScriptInterpreter just for setting the output file handle
798 // as the constructor will know how to do the right thing on its own
799 const bool can_create = false;
800 ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create);
801 if (script_interpreter)
802 script_interpreter->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803}
804
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805void
806Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
807{
Greg Clayton44d93782014-01-27 23:43:24 +0000808 if (m_error_file_sp)
809 m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership);
810 else
811 m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
812
813 File &err_file = m_error_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000814 if (err_file.IsValid() == false)
815 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816}
817
Jim Inghamc5917d92012-11-30 20:23:19 +0000818void
819Debugger::SaveInputTerminalState ()
820{
Greg Clayton44d93782014-01-27 23:43:24 +0000821 if (m_input_file_sp)
822 {
823 File &in_file = m_input_file_sp->GetFile();
824 if (in_file.GetDescriptor() != File::kInvalidDescriptor)
825 m_terminal_state.Save(in_file.GetDescriptor(), true);
826 }
Jim Inghamc5917d92012-11-30 20:23:19 +0000827}
828
829void
830Debugger::RestoreInputTerminalState ()
831{
832 m_terminal_state.Restore();
833}
834
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000835ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000836Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837{
838 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000839 TargetSP target_sp(GetSelectedTarget());
840 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000841
842 if (target_sp)
843 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000844 ProcessSP process_sp (target_sp->GetProcessSP());
845 exe_ctx.SetProcessSP (process_sp);
846 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000847 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000848 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
849 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000851 exe_ctx.SetThreadSP (thread_sp);
852 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
853 if (exe_ctx.GetFramePtr() == NULL)
854 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 }
856 }
857 }
858 return exe_ctx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859}
860
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861void
Caroline Ticeefed6132010-11-19 20:47:54 +0000862Debugger::DispatchInputInterrupt ()
863{
Greg Clayton44d93782014-01-27 23:43:24 +0000864 Mutex::Locker locker (m_input_reader_stack.GetMutex());
865 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000866 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000867 reader_sp->Interrupt();
Caroline Ticeefed6132010-11-19 20:47:54 +0000868}
869
870void
871Debugger::DispatchInputEndOfFile ()
872{
Greg Clayton44d93782014-01-27 23:43:24 +0000873 Mutex::Locker locker (m_input_reader_stack.GetMutex());
874 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000875 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000876 reader_sp->GotEOF();
Caroline Ticeefed6132010-11-19 20:47:54 +0000877}
878
879void
Greg Clayton44d93782014-01-27 23:43:24 +0000880Debugger::ClearIOHandlers ()
Caroline Tice3d6086f2010-12-20 18:35:50 +0000881{
Caroline Ticeb44880c2011-02-10 01:15:13 +0000882 // 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 +0000883 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000884 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000885 {
Greg Clayton44d93782014-01-27 23:43:24 +0000886 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000887 if (reader_sp)
Pavel Labath44464872015-05-27 12:40:32 +0000888 PopIOHandler (reader_sp);
Caroline Tice3d6086f2010-12-20 18:35:50 +0000889 }
890}
891
892void
Siva Chandra9aaab552015-02-26 19:26:36 +0000893Debugger::ExecuteIOHandlers()
Caroline Tice969ed3d2011-05-02 20:41:46 +0000894{
Greg Clayton44d93782014-01-27 23:43:24 +0000895 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896 {
Greg Clayton44d93782014-01-27 23:43:24 +0000897 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000898 if (!reader_sp)
899 break;
900
Greg Clayton44d93782014-01-27 23:43:24 +0000901 reader_sp->Run();
Greg Clayton44d93782014-01-27 23:43:24 +0000902
903 // Remove all input readers that are done from the top of the stack
904 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000905 {
Greg Clayton44d93782014-01-27 23:43:24 +0000906 IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
907 if (top_reader_sp && top_reader_sp->GetIsDone())
Pavel Labath44464872015-05-27 12:40:32 +0000908 PopIOHandler (top_reader_sp);
Greg Clayton44d93782014-01-27 23:43:24 +0000909 else
910 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 }
912 }
Greg Clayton44d93782014-01-27 23:43:24 +0000913 ClearIOHandlers();
914}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000915
Greg Clayton44d93782014-01-27 23:43:24 +0000916bool
917Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
918{
919 return m_input_reader_stack.IsTop (reader_sp);
920}
921
Pavel Labath44464872015-05-27 12:40:32 +0000922void
923Debugger::PrintAsync (const char *s, size_t len, bool is_stdout)
924{
925 lldb::StreamFileSP stream = is_stdout ? GetOutputFile() : GetErrorFile();
926 m_input_reader_stack.PrintAsync(stream.get(), s, len);
927}
Greg Clayton44d93782014-01-27 23:43:24 +0000928
929ConstString
930Debugger::GetTopIOHandlerControlSequence(char ch)
931{
932 return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000933}
934
Kate Stonea487aa42015-01-15 00:52:41 +0000935const char *
936Debugger::GetIOHandlerCommandPrefix()
937{
938 return m_input_reader_stack.GetTopIOHandlerCommandPrefix();
939}
940
941const char *
942Debugger::GetIOHandlerHelpPrologue()
943{
944 return m_input_reader_stack.GetTopIOHandlerHelpPrologue();
945}
946
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000947void
Greg Clayton44d93782014-01-27 23:43:24 +0000948Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
949{
Greg Clayton44d93782014-01-27 23:43:24 +0000950 PushIOHandler (reader_sp);
Pavel Labath44464872015-05-27 12:40:32 +0000951
Greg Clayton577508d2014-06-20 00:23:57 +0000952 IOHandlerSP top_reader_sp = reader_sp;
953 while (top_reader_sp)
954 {
Greg Clayton577508d2014-06-20 00:23:57 +0000955 top_reader_sp->Run();
Pavel Labath44464872015-05-27 12:40:32 +0000956
Greg Clayton577508d2014-06-20 00:23:57 +0000957 if (top_reader_sp.get() == reader_sp.get())
958 {
959 if (PopIOHandler (reader_sp))
960 break;
961 }
Pavel Labath44464872015-05-27 12:40:32 +0000962
Greg Clayton577508d2014-06-20 00:23:57 +0000963 while (1)
964 {
965 top_reader_sp = m_input_reader_stack.Top();
966 if (top_reader_sp && top_reader_sp->GetIsDone())
Pavel Labath44464872015-05-27 12:40:32 +0000967 PopIOHandler (top_reader_sp);
Greg Clayton577508d2014-06-20 00:23:57 +0000968 else
969 break;
970 }
971 }
Greg Clayton44d93782014-01-27 23:43:24 +0000972}
973
974void
975Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
976{
977 // Before an IOHandler runs, it must have in/out/err streams.
978 // This function is called when one ore more of the streams
979 // are NULL. We use the top input reader's in/out/err streams,
980 // or fall back to the debugger file handles, or we fall back
981 // onto stdin/stdout/stderr as a last resort.
982
983 Mutex::Locker locker (m_input_reader_stack.GetMutex());
984 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
985 // If no STDIN has been set, then set it appropriately
986 if (!in)
987 {
988 if (top_reader_sp)
989 in = top_reader_sp->GetInputStreamFile();
990 else
991 in = GetInputFile();
992
993 // If there is nothing, use stdin
994 if (!in)
995 in = StreamFileSP(new StreamFile(stdin, false));
996 }
997 // If no STDOUT has been set, then set it appropriately
998 if (!out)
999 {
1000 if (top_reader_sp)
1001 out = top_reader_sp->GetOutputStreamFile();
1002 else
1003 out = GetOutputFile();
1004
1005 // If there is nothing, use stdout
1006 if (!out)
1007 out = StreamFileSP(new StreamFile(stdout, false));
1008 }
1009 // If no STDERR has been set, then set it appropriately
1010 if (!err)
1011 {
1012 if (top_reader_sp)
1013 err = top_reader_sp->GetErrorStreamFile();
1014 else
1015 err = GetErrorFile();
1016
1017 // If there is nothing, use stderr
1018 if (!err)
1019 err = StreamFileSP(new StreamFile(stdout, false));
1020
1021 }
1022}
1023
1024void
1025Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026{
1027 if (!reader_sp)
1028 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +00001029
Pavel Labath44464872015-05-27 12:40:32 +00001030 Mutex::Locker locker (m_input_reader_stack.GetMutex());
1031
1032 // Get the current top input reader...
Greg Clayton44d93782014-01-27 23:43:24 +00001033 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +00001034
Greg Claytonb4874f12014-02-28 18:22:24 +00001035 // Don't push the same IO handler twice...
Pavel Labath44464872015-05-27 12:40:32 +00001036 if (reader_sp == top_reader_sp)
1037 return;
Greg Clayton44d93782014-01-27 23:43:24 +00001038
Pavel Labath44464872015-05-27 12:40:32 +00001039 // Push our new input reader
1040 m_input_reader_stack.Push (reader_sp);
1041 reader_sp->Activate();
1042
1043 // Interrupt the top input reader to it will exit its Run() function
1044 // and let this new input reader take over
1045 if (top_reader_sp)
1046 {
1047 top_reader_sp->Deactivate();
1048 top_reader_sp->Cancel();
Greg Claytonb4874f12014-02-28 18:22:24 +00001049 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001050}
1051
1052bool
Greg Clayton44d93782014-01-27 23:43:24 +00001053Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054{
Pavel Labath44464872015-05-27 12:40:32 +00001055 if (! pop_reader_sp)
1056 return false;
1057
Greg Clayton44d93782014-01-27 23:43:24 +00001058 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059
1060 // The reader on the stop of the stack is done, so let the next
Bruce Mitchener6a7f3332014-06-27 02:42:12 +00001061 // read on the stack refresh its prompt and if there is one...
Pavel Labath44464872015-05-27 12:40:32 +00001062 if (m_input_reader_stack.IsEmpty())
1063 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064
Greg Clayton44d93782014-01-27 23:43:24 +00001065 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Greg Clayton66111032010-06-23 01:19:29 +00001066
Pavel Labath44464872015-05-27 12:40:32 +00001067 if (pop_reader_sp != reader_sp)
1068 return false;
1069
1070 reader_sp->Deactivate();
1071 reader_sp->Cancel();
1072 m_input_reader_stack.Pop ();
1073
1074 reader_sp = m_input_reader_stack.Top();
1075 if (reader_sp)
1076 reader_sp->Activate();
1077
1078 return true;
1079}
Greg Clayton44d93782014-01-27 23:43:24 +00001080
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001081StreamSP
1082Debugger::GetAsyncOutputStream ()
1083{
Pavel Labath44464872015-05-27 12:40:32 +00001084 return StreamSP (new StreamAsynchronousIO (*this, true));
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001085}
1086
1087StreamSP
1088Debugger::GetAsyncErrorStream ()
1089{
Pavel Labath44464872015-05-27 12:40:32 +00001090 return StreamSP (new StreamAsynchronousIO (*this, false));
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001091}
1092
Greg Claytonc7bece562013-01-25 18:06:21 +00001093size_t
Enrico Granata061858c2012-02-15 02:34:21 +00001094Debugger::GetNumDebuggers()
1095{
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001096 if (lldb_initialized)
Greg Claytonc15f55e2012-03-30 20:53:46 +00001097 {
1098 Mutex::Locker locker (GetDebuggerListMutex ());
1099 return GetDebuggerList().size();
1100 }
1101 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +00001102}
1103
1104lldb::DebuggerSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001105Debugger::GetDebuggerAtIndex (size_t index)
Enrico Granata061858c2012-02-15 02:34:21 +00001106{
1107 DebuggerSP debugger_sp;
1108
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001109 if (lldb_initialized)
Greg Claytonc15f55e2012-03-30 20:53:46 +00001110 {
1111 Mutex::Locker locker (GetDebuggerListMutex ());
1112 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +00001113
Greg Claytonc15f55e2012-03-30 20:53:46 +00001114 if (index < debugger_list.size())
1115 debugger_sp = debugger_list[index];
1116 }
1117
Enrico Granata061858c2012-02-15 02:34:21 +00001118 return debugger_sp;
1119}
1120
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001121DebuggerSP
1122Debugger::FindDebuggerWithID (lldb::user_id_t id)
1123{
Greg Clayton4d122c42011-09-17 08:33:22 +00001124 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001125
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001126 if (lldb_initialized)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001127 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001128 Mutex::Locker locker (GetDebuggerListMutex ());
1129 DebuggerList &debugger_list = GetDebuggerList();
1130 DebuggerList::iterator pos, end = debugger_list.end();
1131 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001132 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001133 if ((*pos).get()->GetID() == id)
1134 {
1135 debugger_sp = *pos;
1136 break;
1137 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001138 }
1139 }
1140 return debugger_sp;
1141}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001142
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001143#if 0
Greg Clayton1b654882010-09-19 02:33:57 +00001144static void
Jason Molendab57e4a12013-11-04 09:33:30 +00001145TestPromptFormats (StackFrame *frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001146{
1147 if (frame == NULL)
1148 return;
1149
1150 StreamString s;
1151 const char *prompt_format =
1152 "{addr = '${addr}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001153 "{addr-file-or-load = '${addr-file-or-load}'\n}"
1154 "{current-pc-arrow = '${current-pc-arrow}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001155 "{process.id = '${process.id}'\n}"
1156 "{process.name = '${process.name}'\n}"
1157 "{process.file.basename = '${process.file.basename}'\n}"
1158 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1159 "{thread.id = '${thread.id}'\n}"
1160 "{thread.index = '${thread.index}'\n}"
1161 "{thread.name = '${thread.name}'\n}"
1162 "{thread.queue = '${thread.queue}'\n}"
1163 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1164 "{target.arch = '${target.arch}'\n}"
1165 "{module.file.basename = '${module.file.basename}'\n}"
1166 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1167 "{file.basename = '${file.basename}'\n}"
1168 "{file.fullpath = '${file.fullpath}'\n}"
1169 "{frame.index = '${frame.index}'\n}"
1170 "{frame.pc = '${frame.pc}'\n}"
1171 "{frame.sp = '${frame.sp}'\n}"
1172 "{frame.fp = '${frame.fp}'\n}"
1173 "{frame.flags = '${frame.flags}'\n}"
1174 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1175 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1176 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1177 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1178 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1179 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1180 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1181 "{function.id = '${function.id}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001182 "{function.changed = '${function.changed}'\n}"
1183 "{function.initial-function = '${function.initial-function}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001184 "{function.name = '${function.name}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001185 "{function.name-without-args = '${function.name-without-args}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +00001186 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001187 "{function.addr-offset = '${function.addr-offset}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001188 "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001189 "{function.line-offset = '${function.line-offset}'\n}"
1190 "{function.pc-offset = '${function.pc-offset}'\n}"
1191 "{line.file.basename = '${line.file.basename}'\n}"
1192 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1193 "{line.number = '${line.number}'\n}"
1194 "{line.start-addr = '${line.start-addr}'\n}"
1195 "{line.end-addr = '${line.end-addr}'\n}"
1196;
1197
1198 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1199 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +00001200 frame->CalculateExecutionContext(exe_ctx);
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001201 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
Greg Clayton1b654882010-09-19 02:33:57 +00001202 {
1203 printf("%s\n", s.GetData());
1204 }
1205 else
1206 {
Greg Clayton1b654882010-09-19 02:33:57 +00001207 printf ("what we got: %s\n", s.GetData());
1208 }
1209}
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001210#endif
Greg Clayton1b654882010-09-19 02:33:57 +00001211
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001212bool
Greg Clayton554f68d2015-02-04 22:00:53 +00001213Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
Jason Molendaaff1b352014-10-10 23:07:36 +00001214 const SymbolContext *sc,
1215 const SymbolContext *prev_sc,
1216 const ExecutionContext *exe_ctx,
1217 const Address *addr,
1218 Stream &s)
1219{
Greg Clayton554f68d2015-02-04 22:00:53 +00001220 FormatEntity::Entry format_entry;
1221
1222 if (format == NULL)
Jason Molendaaff1b352014-10-10 23:07:36 +00001223 {
Greg Clayton554f68d2015-02-04 22:00:53 +00001224 if (exe_ctx != NULL && exe_ctx->HasTargetScope())
1225 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1226 if (format == NULL)
1227 {
1228 FormatEntity::Parse("${addr}: ", format_entry);
1229 format = &format_entry;
1230 }
Jason Molendaaff1b352014-10-10 23:07:36 +00001231 }
1232 bool function_changed = false;
1233 bool initial_function = false;
1234 if (prev_sc && (prev_sc->function || prev_sc->symbol))
1235 {
1236 if (sc && (sc->function || sc->symbol))
1237 {
1238 if (prev_sc->symbol && sc->symbol)
1239 {
1240 if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType()))
1241 {
1242 function_changed = true;
1243 }
1244 }
1245 else if (prev_sc->function && sc->function)
1246 {
1247 if (prev_sc->function->GetMangled() != sc->function->GetMangled())
1248 {
1249 function_changed = true;
1250 }
1251 }
1252 }
1253 }
1254 // The first context on a list of instructions will have a prev_sc that
1255 // has no Function or Symbol -- if SymbolContext had an IsValid() method, it
1256 // would return false. But we do get a prev_sc pointer.
1257 if ((sc && (sc->function || sc->symbol))
1258 && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL))
1259 {
1260 initial_function = true;
1261 }
Greg Clayton554f68d2015-02-04 22:00:53 +00001262 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, NULL, function_changed, initial_function);
Jason Molendaaff1b352014-10-10 23:07:36 +00001263}
1264
1265
Jim Ingham228063c2012-02-21 02:23:08 +00001266void
1267Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1268{
Jim Ingham4f02b222012-02-22 22:49:20 +00001269 // For simplicity's sake, I am not going to deal with how to close down any
1270 // open logging streams, I just redirect everything from here on out to the
1271 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00001272 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
1273}
1274
1275bool
1276Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
1277{
Jim Ingham228063c2012-02-21 02:23:08 +00001278 StreamSP log_stream_sp;
Sean Callanan9a028512012-08-09 00:50:26 +00001279 if (m_log_callback_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001280 {
1281 log_stream_sp = m_log_callback_stream_sp;
1282 // For now when using the callback mode you always get thread & timestamp.
1283 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1284 }
1285 else if (log_file == NULL || *log_file == '\0')
1286 {
Greg Clayton44d93782014-01-27 23:43:24 +00001287 log_stream_sp = GetOutputFile();
Jim Ingham228063c2012-02-21 02:23:08 +00001288 }
1289 else
1290 {
1291 LogStreamMap::iterator pos = m_log_streams.find(log_file);
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001292 if (pos != m_log_streams.end())
1293 log_stream_sp = pos->second.lock();
1294 if (!log_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001295 {
Pavel Labath8ac06992015-03-20 09:43:20 +00001296 uint32_t options = File::eOpenOptionWrite | File::eOpenOptionCanCreate
1297 | File::eOpenOptionCloseOnExec | File::eOpenOptionAppend;
1298 if (! (log_options & LLDB_LOG_OPTION_APPEND))
1299 options |= File::eOpenOptionTruncate;
1300
1301 log_stream_sp.reset (new StreamFile (log_file, options));
Jim Ingham228063c2012-02-21 02:23:08 +00001302 m_log_streams[log_file] = log_stream_sp;
1303 }
Jim Ingham228063c2012-02-21 02:23:08 +00001304 }
1305 assert (log_stream_sp.get());
1306
1307 if (log_options == 0)
1308 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
1309
Tamas Berghammer9c9ecce2015-05-27 13:34:04 +00001310 return Log::EnableLogChannel(log_stream_sp, log_options, channel, categories, error_stream);
Jim Ingham228063c2012-02-21 02:23:08 +00001311}
1312
Greg Clayton9585fbf2013-03-19 00:20:55 +00001313SourceManager &
1314Debugger::GetSourceManager ()
1315{
1316 if (m_source_manager_ap.get() == NULL)
1317 m_source_manager_ap.reset (new SourceManager (shared_from_this()));
1318 return *m_source_manager_ap;
1319}
1320
1321
Greg Clayton44d93782014-01-27 23:43:24 +00001322
1323// This function handles events that were broadcast by the process.
1324void
1325Debugger::HandleBreakpointEvent (const EventSP &event_sp)
1326{
1327 using namespace lldb;
1328 const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp);
1329
1330// if (event_type & eBreakpointEventTypeAdded
1331// || event_type & eBreakpointEventTypeRemoved
1332// || event_type & eBreakpointEventTypeEnabled
1333// || event_type & eBreakpointEventTypeDisabled
1334// || event_type & eBreakpointEventTypeCommandChanged
1335// || event_type & eBreakpointEventTypeConditionChanged
1336// || event_type & eBreakpointEventTypeIgnoreChanged
1337// || event_type & eBreakpointEventTypeLocationsResolved)
1338// {
1339// // Don't do anything about these events, since the breakpoint commands already echo these actions.
1340// }
1341//
1342 if (event_type & eBreakpointEventTypeLocationsAdded)
1343 {
1344 uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp);
1345 if (num_new_locations > 0)
1346 {
1347 BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
Pavel Labath44464872015-05-27 12:40:32 +00001348 StreamSP output_sp (GetAsyncOutputStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001349 if (output_sp)
1350 {
1351 output_sp->Printf("%d location%s added to breakpoint %d\n",
1352 num_new_locations,
1353 num_new_locations == 1 ? "" : "s",
1354 breakpoint->GetID());
Pavel Labath44464872015-05-27 12:40:32 +00001355 output_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001356 }
1357 }
1358 }
1359// else if (event_type & eBreakpointEventTypeLocationsRemoved)
1360// {
1361// // These locations just get disabled, not sure it is worth spamming folks about this on the command line.
1362// }
1363// else if (event_type & eBreakpointEventTypeLocationsResolved)
1364// {
1365// // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy.
1366// }
1367}
1368
1369size_t
1370Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
1371{
1372 size_t total_bytes = 0;
1373 if (stream == NULL)
1374 stream = GetOutputFile().get();
1375
1376 if (stream)
1377 {
1378 // The process has stuff waiting for stdout; get it and write it out to the appropriate place.
1379 if (process == NULL)
1380 {
1381 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1382 if (target_sp)
1383 process = target_sp->GetProcessSP().get();
1384 }
1385 if (process)
1386 {
1387 Error error;
1388 size_t len;
1389 char stdio_buffer[1024];
1390 while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1391 {
1392 stream->Write(stdio_buffer, len);
1393 total_bytes += len;
1394 }
1395 }
1396 stream->Flush();
1397 }
1398 return total_bytes;
1399}
1400
1401size_t
1402Debugger::GetProcessSTDERR (Process *process, Stream *stream)
1403{
1404 size_t total_bytes = 0;
1405 if (stream == NULL)
1406 stream = GetOutputFile().get();
1407
1408 if (stream)
1409 {
1410 // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
1411 if (process == NULL)
1412 {
1413 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1414 if (target_sp)
1415 process = target_sp->GetProcessSP().get();
1416 }
1417 if (process)
1418 {
1419 Error error;
1420 size_t len;
1421 char stdio_buffer[1024];
1422 while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1423 {
1424 stream->Write(stdio_buffer, len);
1425 total_bytes += len;
1426 }
1427 }
1428 stream->Flush();
1429 }
1430 return total_bytes;
1431}
1432
Greg Claytondc6224e2014-10-21 01:00:42 +00001433
Greg Clayton44d93782014-01-27 23:43:24 +00001434// This function handles events that were broadcast by the process.
1435void
1436Debugger::HandleProcessEvent (const EventSP &event_sp)
1437{
1438 using namespace lldb;
1439 const uint32_t event_type = event_sp->GetType();
1440 ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
Greg Claytondc6224e2014-10-21 01:00:42 +00001441
Pavel Labath44464872015-05-27 12:40:32 +00001442 StreamSP output_stream_sp = GetAsyncOutputStream();
1443 StreamSP error_stream_sp = GetAsyncErrorStream();
Greg Clayton44d93782014-01-27 23:43:24 +00001444 const bool gui_enabled = IsForwardingEvents();
Greg Clayton44d93782014-01-27 23:43:24 +00001445
Greg Claytonb4874f12014-02-28 18:22:24 +00001446 if (!gui_enabled)
1447 {
1448 bool pop_process_io_handler = false;
1449 assert (process_sp);
Greg Claytondc6224e2014-10-21 01:00:42 +00001450
Pavel Labath44464872015-05-27 12:40:32 +00001451 bool state_is_stopped = false;
1452 const bool got_state_changed = (event_type & Process::eBroadcastBitStateChanged) != 0;
1453 const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0;
1454 const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0;
1455 if (got_state_changed)
Greg Clayton44d93782014-01-27 23:43:24 +00001456 {
Pavel Labath44464872015-05-27 12:40:32 +00001457 StateType event_state = Process::ProcessEventData::GetStateFromEvent (event_sp.get());
1458 state_is_stopped = StateIsStoppedState(event_state, false);
Greg Claytonb4874f12014-02-28 18:22:24 +00001459 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001460
Pavel Labath44464872015-05-27 12:40:32 +00001461 // Display running state changes first before any STDIO
1462 if (got_state_changed && !state_is_stopped)
Greg Claytonb4874f12014-02-28 18:22:24 +00001463 {
Pavel Labath44464872015-05-27 12:40:32 +00001464 Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler);
Greg Claytonb4874f12014-02-28 18:22:24 +00001465 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001466
Pavel Labath44464872015-05-27 12:40:32 +00001467 // Now display and STDOUT
1468 if (got_stdout || got_state_changed)
Greg Claytonb4874f12014-02-28 18:22:24 +00001469 {
Pavel Labath44464872015-05-27 12:40:32 +00001470 GetProcessSTDOUT (process_sp.get(), output_stream_sp.get());
Greg Clayton44d93782014-01-27 23:43:24 +00001471 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001472
Pavel Labath44464872015-05-27 12:40:32 +00001473 // Now display and STDERR
1474 if (got_stderr || got_state_changed)
Greg Claytonb4874f12014-02-28 18:22:24 +00001475 {
Pavel Labath44464872015-05-27 12:40:32 +00001476 GetProcessSTDERR (process_sp.get(), error_stream_sp.get());
Greg Claytonb4874f12014-02-28 18:22:24 +00001477 }
1478
Pavel Labath44464872015-05-27 12:40:32 +00001479 // Now display any stopped state changes after any STDIO
1480 if (got_state_changed && state_is_stopped)
1481 {
1482 Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler);
1483 }
1484
1485 output_stream_sp->Flush();
1486 error_stream_sp->Flush();
1487
Greg Claytonb4874f12014-02-28 18:22:24 +00001488 if (pop_process_io_handler)
1489 process_sp->PopProcessIOHandler();
1490 }
Greg Clayton44d93782014-01-27 23:43:24 +00001491}
1492
1493void
1494Debugger::HandleThreadEvent (const EventSP &event_sp)
1495{
1496 // At present the only thread event we handle is the Frame Changed event,
1497 // and all we do for that is just reprint the thread status for that thread.
1498 using namespace lldb;
1499 const uint32_t event_type = event_sp->GetType();
1500 if (event_type == Thread::eBroadcastBitStackChanged ||
1501 event_type == Thread::eBroadcastBitThreadSelected )
1502 {
1503 ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get()));
1504 if (thread_sp)
1505 {
Pavel Labath44464872015-05-27 12:40:32 +00001506 thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1);
Greg Clayton44d93782014-01-27 23:43:24 +00001507 }
1508 }
1509}
1510
1511bool
1512Debugger::IsForwardingEvents ()
1513{
1514 return (bool)m_forward_listener_sp;
1515}
1516
1517void
1518Debugger::EnableForwardEvents (const ListenerSP &listener_sp)
1519{
1520 m_forward_listener_sp = listener_sp;
1521}
1522
1523void
1524Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
1525{
1526 m_forward_listener_sp.reset();
1527}
1528
1529
1530void
1531Debugger::DefaultEventHandler()
1532{
1533 Listener& listener(GetListener());
1534 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1535 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1536 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1537 BroadcastEventSpec target_event_spec (broadcaster_class_target,
1538 Target::eBroadcastBitBreakpointChanged);
1539
1540 BroadcastEventSpec process_event_spec (broadcaster_class_process,
1541 Process::eBroadcastBitStateChanged |
1542 Process::eBroadcastBitSTDOUT |
1543 Process::eBroadcastBitSTDERR);
1544
1545 BroadcastEventSpec thread_event_spec (broadcaster_class_thread,
1546 Thread::eBroadcastBitStackChanged |
1547 Thread::eBroadcastBitThreadSelected );
1548
1549 listener.StartListeningForEventSpec (*this, target_event_spec);
1550 listener.StartListeningForEventSpec (*this, process_event_spec);
1551 listener.StartListeningForEventSpec (*this, thread_event_spec);
1552 listener.StartListeningForEvents (m_command_interpreter_ap.get(),
1553 CommandInterpreter::eBroadcastBitQuitCommandReceived |
1554 CommandInterpreter::eBroadcastBitAsynchronousOutputData |
1555 CommandInterpreter::eBroadcastBitAsynchronousErrorData );
Greg Claytonafa91e332014-12-01 22:41:27 +00001556
1557 // Let the thread that spawned us know that we have started up and
1558 // that we are now listening to all required events so no events get missed
1559 m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
1560
Greg Clayton44d93782014-01-27 23:43:24 +00001561 bool done = false;
1562 while (!done)
1563 {
Greg Clayton44d93782014-01-27 23:43:24 +00001564 EventSP event_sp;
1565 if (listener.WaitForEvent(NULL, event_sp))
1566 {
1567 if (event_sp)
1568 {
1569 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1570 if (broadcaster)
1571 {
1572 uint32_t event_type = event_sp->GetType();
1573 ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
1574 if (broadcaster_class == broadcaster_class_process)
1575 {
1576 HandleProcessEvent (event_sp);
1577 }
1578 else if (broadcaster_class == broadcaster_class_target)
1579 {
1580 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get()))
1581 {
1582 HandleBreakpointEvent (event_sp);
1583 }
1584 }
1585 else if (broadcaster_class == broadcaster_class_thread)
1586 {
1587 HandleThreadEvent (event_sp);
1588 }
1589 else if (broadcaster == m_command_interpreter_ap.get())
1590 {
1591 if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived)
1592 {
1593 done = true;
1594 }
1595 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData)
1596 {
1597 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1598 if (data && data[0])
1599 {
Pavel Labath44464872015-05-27 12:40:32 +00001600 StreamSP error_sp (GetAsyncErrorStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001601 if (error_sp)
1602 {
Greg Clayton44d93782014-01-27 23:43:24 +00001603 error_sp->PutCString(data);
1604 error_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001605 }
1606 }
1607 }
1608 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData)
1609 {
1610 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1611 if (data && data[0])
1612 {
Pavel Labath44464872015-05-27 12:40:32 +00001613 StreamSP output_sp (GetAsyncOutputStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001614 if (output_sp)
1615 {
Greg Clayton44d93782014-01-27 23:43:24 +00001616 output_sp->PutCString(data);
1617 output_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001618 }
1619 }
1620 }
1621 }
1622 }
1623
1624 if (m_forward_listener_sp)
1625 m_forward_listener_sp->AddEvent(event_sp);
1626 }
1627 }
1628 }
1629}
1630
1631lldb::thread_result_t
1632Debugger::EventHandlerThread (lldb::thread_arg_t arg)
1633{
1634 ((Debugger *)arg)->DefaultEventHandler();
1635 return NULL;
1636}
1637
1638bool
1639Debugger::StartEventHandlerThread()
1640{
Zachary Turneracee96a2014-09-23 18:32:09 +00001641 if (!m_event_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001642 {
Greg Claytonafa91e332014-12-01 22:41:27 +00001643 // We must synchronize with the DefaultEventHandler() thread to ensure
1644 // it is up and running and listening to events before we return from
1645 // this function. We do this by listening to events for the
1646 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1647 Listener listener("lldb.debugger.event-handler");
1648 listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
1649
Zachary Turner7c2896a2014-10-24 22:06:29 +00001650 // Use larger 8MB stack for this thread
Greg Claytonafa91e332014-12-01 22:41:27 +00001651 m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread,
1652 this,
1653 NULL,
Zachary Turner7c2896a2014-10-24 22:06:29 +00001654 g_debugger_event_thread_stack_bytes);
Greg Claytonafa91e332014-12-01 22:41:27 +00001655
1656 // Make sure DefaultEventHandler() is running and listening to events before we return
1657 // from this function. We are only listening for events of type
1658 // eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
1659 // to wait an infinite amount of time for it (NULL timeout as the first parameter)
1660 lldb::EventSP event_sp;
1661 listener.WaitForEvent(NULL, event_sp);
Greg Clayton807b6b32014-10-15 18:03:59 +00001662 }
Zachary Turneracee96a2014-09-23 18:32:09 +00001663 return m_event_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001664}
1665
1666void
1667Debugger::StopEventHandlerThread()
1668{
Zachary Turneracee96a2014-09-23 18:32:09 +00001669 if (m_event_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001670 {
1671 GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
Zachary Turner39de3112014-09-09 20:54:56 +00001672 m_event_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001673 }
1674}
1675
1676
1677lldb::thread_result_t
1678Debugger::IOHandlerThread (lldb::thread_arg_t arg)
1679{
1680 Debugger *debugger = (Debugger *)arg;
Siva Chandra9aaab552015-02-26 19:26:36 +00001681 debugger->ExecuteIOHandlers();
Greg Clayton44d93782014-01-27 23:43:24 +00001682 debugger->StopEventHandlerThread();
1683 return NULL;
1684}
1685
1686bool
1687Debugger::StartIOHandlerThread()
1688{
Zachary Turneracee96a2014-09-23 18:32:09 +00001689 if (!m_io_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001690 m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
1691 IOHandlerThread,
1692 this,
1693 NULL,
1694 8*1024*1024); // Use larger 8MB stack for this thread
Zachary Turneracee96a2014-09-23 18:32:09 +00001695 return m_io_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001696}
1697
1698void
1699Debugger::StopIOHandlerThread()
1700{
Zachary Turneracee96a2014-09-23 18:32:09 +00001701 if (m_io_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001702 {
1703 if (m_input_file_sp)
1704 m_input_file_sp->GetFile().Close();
Zachary Turner39de3112014-09-09 20:54:56 +00001705 m_io_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001706 }
1707}
1708
Jim Ingham893c9322014-11-22 01:42:44 +00001709Target *
1710Debugger::GetDummyTarget()
1711{
1712 return m_target_list.GetDummyTarget (*this).get();
1713}
1714
1715Target *
Jim Ingham33df7cd2014-12-06 01:28:03 +00001716Debugger::GetSelectedOrDummyTarget(bool prefer_dummy)
Jim Ingham893c9322014-11-22 01:42:44 +00001717{
Jim Ingham33df7cd2014-12-06 01:28:03 +00001718 Target *target = nullptr;
1719 if (!prefer_dummy)
1720 {
1721 target = m_target_list.GetSelectedTarget().get();
1722 if (target)
1723 return target;
1724 }
1725
Jim Ingham893c9322014-11-22 01:42:44 +00001726 return GetDummyTarget();
1727}
Greg Clayton44d93782014-01-27 23:43:24 +00001728