blob: c9d50052523a1e6304155fac6242042d8a0837ca [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"
Zachary Turner633a29c2015-03-04 01:58:01 +000042#include "lldb/Interpreter/OptionValueProperties.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000043#include "lldb/Interpreter/OptionValueSInt64.h"
44#include "lldb/Interpreter/OptionValueString.h"
Greg Clayton1f746072012-08-29 21:13:06 +000045#include "lldb/Symbol/ClangASTContext.h"
46#include "lldb/Symbol/CompileUnit.h"
47#include "lldb/Symbol/Function.h"
48#include "lldb/Symbol/Symbol.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000049#include "lldb/Symbol/VariableList.h"
Jason Molendaaff1b352014-10-10 23:07:36 +000050#include "lldb/Target/CPPLanguageRuntime.h"
51#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "lldb/Target/TargetList.h"
53#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000054#include "lldb/Target/RegisterContext.h"
Greg Clayton5fb8f792013-12-02 19:35:49 +000055#include "lldb/Target/SectionLoadList.h"
Greg Clayton1b654882010-09-19 02:33:57 +000056#include "lldb/Target/StopInfo.h"
Enrico Granata84a53df2013-05-20 22:29:23 +000057#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000059#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
Zachary Turner58a559c2014-08-27 20:15:09 +000061#include "llvm/Support/DynamicLibrary.h"
62
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063using namespace lldb;
64using namespace lldb_private;
65
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
Greg Clayton1b654882010-09-19 02:33:57 +000067static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000068static lldb::user_id_t g_unique_id = 1;
Zachary Turner7c2896a2014-10-24 22:06:29 +000069static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000070
Greg Clayton1b654882010-09-19 02:33:57 +000071#pragma mark Static Functions
72
73static Mutex &
74GetDebuggerListMutex ()
75{
76 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
77 return g_mutex;
78}
79
80typedef std::vector<DebuggerSP> DebuggerList;
81
82static DebuggerList &
83GetDebuggerList()
84{
85 // hide the static debugger list inside a singleton accessor to avoid
Bruce Mitchener6a7f3332014-06-27 02:42:12 +000086 // global init constructors
Greg Clayton1b654882010-09-19 02:33:57 +000087 static DebuggerList g_list;
88 return g_list;
89}
Greg Claytone372b982011-11-21 21:44:34 +000090
91OptionEnumValueElement
Greg Clayton67cc0632012-08-22 17:17:09 +000092g_show_disassembly_enum_values[] =
Greg Claytone372b982011-11-21 21:44:34 +000093{
Greg Clayton67cc0632012-08-22 17:17:09 +000094 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
95 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
96 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
Greg Claytone372b982011-11-21 21:44:34 +000097 { 0, NULL, NULL }
98};
99
Greg Clayton67cc0632012-08-22 17:17:09 +0000100OptionEnumValueElement
101g_language_enumerators[] =
102{
103 { eScriptLanguageNone, "none", "Disable scripting languages."},
104 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
105 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
Greg Claytona12993c2012-09-13 23:03:20 +0000106 { 0, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000107};
Greg Claytone372b982011-11-21 21:44:34 +0000108
Greg Clayton67cc0632012-08-22 17:17:09 +0000109#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
110#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
111
Michael Sartain0769b2b2013-07-30 16:44:36 +0000112#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000113 "{, ${frame.pc}}"\
114 MODULE_WITH_FUNC\
115 FILE_AND_LINE\
Michael Sartain0769b2b2013-07-30 16:44:36 +0000116 "{, name = '${thread.name}'}"\
117 "{, queue = '${thread.queue}'}"\
Jason Molenda705b1802014-06-13 02:37:02 +0000118 "{, activity = '${thread.info.activity.name}'}" \
119 "{, ${thread.info.trace_messages} messages}" \
Greg Clayton67cc0632012-08-22 17:17:09 +0000120 "{, stop reason = ${thread.stop-reason}}"\
121 "{\\nReturn value: ${thread.return-value}}"\
Jim Ingham30fadaf2014-07-08 01:07:32 +0000122 "{\\nCompleted expression: ${thread.completed-expression}}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000123 "\\n"
124
125#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
126 MODULE_WITH_FUNC\
127 FILE_AND_LINE\
128 "\\n"
129
Jason Molendac980fa92015-02-13 23:24:21 +0000130// Three parts to this disassembly format specification:
131// 1. If this is a new function/symbol (no previous symbol/function), print
132// dylib`funcname:\n
133// 2. If this is a symbol context change (different from previous symbol/function), print
134// dylib`funcname:\n
135// 3. print
136// address <+offset>:
137#define DEFAULT_DISASSEMBLY_FORMAT "{${function.initial-function}{${module.file.basename}`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name-without-args}}:\n}{${current-pc-arrow} }${addr-file-or-load}{ <${function.concrete-only-addr-offset-no-padding}>}: "
138
139// gdb's disassembly format can be emulated with
140// ${current-pc-arrow}${addr-file-or-load}{ <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>}:
141
142// lldb's original format for disassembly would look like this format string -
143// {${function.initial-function}{${module.file.basename}`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name-without-args}}:\n}{${current-pc-arrow} }{${addr-file-or-load}}:
144
Greg Clayton67cc0632012-08-22 17:17:09 +0000145
Greg Clayton754a9362012-08-23 00:22:02 +0000146static PropertyDefinition
147g_properties[] =
Greg Clayton67cc0632012-08-22 17:17:09 +0000148{
Greg Clayton554f68d2015-02-04 22:00:53 +0000149{ "auto-confirm", OptionValue::eTypeBoolean , true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
150{ "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, NULL, "The default disassembly format string to use when disassembling instruction sequences." },
151{ "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
152{ "notify-void", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
153{ "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
154{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
155{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
156{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
157{ "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." },
158{ "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." },
159{ "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
160{ "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
161{ "use-external-editor", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Whether to use an external editor or not." },
162{ "use-color", OptionValue::eTypeBoolean , true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
163{ "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
164{ "escape-non-printables", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
165{ NULL, OptionValue::eTypeInvalid , true, 0 , NULL, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000166};
167
168enum
169{
170 ePropertyAutoConfirm = 0,
Jason Molendaaff1b352014-10-10 23:07:36 +0000171 ePropertyDisassemblyFormat,
Greg Clayton67cc0632012-08-22 17:17:09 +0000172 ePropertyFrameFormat,
173 ePropertyNotiftVoid,
174 ePropertyPrompt,
175 ePropertyScriptLanguage,
176 ePropertyStopDisassemblyCount,
177 ePropertyStopDisassemblyDisplay,
178 ePropertyStopLineCountAfter,
179 ePropertyStopLineCountBefore,
180 ePropertyTerminalWidth,
181 ePropertyThreadFormat,
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000182 ePropertyUseExternalEditor,
183 ePropertyUseColor,
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000184 ePropertyAutoOneLineSummaries,
185 ePropertyEscapeNonPrintables
Greg Clayton67cc0632012-08-22 17:17:09 +0000186};
187
Greg Clayton5fb8f792013-12-02 19:35:49 +0000188Debugger::LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
Greg Clayton4c054102012-09-01 00:38:36 +0000189
190Error
191Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
192 VarSetOperationType op,
193 const char *property_path,
194 const char *value)
195{
Enrico Granata84a53df2013-05-20 22:29:23 +0000196 bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000197 bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0;
Enrico Granata84a53df2013-05-20 22:29:23 +0000198 TargetSP target_sp;
Enrico Granata397ddd52013-05-21 20:13:34 +0000199 LoadScriptFromSymFile load_script_old_value;
Enrico Granata84a53df2013-05-20 22:29:23 +0000200 if (is_load_script && exe_ctx->GetTargetSP())
201 {
202 target_sp = exe_ctx->GetTargetSP();
203 load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
204 }
Greg Clayton4c054102012-09-01 00:38:36 +0000205 Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value));
206 if (error.Success())
207 {
Enrico Granata84a53df2013-05-20 22:29:23 +0000208 // FIXME it would be nice to have "on-change" callbacks for properties
Greg Clayton4c054102012-09-01 00:38:36 +0000209 if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0)
210 {
211 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000212 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
213 if (str.length())
214 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000215 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton4c054102012-09-01 00:38:36 +0000216 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
217 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
218 }
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000219 else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0)
220 {
221 // use-color changed. Ping the prompt so it can reset the ansi terminal codes.
222 SetPrompt (GetPrompt());
223 }
Enrico Granata397ddd52013-05-21 20:13:34 +0000224 else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn)
Enrico Granata84a53df2013-05-20 22:29:23 +0000225 {
Enrico Granata397ddd52013-05-21 20:13:34 +0000226 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue)
Enrico Granata84a53df2013-05-20 22:29:23 +0000227 {
228 std::list<Error> errors;
Enrico Granata97303392013-05-21 00:00:30 +0000229 StreamString feedback_stream;
230 if (!target_sp->LoadScriptingResources(errors,&feedback_stream))
Enrico Granata84a53df2013-05-20 22:29:23 +0000231 {
Greg Clayton44d93782014-01-27 23:43:24 +0000232 StreamFileSP stream_sp (GetErrorFile());
233 if (stream_sp)
Enrico Granata84a53df2013-05-20 22:29:23 +0000234 {
Greg Clayton44d93782014-01-27 23:43:24 +0000235 for (auto error : errors)
236 {
237 stream_sp->Printf("%s\n",error.AsCString());
238 }
239 if (feedback_stream.GetSize())
240 stream_sp->Printf("%s",feedback_stream.GetData());
Enrico Granata84a53df2013-05-20 22:29:23 +0000241 }
242 }
243 }
244 }
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000245 else if (is_escape_non_printables)
246 {
247 DataVisualization::ForceUpdate();
248 }
Greg Clayton4c054102012-09-01 00:38:36 +0000249 }
250 return error;
251}
252
Greg Clayton67cc0632012-08-22 17:17:09 +0000253bool
254Debugger::GetAutoConfirm () const
255{
256 const uint32_t idx = ePropertyAutoConfirm;
Greg Clayton754a9362012-08-23 00:22:02 +0000257 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000258}
259
Greg Clayton554f68d2015-02-04 22:00:53 +0000260const FormatEntity::Entry *
Jason Molendaaff1b352014-10-10 23:07:36 +0000261Debugger::GetDisassemblyFormat() const
262{
263 const uint32_t idx = ePropertyDisassemblyFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000264 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Jason Molendaaff1b352014-10-10 23:07:36 +0000265}
266
Greg Clayton554f68d2015-02-04 22:00:53 +0000267const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000268Debugger::GetFrameFormat() const
269{
270 const uint32_t idx = ePropertyFrameFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000271 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000272}
273
274bool
275Debugger::GetNotifyVoid () const
276{
277 const uint32_t idx = ePropertyNotiftVoid;
Greg Clayton754a9362012-08-23 00:22:02 +0000278 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000279}
280
281const char *
282Debugger::GetPrompt() const
283{
284 const uint32_t idx = ePropertyPrompt;
Greg Clayton754a9362012-08-23 00:22:02 +0000285 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000286}
287
288void
289Debugger::SetPrompt(const char *p)
290{
291 const uint32_t idx = ePropertyPrompt;
292 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
293 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000294 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
295 if (str.length())
296 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000297 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton67cc0632012-08-22 17:17:09 +0000298}
299
Greg Clayton554f68d2015-02-04 22:00:53 +0000300const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000301Debugger::GetThreadFormat() const
302{
303 const uint32_t idx = ePropertyThreadFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000304 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000305}
306
307lldb::ScriptLanguage
308Debugger::GetScriptLanguage() const
309{
310 const uint32_t idx = ePropertyScriptLanguage;
Greg Clayton754a9362012-08-23 00:22:02 +0000311 return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000312}
313
314bool
315Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
316{
317 const uint32_t idx = ePropertyScriptLanguage;
318 return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
319}
320
321uint32_t
322Debugger::GetTerminalWidth () const
323{
324 const uint32_t idx = ePropertyTerminalWidth;
Greg Clayton754a9362012-08-23 00:22:02 +0000325 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000326}
327
328bool
329Debugger::SetTerminalWidth (uint32_t term_width)
330{
331 const uint32_t idx = ePropertyTerminalWidth;
332 return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
333}
334
335bool
336Debugger::GetUseExternalEditor () const
337{
338 const uint32_t idx = ePropertyUseExternalEditor;
Greg Clayton754a9362012-08-23 00:22:02 +0000339 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000340}
341
342bool
343Debugger::SetUseExternalEditor (bool b)
344{
345 const uint32_t idx = ePropertyUseExternalEditor;
346 return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
347}
348
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000349bool
350Debugger::GetUseColor () const
351{
352 const uint32_t idx = ePropertyUseColor;
353 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
354}
355
356bool
357Debugger::SetUseColor (bool b)
358{
359 const uint32_t idx = ePropertyUseColor;
360 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
361 SetPrompt (GetPrompt());
362 return ret;
363}
364
Greg Clayton67cc0632012-08-22 17:17:09 +0000365uint32_t
366Debugger::GetStopSourceLineCount (bool before) const
367{
368 const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
Greg Clayton754a9362012-08-23 00:22:02 +0000369 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000370}
371
372Debugger::StopDisassemblyType
373Debugger::GetStopDisassemblyDisplay () const
374{
375 const uint32_t idx = ePropertyStopDisassemblyDisplay;
Greg Clayton754a9362012-08-23 00:22:02 +0000376 return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000377}
378
379uint32_t
380Debugger::GetDisassemblyLineCount () const
381{
382 const uint32_t idx = ePropertyStopDisassemblyCount;
Greg Clayton754a9362012-08-23 00:22:02 +0000383 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000384}
Greg Claytone372b982011-11-21 21:44:34 +0000385
Enrico Granata553fad52013-10-25 23:09:40 +0000386bool
Enrico Granata90a8db32013-10-31 21:01:07 +0000387Debugger::GetAutoOneLineSummaries () const
Enrico Granata553fad52013-10-25 23:09:40 +0000388{
Enrico Granata90a8db32013-10-31 21:01:07 +0000389 const uint32_t idx = ePropertyAutoOneLineSummaries;
Enrico Granata553fad52013-10-25 23:09:40 +0000390 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000391}
Enrico Granata553fad52013-10-25 23:09:40 +0000392
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000393bool
394Debugger::GetEscapeNonPrintables () const
395{
396 const uint32_t idx = ePropertyEscapeNonPrintables;
397 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granata553fad52013-10-25 23:09:40 +0000398}
399
Greg Clayton1b654882010-09-19 02:33:57 +0000400#pragma mark Debugger
401
Greg Clayton67cc0632012-08-22 17:17:09 +0000402//const DebuggerPropertiesSP &
403//Debugger::GetSettings() const
404//{
405// return m_properties_sp;
406//}
407//
Greg Clayton99d0faf2010-11-18 23:32:35 +0000408
Caroline Tice2f88aad2011-01-14 00:29:16 +0000409int
410Debugger::TestDebuggerRefCount ()
411{
412 return g_shared_debugger_refcount;
413}
414
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415void
Greg Clayton5fb8f792013-12-02 19:35:49 +0000416Debugger::Initialize (LoadPluginCallbackType load_plugin_callback)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000418 g_load_plugin_callback = load_plugin_callback;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000419 if (g_shared_debugger_refcount++ == 0)
Greg Claytondbe54502010-11-19 03:46:01 +0000420 lldb_private::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421}
422
423void
424Debugger::Terminate ()
425{
Greg Clayton66111032010-06-23 01:19:29 +0000426 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 {
Greg Clayton66111032010-06-23 01:19:29 +0000428 g_shared_debugger_refcount--;
429 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430 {
Greg Claytondbe54502010-11-19 03:46:01 +0000431 lldb_private::WillTerminate();
432 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000433
434 // Clear our master list of debugger objects
435 Mutex::Locker locker (GetDebuggerListMutex ());
436 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 }
439}
440
Caroline Tice20bd37f2011-03-10 22:14:10 +0000441void
442Debugger::SettingsInitialize ()
443{
Greg Clayton6920b522012-08-22 18:39:03 +0000444 Target::SettingsInitialize ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000445}
446
447void
448Debugger::SettingsTerminate ()
449{
Greg Clayton6920b522012-08-22 18:39:03 +0000450 Target::SettingsTerminate ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000451}
452
Enrico Granata21dfcd92012-09-28 23:57:51 +0000453bool
Enrico Granatae743c782013-04-24 21:29:08 +0000454Debugger::LoadPlugin (const FileSpec& spec, Error& error)
Enrico Granata21dfcd92012-09-28 23:57:51 +0000455{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000456 if (g_load_plugin_callback)
Enrico Granatae743c782013-04-24 21:29:08 +0000457 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000458 llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error);
459 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +0000460 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000461 m_loaded_plugins.push_back(dynlib);
Greg Clayton5fb8f792013-12-02 19:35:49 +0000462 return true;
463 }
Enrico Granatae743c782013-04-24 21:29:08 +0000464 }
Greg Clayton5fb8f792013-12-02 19:35:49 +0000465 else
Enrico Granatae743c782013-04-24 21:29:08 +0000466 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000467 // The g_load_plugin_callback is registered in SBDebugger::Initialize()
468 // and if the public API layer isn't available (code is linking against
469 // all of the internal LLDB static libraries), then we can't load plugins
470 error.SetErrorString("Public API layer is not available");
Enrico Granatae743c782013-04-24 21:29:08 +0000471 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000472 return false;
473}
474
475static FileSpec::EnumerateDirectoryResult
476LoadPluginCallback
477(
478 void *baton,
479 FileSpec::FileType file_type,
480 const FileSpec &file_spec
481 )
482{
483 Error error;
484
485 static ConstString g_dylibext("dylib");
Michael Sartain3cf443d2013-07-17 00:26:30 +0000486 static ConstString g_solibext("so");
Enrico Granata21dfcd92012-09-28 23:57:51 +0000487
488 if (!baton)
489 return FileSpec::eEnumerateDirectoryResultQuit;
490
491 Debugger *debugger = (Debugger*)baton;
492
493 // If we have a regular file, a symbolic link or unknown file type, try
494 // and process the file. We must handle unknown as sometimes the directory
495 // enumeration might be enumerating a file system that doesn't have correct
496 // file type information.
497 if (file_type == FileSpec::eFileTypeRegular ||
498 file_type == FileSpec::eFileTypeSymbolicLink ||
499 file_type == FileSpec::eFileTypeUnknown )
500 {
501 FileSpec plugin_file_spec (file_spec);
502 plugin_file_spec.ResolvePath ();
503
Michael Sartain3cf443d2013-07-17 00:26:30 +0000504 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
505 plugin_file_spec.GetFileNameExtension() != g_solibext)
506 {
Enrico Granata21dfcd92012-09-28 23:57:51 +0000507 return FileSpec::eEnumerateDirectoryResultNext;
Michael Sartain3cf443d2013-07-17 00:26:30 +0000508 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000509
Enrico Granatae743c782013-04-24 21:29:08 +0000510 Error plugin_load_error;
511 debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000512
513 return FileSpec::eEnumerateDirectoryResultNext;
514 }
515
516 else if (file_type == FileSpec::eFileTypeUnknown ||
517 file_type == FileSpec::eFileTypeDirectory ||
518 file_type == FileSpec::eFileTypeSymbolicLink )
519 {
520 // Try and recurse into anything that a directory or symbolic link.
521 // We must also do this for unknown as sometimes the directory enumeration
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000522 // might be enumerating a file system that doesn't have correct file type
Enrico Granata21dfcd92012-09-28 23:57:51 +0000523 // information.
524 return FileSpec::eEnumerateDirectoryResultEnter;
525 }
526
527 return FileSpec::eEnumerateDirectoryResultNext;
528}
529
530void
531Debugger::InstanceInitialize ()
532{
533 FileSpec dir_spec;
534 const bool find_directories = true;
535 const bool find_files = true;
536 const bool find_other = true;
537 char dir_path[PATH_MAX];
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000538 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000539 {
540 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
541 {
542 FileSpec::EnumerateDirectory (dir_path,
543 find_directories,
544 find_files,
545 find_other,
546 LoadPluginCallback,
547 this);
548 }
549 }
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000550
551 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000552 {
553 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
554 {
555 FileSpec::EnumerateDirectory (dir_path,
556 find_directories,
557 find_files,
558 find_other,
559 LoadPluginCallback,
560 this);
561 }
562 }
Greg Claytone8cd0c92012-10-19 18:02:49 +0000563
564 PluginManager::DebuggerInitialize (*this);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000565}
566
Greg Clayton66111032010-06-23 01:19:29 +0000567DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000568Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000569{
Jim Ingham228063c2012-02-21 02:23:08 +0000570 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Greg Claytonc15f55e2012-03-30 20:53:46 +0000571 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000572 {
573 Mutex::Locker locker (GetDebuggerListMutex ());
574 GetDebuggerList().push_back(debugger_sp);
575 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000576 debugger_sp->InstanceInitialize ();
Greg Clayton66111032010-06-23 01:19:29 +0000577 return debugger_sp;
578}
579
Caroline Ticee02657b2011-01-22 01:02:07 +0000580void
Greg Clayton4d122c42011-09-17 08:33:22 +0000581Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000582{
583 if (debugger_sp.get() == NULL)
584 return;
585
Jim Ingham8314c522011-09-15 21:36:42 +0000586 debugger_sp->Clear();
587
Greg Claytonc15f55e2012-03-30 20:53:46 +0000588 if (g_shared_debugger_refcount > 0)
Caroline Ticee02657b2011-01-22 01:02:07 +0000589 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000590 Mutex::Locker locker (GetDebuggerListMutex ());
591 DebuggerList &debugger_list = GetDebuggerList ();
592 DebuggerList::iterator pos, end = debugger_list.end();
593 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000594 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000595 if ((*pos).get() == debugger_sp.get())
596 {
597 debugger_list.erase (pos);
598 return;
599 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000600 }
601 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000602}
603
Greg Clayton4d122c42011-09-17 08:33:22 +0000604DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000605Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
606{
Greg Clayton4d122c42011-09-17 08:33:22 +0000607 DebuggerSP debugger_sp;
Greg Clayton6920b522012-08-22 18:39:03 +0000608 if (g_shared_debugger_refcount > 0)
609 {
610 Mutex::Locker locker (GetDebuggerListMutex ());
611 DebuggerList &debugger_list = GetDebuggerList();
612 DebuggerList::iterator pos, end = debugger_list.end();
613
614 for (pos = debugger_list.begin(); pos != end; ++pos)
615 {
616 if ((*pos).get()->m_instance_name == instance_name)
617 {
618 debugger_sp = *pos;
619 break;
620 }
621 }
622 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000623 return debugger_sp;
624}
Greg Clayton66111032010-06-23 01:19:29 +0000625
626TargetSP
627Debugger::FindTargetWithProcessID (lldb::pid_t pid)
628{
Greg Clayton4d122c42011-09-17 08:33:22 +0000629 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000630 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000631 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000632 Mutex::Locker locker (GetDebuggerListMutex ());
633 DebuggerList &debugger_list = GetDebuggerList();
634 DebuggerList::iterator pos, end = debugger_list.end();
635 for (pos = debugger_list.begin(); pos != end; ++pos)
636 {
637 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
638 if (target_sp)
639 break;
640 }
Greg Clayton66111032010-06-23 01:19:29 +0000641 }
642 return target_sp;
643}
644
Greg Claytone4e45922011-11-16 05:37:56 +0000645TargetSP
646Debugger::FindTargetWithProcess (Process *process)
647{
648 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000649 if (g_shared_debugger_refcount > 0)
Greg Claytone4e45922011-11-16 05:37:56 +0000650 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000651 Mutex::Locker locker (GetDebuggerListMutex ());
652 DebuggerList &debugger_list = GetDebuggerList();
653 DebuggerList::iterator pos, end = debugger_list.end();
654 for (pos = debugger_list.begin(); pos != end; ++pos)
655 {
656 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
657 if (target_sp)
658 break;
659 }
Greg Claytone4e45922011-11-16 05:37:56 +0000660 }
661 return target_sp;
662}
663
Jason Molendae6481c72014-09-12 01:50:46 +0000664Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
665 UserID(g_unique_id++),
666 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
667 m_input_file_sp(new StreamFile(stdin, false)),
668 m_output_file_sp(new StreamFile(stdout, false)),
669 m_error_file_sp(new StreamFile(stderr, false)),
670 m_terminal_state(),
671 m_target_list(*this),
672 m_platform_list(),
673 m_listener("lldb.Debugger"),
674 m_source_manager_ap(),
675 m_source_file_cache(),
676 m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)),
677 m_input_reader_stack(),
678 m_instance_name(),
Greg Claytonafa91e332014-12-01 22:41:27 +0000679 m_loaded_plugins(),
680 m_event_handler_thread (),
681 m_io_handler_thread (),
682 m_sync_broadcaster (NULL, "lldb.debugger.sync")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683{
Greg Clayton67cc0632012-08-22 17:17:09 +0000684 char instance_cstr[256];
685 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
686 m_instance_name.SetCString(instance_cstr);
Jim Ingham228063c2012-02-21 02:23:08 +0000687 if (log_callback)
688 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000689 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000690 // Always add our default platform to the platform list
Greg Clayton615eb7e2014-09-19 20:11:50 +0000691 PlatformSP default_platform_sp (Platform::GetHostPlatform());
Greg Claytonded470d2011-03-19 01:12:21 +0000692 assert (default_platform_sp.get());
693 m_platform_list.Append (default_platform_sp, true);
Greg Clayton67cc0632012-08-22 17:17:09 +0000694
Greg Clayton754a9362012-08-23 00:22:02 +0000695 m_collection_sp->Initialize (g_properties);
Greg Clayton67cc0632012-08-22 17:17:09 +0000696 m_collection_sp->AppendProperty (ConstString("target"),
697 ConstString("Settings specify to debugging targets."),
698 true,
699 Target::GetGlobalProperties()->GetValueProperties());
Greg Clayton754a9362012-08-23 00:22:02 +0000700 if (m_command_interpreter_ap.get())
701 {
702 m_collection_sp->AppendProperty (ConstString("interpreter"),
703 ConstString("Settings specify to the debugger's command interpreter."),
704 true,
705 m_command_interpreter_ap->GetValueProperties());
706 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000707 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
708 term_width->SetMinimumValue(10);
709 term_width->SetMaximumValue(1024);
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000710
711 // Turn off use-color if this is a dumb terminal.
712 const char *term = getenv ("TERM");
713 if (term && !strcmp (term, "dumb"))
714 SetUseColor (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715}
716
717Debugger::~Debugger ()
718{
Jim Ingham8314c522011-09-15 21:36:42 +0000719 Clear();
720}
721
722void
723Debugger::Clear()
724{
Greg Clayton44d93782014-01-27 23:43:24 +0000725 ClearIOHandlers();
726 StopIOHandlerThread();
727 StopEventHandlerThread();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000728 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000729 int num_targets = m_target_list.GetNumTargets();
730 for (int i = 0; i < num_targets; i++)
731 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000732 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
733 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000734 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000735 ProcessSP process_sp (target_sp->GetProcessSP());
736 if (process_sp)
Jim Ingham1fd07052013-02-27 19:13:05 +0000737 process_sp->Finalize();
Greg Claytonccbc08e2012-01-14 17:04:19 +0000738 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000739 }
Greg Clayton66111032010-06-23 01:19:29 +0000740 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000741 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000742
743 // Close the input file _before_ we close the input read communications class
744 // as it does NOT own the input file, our m_input_file does.
Jim Inghamc5917d92012-11-30 20:23:19 +0000745 m_terminal_state.Clear();
Greg Clayton44d93782014-01-27 23:43:24 +0000746 if (m_input_file_sp)
747 m_input_file_sp->GetFile().Close ();
Greg Clayton0c4129f2014-04-25 00:35:14 +0000748
749 m_command_interpreter_ap->Clear();
Jim Ingham8314c522011-09-15 21:36:42 +0000750}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000751
752bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000753Debugger::GetCloseInputOnEOF () const
754{
Greg Clayton44d93782014-01-27 23:43:24 +0000755// return m_input_comm.GetCloseOnEOF();
756 return false;
Greg Claytonfc3f0272011-05-29 04:06:55 +0000757}
758
759void
760Debugger::SetCloseInputOnEOF (bool b)
761{
Greg Clayton44d93782014-01-27 23:43:24 +0000762// m_input_comm.SetCloseOnEOF(b);
Greg Claytonfc3f0272011-05-29 04:06:55 +0000763}
764
765bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766Debugger::GetAsyncExecution ()
767{
Greg Clayton66111032010-06-23 01:19:29 +0000768 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769}
770
771void
772Debugger::SetAsyncExecution (bool async_execution)
773{
Greg Clayton66111032010-06-23 01:19:29 +0000774 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775}
776
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777
778void
779Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
780{
Greg Clayton44d93782014-01-27 23:43:24 +0000781 if (m_input_file_sp)
782 m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership);
783 else
784 m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
785
786 File &in_file = m_input_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000787 if (in_file.IsValid() == false)
788 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789
Jim Inghamc5917d92012-11-30 20:23:19 +0000790 // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
791 SaveInputTerminalState ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792}
793
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000794void
795Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
796{
Greg Clayton44d93782014-01-27 23:43:24 +0000797 if (m_output_file_sp)
798 m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership);
799 else
800 m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
801
802 File &out_file = m_output_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000803 if (out_file.IsValid() == false)
804 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000805
Enrico Granatab5887262012-10-29 21:18:03 +0000806 // do not create the ScriptInterpreter just for setting the output file handle
807 // as the constructor will know how to do the right thing on its own
808 const bool can_create = false;
809 ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create);
810 if (script_interpreter)
811 script_interpreter->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814void
815Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
816{
Greg Clayton44d93782014-01-27 23:43:24 +0000817 if (m_error_file_sp)
818 m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership);
819 else
820 m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
821
822 File &err_file = m_error_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000823 if (err_file.IsValid() == false)
824 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825}
826
Jim Inghamc5917d92012-11-30 20:23:19 +0000827void
828Debugger::SaveInputTerminalState ()
829{
Greg Clayton44d93782014-01-27 23:43:24 +0000830 if (m_input_file_sp)
831 {
832 File &in_file = m_input_file_sp->GetFile();
833 if (in_file.GetDescriptor() != File::kInvalidDescriptor)
834 m_terminal_state.Save(in_file.GetDescriptor(), true);
835 }
Jim Inghamc5917d92012-11-30 20:23:19 +0000836}
837
838void
839Debugger::RestoreInputTerminalState ()
840{
841 m_terminal_state.Restore();
842}
843
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000844ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000845Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846{
847 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000848 TargetSP target_sp(GetSelectedTarget());
849 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850
851 if (target_sp)
852 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000853 ProcessSP process_sp (target_sp->GetProcessSP());
854 exe_ctx.SetProcessSP (process_sp);
855 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000856 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000857 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
858 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000860 exe_ctx.SetThreadSP (thread_sp);
861 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
862 if (exe_ctx.GetFramePtr() == NULL)
863 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000864 }
865 }
866 }
867 return exe_ctx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868}
869
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870void
Caroline Ticeefed6132010-11-19 20:47:54 +0000871Debugger::DispatchInputInterrupt ()
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->Interrupt();
Caroline Ticeefed6132010-11-19 20:47:54 +0000877}
878
879void
880Debugger::DispatchInputEndOfFile ()
881{
Greg Clayton44d93782014-01-27 23:43:24 +0000882 Mutex::Locker locker (m_input_reader_stack.GetMutex());
883 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000884 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000885 reader_sp->GotEOF();
Caroline Ticeefed6132010-11-19 20:47:54 +0000886}
887
888void
Greg Clayton44d93782014-01-27 23:43:24 +0000889Debugger::ClearIOHandlers ()
Caroline Tice3d6086f2010-12-20 18:35:50 +0000890{
Caroline Ticeb44880c2011-02-10 01:15:13 +0000891 // 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 +0000892 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000893 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000894 {
Greg Clayton44d93782014-01-27 23:43:24 +0000895 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000896 if (reader_sp)
897 {
Greg Clayton44d93782014-01-27 23:43:24 +0000898 m_input_reader_stack.Pop();
899 reader_sp->SetIsDone(true);
Greg Claytone68f5d62014-02-24 22:50:57 +0000900 reader_sp->Cancel();
Caroline Tice3d6086f2010-12-20 18:35:50 +0000901 }
902 }
903}
904
905void
Siva Chandra9aaab552015-02-26 19:26:36 +0000906Debugger::ExecuteIOHandlers()
Caroline Tice969ed3d2011-05-02 20:41:46 +0000907{
Caroline Tice9088b062011-05-09 23:06:58 +0000908
Greg Clayton44d93782014-01-27 23:43:24 +0000909 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000910 {
Greg Clayton44d93782014-01-27 23:43:24 +0000911 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000912 if (!reader_sp)
913 break;
914
Greg Clayton44d93782014-01-27 23:43:24 +0000915 reader_sp->Activate();
916 reader_sp->Run();
917 reader_sp->Deactivate();
918
919 // Remove all input readers that are done from the top of the stack
920 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000921 {
Greg Clayton44d93782014-01-27 23:43:24 +0000922 IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
923 if (top_reader_sp && top_reader_sp->GetIsDone())
924 m_input_reader_stack.Pop();
925 else
926 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000927 }
928 }
Greg Clayton44d93782014-01-27 23:43:24 +0000929 ClearIOHandlers();
930}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931
Greg Clayton44d93782014-01-27 23:43:24 +0000932bool
933Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
934{
935 return m_input_reader_stack.IsTop (reader_sp);
936}
937
938
939ConstString
940Debugger::GetTopIOHandlerControlSequence(char ch)
941{
942 return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000943}
944
Kate Stonea487aa42015-01-15 00:52:41 +0000945const char *
946Debugger::GetIOHandlerCommandPrefix()
947{
948 return m_input_reader_stack.GetTopIOHandlerCommandPrefix();
949}
950
951const char *
952Debugger::GetIOHandlerHelpPrologue()
953{
954 return m_input_reader_stack.GetTopIOHandlerHelpPrologue();
955}
956
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000957void
Greg Clayton44d93782014-01-27 23:43:24 +0000958Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
959{
Greg Clayton44d93782014-01-27 23:43:24 +0000960 PushIOHandler (reader_sp);
Greg Clayton577508d2014-06-20 00:23:57 +0000961
962 IOHandlerSP top_reader_sp = reader_sp;
963 while (top_reader_sp)
964 {
965 top_reader_sp->Activate();
966 top_reader_sp->Run();
967 top_reader_sp->Deactivate();
968
969 if (top_reader_sp.get() == reader_sp.get())
970 {
971 if (PopIOHandler (reader_sp))
972 break;
973 }
974
975 while (1)
976 {
977 top_reader_sp = m_input_reader_stack.Top();
978 if (top_reader_sp && top_reader_sp->GetIsDone())
979 m_input_reader_stack.Pop();
980 else
981 break;
982 }
983 }
Greg Clayton44d93782014-01-27 23:43:24 +0000984}
985
986void
987Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
988{
989 // Before an IOHandler runs, it must have in/out/err streams.
990 // This function is called when one ore more of the streams
991 // are NULL. We use the top input reader's in/out/err streams,
992 // or fall back to the debugger file handles, or we fall back
993 // onto stdin/stdout/stderr as a last resort.
994
995 Mutex::Locker locker (m_input_reader_stack.GetMutex());
996 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
997 // If no STDIN has been set, then set it appropriately
998 if (!in)
999 {
1000 if (top_reader_sp)
1001 in = top_reader_sp->GetInputStreamFile();
1002 else
1003 in = GetInputFile();
1004
1005 // If there is nothing, use stdin
1006 if (!in)
1007 in = StreamFileSP(new StreamFile(stdin, false));
1008 }
1009 // If no STDOUT has been set, then set it appropriately
1010 if (!out)
1011 {
1012 if (top_reader_sp)
1013 out = top_reader_sp->GetOutputStreamFile();
1014 else
1015 out = GetOutputFile();
1016
1017 // If there is nothing, use stdout
1018 if (!out)
1019 out = StreamFileSP(new StreamFile(stdout, false));
1020 }
1021 // If no STDERR has been set, then set it appropriately
1022 if (!err)
1023 {
1024 if (top_reader_sp)
1025 err = top_reader_sp->GetErrorStreamFile();
1026 else
1027 err = GetErrorFile();
1028
1029 // If there is nothing, use stderr
1030 if (!err)
1031 err = StreamFileSP(new StreamFile(stdout, false));
1032
1033 }
1034}
1035
1036void
1037Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038{
1039 if (!reader_sp)
1040 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +00001041
Greg Clayton44d93782014-01-27 23:43:24 +00001042 // Got the current top input reader...
1043 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +00001044
Greg Claytonb4874f12014-02-28 18:22:24 +00001045 // Don't push the same IO handler twice...
1046 if (reader_sp.get() != top_reader_sp.get())
1047 {
1048 // Push our new input reader
1049 m_input_reader_stack.Push (reader_sp);
Greg Clayton44d93782014-01-27 23:43:24 +00001050
Greg Claytonb4874f12014-02-28 18:22:24 +00001051 // Interrupt the top input reader to it will exit its Run() function
1052 // and let this new input reader take over
1053 if (top_reader_sp)
1054 top_reader_sp->Deactivate();
1055 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056}
1057
1058bool
Greg Clayton44d93782014-01-27 23:43:24 +00001059Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060{
1061 bool result = false;
Greg Clayton44d93782014-01-27 23:43:24 +00001062
1063 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064
1065 // The reader on the stop of the stack is done, so let the next
Bruce Mitchener6a7f3332014-06-27 02:42:12 +00001066 // read on the stack refresh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +00001067 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068 {
Greg Clayton44d93782014-01-27 23:43:24 +00001069 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001070
1071 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
1072 {
Greg Clayton44d93782014-01-27 23:43:24 +00001073 reader_sp->Deactivate();
Greg Claytonb4874f12014-02-28 18:22:24 +00001074 reader_sp->Cancel();
Caroline Ticed5a0a01b2011-06-02 19:18:55 +00001075 m_input_reader_stack.Pop ();
Greg Clayton44d93782014-01-27 23:43:24 +00001076
1077 reader_sp = m_input_reader_stack.Top();
1078 if (reader_sp)
1079 reader_sp->Activate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080
Greg Clayton44d93782014-01-27 23:43:24 +00001081 result = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001082 }
1083 }
1084 return result;
1085}
1086
1087bool
Greg Clayton44d93782014-01-27 23:43:24 +00001088Debugger::HideTopIOHandler()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001089{
Greg Clayton44d93782014-01-27 23:43:24 +00001090 Mutex::Locker locker;
1091
1092 if (locker.TryLock(m_input_reader_stack.GetMutex()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001093 {
Greg Clayton44d93782014-01-27 23:43:24 +00001094 IOHandlerSP reader_sp(m_input_reader_stack.Top());
1095 if (reader_sp)
1096 reader_sp->Hide();
1097 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001098 }
Greg Clayton44d93782014-01-27 23:43:24 +00001099 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100}
1101
1102void
Greg Clayton44d93782014-01-27 23:43:24 +00001103Debugger::RefreshTopIOHandler()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001104{
Greg Clayton44d93782014-01-27 23:43:24 +00001105 IOHandlerSP reader_sp(m_input_reader_stack.Top());
1106 if (reader_sp)
1107 reader_sp->Refresh();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001108}
Greg Clayton66111032010-06-23 01:19:29 +00001109
Greg Clayton44d93782014-01-27 23:43:24 +00001110
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001111StreamSP
1112Debugger::GetAsyncOutputStream ()
1113{
1114 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1115 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
1116}
1117
1118StreamSP
1119Debugger::GetAsyncErrorStream ()
1120{
1121 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1122 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
1123}
1124
Greg Claytonc7bece562013-01-25 18:06:21 +00001125size_t
Enrico Granata061858c2012-02-15 02:34:21 +00001126Debugger::GetNumDebuggers()
1127{
Greg Claytonc15f55e2012-03-30 20:53:46 +00001128 if (g_shared_debugger_refcount > 0)
1129 {
1130 Mutex::Locker locker (GetDebuggerListMutex ());
1131 return GetDebuggerList().size();
1132 }
1133 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +00001134}
1135
1136lldb::DebuggerSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001137Debugger::GetDebuggerAtIndex (size_t index)
Enrico Granata061858c2012-02-15 02:34:21 +00001138{
1139 DebuggerSP debugger_sp;
1140
Greg Claytonc15f55e2012-03-30 20:53:46 +00001141 if (g_shared_debugger_refcount > 0)
1142 {
1143 Mutex::Locker locker (GetDebuggerListMutex ());
1144 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +00001145
Greg Claytonc15f55e2012-03-30 20:53:46 +00001146 if (index < debugger_list.size())
1147 debugger_sp = debugger_list[index];
1148 }
1149
Enrico Granata061858c2012-02-15 02:34:21 +00001150 return debugger_sp;
1151}
1152
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001153DebuggerSP
1154Debugger::FindDebuggerWithID (lldb::user_id_t id)
1155{
Greg Clayton4d122c42011-09-17 08:33:22 +00001156 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001157
Greg Claytonc15f55e2012-03-30 20:53:46 +00001158 if (g_shared_debugger_refcount > 0)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001159 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001160 Mutex::Locker locker (GetDebuggerListMutex ());
1161 DebuggerList &debugger_list = GetDebuggerList();
1162 DebuggerList::iterator pos, end = debugger_list.end();
1163 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001164 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001165 if ((*pos).get()->GetID() == id)
1166 {
1167 debugger_sp = *pos;
1168 break;
1169 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001170 }
1171 }
1172 return debugger_sp;
1173}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001174
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001175#if 0
Greg Clayton1b654882010-09-19 02:33:57 +00001176static void
Jason Molendab57e4a12013-11-04 09:33:30 +00001177TestPromptFormats (StackFrame *frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001178{
1179 if (frame == NULL)
1180 return;
1181
1182 StreamString s;
1183 const char *prompt_format =
1184 "{addr = '${addr}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001185 "{addr-file-or-load = '${addr-file-or-load}'\n}"
1186 "{current-pc-arrow = '${current-pc-arrow}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001187 "{process.id = '${process.id}'\n}"
1188 "{process.name = '${process.name}'\n}"
1189 "{process.file.basename = '${process.file.basename}'\n}"
1190 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1191 "{thread.id = '${thread.id}'\n}"
1192 "{thread.index = '${thread.index}'\n}"
1193 "{thread.name = '${thread.name}'\n}"
1194 "{thread.queue = '${thread.queue}'\n}"
1195 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1196 "{target.arch = '${target.arch}'\n}"
1197 "{module.file.basename = '${module.file.basename}'\n}"
1198 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1199 "{file.basename = '${file.basename}'\n}"
1200 "{file.fullpath = '${file.fullpath}'\n}"
1201 "{frame.index = '${frame.index}'\n}"
1202 "{frame.pc = '${frame.pc}'\n}"
1203 "{frame.sp = '${frame.sp}'\n}"
1204 "{frame.fp = '${frame.fp}'\n}"
1205 "{frame.flags = '${frame.flags}'\n}"
1206 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1207 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1208 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1209 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1210 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1211 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1212 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1213 "{function.id = '${function.id}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001214 "{function.changed = '${function.changed}'\n}"
1215 "{function.initial-function = '${function.initial-function}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001216 "{function.name = '${function.name}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001217 "{function.name-without-args = '${function.name-without-args}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +00001218 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001219 "{function.addr-offset = '${function.addr-offset}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001220 "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001221 "{function.line-offset = '${function.line-offset}'\n}"
1222 "{function.pc-offset = '${function.pc-offset}'\n}"
1223 "{line.file.basename = '${line.file.basename}'\n}"
1224 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1225 "{line.number = '${line.number}'\n}"
1226 "{line.start-addr = '${line.start-addr}'\n}"
1227 "{line.end-addr = '${line.end-addr}'\n}"
1228;
1229
1230 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1231 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +00001232 frame->CalculateExecutionContext(exe_ctx);
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001233 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
Greg Clayton1b654882010-09-19 02:33:57 +00001234 {
1235 printf("%s\n", s.GetData());
1236 }
1237 else
1238 {
Greg Clayton1b654882010-09-19 02:33:57 +00001239 printf ("what we got: %s\n", s.GetData());
1240 }
1241}
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001242#endif
Greg Clayton1b654882010-09-19 02:33:57 +00001243
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001244bool
Greg Clayton554f68d2015-02-04 22:00:53 +00001245Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
Jason Molendaaff1b352014-10-10 23:07:36 +00001246 const SymbolContext *sc,
1247 const SymbolContext *prev_sc,
1248 const ExecutionContext *exe_ctx,
1249 const Address *addr,
1250 Stream &s)
1251{
Greg Clayton554f68d2015-02-04 22:00:53 +00001252 FormatEntity::Entry format_entry;
1253
1254 if (format == NULL)
Jason Molendaaff1b352014-10-10 23:07:36 +00001255 {
Greg Clayton554f68d2015-02-04 22:00:53 +00001256 if (exe_ctx != NULL && exe_ctx->HasTargetScope())
1257 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1258 if (format == NULL)
1259 {
1260 FormatEntity::Parse("${addr}: ", format_entry);
1261 format = &format_entry;
1262 }
Jason Molendaaff1b352014-10-10 23:07:36 +00001263 }
1264 bool function_changed = false;
1265 bool initial_function = false;
1266 if (prev_sc && (prev_sc->function || prev_sc->symbol))
1267 {
1268 if (sc && (sc->function || sc->symbol))
1269 {
1270 if (prev_sc->symbol && sc->symbol)
1271 {
1272 if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType()))
1273 {
1274 function_changed = true;
1275 }
1276 }
1277 else if (prev_sc->function && sc->function)
1278 {
1279 if (prev_sc->function->GetMangled() != sc->function->GetMangled())
1280 {
1281 function_changed = true;
1282 }
1283 }
1284 }
1285 }
1286 // The first context on a list of instructions will have a prev_sc that
1287 // has no Function or Symbol -- if SymbolContext had an IsValid() method, it
1288 // would return false. But we do get a prev_sc pointer.
1289 if ((sc && (sc->function || sc->symbol))
1290 && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL))
1291 {
1292 initial_function = true;
1293 }
Greg Clayton554f68d2015-02-04 22:00:53 +00001294 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, NULL, function_changed, initial_function);
Jason Molendaaff1b352014-10-10 23:07:36 +00001295}
1296
1297
Jim Ingham228063c2012-02-21 02:23:08 +00001298void
1299Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1300{
Jim Ingham4f02b222012-02-22 22:49:20 +00001301 // For simplicity's sake, I am not going to deal with how to close down any
1302 // open logging streams, I just redirect everything from here on out to the
1303 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00001304 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
1305}
1306
1307bool
1308Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
1309{
1310 Log::Callbacks log_callbacks;
1311
1312 StreamSP log_stream_sp;
Sean Callanan9a028512012-08-09 00:50:26 +00001313 if (m_log_callback_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001314 {
1315 log_stream_sp = m_log_callback_stream_sp;
1316 // For now when using the callback mode you always get thread & timestamp.
1317 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1318 }
1319 else if (log_file == NULL || *log_file == '\0')
1320 {
Greg Clayton44d93782014-01-27 23:43:24 +00001321 log_stream_sp = GetOutputFile();
Jim Ingham228063c2012-02-21 02:23:08 +00001322 }
1323 else
1324 {
1325 LogStreamMap::iterator pos = m_log_streams.find(log_file);
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001326 if (pos != m_log_streams.end())
1327 log_stream_sp = pos->second.lock();
1328 if (!log_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001329 {
1330 log_stream_sp.reset (new StreamFile (log_file));
1331 m_log_streams[log_file] = log_stream_sp;
1332 }
Jim Ingham228063c2012-02-21 02:23:08 +00001333 }
1334 assert (log_stream_sp.get());
1335
1336 if (log_options == 0)
1337 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
1338
Greg Clayton57abc5d2013-05-10 21:47:16 +00001339 if (Log::GetLogChannelCallbacks (ConstString(channel), log_callbacks))
Jim Ingham228063c2012-02-21 02:23:08 +00001340 {
1341 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
1342 return true;
1343 }
1344 else
1345 {
1346 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
1347 if (log_channel_sp)
1348 {
1349 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
1350 {
1351 return true;
1352 }
1353 else
1354 {
1355 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
1356 return false;
1357 }
1358 }
1359 else
1360 {
1361 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
1362 return false;
1363 }
1364 }
1365 return false;
1366}
1367
Greg Clayton9585fbf2013-03-19 00:20:55 +00001368SourceManager &
1369Debugger::GetSourceManager ()
1370{
1371 if (m_source_manager_ap.get() == NULL)
1372 m_source_manager_ap.reset (new SourceManager (shared_from_this()));
1373 return *m_source_manager_ap;
1374}
1375
1376
Greg Clayton44d93782014-01-27 23:43:24 +00001377
1378// This function handles events that were broadcast by the process.
1379void
1380Debugger::HandleBreakpointEvent (const EventSP &event_sp)
1381{
1382 using namespace lldb;
1383 const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp);
1384
1385// if (event_type & eBreakpointEventTypeAdded
1386// || event_type & eBreakpointEventTypeRemoved
1387// || event_type & eBreakpointEventTypeEnabled
1388// || event_type & eBreakpointEventTypeDisabled
1389// || event_type & eBreakpointEventTypeCommandChanged
1390// || event_type & eBreakpointEventTypeConditionChanged
1391// || event_type & eBreakpointEventTypeIgnoreChanged
1392// || event_type & eBreakpointEventTypeLocationsResolved)
1393// {
1394// // Don't do anything about these events, since the breakpoint commands already echo these actions.
1395// }
1396//
1397 if (event_type & eBreakpointEventTypeLocationsAdded)
1398 {
1399 uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp);
1400 if (num_new_locations > 0)
1401 {
1402 BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
1403 StreamFileSP output_sp (GetOutputFile());
1404 if (output_sp)
1405 {
1406 output_sp->Printf("%d location%s added to breakpoint %d\n",
1407 num_new_locations,
1408 num_new_locations == 1 ? "" : "s",
1409 breakpoint->GetID());
1410 RefreshTopIOHandler();
1411 }
1412 }
1413 }
1414// else if (event_type & eBreakpointEventTypeLocationsRemoved)
1415// {
1416// // These locations just get disabled, not sure it is worth spamming folks about this on the command line.
1417// }
1418// else if (event_type & eBreakpointEventTypeLocationsResolved)
1419// {
1420// // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy.
1421// }
1422}
1423
1424size_t
1425Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
1426{
1427 size_t total_bytes = 0;
1428 if (stream == NULL)
1429 stream = GetOutputFile().get();
1430
1431 if (stream)
1432 {
1433 // The process has stuff waiting for stdout; get it and write it out to the appropriate place.
1434 if (process == NULL)
1435 {
1436 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1437 if (target_sp)
1438 process = target_sp->GetProcessSP().get();
1439 }
1440 if (process)
1441 {
1442 Error error;
1443 size_t len;
1444 char stdio_buffer[1024];
1445 while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1446 {
1447 stream->Write(stdio_buffer, len);
1448 total_bytes += len;
1449 }
1450 }
1451 stream->Flush();
1452 }
1453 return total_bytes;
1454}
1455
1456size_t
1457Debugger::GetProcessSTDERR (Process *process, Stream *stream)
1458{
1459 size_t total_bytes = 0;
1460 if (stream == NULL)
1461 stream = GetOutputFile().get();
1462
1463 if (stream)
1464 {
1465 // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
1466 if (process == NULL)
1467 {
1468 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1469 if (target_sp)
1470 process = target_sp->GetProcessSP().get();
1471 }
1472 if (process)
1473 {
1474 Error error;
1475 size_t len;
1476 char stdio_buffer[1024];
1477 while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1478 {
1479 stream->Write(stdio_buffer, len);
1480 total_bytes += len;
1481 }
1482 }
1483 stream->Flush();
1484 }
1485 return total_bytes;
1486}
1487
Greg Claytondc6224e2014-10-21 01:00:42 +00001488
Greg Clayton44d93782014-01-27 23:43:24 +00001489// This function handles events that were broadcast by the process.
1490void
1491Debugger::HandleProcessEvent (const EventSP &event_sp)
1492{
1493 using namespace lldb;
1494 const uint32_t event_type = event_sp->GetType();
1495 ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
Greg Claytondc6224e2014-10-21 01:00:42 +00001496
Greg Claytonb4874f12014-02-28 18:22:24 +00001497 StreamString output_stream;
1498 StreamString error_stream;
Greg Clayton44d93782014-01-27 23:43:24 +00001499 const bool gui_enabled = IsForwardingEvents();
Greg Clayton44d93782014-01-27 23:43:24 +00001500
Greg Claytonb4874f12014-02-28 18:22:24 +00001501 if (!gui_enabled)
1502 {
1503 bool pop_process_io_handler = false;
1504 assert (process_sp);
Greg Claytondc6224e2014-10-21 01:00:42 +00001505
Greg Claytonb4874f12014-02-28 18:22:24 +00001506 if (event_type & Process::eBroadcastBitSTDOUT || event_type & Process::eBroadcastBitStateChanged)
Greg Clayton44d93782014-01-27 23:43:24 +00001507 {
Greg Claytonb4874f12014-02-28 18:22:24 +00001508 GetProcessSTDOUT (process_sp.get(), &output_stream);
1509 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001510
Greg Claytonb4874f12014-02-28 18:22:24 +00001511 if (event_type & Process::eBroadcastBitSTDERR || event_type & Process::eBroadcastBitStateChanged)
1512 {
1513 GetProcessSTDERR (process_sp.get(), &error_stream);
1514 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001515
Greg Claytonb4874f12014-02-28 18:22:24 +00001516 if (event_type & Process::eBroadcastBitStateChanged)
1517 {
Greg Claytondc6224e2014-10-21 01:00:42 +00001518 Process::HandleProcessStateChangedEvent (event_sp, &output_stream, pop_process_io_handler);
Greg Clayton44d93782014-01-27 23:43:24 +00001519 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001520
Greg Claytonb4874f12014-02-28 18:22:24 +00001521 if (output_stream.GetSize() || error_stream.GetSize())
1522 {
1523 StreamFileSP error_stream_sp (GetOutputFile());
Greg Clayton6fea17e2014-03-03 19:15:20 +00001524 bool top_io_handler_hid = false;
Greg Claytondc6224e2014-10-21 01:00:42 +00001525
Greg Clayton6fea17e2014-03-03 19:15:20 +00001526 if (process_sp->ProcessIOHandlerIsActive() == false)
1527 top_io_handler_hid = HideTopIOHandler();
Greg Claytonb4874f12014-02-28 18:22:24 +00001528
1529 if (output_stream.GetSize())
1530 {
1531 StreamFileSP output_stream_sp (GetOutputFile());
1532 if (output_stream_sp)
1533 output_stream_sp->Write (output_stream.GetData(), output_stream.GetSize());
1534 }
1535
1536 if (error_stream.GetSize())
1537 {
1538 StreamFileSP error_stream_sp (GetErrorFile());
1539 if (error_stream_sp)
1540 error_stream_sp->Write (error_stream.GetData(), error_stream.GetSize());
1541 }
1542
1543 if (top_io_handler_hid)
1544 RefreshTopIOHandler();
1545 }
1546
1547 if (pop_process_io_handler)
1548 process_sp->PopProcessIOHandler();
1549 }
Greg Clayton44d93782014-01-27 23:43:24 +00001550}
1551
1552void
1553Debugger::HandleThreadEvent (const EventSP &event_sp)
1554{
1555 // At present the only thread event we handle is the Frame Changed event,
1556 // and all we do for that is just reprint the thread status for that thread.
1557 using namespace lldb;
1558 const uint32_t event_type = event_sp->GetType();
1559 if (event_type == Thread::eBroadcastBitStackChanged ||
1560 event_type == Thread::eBroadcastBitThreadSelected )
1561 {
1562 ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get()));
1563 if (thread_sp)
1564 {
1565 HideTopIOHandler();
1566 StreamFileSP stream_sp (GetOutputFile());
1567 thread_sp->GetStatus(*stream_sp, 0, 1, 1);
1568 RefreshTopIOHandler();
1569 }
1570 }
1571}
1572
1573bool
1574Debugger::IsForwardingEvents ()
1575{
1576 return (bool)m_forward_listener_sp;
1577}
1578
1579void
1580Debugger::EnableForwardEvents (const ListenerSP &listener_sp)
1581{
1582 m_forward_listener_sp = listener_sp;
1583}
1584
1585void
1586Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
1587{
1588 m_forward_listener_sp.reset();
1589}
1590
1591
1592void
1593Debugger::DefaultEventHandler()
1594{
1595 Listener& listener(GetListener());
1596 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1597 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1598 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1599 BroadcastEventSpec target_event_spec (broadcaster_class_target,
1600 Target::eBroadcastBitBreakpointChanged);
1601
1602 BroadcastEventSpec process_event_spec (broadcaster_class_process,
1603 Process::eBroadcastBitStateChanged |
1604 Process::eBroadcastBitSTDOUT |
1605 Process::eBroadcastBitSTDERR);
1606
1607 BroadcastEventSpec thread_event_spec (broadcaster_class_thread,
1608 Thread::eBroadcastBitStackChanged |
1609 Thread::eBroadcastBitThreadSelected );
1610
1611 listener.StartListeningForEventSpec (*this, target_event_spec);
1612 listener.StartListeningForEventSpec (*this, process_event_spec);
1613 listener.StartListeningForEventSpec (*this, thread_event_spec);
1614 listener.StartListeningForEvents (m_command_interpreter_ap.get(),
1615 CommandInterpreter::eBroadcastBitQuitCommandReceived |
1616 CommandInterpreter::eBroadcastBitAsynchronousOutputData |
1617 CommandInterpreter::eBroadcastBitAsynchronousErrorData );
Greg Claytonafa91e332014-12-01 22:41:27 +00001618
1619 // Let the thread that spawned us know that we have started up and
1620 // that we are now listening to all required events so no events get missed
1621 m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
1622
Greg Clayton44d93782014-01-27 23:43:24 +00001623 bool done = false;
1624 while (!done)
1625 {
Greg Clayton44d93782014-01-27 23:43:24 +00001626 EventSP event_sp;
1627 if (listener.WaitForEvent(NULL, event_sp))
1628 {
1629 if (event_sp)
1630 {
1631 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1632 if (broadcaster)
1633 {
1634 uint32_t event_type = event_sp->GetType();
1635 ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
1636 if (broadcaster_class == broadcaster_class_process)
1637 {
1638 HandleProcessEvent (event_sp);
1639 }
1640 else if (broadcaster_class == broadcaster_class_target)
1641 {
1642 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get()))
1643 {
1644 HandleBreakpointEvent (event_sp);
1645 }
1646 }
1647 else if (broadcaster_class == broadcaster_class_thread)
1648 {
1649 HandleThreadEvent (event_sp);
1650 }
1651 else if (broadcaster == m_command_interpreter_ap.get())
1652 {
1653 if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived)
1654 {
1655 done = true;
1656 }
1657 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData)
1658 {
1659 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1660 if (data && data[0])
1661 {
1662 StreamFileSP error_sp (GetErrorFile());
1663 if (error_sp)
1664 {
1665 HideTopIOHandler();
1666 error_sp->PutCString(data);
1667 error_sp->Flush();
1668 RefreshTopIOHandler();
1669 }
1670 }
1671 }
1672 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData)
1673 {
1674 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1675 if (data && data[0])
1676 {
1677 StreamFileSP output_sp (GetOutputFile());
1678 if (output_sp)
1679 {
1680 HideTopIOHandler();
1681 output_sp->PutCString(data);
1682 output_sp->Flush();
1683 RefreshTopIOHandler();
1684 }
1685 }
1686 }
1687 }
1688 }
1689
1690 if (m_forward_listener_sp)
1691 m_forward_listener_sp->AddEvent(event_sp);
1692 }
1693 }
1694 }
1695}
1696
1697lldb::thread_result_t
1698Debugger::EventHandlerThread (lldb::thread_arg_t arg)
1699{
1700 ((Debugger *)arg)->DefaultEventHandler();
1701 return NULL;
1702}
1703
1704bool
1705Debugger::StartEventHandlerThread()
1706{
Zachary Turneracee96a2014-09-23 18:32:09 +00001707 if (!m_event_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001708 {
Greg Claytonafa91e332014-12-01 22:41:27 +00001709 // We must synchronize with the DefaultEventHandler() thread to ensure
1710 // it is up and running and listening to events before we return from
1711 // this function. We do this by listening to events for the
1712 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1713 Listener listener("lldb.debugger.event-handler");
1714 listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
1715
Zachary Turner7c2896a2014-10-24 22:06:29 +00001716 // Use larger 8MB stack for this thread
Greg Claytonafa91e332014-12-01 22:41:27 +00001717 m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread,
1718 this,
1719 NULL,
Zachary Turner7c2896a2014-10-24 22:06:29 +00001720 g_debugger_event_thread_stack_bytes);
Greg Claytonafa91e332014-12-01 22:41:27 +00001721
1722 // Make sure DefaultEventHandler() is running and listening to events before we return
1723 // from this function. We are only listening for events of type
1724 // eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
1725 // to wait an infinite amount of time for it (NULL timeout as the first parameter)
1726 lldb::EventSP event_sp;
1727 listener.WaitForEvent(NULL, event_sp);
Greg Clayton807b6b32014-10-15 18:03:59 +00001728 }
Zachary Turneracee96a2014-09-23 18:32:09 +00001729 return m_event_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001730}
1731
1732void
1733Debugger::StopEventHandlerThread()
1734{
Zachary Turneracee96a2014-09-23 18:32:09 +00001735 if (m_event_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001736 {
1737 GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
Zachary Turner39de3112014-09-09 20:54:56 +00001738 m_event_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001739 }
1740}
1741
1742
1743lldb::thread_result_t
1744Debugger::IOHandlerThread (lldb::thread_arg_t arg)
1745{
1746 Debugger *debugger = (Debugger *)arg;
Siva Chandra9aaab552015-02-26 19:26:36 +00001747 debugger->ExecuteIOHandlers();
Greg Clayton44d93782014-01-27 23:43:24 +00001748 debugger->StopEventHandlerThread();
1749 return NULL;
1750}
1751
1752bool
1753Debugger::StartIOHandlerThread()
1754{
Zachary Turneracee96a2014-09-23 18:32:09 +00001755 if (!m_io_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001756 m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
1757 IOHandlerThread,
1758 this,
1759 NULL,
1760 8*1024*1024); // Use larger 8MB stack for this thread
Zachary Turneracee96a2014-09-23 18:32:09 +00001761 return m_io_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001762}
1763
1764void
1765Debugger::StopIOHandlerThread()
1766{
Zachary Turneracee96a2014-09-23 18:32:09 +00001767 if (m_io_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001768 {
1769 if (m_input_file_sp)
1770 m_input_file_sp->GetFile().Close();
Zachary Turner39de3112014-09-09 20:54:56 +00001771 m_io_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001772 }
1773}
1774
Jim Ingham893c9322014-11-22 01:42:44 +00001775Target *
1776Debugger::GetDummyTarget()
1777{
1778 return m_target_list.GetDummyTarget (*this).get();
1779}
1780
1781Target *
Jim Ingham33df7cd2014-12-06 01:28:03 +00001782Debugger::GetSelectedOrDummyTarget(bool prefer_dummy)
Jim Ingham893c9322014-11-22 01:42:44 +00001783{
Jim Ingham33df7cd2014-12-06 01:28:03 +00001784 Target *target = nullptr;
1785 if (!prefer_dummy)
1786 {
1787 target = m_target_list.GetSelectedTarget().get();
1788 if (target)
1789 return target;
1790 }
1791
Jim Ingham893c9322014-11-22 01:42:44 +00001792 return GetDummyTarget();
1793}
Greg Clayton44d93782014-01-27 23:43:24 +00001794