blob: 7b3cffbafb6211a43750dcc2419d2b4e6732d838 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton4a33d312011-06-23 17:59:56 +000012#include "lldb/Core/Debugger.h"
13
14#include <map>
15
Enrico Granata4becb372011-06-29 22:27:15 +000016#include "clang/AST/DeclCXX.h"
17#include "clang/AST/Type.h"
Jason Molenda705b1802014-06-13 02:37:02 +000018#include "llvm/ADT/StringRef.h"
Enrico Granata4becb372011-06-29 22:27:15 +000019
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/lldb-private.h"
Greg Clayton554f68d2015-02-04 22:00:53 +000021#include "lldb/Core/FormatEntity.h"
Greg Clayton1f746072012-08-29 21:13:06 +000022#include "lldb/Core/Module.h"
Greg Claytone8cd0c92012-10-19 18:02:49 +000023#include "lldb/Core/PluginManager.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000024#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000026#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000027#include "lldb/Core/StreamCallback.h"
Greg Clayton44d93782014-01-27 23:43:24 +000028#include "lldb/Core/StreamFile.h"
Greg Clayton1b654882010-09-19 02:33:57 +000029#include "lldb/Core/StreamString.h"
Jason Molenda705b1802014-06-13 02:37:02 +000030#include "lldb/Core/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000032#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000033#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000034#include "lldb/DataFormatters/DataVisualization.h"
35#include "lldb/DataFormatters/FormatManager.h"
Enrico Granata894f7352014-03-25 22:03:52 +000036#include "lldb/DataFormatters/TypeSummary.h"
Zachary Turner93a66fc2014-10-06 21:22:36 +000037#include "lldb/Host/ConnectionFileDescriptor.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000038#include "lldb/Host/HostInfo.h"
Greg Claytona3406612011-02-07 23:24:47 +000039#include "lldb/Host/Terminal.h"
Zachary Turner39de3112014-09-09 20:54:56 +000040#include "lldb/Host/ThreadLauncher.h"
Greg Clayton66111032010-06-23 01:19:29 +000041#include "lldb/Interpreter/CommandInterpreter.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"
Jason Molendaaff1b352014-10-10 23:07:36 +000049#include "lldb/Target/CPPLanguageRuntime.h"
50#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Target/TargetList.h"
52#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000053#include "lldb/Target/RegisterContext.h"
Greg Clayton5fb8f792013-12-02 19:35:49 +000054#include "lldb/Target/SectionLoadList.h"
Greg Clayton1b654882010-09-19 02:33:57 +000055#include "lldb/Target/StopInfo.h"
Enrico Granata84a53df2013-05-20 22:29:23 +000056#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000058#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059
Zachary Turner58a559c2014-08-27 20:15:09 +000060#include "llvm/Support/DynamicLibrary.h"
61
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062using namespace lldb;
63using namespace lldb_private;
64
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Greg Clayton1b654882010-09-19 02:33:57 +000066static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000067static lldb::user_id_t g_unique_id = 1;
Zachary Turner7c2896a2014-10-24 22:06:29 +000068static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000069
Greg Clayton1b654882010-09-19 02:33:57 +000070#pragma mark Static Functions
71
72static Mutex &
73GetDebuggerListMutex ()
74{
75 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
76 return g_mutex;
77}
78
79typedef std::vector<DebuggerSP> DebuggerList;
80
81static DebuggerList &
82GetDebuggerList()
83{
84 // hide the static debugger list inside a singleton accessor to avoid
Bruce Mitchener6a7f3332014-06-27 02:42:12 +000085 // global init constructors
Greg Clayton1b654882010-09-19 02:33:57 +000086 static DebuggerList g_list;
87 return g_list;
88}
Greg Claytone372b982011-11-21 21:44:34 +000089
90OptionEnumValueElement
Greg Clayton67cc0632012-08-22 17:17:09 +000091g_show_disassembly_enum_values[] =
Greg Claytone372b982011-11-21 21:44:34 +000092{
Greg Clayton67cc0632012-08-22 17:17:09 +000093 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
94 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
95 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
Greg Claytone372b982011-11-21 21:44:34 +000096 { 0, NULL, NULL }
97};
98
Greg Clayton67cc0632012-08-22 17:17:09 +000099OptionEnumValueElement
100g_language_enumerators[] =
101{
102 { eScriptLanguageNone, "none", "Disable scripting languages."},
103 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
104 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
Greg Claytona12993c2012-09-13 23:03:20 +0000105 { 0, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000106};
Greg Claytone372b982011-11-21 21:44:34 +0000107
Greg Clayton67cc0632012-08-22 17:17:09 +0000108#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
109#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
110
Michael Sartain0769b2b2013-07-30 16:44:36 +0000111#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000112 "{, ${frame.pc}}"\
113 MODULE_WITH_FUNC\
114 FILE_AND_LINE\
Michael Sartain0769b2b2013-07-30 16:44:36 +0000115 "{, name = '${thread.name}'}"\
116 "{, queue = '${thread.queue}'}"\
Jason Molenda705b1802014-06-13 02:37:02 +0000117 "{, activity = '${thread.info.activity.name}'}" \
118 "{, ${thread.info.trace_messages} messages}" \
Greg Clayton67cc0632012-08-22 17:17:09 +0000119 "{, stop reason = ${thread.stop-reason}}"\
120 "{\\nReturn value: ${thread.return-value}}"\
Jim Ingham30fadaf2014-07-08 01:07:32 +0000121 "{\\nCompleted expression: ${thread.completed-expression}}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000122 "\\n"
123
124#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
125 MODULE_WITH_FUNC\
126 FILE_AND_LINE\
127 "\\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
Greg Clayton5fb8f792013-12-02 19:35:49 +0000187Debugger::LoadPluginCallbackType 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
Caroline Tice2f88aad2011-01-14 00:29:16 +0000408int
409Debugger::TestDebuggerRefCount ()
410{
411 return g_shared_debugger_refcount;
412}
413
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414void
Greg Clayton5fb8f792013-12-02 19:35:49 +0000415Debugger::Initialize (LoadPluginCallbackType load_plugin_callback)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000417 g_load_plugin_callback = load_plugin_callback;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000418 if (g_shared_debugger_refcount++ == 0)
Greg Claytondbe54502010-11-19 03:46:01 +0000419 lldb_private::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420}
421
422void
423Debugger::Terminate ()
424{
Greg Clayton66111032010-06-23 01:19:29 +0000425 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 {
Greg Clayton66111032010-06-23 01:19:29 +0000427 g_shared_debugger_refcount--;
428 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 {
Greg Claytondbe54502010-11-19 03:46:01 +0000430 lldb_private::WillTerminate();
431 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000432
433 // Clear our master list of debugger objects
434 Mutex::Locker locker (GetDebuggerListMutex ());
435 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 }
438}
439
Caroline Tice20bd37f2011-03-10 22:14:10 +0000440void
441Debugger::SettingsInitialize ()
442{
Greg Clayton6920b522012-08-22 18:39:03 +0000443 Target::SettingsInitialize ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000444}
445
446void
447Debugger::SettingsTerminate ()
448{
Greg Clayton6920b522012-08-22 18:39:03 +0000449 Target::SettingsTerminate ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000450}
451
Enrico Granata21dfcd92012-09-28 23:57:51 +0000452bool
Enrico Granatae743c782013-04-24 21:29:08 +0000453Debugger::LoadPlugin (const FileSpec& spec, Error& error)
Enrico Granata21dfcd92012-09-28 23:57:51 +0000454{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000455 if (g_load_plugin_callback)
Enrico Granatae743c782013-04-24 21:29:08 +0000456 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000457 llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error);
458 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +0000459 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000460 m_loaded_plugins.push_back(dynlib);
Greg Clayton5fb8f792013-12-02 19:35:49 +0000461 return true;
462 }
Enrico Granatae743c782013-04-24 21:29:08 +0000463 }
Greg Clayton5fb8f792013-12-02 19:35:49 +0000464 else
Enrico Granatae743c782013-04-24 21:29:08 +0000465 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000466 // The g_load_plugin_callback is registered in SBDebugger::Initialize()
467 // and if the public API layer isn't available (code is linking against
468 // all of the internal LLDB static libraries), then we can't load plugins
469 error.SetErrorString("Public API layer is not available");
Enrico Granatae743c782013-04-24 21:29:08 +0000470 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000471 return false;
472}
473
474static FileSpec::EnumerateDirectoryResult
475LoadPluginCallback
476(
477 void *baton,
478 FileSpec::FileType file_type,
479 const FileSpec &file_spec
480 )
481{
482 Error error;
483
484 static ConstString g_dylibext("dylib");
Michael Sartain3cf443d2013-07-17 00:26:30 +0000485 static ConstString g_solibext("so");
Enrico Granata21dfcd92012-09-28 23:57:51 +0000486
487 if (!baton)
488 return FileSpec::eEnumerateDirectoryResultQuit;
489
490 Debugger *debugger = (Debugger*)baton;
491
492 // If we have a regular file, a symbolic link or unknown file type, try
493 // and process the file. We must handle unknown as sometimes the directory
494 // enumeration might be enumerating a file system that doesn't have correct
495 // file type information.
496 if (file_type == FileSpec::eFileTypeRegular ||
497 file_type == FileSpec::eFileTypeSymbolicLink ||
498 file_type == FileSpec::eFileTypeUnknown )
499 {
500 FileSpec plugin_file_spec (file_spec);
501 plugin_file_spec.ResolvePath ();
502
Michael Sartain3cf443d2013-07-17 00:26:30 +0000503 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
504 plugin_file_spec.GetFileNameExtension() != g_solibext)
505 {
Enrico Granata21dfcd92012-09-28 23:57:51 +0000506 return FileSpec::eEnumerateDirectoryResultNext;
Michael Sartain3cf443d2013-07-17 00:26:30 +0000507 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000508
Enrico Granatae743c782013-04-24 21:29:08 +0000509 Error plugin_load_error;
510 debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000511
512 return FileSpec::eEnumerateDirectoryResultNext;
513 }
514
515 else if (file_type == FileSpec::eFileTypeUnknown ||
516 file_type == FileSpec::eFileTypeDirectory ||
517 file_type == FileSpec::eFileTypeSymbolicLink )
518 {
519 // Try and recurse into anything that a directory or symbolic link.
520 // We must also do this for unknown as sometimes the directory enumeration
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000521 // might be enumerating a file system that doesn't have correct file type
Enrico Granata21dfcd92012-09-28 23:57:51 +0000522 // information.
523 return FileSpec::eEnumerateDirectoryResultEnter;
524 }
525
526 return FileSpec::eEnumerateDirectoryResultNext;
527}
528
529void
530Debugger::InstanceInitialize ()
531{
532 FileSpec dir_spec;
533 const bool find_directories = true;
534 const bool find_files = true;
535 const bool find_other = true;
536 char dir_path[PATH_MAX];
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000537 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, 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 }
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000549
550 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000551 {
552 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
553 {
554 FileSpec::EnumerateDirectory (dir_path,
555 find_directories,
556 find_files,
557 find_other,
558 LoadPluginCallback,
559 this);
560 }
561 }
Greg Claytone8cd0c92012-10-19 18:02:49 +0000562
563 PluginManager::DebuggerInitialize (*this);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000564}
565
Greg Clayton66111032010-06-23 01:19:29 +0000566DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000567Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000568{
Jim Ingham228063c2012-02-21 02:23:08 +0000569 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Greg Claytonc15f55e2012-03-30 20:53:46 +0000570 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000571 {
572 Mutex::Locker locker (GetDebuggerListMutex ());
573 GetDebuggerList().push_back(debugger_sp);
574 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000575 debugger_sp->InstanceInitialize ();
Greg Clayton66111032010-06-23 01:19:29 +0000576 return debugger_sp;
577}
578
Caroline Ticee02657b2011-01-22 01:02:07 +0000579void
Greg Clayton4d122c42011-09-17 08:33:22 +0000580Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000581{
582 if (debugger_sp.get() == NULL)
583 return;
584
Jim Ingham8314c522011-09-15 21:36:42 +0000585 debugger_sp->Clear();
586
Greg Claytonc15f55e2012-03-30 20:53:46 +0000587 if (g_shared_debugger_refcount > 0)
Caroline Ticee02657b2011-01-22 01:02:07 +0000588 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000589 Mutex::Locker locker (GetDebuggerListMutex ());
590 DebuggerList &debugger_list = GetDebuggerList ();
591 DebuggerList::iterator pos, end = debugger_list.end();
592 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000593 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000594 if ((*pos).get() == debugger_sp.get())
595 {
596 debugger_list.erase (pos);
597 return;
598 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000599 }
600 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000601}
602
Greg Clayton4d122c42011-09-17 08:33:22 +0000603DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000604Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
605{
Greg Clayton4d122c42011-09-17 08:33:22 +0000606 DebuggerSP debugger_sp;
Greg Clayton6920b522012-08-22 18:39:03 +0000607 if (g_shared_debugger_refcount > 0)
608 {
609 Mutex::Locker locker (GetDebuggerListMutex ());
610 DebuggerList &debugger_list = GetDebuggerList();
611 DebuggerList::iterator pos, end = debugger_list.end();
612
613 for (pos = debugger_list.begin(); pos != end; ++pos)
614 {
615 if ((*pos).get()->m_instance_name == instance_name)
616 {
617 debugger_sp = *pos;
618 break;
619 }
620 }
621 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000622 return debugger_sp;
623}
Greg Clayton66111032010-06-23 01:19:29 +0000624
625TargetSP
626Debugger::FindTargetWithProcessID (lldb::pid_t pid)
627{
Greg Clayton4d122c42011-09-17 08:33:22 +0000628 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000629 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000630 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000631 Mutex::Locker locker (GetDebuggerListMutex ());
632 DebuggerList &debugger_list = GetDebuggerList();
633 DebuggerList::iterator pos, end = debugger_list.end();
634 for (pos = debugger_list.begin(); pos != end; ++pos)
635 {
636 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
637 if (target_sp)
638 break;
639 }
Greg Clayton66111032010-06-23 01:19:29 +0000640 }
641 return target_sp;
642}
643
Greg Claytone4e45922011-11-16 05:37:56 +0000644TargetSP
645Debugger::FindTargetWithProcess (Process *process)
646{
647 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000648 if (g_shared_debugger_refcount > 0)
Greg Claytone4e45922011-11-16 05:37:56 +0000649 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000650 Mutex::Locker locker (GetDebuggerListMutex ());
651 DebuggerList &debugger_list = GetDebuggerList();
652 DebuggerList::iterator pos, end = debugger_list.end();
653 for (pos = debugger_list.begin(); pos != end; ++pos)
654 {
655 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
656 if (target_sp)
657 break;
658 }
Greg Claytone4e45922011-11-16 05:37:56 +0000659 }
660 return target_sp;
661}
662
Jason Molendae6481c72014-09-12 01:50:46 +0000663Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
664 UserID(g_unique_id++),
665 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
666 m_input_file_sp(new StreamFile(stdin, false)),
667 m_output_file_sp(new StreamFile(stdout, false)),
668 m_error_file_sp(new StreamFile(stderr, false)),
669 m_terminal_state(),
670 m_target_list(*this),
671 m_platform_list(),
672 m_listener("lldb.Debugger"),
673 m_source_manager_ap(),
674 m_source_file_cache(),
675 m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)),
676 m_input_reader_stack(),
677 m_instance_name(),
Greg Claytonafa91e332014-12-01 22:41:27 +0000678 m_loaded_plugins(),
679 m_event_handler_thread (),
680 m_io_handler_thread (),
681 m_sync_broadcaster (NULL, "lldb.debugger.sync")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682{
Greg Clayton67cc0632012-08-22 17:17:09 +0000683 char instance_cstr[256];
684 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
685 m_instance_name.SetCString(instance_cstr);
Jim Ingham228063c2012-02-21 02:23:08 +0000686 if (log_callback)
687 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000688 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000689 // Always add our default platform to the platform list
Greg Clayton615eb7e2014-09-19 20:11:50 +0000690 PlatformSP default_platform_sp (Platform::GetHostPlatform());
Greg Claytonded470d2011-03-19 01:12:21 +0000691 assert (default_platform_sp.get());
692 m_platform_list.Append (default_platform_sp, true);
Greg Clayton67cc0632012-08-22 17:17:09 +0000693
Greg Clayton754a9362012-08-23 00:22:02 +0000694 m_collection_sp->Initialize (g_properties);
Greg Clayton67cc0632012-08-22 17:17:09 +0000695 m_collection_sp->AppendProperty (ConstString("target"),
696 ConstString("Settings specify to debugging targets."),
697 true,
698 Target::GetGlobalProperties()->GetValueProperties());
Greg Clayton754a9362012-08-23 00:22:02 +0000699 if (m_command_interpreter_ap.get())
700 {
701 m_collection_sp->AppendProperty (ConstString("interpreter"),
702 ConstString("Settings specify to the debugger's command interpreter."),
703 true,
704 m_command_interpreter_ap->GetValueProperties());
705 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000706 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
707 term_width->SetMinimumValue(10);
708 term_width->SetMaximumValue(1024);
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000709
710 // Turn off use-color if this is a dumb terminal.
711 const char *term = getenv ("TERM");
712 if (term && !strcmp (term, "dumb"))
713 SetUseColor (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714}
715
716Debugger::~Debugger ()
717{
Jim Ingham8314c522011-09-15 21:36:42 +0000718 Clear();
719}
720
721void
722Debugger::Clear()
723{
Greg Clayton44d93782014-01-27 23:43:24 +0000724 ClearIOHandlers();
725 StopIOHandlerThread();
726 StopEventHandlerThread();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000727 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000728 int num_targets = m_target_list.GetNumTargets();
729 for (int i = 0; i < num_targets; i++)
730 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000731 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
732 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000733 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000734 ProcessSP process_sp (target_sp->GetProcessSP());
735 if (process_sp)
Jim Ingham1fd07052013-02-27 19:13:05 +0000736 process_sp->Finalize();
Greg Claytonccbc08e2012-01-14 17:04:19 +0000737 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000738 }
Greg Clayton66111032010-06-23 01:19:29 +0000739 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000740 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000741
742 // Close the input file _before_ we close the input read communications class
743 // as it does NOT own the input file, our m_input_file does.
Jim Inghamc5917d92012-11-30 20:23:19 +0000744 m_terminal_state.Clear();
Greg Clayton44d93782014-01-27 23:43:24 +0000745 if (m_input_file_sp)
746 m_input_file_sp->GetFile().Close ();
Greg Clayton0c4129f2014-04-25 00:35:14 +0000747
748 m_command_interpreter_ap->Clear();
Jim Ingham8314c522011-09-15 21:36:42 +0000749}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750
751bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000752Debugger::GetCloseInputOnEOF () const
753{
Greg Clayton44d93782014-01-27 23:43:24 +0000754// return m_input_comm.GetCloseOnEOF();
755 return false;
Greg Claytonfc3f0272011-05-29 04:06:55 +0000756}
757
758void
759Debugger::SetCloseInputOnEOF (bool b)
760{
Greg Clayton44d93782014-01-27 23:43:24 +0000761// m_input_comm.SetCloseOnEOF(b);
Greg Claytonfc3f0272011-05-29 04:06:55 +0000762}
763
764bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765Debugger::GetAsyncExecution ()
766{
Greg Clayton66111032010-06-23 01:19:29 +0000767 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768}
769
770void
771Debugger::SetAsyncExecution (bool async_execution)
772{
Greg Clayton66111032010-06-23 01:19:29 +0000773 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000774}
775
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776
777void
778Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
779{
Greg Clayton44d93782014-01-27 23:43:24 +0000780 if (m_input_file_sp)
781 m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership);
782 else
783 m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
784
785 File &in_file = m_input_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000786 if (in_file.IsValid() == false)
787 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788
Jim Inghamc5917d92012-11-30 20:23:19 +0000789 // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
790 SaveInputTerminalState ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791}
792
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793void
794Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
795{
Greg Clayton44d93782014-01-27 23:43:24 +0000796 if (m_output_file_sp)
797 m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership);
798 else
799 m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
800
801 File &out_file = m_output_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000802 if (out_file.IsValid() == false)
803 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000804
Enrico Granatab5887262012-10-29 21:18:03 +0000805 // do not create the ScriptInterpreter just for setting the output file handle
806 // as the constructor will know how to do the right thing on its own
807 const bool can_create = false;
808 ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create);
809 if (script_interpreter)
810 script_interpreter->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811}
812
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813void
814Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
815{
Greg Clayton44d93782014-01-27 23:43:24 +0000816 if (m_error_file_sp)
817 m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership);
818 else
819 m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
820
821 File &err_file = m_error_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000822 if (err_file.IsValid() == false)
823 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824}
825
Jim Inghamc5917d92012-11-30 20:23:19 +0000826void
827Debugger::SaveInputTerminalState ()
828{
Greg Clayton44d93782014-01-27 23:43:24 +0000829 if (m_input_file_sp)
830 {
831 File &in_file = m_input_file_sp->GetFile();
832 if (in_file.GetDescriptor() != File::kInvalidDescriptor)
833 m_terminal_state.Save(in_file.GetDescriptor(), true);
834 }
Jim Inghamc5917d92012-11-30 20:23:19 +0000835}
836
837void
838Debugger::RestoreInputTerminalState ()
839{
840 m_terminal_state.Restore();
841}
842
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000843ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000844Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845{
846 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000847 TargetSP target_sp(GetSelectedTarget());
848 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849
850 if (target_sp)
851 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000852 ProcessSP process_sp (target_sp->GetProcessSP());
853 exe_ctx.SetProcessSP (process_sp);
854 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000856 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
857 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000859 exe_ctx.SetThreadSP (thread_sp);
860 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
861 if (exe_ctx.GetFramePtr() == NULL)
862 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 }
864 }
865 }
866 return exe_ctx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867}
868
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000869void
Caroline Ticeefed6132010-11-19 20:47:54 +0000870Debugger::DispatchInputInterrupt ()
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->Interrupt();
Caroline Ticeefed6132010-11-19 20:47:54 +0000876}
877
878void
879Debugger::DispatchInputEndOfFile ()
880{
Greg Clayton44d93782014-01-27 23:43:24 +0000881 Mutex::Locker locker (m_input_reader_stack.GetMutex());
882 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000883 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000884 reader_sp->GotEOF();
Caroline Ticeefed6132010-11-19 20:47:54 +0000885}
886
887void
Greg Clayton44d93782014-01-27 23:43:24 +0000888Debugger::ClearIOHandlers ()
Caroline Tice3d6086f2010-12-20 18:35:50 +0000889{
Caroline Ticeb44880c2011-02-10 01:15:13 +0000890 // 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 +0000891 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000892 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000893 {
Greg Clayton44d93782014-01-27 23:43:24 +0000894 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000895 if (reader_sp)
896 {
Greg Clayton44d93782014-01-27 23:43:24 +0000897 m_input_reader_stack.Pop();
898 reader_sp->SetIsDone(true);
Greg Claytone68f5d62014-02-24 22:50:57 +0000899 reader_sp->Cancel();
Caroline Tice3d6086f2010-12-20 18:35:50 +0000900 }
901 }
902}
903
904void
Siva Chandra9aaab552015-02-26 19:26:36 +0000905Debugger::ExecuteIOHandlers()
Caroline Tice969ed3d2011-05-02 20:41:46 +0000906{
Caroline Tice9088b062011-05-09 23:06:58 +0000907
Greg Clayton44d93782014-01-27 23:43:24 +0000908 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909 {
Greg Clayton44d93782014-01-27 23:43:24 +0000910 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 if (!reader_sp)
912 break;
913
Greg Clayton44d93782014-01-27 23:43:24 +0000914 reader_sp->Activate();
915 reader_sp->Run();
916 reader_sp->Deactivate();
917
918 // Remove all input readers that are done from the top of the stack
919 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000920 {
Greg Clayton44d93782014-01-27 23:43:24 +0000921 IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
922 if (top_reader_sp && top_reader_sp->GetIsDone())
923 m_input_reader_stack.Pop();
924 else
925 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926 }
927 }
Greg Clayton44d93782014-01-27 23:43:24 +0000928 ClearIOHandlers();
929}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930
Greg Clayton44d93782014-01-27 23:43:24 +0000931bool
932Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
933{
934 return m_input_reader_stack.IsTop (reader_sp);
935}
936
937
938ConstString
939Debugger::GetTopIOHandlerControlSequence(char ch)
940{
941 return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000942}
943
Kate Stonea487aa42015-01-15 00:52:41 +0000944const char *
945Debugger::GetIOHandlerCommandPrefix()
946{
947 return m_input_reader_stack.GetTopIOHandlerCommandPrefix();
948}
949
950const char *
951Debugger::GetIOHandlerHelpPrologue()
952{
953 return m_input_reader_stack.GetTopIOHandlerHelpPrologue();
954}
955
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956void
Greg Clayton44d93782014-01-27 23:43:24 +0000957Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
958{
Greg Clayton44d93782014-01-27 23:43:24 +0000959 PushIOHandler (reader_sp);
Greg Clayton577508d2014-06-20 00:23:57 +0000960
961 IOHandlerSP top_reader_sp = reader_sp;
962 while (top_reader_sp)
963 {
964 top_reader_sp->Activate();
965 top_reader_sp->Run();
966 top_reader_sp->Deactivate();
967
968 if (top_reader_sp.get() == reader_sp.get())
969 {
970 if (PopIOHandler (reader_sp))
971 break;
972 }
973
974 while (1)
975 {
976 top_reader_sp = m_input_reader_stack.Top();
977 if (top_reader_sp && top_reader_sp->GetIsDone())
978 m_input_reader_stack.Pop();
979 else
980 break;
981 }
982 }
Greg Clayton44d93782014-01-27 23:43:24 +0000983}
984
985void
986Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
987{
988 // Before an IOHandler runs, it must have in/out/err streams.
989 // This function is called when one ore more of the streams
990 // are NULL. We use the top input reader's in/out/err streams,
991 // or fall back to the debugger file handles, or we fall back
992 // onto stdin/stdout/stderr as a last resort.
993
994 Mutex::Locker locker (m_input_reader_stack.GetMutex());
995 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
996 // If no STDIN has been set, then set it appropriately
997 if (!in)
998 {
999 if (top_reader_sp)
1000 in = top_reader_sp->GetInputStreamFile();
1001 else
1002 in = GetInputFile();
1003
1004 // If there is nothing, use stdin
1005 if (!in)
1006 in = StreamFileSP(new StreamFile(stdin, false));
1007 }
1008 // If no STDOUT has been set, then set it appropriately
1009 if (!out)
1010 {
1011 if (top_reader_sp)
1012 out = top_reader_sp->GetOutputStreamFile();
1013 else
1014 out = GetOutputFile();
1015
1016 // If there is nothing, use stdout
1017 if (!out)
1018 out = StreamFileSP(new StreamFile(stdout, false));
1019 }
1020 // If no STDERR has been set, then set it appropriately
1021 if (!err)
1022 {
1023 if (top_reader_sp)
1024 err = top_reader_sp->GetErrorStreamFile();
1025 else
1026 err = GetErrorFile();
1027
1028 // If there is nothing, use stderr
1029 if (!err)
1030 err = StreamFileSP(new StreamFile(stdout, false));
1031
1032 }
1033}
1034
1035void
1036Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001037{
1038 if (!reader_sp)
1039 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +00001040
Greg Clayton44d93782014-01-27 23:43:24 +00001041 // Got the current top input reader...
1042 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +00001043
Greg Claytonb4874f12014-02-28 18:22:24 +00001044 // Don't push the same IO handler twice...
1045 if (reader_sp.get() != top_reader_sp.get())
1046 {
1047 // Push our new input reader
1048 m_input_reader_stack.Push (reader_sp);
Greg Clayton44d93782014-01-27 23:43:24 +00001049
Greg Claytonb4874f12014-02-28 18:22:24 +00001050 // Interrupt the top input reader to it will exit its Run() function
1051 // and let this new input reader take over
1052 if (top_reader_sp)
1053 top_reader_sp->Deactivate();
1054 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055}
1056
1057bool
Greg Clayton44d93782014-01-27 23:43:24 +00001058Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059{
1060 bool result = false;
Greg Clayton44d93782014-01-27 23:43:24 +00001061
1062 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063
1064 // The reader on the stop of the stack is done, so let the next
Bruce Mitchener6a7f3332014-06-27 02:42:12 +00001065 // read on the stack refresh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +00001066 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001067 {
Greg Clayton44d93782014-01-27 23:43:24 +00001068 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001069
1070 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
1071 {
Greg Clayton44d93782014-01-27 23:43:24 +00001072 reader_sp->Deactivate();
Greg Claytonb4874f12014-02-28 18:22:24 +00001073 reader_sp->Cancel();
Caroline Ticed5a0a01b2011-06-02 19:18:55 +00001074 m_input_reader_stack.Pop ();
Greg Clayton44d93782014-01-27 23:43:24 +00001075
1076 reader_sp = m_input_reader_stack.Top();
1077 if (reader_sp)
1078 reader_sp->Activate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079
Greg Clayton44d93782014-01-27 23:43:24 +00001080 result = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001081 }
1082 }
1083 return result;
1084}
1085
1086bool
Greg Clayton44d93782014-01-27 23:43:24 +00001087Debugger::HideTopIOHandler()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001088{
Greg Clayton44d93782014-01-27 23:43:24 +00001089 Mutex::Locker locker;
1090
1091 if (locker.TryLock(m_input_reader_stack.GetMutex()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092 {
Greg Clayton44d93782014-01-27 23:43:24 +00001093 IOHandlerSP reader_sp(m_input_reader_stack.Top());
1094 if (reader_sp)
1095 reader_sp->Hide();
1096 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097 }
Greg Clayton44d93782014-01-27 23:43:24 +00001098 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099}
1100
1101void
Greg Clayton44d93782014-01-27 23:43:24 +00001102Debugger::RefreshTopIOHandler()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103{
Greg Clayton44d93782014-01-27 23:43:24 +00001104 IOHandlerSP reader_sp(m_input_reader_stack.Top());
1105 if (reader_sp)
1106 reader_sp->Refresh();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001107}
Greg Clayton66111032010-06-23 01:19:29 +00001108
Greg Clayton44d93782014-01-27 23:43:24 +00001109
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001110StreamSP
1111Debugger::GetAsyncOutputStream ()
1112{
1113 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1114 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
1115}
1116
1117StreamSP
1118Debugger::GetAsyncErrorStream ()
1119{
1120 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1121 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
1122}
1123
Greg Claytonc7bece562013-01-25 18:06:21 +00001124size_t
Enrico Granata061858c2012-02-15 02:34:21 +00001125Debugger::GetNumDebuggers()
1126{
Greg Claytonc15f55e2012-03-30 20:53:46 +00001127 if (g_shared_debugger_refcount > 0)
1128 {
1129 Mutex::Locker locker (GetDebuggerListMutex ());
1130 return GetDebuggerList().size();
1131 }
1132 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +00001133}
1134
1135lldb::DebuggerSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001136Debugger::GetDebuggerAtIndex (size_t index)
Enrico Granata061858c2012-02-15 02:34:21 +00001137{
1138 DebuggerSP debugger_sp;
1139
Greg Claytonc15f55e2012-03-30 20:53:46 +00001140 if (g_shared_debugger_refcount > 0)
1141 {
1142 Mutex::Locker locker (GetDebuggerListMutex ());
1143 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +00001144
Greg Claytonc15f55e2012-03-30 20:53:46 +00001145 if (index < debugger_list.size())
1146 debugger_sp = debugger_list[index];
1147 }
1148
Enrico Granata061858c2012-02-15 02:34:21 +00001149 return debugger_sp;
1150}
1151
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001152DebuggerSP
1153Debugger::FindDebuggerWithID (lldb::user_id_t id)
1154{
Greg Clayton4d122c42011-09-17 08:33:22 +00001155 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001156
Greg Claytonc15f55e2012-03-30 20:53:46 +00001157 if (g_shared_debugger_refcount > 0)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001158 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001159 Mutex::Locker locker (GetDebuggerListMutex ());
1160 DebuggerList &debugger_list = GetDebuggerList();
1161 DebuggerList::iterator pos, end = debugger_list.end();
1162 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001163 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001164 if ((*pos).get()->GetID() == id)
1165 {
1166 debugger_sp = *pos;
1167 break;
1168 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001169 }
1170 }
1171 return debugger_sp;
1172}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001173
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001174#if 0
Greg Clayton1b654882010-09-19 02:33:57 +00001175static void
Jason Molendab57e4a12013-11-04 09:33:30 +00001176TestPromptFormats (StackFrame *frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001177{
1178 if (frame == NULL)
1179 return;
1180
1181 StreamString s;
1182 const char *prompt_format =
1183 "{addr = '${addr}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001184 "{addr-file-or-load = '${addr-file-or-load}'\n}"
1185 "{current-pc-arrow = '${current-pc-arrow}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001186 "{process.id = '${process.id}'\n}"
1187 "{process.name = '${process.name}'\n}"
1188 "{process.file.basename = '${process.file.basename}'\n}"
1189 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1190 "{thread.id = '${thread.id}'\n}"
1191 "{thread.index = '${thread.index}'\n}"
1192 "{thread.name = '${thread.name}'\n}"
1193 "{thread.queue = '${thread.queue}'\n}"
1194 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1195 "{target.arch = '${target.arch}'\n}"
1196 "{module.file.basename = '${module.file.basename}'\n}"
1197 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1198 "{file.basename = '${file.basename}'\n}"
1199 "{file.fullpath = '${file.fullpath}'\n}"
1200 "{frame.index = '${frame.index}'\n}"
1201 "{frame.pc = '${frame.pc}'\n}"
1202 "{frame.sp = '${frame.sp}'\n}"
1203 "{frame.fp = '${frame.fp}'\n}"
1204 "{frame.flags = '${frame.flags}'\n}"
1205 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1206 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1207 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1208 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1209 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1210 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1211 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1212 "{function.id = '${function.id}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001213 "{function.changed = '${function.changed}'\n}"
1214 "{function.initial-function = '${function.initial-function}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001215 "{function.name = '${function.name}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001216 "{function.name-without-args = '${function.name-without-args}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +00001217 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001218 "{function.addr-offset = '${function.addr-offset}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001219 "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001220 "{function.line-offset = '${function.line-offset}'\n}"
1221 "{function.pc-offset = '${function.pc-offset}'\n}"
1222 "{line.file.basename = '${line.file.basename}'\n}"
1223 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1224 "{line.number = '${line.number}'\n}"
1225 "{line.start-addr = '${line.start-addr}'\n}"
1226 "{line.end-addr = '${line.end-addr}'\n}"
1227;
1228
1229 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1230 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +00001231 frame->CalculateExecutionContext(exe_ctx);
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001232 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
Greg Clayton1b654882010-09-19 02:33:57 +00001233 {
1234 printf("%s\n", s.GetData());
1235 }
1236 else
1237 {
Greg Clayton1b654882010-09-19 02:33:57 +00001238 printf ("what we got: %s\n", s.GetData());
1239 }
1240}
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001241#endif
Greg Clayton1b654882010-09-19 02:33:57 +00001242
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001243bool
Greg Clayton554f68d2015-02-04 22:00:53 +00001244Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
Jason Molendaaff1b352014-10-10 23:07:36 +00001245 const SymbolContext *sc,
1246 const SymbolContext *prev_sc,
1247 const ExecutionContext *exe_ctx,
1248 const Address *addr,
1249 Stream &s)
1250{
Greg Clayton554f68d2015-02-04 22:00:53 +00001251 FormatEntity::Entry format_entry;
1252
1253 if (format == NULL)
Jason Molendaaff1b352014-10-10 23:07:36 +00001254 {
Greg Clayton554f68d2015-02-04 22:00:53 +00001255 if (exe_ctx != NULL && exe_ctx->HasTargetScope())
1256 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1257 if (format == NULL)
1258 {
1259 FormatEntity::Parse("${addr}: ", format_entry);
1260 format = &format_entry;
1261 }
Jason Molendaaff1b352014-10-10 23:07:36 +00001262 }
1263 bool function_changed = false;
1264 bool initial_function = false;
1265 if (prev_sc && (prev_sc->function || prev_sc->symbol))
1266 {
1267 if (sc && (sc->function || sc->symbol))
1268 {
1269 if (prev_sc->symbol && sc->symbol)
1270 {
1271 if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType()))
1272 {
1273 function_changed = true;
1274 }
1275 }
1276 else if (prev_sc->function && sc->function)
1277 {
1278 if (prev_sc->function->GetMangled() != sc->function->GetMangled())
1279 {
1280 function_changed = true;
1281 }
1282 }
1283 }
1284 }
1285 // The first context on a list of instructions will have a prev_sc that
1286 // has no Function or Symbol -- if SymbolContext had an IsValid() method, it
1287 // would return false. But we do get a prev_sc pointer.
1288 if ((sc && (sc->function || sc->symbol))
1289 && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL))
1290 {
1291 initial_function = true;
1292 }
Greg Clayton554f68d2015-02-04 22:00:53 +00001293 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, NULL, function_changed, initial_function);
Jason Molendaaff1b352014-10-10 23:07:36 +00001294}
1295
1296
Jim Ingham228063c2012-02-21 02:23:08 +00001297void
1298Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1299{
Jim Ingham4f02b222012-02-22 22:49:20 +00001300 // For simplicity's sake, I am not going to deal with how to close down any
1301 // open logging streams, I just redirect everything from here on out to the
1302 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00001303 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
1304}
1305
1306bool
1307Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
1308{
1309 Log::Callbacks log_callbacks;
1310
1311 StreamSP log_stream_sp;
Sean Callanan9a028512012-08-09 00:50:26 +00001312 if (m_log_callback_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001313 {
1314 log_stream_sp = m_log_callback_stream_sp;
1315 // For now when using the callback mode you always get thread & timestamp.
1316 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1317 }
1318 else if (log_file == NULL || *log_file == '\0')
1319 {
Greg Clayton44d93782014-01-27 23:43:24 +00001320 log_stream_sp = GetOutputFile();
Jim Ingham228063c2012-02-21 02:23:08 +00001321 }
1322 else
1323 {
1324 LogStreamMap::iterator pos = m_log_streams.find(log_file);
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001325 if (pos != m_log_streams.end())
1326 log_stream_sp = pos->second.lock();
1327 if (!log_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001328 {
1329 log_stream_sp.reset (new StreamFile (log_file));
1330 m_log_streams[log_file] = log_stream_sp;
1331 }
Jim Ingham228063c2012-02-21 02:23:08 +00001332 }
1333 assert (log_stream_sp.get());
1334
1335 if (log_options == 0)
1336 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
1337
Greg Clayton57abc5d2013-05-10 21:47:16 +00001338 if (Log::GetLogChannelCallbacks (ConstString(channel), log_callbacks))
Jim Ingham228063c2012-02-21 02:23:08 +00001339 {
1340 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
1341 return true;
1342 }
1343 else
1344 {
1345 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
1346 if (log_channel_sp)
1347 {
1348 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
1349 {
1350 return true;
1351 }
1352 else
1353 {
1354 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
1355 return false;
1356 }
1357 }
1358 else
1359 {
1360 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
1361 return false;
1362 }
1363 }
1364 return false;
1365}
1366
Greg Clayton9585fbf2013-03-19 00:20:55 +00001367SourceManager &
1368Debugger::GetSourceManager ()
1369{
1370 if (m_source_manager_ap.get() == NULL)
1371 m_source_manager_ap.reset (new SourceManager (shared_from_this()));
1372 return *m_source_manager_ap;
1373}
1374
1375
Greg Clayton44d93782014-01-27 23:43:24 +00001376
1377// This function handles events that were broadcast by the process.
1378void
1379Debugger::HandleBreakpointEvent (const EventSP &event_sp)
1380{
1381 using namespace lldb;
1382 const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp);
1383
1384// if (event_type & eBreakpointEventTypeAdded
1385// || event_type & eBreakpointEventTypeRemoved
1386// || event_type & eBreakpointEventTypeEnabled
1387// || event_type & eBreakpointEventTypeDisabled
1388// || event_type & eBreakpointEventTypeCommandChanged
1389// || event_type & eBreakpointEventTypeConditionChanged
1390// || event_type & eBreakpointEventTypeIgnoreChanged
1391// || event_type & eBreakpointEventTypeLocationsResolved)
1392// {
1393// // Don't do anything about these events, since the breakpoint commands already echo these actions.
1394// }
1395//
1396 if (event_type & eBreakpointEventTypeLocationsAdded)
1397 {
1398 uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp);
1399 if (num_new_locations > 0)
1400 {
1401 BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
1402 StreamFileSP output_sp (GetOutputFile());
1403 if (output_sp)
1404 {
1405 output_sp->Printf("%d location%s added to breakpoint %d\n",
1406 num_new_locations,
1407 num_new_locations == 1 ? "" : "s",
1408 breakpoint->GetID());
1409 RefreshTopIOHandler();
1410 }
1411 }
1412 }
1413// else if (event_type & eBreakpointEventTypeLocationsRemoved)
1414// {
1415// // These locations just get disabled, not sure it is worth spamming folks about this on the command line.
1416// }
1417// else if (event_type & eBreakpointEventTypeLocationsResolved)
1418// {
1419// // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy.
1420// }
1421}
1422
1423size_t
1424Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
1425{
1426 size_t total_bytes = 0;
1427 if (stream == NULL)
1428 stream = GetOutputFile().get();
1429
1430 if (stream)
1431 {
1432 // The process has stuff waiting for stdout; get it and write it out to the appropriate place.
1433 if (process == NULL)
1434 {
1435 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1436 if (target_sp)
1437 process = target_sp->GetProcessSP().get();
1438 }
1439 if (process)
1440 {
1441 Error error;
1442 size_t len;
1443 char stdio_buffer[1024];
1444 while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1445 {
1446 stream->Write(stdio_buffer, len);
1447 total_bytes += len;
1448 }
1449 }
1450 stream->Flush();
1451 }
1452 return total_bytes;
1453}
1454
1455size_t
1456Debugger::GetProcessSTDERR (Process *process, Stream *stream)
1457{
1458 size_t total_bytes = 0;
1459 if (stream == NULL)
1460 stream = GetOutputFile().get();
1461
1462 if (stream)
1463 {
1464 // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
1465 if (process == NULL)
1466 {
1467 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1468 if (target_sp)
1469 process = target_sp->GetProcessSP().get();
1470 }
1471 if (process)
1472 {
1473 Error error;
1474 size_t len;
1475 char stdio_buffer[1024];
1476 while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1477 {
1478 stream->Write(stdio_buffer, len);
1479 total_bytes += len;
1480 }
1481 }
1482 stream->Flush();
1483 }
1484 return total_bytes;
1485}
1486
Greg Claytondc6224e2014-10-21 01:00:42 +00001487
Greg Clayton44d93782014-01-27 23:43:24 +00001488// This function handles events that were broadcast by the process.
1489void
1490Debugger::HandleProcessEvent (const EventSP &event_sp)
1491{
1492 using namespace lldb;
1493 const uint32_t event_type = event_sp->GetType();
1494 ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
Greg Claytondc6224e2014-10-21 01:00:42 +00001495
Greg Claytonb4874f12014-02-28 18:22:24 +00001496 StreamString output_stream;
1497 StreamString error_stream;
Greg Clayton44d93782014-01-27 23:43:24 +00001498 const bool gui_enabled = IsForwardingEvents();
Greg Clayton44d93782014-01-27 23:43:24 +00001499
Greg Claytonb4874f12014-02-28 18:22:24 +00001500 if (!gui_enabled)
1501 {
1502 bool pop_process_io_handler = false;
1503 assert (process_sp);
Greg Claytondc6224e2014-10-21 01:00:42 +00001504
Greg Claytonb4874f12014-02-28 18:22:24 +00001505 if (event_type & Process::eBroadcastBitSTDOUT || event_type & Process::eBroadcastBitStateChanged)
Greg Clayton44d93782014-01-27 23:43:24 +00001506 {
Greg Claytonb4874f12014-02-28 18:22:24 +00001507 GetProcessSTDOUT (process_sp.get(), &output_stream);
1508 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001509
Greg Claytonb4874f12014-02-28 18:22:24 +00001510 if (event_type & Process::eBroadcastBitSTDERR || event_type & Process::eBroadcastBitStateChanged)
1511 {
1512 GetProcessSTDERR (process_sp.get(), &error_stream);
1513 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001514
Greg Claytonb4874f12014-02-28 18:22:24 +00001515 if (event_type & Process::eBroadcastBitStateChanged)
1516 {
Greg Claytondc6224e2014-10-21 01:00:42 +00001517 Process::HandleProcessStateChangedEvent (event_sp, &output_stream, pop_process_io_handler);
Greg Clayton44d93782014-01-27 23:43:24 +00001518 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001519
Greg Claytonb4874f12014-02-28 18:22:24 +00001520 if (output_stream.GetSize() || error_stream.GetSize())
1521 {
1522 StreamFileSP error_stream_sp (GetOutputFile());
Greg Clayton6fea17e2014-03-03 19:15:20 +00001523 bool top_io_handler_hid = false;
Greg Claytondc6224e2014-10-21 01:00:42 +00001524
Greg Clayton6fea17e2014-03-03 19:15:20 +00001525 if (process_sp->ProcessIOHandlerIsActive() == false)
1526 top_io_handler_hid = HideTopIOHandler();
Greg Claytonb4874f12014-02-28 18:22:24 +00001527
1528 if (output_stream.GetSize())
1529 {
1530 StreamFileSP output_stream_sp (GetOutputFile());
1531 if (output_stream_sp)
1532 output_stream_sp->Write (output_stream.GetData(), output_stream.GetSize());
1533 }
1534
1535 if (error_stream.GetSize())
1536 {
1537 StreamFileSP error_stream_sp (GetErrorFile());
1538 if (error_stream_sp)
1539 error_stream_sp->Write (error_stream.GetData(), error_stream.GetSize());
1540 }
1541
1542 if (top_io_handler_hid)
1543 RefreshTopIOHandler();
1544 }
1545
1546 if (pop_process_io_handler)
1547 process_sp->PopProcessIOHandler();
1548 }
Greg Clayton44d93782014-01-27 23:43:24 +00001549}
1550
1551void
1552Debugger::HandleThreadEvent (const EventSP &event_sp)
1553{
1554 // At present the only thread event we handle is the Frame Changed event,
1555 // and all we do for that is just reprint the thread status for that thread.
1556 using namespace lldb;
1557 const uint32_t event_type = event_sp->GetType();
1558 if (event_type == Thread::eBroadcastBitStackChanged ||
1559 event_type == Thread::eBroadcastBitThreadSelected )
1560 {
1561 ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get()));
1562 if (thread_sp)
1563 {
1564 HideTopIOHandler();
1565 StreamFileSP stream_sp (GetOutputFile());
1566 thread_sp->GetStatus(*stream_sp, 0, 1, 1);
1567 RefreshTopIOHandler();
1568 }
1569 }
1570}
1571
1572bool
1573Debugger::IsForwardingEvents ()
1574{
1575 return (bool)m_forward_listener_sp;
1576}
1577
1578void
1579Debugger::EnableForwardEvents (const ListenerSP &listener_sp)
1580{
1581 m_forward_listener_sp = listener_sp;
1582}
1583
1584void
1585Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
1586{
1587 m_forward_listener_sp.reset();
1588}
1589
1590
1591void
1592Debugger::DefaultEventHandler()
1593{
1594 Listener& listener(GetListener());
1595 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1596 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1597 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1598 BroadcastEventSpec target_event_spec (broadcaster_class_target,
1599 Target::eBroadcastBitBreakpointChanged);
1600
1601 BroadcastEventSpec process_event_spec (broadcaster_class_process,
1602 Process::eBroadcastBitStateChanged |
1603 Process::eBroadcastBitSTDOUT |
1604 Process::eBroadcastBitSTDERR);
1605
1606 BroadcastEventSpec thread_event_spec (broadcaster_class_thread,
1607 Thread::eBroadcastBitStackChanged |
1608 Thread::eBroadcastBitThreadSelected );
1609
1610 listener.StartListeningForEventSpec (*this, target_event_spec);
1611 listener.StartListeningForEventSpec (*this, process_event_spec);
1612 listener.StartListeningForEventSpec (*this, thread_event_spec);
1613 listener.StartListeningForEvents (m_command_interpreter_ap.get(),
1614 CommandInterpreter::eBroadcastBitQuitCommandReceived |
1615 CommandInterpreter::eBroadcastBitAsynchronousOutputData |
1616 CommandInterpreter::eBroadcastBitAsynchronousErrorData );
Greg Claytonafa91e332014-12-01 22:41:27 +00001617
1618 // Let the thread that spawned us know that we have started up and
1619 // that we are now listening to all required events so no events get missed
1620 m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
1621
Greg Clayton44d93782014-01-27 23:43:24 +00001622 bool done = false;
1623 while (!done)
1624 {
Greg Clayton44d93782014-01-27 23:43:24 +00001625 EventSP event_sp;
1626 if (listener.WaitForEvent(NULL, event_sp))
1627 {
1628 if (event_sp)
1629 {
1630 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1631 if (broadcaster)
1632 {
1633 uint32_t event_type = event_sp->GetType();
1634 ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
1635 if (broadcaster_class == broadcaster_class_process)
1636 {
1637 HandleProcessEvent (event_sp);
1638 }
1639 else if (broadcaster_class == broadcaster_class_target)
1640 {
1641 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get()))
1642 {
1643 HandleBreakpointEvent (event_sp);
1644 }
1645 }
1646 else if (broadcaster_class == broadcaster_class_thread)
1647 {
1648 HandleThreadEvent (event_sp);
1649 }
1650 else if (broadcaster == m_command_interpreter_ap.get())
1651 {
1652 if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived)
1653 {
1654 done = true;
1655 }
1656 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData)
1657 {
1658 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1659 if (data && data[0])
1660 {
1661 StreamFileSP error_sp (GetErrorFile());
1662 if (error_sp)
1663 {
1664 HideTopIOHandler();
1665 error_sp->PutCString(data);
1666 error_sp->Flush();
1667 RefreshTopIOHandler();
1668 }
1669 }
1670 }
1671 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData)
1672 {
1673 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1674 if (data && data[0])
1675 {
1676 StreamFileSP output_sp (GetOutputFile());
1677 if (output_sp)
1678 {
1679 HideTopIOHandler();
1680 output_sp->PutCString(data);
1681 output_sp->Flush();
1682 RefreshTopIOHandler();
1683 }
1684 }
1685 }
1686 }
1687 }
1688
1689 if (m_forward_listener_sp)
1690 m_forward_listener_sp->AddEvent(event_sp);
1691 }
1692 }
1693 }
1694}
1695
1696lldb::thread_result_t
1697Debugger::EventHandlerThread (lldb::thread_arg_t arg)
1698{
1699 ((Debugger *)arg)->DefaultEventHandler();
1700 return NULL;
1701}
1702
1703bool
1704Debugger::StartEventHandlerThread()
1705{
Zachary Turneracee96a2014-09-23 18:32:09 +00001706 if (!m_event_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001707 {
Greg Claytonafa91e332014-12-01 22:41:27 +00001708 // We must synchronize with the DefaultEventHandler() thread to ensure
1709 // it is up and running and listening to events before we return from
1710 // this function. We do this by listening to events for the
1711 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1712 Listener listener("lldb.debugger.event-handler");
1713 listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
1714
Zachary Turner7c2896a2014-10-24 22:06:29 +00001715 // Use larger 8MB stack for this thread
Greg Claytonafa91e332014-12-01 22:41:27 +00001716 m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread,
1717 this,
1718 NULL,
Zachary Turner7c2896a2014-10-24 22:06:29 +00001719 g_debugger_event_thread_stack_bytes);
Greg Claytonafa91e332014-12-01 22:41:27 +00001720
1721 // Make sure DefaultEventHandler() is running and listening to events before we return
1722 // from this function. We are only listening for events of type
1723 // eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
1724 // to wait an infinite amount of time for it (NULL timeout as the first parameter)
1725 lldb::EventSP event_sp;
1726 listener.WaitForEvent(NULL, event_sp);
Greg Clayton807b6b32014-10-15 18:03:59 +00001727 }
Zachary Turneracee96a2014-09-23 18:32:09 +00001728 return m_event_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001729}
1730
1731void
1732Debugger::StopEventHandlerThread()
1733{
Zachary Turneracee96a2014-09-23 18:32:09 +00001734 if (m_event_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001735 {
1736 GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
Zachary Turner39de3112014-09-09 20:54:56 +00001737 m_event_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001738 }
1739}
1740
1741
1742lldb::thread_result_t
1743Debugger::IOHandlerThread (lldb::thread_arg_t arg)
1744{
1745 Debugger *debugger = (Debugger *)arg;
Siva Chandra9aaab552015-02-26 19:26:36 +00001746 debugger->ExecuteIOHandlers();
Greg Clayton44d93782014-01-27 23:43:24 +00001747 debugger->StopEventHandlerThread();
1748 return NULL;
1749}
1750
1751bool
1752Debugger::StartIOHandlerThread()
1753{
Zachary Turneracee96a2014-09-23 18:32:09 +00001754 if (!m_io_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001755 m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
1756 IOHandlerThread,
1757 this,
1758 NULL,
1759 8*1024*1024); // Use larger 8MB stack for this thread
Zachary Turneracee96a2014-09-23 18:32:09 +00001760 return m_io_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001761}
1762
1763void
1764Debugger::StopIOHandlerThread()
1765{
Zachary Turneracee96a2014-09-23 18:32:09 +00001766 if (m_io_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001767 {
1768 if (m_input_file_sp)
1769 m_input_file_sp->GetFile().Close();
Zachary Turner39de3112014-09-09 20:54:56 +00001770 m_io_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001771 }
1772}
1773
Jim Ingham893c9322014-11-22 01:42:44 +00001774Target *
1775Debugger::GetDummyTarget()
1776{
1777 return m_target_list.GetDummyTarget (*this).get();
1778}
1779
1780Target *
Jim Ingham33df7cd2014-12-06 01:28:03 +00001781Debugger::GetSelectedOrDummyTarget(bool prefer_dummy)
Jim Ingham893c9322014-11-22 01:42:44 +00001782{
Jim Ingham33df7cd2014-12-06 01:28:03 +00001783 Target *target = nullptr;
1784 if (!prefer_dummy)
1785 {
1786 target = m_target_list.GetSelectedTarget().get();
1787 if (target)
1788 return target;
1789 }
1790
Jim Ingham893c9322014-11-22 01:42:44 +00001791 return GetDummyTarget();
1792}
Greg Clayton44d93782014-01-27 23:43:24 +00001793