blob: cd41e5d65103633de271525fb79c5cda275521b9 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Greg Clayton4a33d312011-06-23 17:59:56 +000010#include "lldb/Core/Debugger.h"
11
12#include <map>
13
Enrico Granata4becb372011-06-29 22:27:15 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Type.h"
Jason Molenda705b1802014-06-13 02:37:02 +000016#include "llvm/ADT/StringRef.h"
Enrico Granata4becb372011-06-29 22:27:15 +000017
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/lldb-private.h"
Greg Clayton554f68d2015-02-04 22:00:53 +000019#include "lldb/Core/FormatEntity.h"
Greg Clayton1f746072012-08-29 21:13:06 +000020#include "lldb/Core/Module.h"
Greg Claytone8cd0c92012-10-19 18:02:49 +000021#include "lldb/Core/PluginManager.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000022#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000024#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000025#include "lldb/Core/StreamCallback.h"
Greg Clayton44d93782014-01-27 23:43:24 +000026#include "lldb/Core/StreamFile.h"
Greg Clayton1b654882010-09-19 02:33:57 +000027#include "lldb/Core/StreamString.h"
Jason Molenda705b1802014-06-13 02:37:02 +000028#include "lldb/Core/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000030#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000031#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000032#include "lldb/DataFormatters/DataVisualization.h"
33#include "lldb/DataFormatters/FormatManager.h"
Enrico Granata894f7352014-03-25 22:03:52 +000034#include "lldb/DataFormatters/TypeSummary.h"
Zachary Turner93a66fc2014-10-06 21:22:36 +000035#include "lldb/Host/ConnectionFileDescriptor.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000036#include "lldb/Host/HostInfo.h"
Greg Claytona3406612011-02-07 23:24:47 +000037#include "lldb/Host/Terminal.h"
Zachary Turner39de3112014-09-09 20:54:56 +000038#include "lldb/Host/ThreadLauncher.h"
Greg Clayton66111032010-06-23 01:19:29 +000039#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turner633a29c2015-03-04 01:58:01 +000040#include "lldb/Interpreter/OptionValueProperties.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000041#include "lldb/Interpreter/OptionValueSInt64.h"
42#include "lldb/Interpreter/OptionValueString.h"
Greg Clayton1f746072012-08-29 21:13:06 +000043#include "lldb/Symbol/ClangASTContext.h"
44#include "lldb/Symbol/CompileUnit.h"
45#include "lldb/Symbol/Function.h"
46#include "lldb/Symbol/Symbol.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000047#include "lldb/Symbol/VariableList.h"
Jason Molendaaff1b352014-10-10 23:07:36 +000048#include "lldb/Target/CPPLanguageRuntime.h"
49#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/TargetList.h"
51#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000052#include "lldb/Target/RegisterContext.h"
Greg Clayton5fb8f792013-12-02 19:35:49 +000053#include "lldb/Target/SectionLoadList.h"
Greg Clayton1b654882010-09-19 02:33:57 +000054#include "lldb/Target/StopInfo.h"
Enrico Granata84a53df2013-05-20 22:29:23 +000055#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000057#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Zachary Turner58a559c2014-08-27 20:15:09 +000059#include "llvm/Support/DynamicLibrary.h"
60
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061using namespace lldb;
62using namespace lldb_private;
63
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
Caroline Ticeebc1bb22010-06-30 16:22:25 +000065static lldb::user_id_t g_unique_id = 1;
Zachary Turner7c2896a2014-10-24 22:06:29 +000066static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000067
Greg Clayton1b654882010-09-19 02:33:57 +000068#pragma mark Static Functions
69
70static Mutex &
71GetDebuggerListMutex ()
72{
73 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
74 return g_mutex;
75}
76
77typedef std::vector<DebuggerSP> DebuggerList;
78
79static DebuggerList &
80GetDebuggerList()
81{
82 // hide the static debugger list inside a singleton accessor to avoid
Bruce Mitchener6a7f3332014-06-27 02:42:12 +000083 // global init constructors
Greg Clayton1b654882010-09-19 02:33:57 +000084 static DebuggerList g_list;
85 return g_list;
86}
Greg Claytone372b982011-11-21 21:44:34 +000087
88OptionEnumValueElement
Greg Clayton67cc0632012-08-22 17:17:09 +000089g_show_disassembly_enum_values[] =
Greg Claytone372b982011-11-21 21:44:34 +000090{
Greg Clayton67cc0632012-08-22 17:17:09 +000091 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
92 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
93 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
Greg Claytone372b982011-11-21 21:44:34 +000094 { 0, NULL, NULL }
95};
96
Greg Clayton67cc0632012-08-22 17:17:09 +000097OptionEnumValueElement
98g_language_enumerators[] =
99{
100 { eScriptLanguageNone, "none", "Disable scripting languages."},
101 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
102 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
Greg Claytona12993c2012-09-13 23:03:20 +0000103 { 0, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000104};
Greg Claytone372b982011-11-21 21:44:34 +0000105
Greg Clayton67cc0632012-08-22 17:17:09 +0000106#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
107#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
108
Michael Sartain0769b2b2013-07-30 16:44:36 +0000109#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000110 "{, ${frame.pc}}"\
111 MODULE_WITH_FUNC\
112 FILE_AND_LINE\
Michael Sartain0769b2b2013-07-30 16:44:36 +0000113 "{, name = '${thread.name}'}"\
114 "{, queue = '${thread.queue}'}"\
Jason Molenda705b1802014-06-13 02:37:02 +0000115 "{, activity = '${thread.info.activity.name}'}" \
116 "{, ${thread.info.trace_messages} messages}" \
Greg Clayton67cc0632012-08-22 17:17:09 +0000117 "{, stop reason = ${thread.stop-reason}}"\
118 "{\\nReturn value: ${thread.return-value}}"\
Jim Ingham30fadaf2014-07-08 01:07:32 +0000119 "{\\nCompleted expression: ${thread.completed-expression}}"\
Greg Clayton67cc0632012-08-22 17:17:09 +0000120 "\\n"
121
122#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
123 MODULE_WITH_FUNC\
124 FILE_AND_LINE\
125 "\\n"
126
Jason Molendac980fa92015-02-13 23:24:21 +0000127// Three parts to this disassembly format specification:
128// 1. If this is a new function/symbol (no previous symbol/function), print
129// dylib`funcname:\n
130// 2. If this is a symbol context change (different from previous symbol/function), print
131// dylib`funcname:\n
132// 3. print
133// address <+offset>:
134#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}>}: "
135
136// gdb's disassembly format can be emulated with
137// ${current-pc-arrow}${addr-file-or-load}{ <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>}:
138
139// lldb's original format for disassembly would look like this format string -
140// {${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}}:
141
Greg Clayton67cc0632012-08-22 17:17:09 +0000142
Greg Clayton754a9362012-08-23 00:22:02 +0000143static PropertyDefinition
144g_properties[] =
Greg Clayton67cc0632012-08-22 17:17:09 +0000145{
Greg Clayton554f68d2015-02-04 22:00:53 +0000146{ "auto-confirm", OptionValue::eTypeBoolean , true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
147{ "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, NULL, "The default disassembly format string to use when disassembling instruction sequences." },
148{ "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
149{ "notify-void", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
150{ "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
151{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
152{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
153{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
154{ "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." },
155{ "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." },
156{ "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
157{ "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
158{ "use-external-editor", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Whether to use an external editor or not." },
159{ "use-color", OptionValue::eTypeBoolean , true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
160{ "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
161{ "escape-non-printables", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
162{ NULL, OptionValue::eTypeInvalid , true, 0 , NULL, NULL, NULL }
Greg Clayton67cc0632012-08-22 17:17:09 +0000163};
164
165enum
166{
167 ePropertyAutoConfirm = 0,
Jason Molendaaff1b352014-10-10 23:07:36 +0000168 ePropertyDisassemblyFormat,
Greg Clayton67cc0632012-08-22 17:17:09 +0000169 ePropertyFrameFormat,
170 ePropertyNotiftVoid,
171 ePropertyPrompt,
172 ePropertyScriptLanguage,
173 ePropertyStopDisassemblyCount,
174 ePropertyStopDisassemblyDisplay,
175 ePropertyStopLineCountAfter,
176 ePropertyStopLineCountBefore,
177 ePropertyTerminalWidth,
178 ePropertyThreadFormat,
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000179 ePropertyUseExternalEditor,
180 ePropertyUseColor,
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000181 ePropertyAutoOneLineSummaries,
182 ePropertyEscapeNonPrintables
Greg Clayton67cc0632012-08-22 17:17:09 +0000183};
184
Zachary Turner3a006912015-03-19 22:00:21 +0000185LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
Greg Clayton4c054102012-09-01 00:38:36 +0000186
187Error
188Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
189 VarSetOperationType op,
190 const char *property_path,
191 const char *value)
192{
Enrico Granata84a53df2013-05-20 22:29:23 +0000193 bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000194 bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0;
Enrico Granata84a53df2013-05-20 22:29:23 +0000195 TargetSP target_sp;
Enrico Granata397ddd52013-05-21 20:13:34 +0000196 LoadScriptFromSymFile load_script_old_value;
Enrico Granata84a53df2013-05-20 22:29:23 +0000197 if (is_load_script && exe_ctx->GetTargetSP())
198 {
199 target_sp = exe_ctx->GetTargetSP();
200 load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
201 }
Greg Clayton4c054102012-09-01 00:38:36 +0000202 Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value));
203 if (error.Success())
204 {
Enrico Granata84a53df2013-05-20 22:29:23 +0000205 // FIXME it would be nice to have "on-change" callbacks for properties
Greg Clayton4c054102012-09-01 00:38:36 +0000206 if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0)
207 {
208 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000209 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
210 if (str.length())
211 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000212 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton4c054102012-09-01 00:38:36 +0000213 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
214 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
215 }
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000216 else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0)
217 {
218 // use-color changed. Ping the prompt so it can reset the ansi terminal codes.
219 SetPrompt (GetPrompt());
220 }
Enrico Granata397ddd52013-05-21 20:13:34 +0000221 else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn)
Enrico Granata84a53df2013-05-20 22:29:23 +0000222 {
Enrico Granata397ddd52013-05-21 20:13:34 +0000223 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue)
Enrico Granata84a53df2013-05-20 22:29:23 +0000224 {
225 std::list<Error> errors;
Enrico Granata97303392013-05-21 00:00:30 +0000226 StreamString feedback_stream;
227 if (!target_sp->LoadScriptingResources(errors,&feedback_stream))
Enrico Granata84a53df2013-05-20 22:29:23 +0000228 {
Greg Clayton44d93782014-01-27 23:43:24 +0000229 StreamFileSP stream_sp (GetErrorFile());
230 if (stream_sp)
Enrico Granata84a53df2013-05-20 22:29:23 +0000231 {
Greg Clayton44d93782014-01-27 23:43:24 +0000232 for (auto error : errors)
233 {
234 stream_sp->Printf("%s\n",error.AsCString());
235 }
236 if (feedback_stream.GetSize())
237 stream_sp->Printf("%s",feedback_stream.GetData());
Enrico Granata84a53df2013-05-20 22:29:23 +0000238 }
239 }
240 }
241 }
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000242 else if (is_escape_non_printables)
243 {
244 DataVisualization::ForceUpdate();
245 }
Greg Clayton4c054102012-09-01 00:38:36 +0000246 }
247 return error;
248}
249
Greg Clayton67cc0632012-08-22 17:17:09 +0000250bool
251Debugger::GetAutoConfirm () const
252{
253 const uint32_t idx = ePropertyAutoConfirm;
Greg Clayton754a9362012-08-23 00:22:02 +0000254 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000255}
256
Greg Clayton554f68d2015-02-04 22:00:53 +0000257const FormatEntity::Entry *
Jason Molendaaff1b352014-10-10 23:07:36 +0000258Debugger::GetDisassemblyFormat() const
259{
260 const uint32_t idx = ePropertyDisassemblyFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000261 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Jason Molendaaff1b352014-10-10 23:07:36 +0000262}
263
Greg Clayton554f68d2015-02-04 22:00:53 +0000264const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000265Debugger::GetFrameFormat() const
266{
267 const uint32_t idx = ePropertyFrameFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000268 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000269}
270
271bool
272Debugger::GetNotifyVoid () const
273{
274 const uint32_t idx = ePropertyNotiftVoid;
Greg Clayton754a9362012-08-23 00:22:02 +0000275 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000276}
277
278const char *
279Debugger::GetPrompt() const
280{
281 const uint32_t idx = ePropertyPrompt;
Greg Clayton754a9362012-08-23 00:22:02 +0000282 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000283}
284
285void
286Debugger::SetPrompt(const char *p)
287{
288 const uint32_t idx = ePropertyPrompt;
289 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
290 const char *new_prompt = GetPrompt();
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000291 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
292 if (str.length())
293 new_prompt = str.c_str();
Greg Clayton44d93782014-01-27 23:43:24 +0000294 GetCommandInterpreter().UpdatePrompt(new_prompt);
Greg Clayton67cc0632012-08-22 17:17:09 +0000295}
296
Greg Clayton554f68d2015-02-04 22:00:53 +0000297const FormatEntity::Entry *
Greg Clayton67cc0632012-08-22 17:17:09 +0000298Debugger::GetThreadFormat() const
299{
300 const uint32_t idx = ePropertyThreadFormat;
Greg Clayton554f68d2015-02-04 22:00:53 +0000301 return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000302}
303
304lldb::ScriptLanguage
305Debugger::GetScriptLanguage() const
306{
307 const uint32_t idx = ePropertyScriptLanguage;
Greg Clayton754a9362012-08-23 00:22:02 +0000308 return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000309}
310
311bool
312Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
313{
314 const uint32_t idx = ePropertyScriptLanguage;
315 return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
316}
317
318uint32_t
319Debugger::GetTerminalWidth () const
320{
321 const uint32_t idx = ePropertyTerminalWidth;
Greg Clayton754a9362012-08-23 00:22:02 +0000322 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000323}
324
325bool
326Debugger::SetTerminalWidth (uint32_t term_width)
327{
328 const uint32_t idx = ePropertyTerminalWidth;
329 return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
330}
331
332bool
333Debugger::GetUseExternalEditor () const
334{
335 const uint32_t idx = ePropertyUseExternalEditor;
Greg Clayton754a9362012-08-23 00:22:02 +0000336 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
Greg Clayton67cc0632012-08-22 17:17:09 +0000337}
338
339bool
340Debugger::SetUseExternalEditor (bool b)
341{
342 const uint32_t idx = ePropertyUseExternalEditor;
343 return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
344}
345
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000346bool
347Debugger::GetUseColor () const
348{
349 const uint32_t idx = ePropertyUseColor;
350 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
351}
352
353bool
354Debugger::SetUseColor (bool b)
355{
356 const uint32_t idx = ePropertyUseColor;
357 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
358 SetPrompt (GetPrompt());
359 return ret;
360}
361
Greg Clayton67cc0632012-08-22 17:17:09 +0000362uint32_t
363Debugger::GetStopSourceLineCount (bool before) const
364{
365 const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
Greg Clayton754a9362012-08-23 00:22:02 +0000366 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000367}
368
369Debugger::StopDisassemblyType
370Debugger::GetStopDisassemblyDisplay () const
371{
372 const uint32_t idx = ePropertyStopDisassemblyDisplay;
Greg Clayton754a9362012-08-23 00:22:02 +0000373 return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000374}
375
376uint32_t
377Debugger::GetDisassemblyLineCount () const
378{
379 const uint32_t idx = ePropertyStopDisassemblyCount;
Greg Clayton754a9362012-08-23 00:22:02 +0000380 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
Greg Clayton67cc0632012-08-22 17:17:09 +0000381}
Greg Claytone372b982011-11-21 21:44:34 +0000382
Enrico Granata553fad52013-10-25 23:09:40 +0000383bool
Enrico Granata90a8db32013-10-31 21:01:07 +0000384Debugger::GetAutoOneLineSummaries () const
Enrico Granata553fad52013-10-25 23:09:40 +0000385{
Enrico Granata90a8db32013-10-31 21:01:07 +0000386 const uint32_t idx = ePropertyAutoOneLineSummaries;
Enrico Granata553fad52013-10-25 23:09:40 +0000387 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000388}
Enrico Granata553fad52013-10-25 23:09:40 +0000389
Enrico Granataebdc1ac2014-11-05 21:20:48 +0000390bool
391Debugger::GetEscapeNonPrintables () const
392{
393 const uint32_t idx = ePropertyEscapeNonPrintables;
394 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
Enrico Granata553fad52013-10-25 23:09:40 +0000395}
396
Greg Clayton1b654882010-09-19 02:33:57 +0000397#pragma mark Debugger
398
Greg Clayton67cc0632012-08-22 17:17:09 +0000399//const DebuggerPropertiesSP &
400//Debugger::GetSettings() const
401//{
402// return m_properties_sp;
403//}
404//
Greg Clayton99d0faf2010-11-18 23:32:35 +0000405
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000406static bool lldb_initialized = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407void
Zachary Turner3a006912015-03-19 22:00:21 +0000408Debugger::Initialize(LoadPluginCallbackType load_plugin_callback)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000410 assert(!lldb_initialized && "Debugger::Initialize called more than once!");
411
Robert Flackf196c932015-03-10 18:07:47 +0000412 lldb_initialized = true;
Greg Clayton5fb8f792013-12-02 19:35:49 +0000413 g_load_plugin_callback = load_plugin_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414}
415
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000416void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417Debugger::Terminate ()
418{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000419 assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!");
420
421 // Clear our master list of debugger objects
422 Mutex::Locker locker (GetDebuggerListMutex ());
423 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424}
425
Caroline Tice20bd37f2011-03-10 22:14:10 +0000426void
427Debugger::SettingsInitialize ()
428{
Greg Clayton6920b522012-08-22 18:39:03 +0000429 Target::SettingsInitialize ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000430}
431
432void
433Debugger::SettingsTerminate ()
434{
Greg Clayton6920b522012-08-22 18:39:03 +0000435 Target::SettingsTerminate ();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000436}
437
Enrico Granata21dfcd92012-09-28 23:57:51 +0000438bool
Enrico Granatae743c782013-04-24 21:29:08 +0000439Debugger::LoadPlugin (const FileSpec& spec, Error& error)
Enrico Granata21dfcd92012-09-28 23:57:51 +0000440{
Greg Clayton5fb8f792013-12-02 19:35:49 +0000441 if (g_load_plugin_callback)
Enrico Granatae743c782013-04-24 21:29:08 +0000442 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000443 llvm::sys::DynamicLibrary dynlib = g_load_plugin_callback (shared_from_this(), spec, error);
444 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +0000445 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000446 m_loaded_plugins.push_back(dynlib);
Greg Clayton5fb8f792013-12-02 19:35:49 +0000447 return true;
448 }
Enrico Granatae743c782013-04-24 21:29:08 +0000449 }
Greg Clayton5fb8f792013-12-02 19:35:49 +0000450 else
Enrico Granatae743c782013-04-24 21:29:08 +0000451 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000452 // The g_load_plugin_callback is registered in SBDebugger::Initialize()
453 // and if the public API layer isn't available (code is linking against
454 // all of the internal LLDB static libraries), then we can't load plugins
455 error.SetErrorString("Public API layer is not available");
Enrico Granatae743c782013-04-24 21:29:08 +0000456 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000457 return false;
458}
459
460static FileSpec::EnumerateDirectoryResult
461LoadPluginCallback
462(
463 void *baton,
464 FileSpec::FileType file_type,
465 const FileSpec &file_spec
466 )
467{
468 Error error;
469
470 static ConstString g_dylibext("dylib");
Michael Sartain3cf443d2013-07-17 00:26:30 +0000471 static ConstString g_solibext("so");
Enrico Granata21dfcd92012-09-28 23:57:51 +0000472
473 if (!baton)
474 return FileSpec::eEnumerateDirectoryResultQuit;
475
476 Debugger *debugger = (Debugger*)baton;
477
478 // If we have a regular file, a symbolic link or unknown file type, try
479 // and process the file. We must handle unknown as sometimes the directory
480 // enumeration might be enumerating a file system that doesn't have correct
481 // file type information.
482 if (file_type == FileSpec::eFileTypeRegular ||
483 file_type == FileSpec::eFileTypeSymbolicLink ||
484 file_type == FileSpec::eFileTypeUnknown )
485 {
486 FileSpec plugin_file_spec (file_spec);
487 plugin_file_spec.ResolvePath ();
488
Michael Sartain3cf443d2013-07-17 00:26:30 +0000489 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
490 plugin_file_spec.GetFileNameExtension() != g_solibext)
491 {
Enrico Granata21dfcd92012-09-28 23:57:51 +0000492 return FileSpec::eEnumerateDirectoryResultNext;
Michael Sartain3cf443d2013-07-17 00:26:30 +0000493 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000494
Enrico Granatae743c782013-04-24 21:29:08 +0000495 Error plugin_load_error;
496 debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000497
498 return FileSpec::eEnumerateDirectoryResultNext;
499 }
500
501 else if (file_type == FileSpec::eFileTypeUnknown ||
502 file_type == FileSpec::eFileTypeDirectory ||
503 file_type == FileSpec::eFileTypeSymbolicLink )
504 {
505 // Try and recurse into anything that a directory or symbolic link.
506 // We must also do this for unknown as sometimes the directory enumeration
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000507 // might be enumerating a file system that doesn't have correct file type
Enrico Granata21dfcd92012-09-28 23:57:51 +0000508 // information.
509 return FileSpec::eEnumerateDirectoryResultEnter;
510 }
511
512 return FileSpec::eEnumerateDirectoryResultNext;
513}
514
515void
516Debugger::InstanceInitialize ()
517{
518 FileSpec dir_spec;
519 const bool find_directories = true;
520 const bool find_files = true;
521 const bool find_other = true;
522 char dir_path[PATH_MAX];
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000523 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000524 {
525 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
526 {
527 FileSpec::EnumerateDirectory (dir_path,
528 find_directories,
529 find_files,
530 find_other,
531 LoadPluginCallback,
532 this);
533 }
534 }
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000535
536 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec))
Enrico Granata21dfcd92012-09-28 23:57:51 +0000537 {
538 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
539 {
540 FileSpec::EnumerateDirectory (dir_path,
541 find_directories,
542 find_files,
543 find_other,
544 LoadPluginCallback,
545 this);
546 }
547 }
Greg Claytone8cd0c92012-10-19 18:02:49 +0000548
549 PluginManager::DebuggerInitialize (*this);
Enrico Granata21dfcd92012-09-28 23:57:51 +0000550}
551
Greg Clayton66111032010-06-23 01:19:29 +0000552DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000553Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000554{
Jim Ingham228063c2012-02-21 02:23:08 +0000555 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000556 if (lldb_initialized)
Greg Clayton66111032010-06-23 01:19:29 +0000557 {
558 Mutex::Locker locker (GetDebuggerListMutex ());
559 GetDebuggerList().push_back(debugger_sp);
560 }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000561 debugger_sp->InstanceInitialize ();
Greg Clayton66111032010-06-23 01:19:29 +0000562 return debugger_sp;
563}
564
Caroline Ticee02657b2011-01-22 01:02:07 +0000565void
Greg Clayton4d122c42011-09-17 08:33:22 +0000566Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000567{
568 if (debugger_sp.get() == NULL)
569 return;
570
Jim Ingham8314c522011-09-15 21:36:42 +0000571 debugger_sp->Clear();
572
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000573 if (lldb_initialized)
Caroline Ticee02657b2011-01-22 01:02:07 +0000574 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000575 Mutex::Locker locker (GetDebuggerListMutex ());
576 DebuggerList &debugger_list = GetDebuggerList ();
577 DebuggerList::iterator pos, end = debugger_list.end();
578 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000579 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000580 if ((*pos).get() == debugger_sp.get())
581 {
582 debugger_list.erase (pos);
583 return;
584 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000585 }
586 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000587}
588
Greg Clayton4d122c42011-09-17 08:33:22 +0000589DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000590Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
591{
Greg Clayton4d122c42011-09-17 08:33:22 +0000592 DebuggerSP debugger_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000593 if (lldb_initialized)
Greg Clayton6920b522012-08-22 18:39:03 +0000594 {
595 Mutex::Locker locker (GetDebuggerListMutex ());
596 DebuggerList &debugger_list = GetDebuggerList();
597 DebuggerList::iterator pos, end = debugger_list.end();
598
599 for (pos = debugger_list.begin(); pos != end; ++pos)
600 {
601 if ((*pos).get()->m_instance_name == instance_name)
602 {
603 debugger_sp = *pos;
604 break;
605 }
606 }
607 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000608 return debugger_sp;
609}
Greg Clayton66111032010-06-23 01:19:29 +0000610
611TargetSP
612Debugger::FindTargetWithProcessID (lldb::pid_t pid)
613{
Greg Clayton4d122c42011-09-17 08:33:22 +0000614 TargetSP target_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000615 if (lldb_initialized)
Greg Clayton66111032010-06-23 01:19:29 +0000616 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000617 Mutex::Locker locker (GetDebuggerListMutex ());
618 DebuggerList &debugger_list = GetDebuggerList();
619 DebuggerList::iterator pos, end = debugger_list.end();
620 for (pos = debugger_list.begin(); pos != end; ++pos)
621 {
622 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
623 if (target_sp)
624 break;
625 }
Greg Clayton66111032010-06-23 01:19:29 +0000626 }
627 return target_sp;
628}
629
Greg Claytone4e45922011-11-16 05:37:56 +0000630TargetSP
631Debugger::FindTargetWithProcess (Process *process)
632{
633 TargetSP target_sp;
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000634 if (lldb_initialized)
Greg Claytone4e45922011-11-16 05:37:56 +0000635 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000636 Mutex::Locker locker (GetDebuggerListMutex ());
637 DebuggerList &debugger_list = GetDebuggerList();
638 DebuggerList::iterator pos, end = debugger_list.end();
639 for (pos = debugger_list.begin(); pos != end; ++pos)
640 {
641 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
642 if (target_sp)
643 break;
644 }
Greg Claytone4e45922011-11-16 05:37:56 +0000645 }
646 return target_sp;
647}
648
Jason Molendae6481c72014-09-12 01:50:46 +0000649Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
650 UserID(g_unique_id++),
651 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
652 m_input_file_sp(new StreamFile(stdin, false)),
653 m_output_file_sp(new StreamFile(stdout, false)),
654 m_error_file_sp(new StreamFile(stderr, false)),
655 m_terminal_state(),
656 m_target_list(*this),
657 m_platform_list(),
658 m_listener("lldb.Debugger"),
659 m_source_manager_ap(),
660 m_source_file_cache(),
661 m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)),
662 m_input_reader_stack(),
663 m_instance_name(),
Greg Claytonafa91e332014-12-01 22:41:27 +0000664 m_loaded_plugins(),
665 m_event_handler_thread (),
666 m_io_handler_thread (),
667 m_sync_broadcaster (NULL, "lldb.debugger.sync")
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668{
Greg Clayton67cc0632012-08-22 17:17:09 +0000669 char instance_cstr[256];
670 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
671 m_instance_name.SetCString(instance_cstr);
Jim Ingham228063c2012-02-21 02:23:08 +0000672 if (log_callback)
673 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000674 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000675 // Always add our default platform to the platform list
Greg Clayton615eb7e2014-09-19 20:11:50 +0000676 PlatformSP default_platform_sp (Platform::GetHostPlatform());
Greg Claytonded470d2011-03-19 01:12:21 +0000677 assert (default_platform_sp.get());
678 m_platform_list.Append (default_platform_sp, true);
Greg Clayton67cc0632012-08-22 17:17:09 +0000679
Greg Clayton754a9362012-08-23 00:22:02 +0000680 m_collection_sp->Initialize (g_properties);
Greg Clayton67cc0632012-08-22 17:17:09 +0000681 m_collection_sp->AppendProperty (ConstString("target"),
682 ConstString("Settings specify to debugging targets."),
683 true,
684 Target::GetGlobalProperties()->GetValueProperties());
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000685 m_collection_sp->AppendProperty (ConstString("platform"),
686 ConstString("Platform settings."),
687 true,
688 Platform::GetGlobalPlatformProperties()->GetValueProperties());
Greg Clayton754a9362012-08-23 00:22:02 +0000689 if (m_command_interpreter_ap.get())
690 {
691 m_collection_sp->AppendProperty (ConstString("interpreter"),
692 ConstString("Settings specify to the debugger's command interpreter."),
693 true,
694 m_command_interpreter_ap->GetValueProperties());
695 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000696 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
697 term_width->SetMinimumValue(10);
698 term_width->SetMaximumValue(1024);
Michael Sartainc3ce7f272013-05-23 20:47:45 +0000699
700 // Turn off use-color if this is a dumb terminal.
701 const char *term = getenv ("TERM");
702 if (term && !strcmp (term, "dumb"))
703 SetUseColor (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704}
705
706Debugger::~Debugger ()
707{
Jim Ingham8314c522011-09-15 21:36:42 +0000708 Clear();
709}
710
711void
712Debugger::Clear()
713{
Greg Clayton44d93782014-01-27 23:43:24 +0000714 ClearIOHandlers();
715 StopIOHandlerThread();
716 StopEventHandlerThread();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000717 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000718 int num_targets = m_target_list.GetNumTargets();
719 for (int i = 0; i < num_targets; i++)
720 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000721 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
722 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000723 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000724 ProcessSP process_sp (target_sp->GetProcessSP());
725 if (process_sp)
Jim Ingham1fd07052013-02-27 19:13:05 +0000726 process_sp->Finalize();
Greg Claytonccbc08e2012-01-14 17:04:19 +0000727 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000728 }
Greg Clayton66111032010-06-23 01:19:29 +0000729 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000730 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000731
732 // Close the input file _before_ we close the input read communications class
733 // as it does NOT own the input file, our m_input_file does.
Jim Inghamc5917d92012-11-30 20:23:19 +0000734 m_terminal_state.Clear();
Greg Clayton44d93782014-01-27 23:43:24 +0000735 if (m_input_file_sp)
736 m_input_file_sp->GetFile().Close ();
Greg Clayton0c4129f2014-04-25 00:35:14 +0000737
738 m_command_interpreter_ap->Clear();
Jim Ingham8314c522011-09-15 21:36:42 +0000739}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000740
741bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000742Debugger::GetCloseInputOnEOF () const
743{
Greg Clayton44d93782014-01-27 23:43:24 +0000744// return m_input_comm.GetCloseOnEOF();
745 return false;
Greg Claytonfc3f0272011-05-29 04:06:55 +0000746}
747
748void
749Debugger::SetCloseInputOnEOF (bool b)
750{
Greg Clayton44d93782014-01-27 23:43:24 +0000751// m_input_comm.SetCloseOnEOF(b);
Greg Claytonfc3f0272011-05-29 04:06:55 +0000752}
753
754bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755Debugger::GetAsyncExecution ()
756{
Greg Clayton66111032010-06-23 01:19:29 +0000757 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000758}
759
760void
761Debugger::SetAsyncExecution (bool async_execution)
762{
Greg Clayton66111032010-06-23 01:19:29 +0000763 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764}
765
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766
767void
768Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
769{
Greg Clayton44d93782014-01-27 23:43:24 +0000770 if (m_input_file_sp)
771 m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership);
772 else
773 m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
774
775 File &in_file = m_input_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000776 if (in_file.IsValid() == false)
777 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778
Jim Inghamc5917d92012-11-30 20:23:19 +0000779 // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
780 SaveInputTerminalState ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781}
782
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783void
784Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
785{
Greg Clayton44d93782014-01-27 23:43:24 +0000786 if (m_output_file_sp)
787 m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership);
788 else
789 m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
790
791 File &out_file = m_output_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000792 if (out_file.IsValid() == false)
793 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000794
Enrico Granatab5887262012-10-29 21:18:03 +0000795 // do not create the ScriptInterpreter just for setting the output file handle
796 // as the constructor will know how to do the right thing on its own
797 const bool can_create = false;
798 ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create);
799 if (script_interpreter)
800 script_interpreter->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801}
802
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803void
804Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
805{
Greg Clayton44d93782014-01-27 23:43:24 +0000806 if (m_error_file_sp)
807 m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership);
808 else
809 m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
810
811 File &err_file = m_error_file_sp->GetFile();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000812 if (err_file.IsValid() == false)
813 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814}
815
Jim Inghamc5917d92012-11-30 20:23:19 +0000816void
817Debugger::SaveInputTerminalState ()
818{
Greg Clayton44d93782014-01-27 23:43:24 +0000819 if (m_input_file_sp)
820 {
821 File &in_file = m_input_file_sp->GetFile();
822 if (in_file.GetDescriptor() != File::kInvalidDescriptor)
823 m_terminal_state.Save(in_file.GetDescriptor(), true);
824 }
Jim Inghamc5917d92012-11-30 20:23:19 +0000825}
826
827void
828Debugger::RestoreInputTerminalState ()
829{
830 m_terminal_state.Restore();
831}
832
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000834Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000835{
836 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000837 TargetSP target_sp(GetSelectedTarget());
838 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000839
840 if (target_sp)
841 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000842 ProcessSP process_sp (target_sp->GetProcessSP());
843 exe_ctx.SetProcessSP (process_sp);
844 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000846 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
847 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000849 exe_ctx.SetThreadSP (thread_sp);
850 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
851 if (exe_ctx.GetFramePtr() == NULL)
852 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853 }
854 }
855 }
856 return exe_ctx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857}
858
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859void
Caroline Ticeefed6132010-11-19 20:47:54 +0000860Debugger::DispatchInputInterrupt ()
861{
Greg Clayton44d93782014-01-27 23:43:24 +0000862 Mutex::Locker locker (m_input_reader_stack.GetMutex());
863 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000864 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000865 reader_sp->Interrupt();
Caroline Ticeefed6132010-11-19 20:47:54 +0000866}
867
868void
869Debugger::DispatchInputEndOfFile ()
870{
Greg Clayton44d93782014-01-27 23:43:24 +0000871 Mutex::Locker locker (m_input_reader_stack.GetMutex());
872 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +0000873 if (reader_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000874 reader_sp->GotEOF();
Caroline Ticeefed6132010-11-19 20:47:54 +0000875}
876
877void
Greg Clayton44d93782014-01-27 23:43:24 +0000878Debugger::ClearIOHandlers ()
Caroline Tice3d6086f2010-12-20 18:35:50 +0000879{
Caroline Ticeb44880c2011-02-10 01:15:13 +0000880 // 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 +0000881 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000882 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000883 {
Greg Clayton44d93782014-01-27 23:43:24 +0000884 IOHandlerSP reader_sp (m_input_reader_stack.Top());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000885 if (reader_sp)
Pavel Labath44464872015-05-27 12:40:32 +0000886 PopIOHandler (reader_sp);
Caroline Tice3d6086f2010-12-20 18:35:50 +0000887 }
888}
889
890void
Siva Chandra9aaab552015-02-26 19:26:36 +0000891Debugger::ExecuteIOHandlers()
Caroline Tice969ed3d2011-05-02 20:41:46 +0000892{
Greg Clayton44d93782014-01-27 23:43:24 +0000893 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000894 {
Greg Clayton44d93782014-01-27 23:43:24 +0000895 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896 if (!reader_sp)
897 break;
898
Greg Clayton44d93782014-01-27 23:43:24 +0000899 reader_sp->Run();
Greg Clayton44d93782014-01-27 23:43:24 +0000900
901 // Remove all input readers that are done from the top of the stack
902 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903 {
Greg Clayton44d93782014-01-27 23:43:24 +0000904 IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
905 if (top_reader_sp && top_reader_sp->GetIsDone())
Pavel Labath44464872015-05-27 12:40:32 +0000906 PopIOHandler (top_reader_sp);
Greg Clayton44d93782014-01-27 23:43:24 +0000907 else
908 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909 }
910 }
Greg Clayton44d93782014-01-27 23:43:24 +0000911 ClearIOHandlers();
912}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000913
Greg Clayton44d93782014-01-27 23:43:24 +0000914bool
915Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
916{
917 return m_input_reader_stack.IsTop (reader_sp);
918}
919
Pavel Labath44464872015-05-27 12:40:32 +0000920void
921Debugger::PrintAsync (const char *s, size_t len, bool is_stdout)
922{
923 lldb::StreamFileSP stream = is_stdout ? GetOutputFile() : GetErrorFile();
924 m_input_reader_stack.PrintAsync(stream.get(), s, len);
925}
Greg Clayton44d93782014-01-27 23:43:24 +0000926
927ConstString
928Debugger::GetTopIOHandlerControlSequence(char ch)
929{
930 return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931}
932
Kate Stonea487aa42015-01-15 00:52:41 +0000933const char *
934Debugger::GetIOHandlerCommandPrefix()
935{
936 return m_input_reader_stack.GetTopIOHandlerCommandPrefix();
937}
938
939const char *
940Debugger::GetIOHandlerHelpPrologue()
941{
942 return m_input_reader_stack.GetTopIOHandlerHelpPrologue();
943}
944
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000945void
Greg Clayton44d93782014-01-27 23:43:24 +0000946Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
947{
Greg Clayton44d93782014-01-27 23:43:24 +0000948 PushIOHandler (reader_sp);
Pavel Labath44464872015-05-27 12:40:32 +0000949
Greg Clayton577508d2014-06-20 00:23:57 +0000950 IOHandlerSP top_reader_sp = reader_sp;
951 while (top_reader_sp)
952 {
Greg Clayton577508d2014-06-20 00:23:57 +0000953 top_reader_sp->Run();
Pavel Labath44464872015-05-27 12:40:32 +0000954
Greg Clayton577508d2014-06-20 00:23:57 +0000955 if (top_reader_sp.get() == reader_sp.get())
956 {
957 if (PopIOHandler (reader_sp))
958 break;
959 }
Pavel Labath44464872015-05-27 12:40:32 +0000960
Greg Clayton577508d2014-06-20 00:23:57 +0000961 while (1)
962 {
963 top_reader_sp = m_input_reader_stack.Top();
964 if (top_reader_sp && top_reader_sp->GetIsDone())
Pavel Labath44464872015-05-27 12:40:32 +0000965 PopIOHandler (top_reader_sp);
Greg Clayton577508d2014-06-20 00:23:57 +0000966 else
967 break;
968 }
969 }
Greg Clayton44d93782014-01-27 23:43:24 +0000970}
971
972void
973Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
974{
975 // Before an IOHandler runs, it must have in/out/err streams.
976 // This function is called when one ore more of the streams
977 // are NULL. We use the top input reader's in/out/err streams,
978 // or fall back to the debugger file handles, or we fall back
979 // onto stdin/stdout/stderr as a last resort.
980
981 Mutex::Locker locker (m_input_reader_stack.GetMutex());
982 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
983 // If no STDIN has been set, then set it appropriately
984 if (!in)
985 {
986 if (top_reader_sp)
987 in = top_reader_sp->GetInputStreamFile();
988 else
989 in = GetInputFile();
990
991 // If there is nothing, use stdin
992 if (!in)
993 in = StreamFileSP(new StreamFile(stdin, false));
994 }
995 // If no STDOUT has been set, then set it appropriately
996 if (!out)
997 {
998 if (top_reader_sp)
999 out = top_reader_sp->GetOutputStreamFile();
1000 else
1001 out = GetOutputFile();
1002
1003 // If there is nothing, use stdout
1004 if (!out)
1005 out = StreamFileSP(new StreamFile(stdout, false));
1006 }
1007 // If no STDERR has been set, then set it appropriately
1008 if (!err)
1009 {
1010 if (top_reader_sp)
1011 err = top_reader_sp->GetErrorStreamFile();
1012 else
1013 err = GetErrorFile();
1014
1015 // If there is nothing, use stderr
1016 if (!err)
1017 err = StreamFileSP(new StreamFile(stdout, false));
1018
1019 }
1020}
1021
1022void
1023Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024{
1025 if (!reader_sp)
1026 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +00001027
Pavel Labath44464872015-05-27 12:40:32 +00001028 Mutex::Locker locker (m_input_reader_stack.GetMutex());
1029
1030 // Get the current top input reader...
Greg Clayton44d93782014-01-27 23:43:24 +00001031 IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
Caroline Ticeb44880c2011-02-10 01:15:13 +00001032
Greg Claytonb4874f12014-02-28 18:22:24 +00001033 // Don't push the same IO handler twice...
Pavel Labath44464872015-05-27 12:40:32 +00001034 if (reader_sp == top_reader_sp)
1035 return;
Greg Clayton44d93782014-01-27 23:43:24 +00001036
Pavel Labath44464872015-05-27 12:40:32 +00001037 // Push our new input reader
1038 m_input_reader_stack.Push (reader_sp);
1039 reader_sp->Activate();
1040
1041 // Interrupt the top input reader to it will exit its Run() function
1042 // and let this new input reader take over
1043 if (top_reader_sp)
1044 {
1045 top_reader_sp->Deactivate();
1046 top_reader_sp->Cancel();
Greg Claytonb4874f12014-02-28 18:22:24 +00001047 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001048}
1049
1050bool
Greg Clayton44d93782014-01-27 23:43:24 +00001051Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001052{
Pavel Labath44464872015-05-27 12:40:32 +00001053 if (! pop_reader_sp)
1054 return false;
1055
Greg Clayton44d93782014-01-27 23:43:24 +00001056 Mutex::Locker locker (m_input_reader_stack.GetMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001057
1058 // The reader on the stop of the stack is done, so let the next
Bruce Mitchener6a7f3332014-06-27 02:42:12 +00001059 // read on the stack refresh its prompt and if there is one...
Pavel Labath44464872015-05-27 12:40:32 +00001060 if (m_input_reader_stack.IsEmpty())
1061 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062
Greg Clayton44d93782014-01-27 23:43:24 +00001063 IOHandlerSP reader_sp(m_input_reader_stack.Top());
Greg Clayton66111032010-06-23 01:19:29 +00001064
Pavel Labath44464872015-05-27 12:40:32 +00001065 if (pop_reader_sp != reader_sp)
1066 return false;
1067
1068 reader_sp->Deactivate();
1069 reader_sp->Cancel();
1070 m_input_reader_stack.Pop ();
1071
1072 reader_sp = m_input_reader_stack.Top();
1073 if (reader_sp)
1074 reader_sp->Activate();
1075
1076 return true;
1077}
Greg Clayton44d93782014-01-27 23:43:24 +00001078
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001079StreamSP
1080Debugger::GetAsyncOutputStream ()
1081{
Pavel Labath44464872015-05-27 12:40:32 +00001082 return StreamSP (new StreamAsynchronousIO (*this, true));
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001083}
1084
1085StreamSP
1086Debugger::GetAsyncErrorStream ()
1087{
Pavel Labath44464872015-05-27 12:40:32 +00001088 return StreamSP (new StreamAsynchronousIO (*this, false));
Jim Ingham5b52f0c2011-06-02 23:58:26 +00001089}
1090
Greg Claytonc7bece562013-01-25 18:06:21 +00001091size_t
Enrico Granata061858c2012-02-15 02:34:21 +00001092Debugger::GetNumDebuggers()
1093{
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001094 if (lldb_initialized)
Greg Claytonc15f55e2012-03-30 20:53:46 +00001095 {
1096 Mutex::Locker locker (GetDebuggerListMutex ());
1097 return GetDebuggerList().size();
1098 }
1099 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +00001100}
1101
1102lldb::DebuggerSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001103Debugger::GetDebuggerAtIndex (size_t index)
Enrico Granata061858c2012-02-15 02:34:21 +00001104{
1105 DebuggerSP debugger_sp;
1106
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001107 if (lldb_initialized)
Greg Claytonc15f55e2012-03-30 20:53:46 +00001108 {
1109 Mutex::Locker locker (GetDebuggerListMutex ());
1110 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +00001111
Greg Claytonc15f55e2012-03-30 20:53:46 +00001112 if (index < debugger_list.size())
1113 debugger_sp = debugger_list[index];
1114 }
1115
Enrico Granata061858c2012-02-15 02:34:21 +00001116 return debugger_sp;
1117}
1118
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001119DebuggerSP
1120Debugger::FindDebuggerWithID (lldb::user_id_t id)
1121{
Greg Clayton4d122c42011-09-17 08:33:22 +00001122 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001123
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001124 if (lldb_initialized)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001125 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001126 Mutex::Locker locker (GetDebuggerListMutex ());
1127 DebuggerList &debugger_list = GetDebuggerList();
1128 DebuggerList::iterator pos, end = debugger_list.end();
1129 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001130 {
Greg Claytonc15f55e2012-03-30 20:53:46 +00001131 if ((*pos).get()->GetID() == id)
1132 {
1133 debugger_sp = *pos;
1134 break;
1135 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001136 }
1137 }
1138 return debugger_sp;
1139}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001140
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001141#if 0
Greg Clayton1b654882010-09-19 02:33:57 +00001142static void
Jason Molendab57e4a12013-11-04 09:33:30 +00001143TestPromptFormats (StackFrame *frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001144{
1145 if (frame == NULL)
1146 return;
1147
1148 StreamString s;
1149 const char *prompt_format =
1150 "{addr = '${addr}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001151 "{addr-file-or-load = '${addr-file-or-load}'\n}"
1152 "{current-pc-arrow = '${current-pc-arrow}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001153 "{process.id = '${process.id}'\n}"
1154 "{process.name = '${process.name}'\n}"
1155 "{process.file.basename = '${process.file.basename}'\n}"
1156 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1157 "{thread.id = '${thread.id}'\n}"
1158 "{thread.index = '${thread.index}'\n}"
1159 "{thread.name = '${thread.name}'\n}"
1160 "{thread.queue = '${thread.queue}'\n}"
1161 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1162 "{target.arch = '${target.arch}'\n}"
1163 "{module.file.basename = '${module.file.basename}'\n}"
1164 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1165 "{file.basename = '${file.basename}'\n}"
1166 "{file.fullpath = '${file.fullpath}'\n}"
1167 "{frame.index = '${frame.index}'\n}"
1168 "{frame.pc = '${frame.pc}'\n}"
1169 "{frame.sp = '${frame.sp}'\n}"
1170 "{frame.fp = '${frame.fp}'\n}"
1171 "{frame.flags = '${frame.flags}'\n}"
1172 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1173 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1174 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1175 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1176 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1177 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1178 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1179 "{function.id = '${function.id}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001180 "{function.changed = '${function.changed}'\n}"
1181 "{function.initial-function = '${function.initial-function}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001182 "{function.name = '${function.name}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001183 "{function.name-without-args = '${function.name-without-args}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +00001184 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001185 "{function.addr-offset = '${function.addr-offset}'\n}"
Jason Molendaaff1b352014-10-10 23:07:36 +00001186 "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001187 "{function.line-offset = '${function.line-offset}'\n}"
1188 "{function.pc-offset = '${function.pc-offset}'\n}"
1189 "{line.file.basename = '${line.file.basename}'\n}"
1190 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1191 "{line.number = '${line.number}'\n}"
1192 "{line.start-addr = '${line.start-addr}'\n}"
1193 "{line.end-addr = '${line.end-addr}'\n}"
1194;
1195
1196 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1197 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +00001198 frame->CalculateExecutionContext(exe_ctx);
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001199 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
Greg Clayton1b654882010-09-19 02:33:57 +00001200 {
1201 printf("%s\n", s.GetData());
1202 }
1203 else
1204 {
Greg Clayton1b654882010-09-19 02:33:57 +00001205 printf ("what we got: %s\n", s.GetData());
1206 }
1207}
Saleem Abdulrasool2643b902014-03-20 06:08:21 +00001208#endif
Greg Clayton1b654882010-09-19 02:33:57 +00001209
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001210bool
Greg Clayton554f68d2015-02-04 22:00:53 +00001211Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
Jason Molendaaff1b352014-10-10 23:07:36 +00001212 const SymbolContext *sc,
1213 const SymbolContext *prev_sc,
1214 const ExecutionContext *exe_ctx,
1215 const Address *addr,
1216 Stream &s)
1217{
Greg Clayton554f68d2015-02-04 22:00:53 +00001218 FormatEntity::Entry format_entry;
1219
1220 if (format == NULL)
Jason Molendaaff1b352014-10-10 23:07:36 +00001221 {
Greg Clayton554f68d2015-02-04 22:00:53 +00001222 if (exe_ctx != NULL && exe_ctx->HasTargetScope())
1223 format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1224 if (format == NULL)
1225 {
1226 FormatEntity::Parse("${addr}: ", format_entry);
1227 format = &format_entry;
1228 }
Jason Molendaaff1b352014-10-10 23:07:36 +00001229 }
1230 bool function_changed = false;
1231 bool initial_function = false;
1232 if (prev_sc && (prev_sc->function || prev_sc->symbol))
1233 {
1234 if (sc && (sc->function || sc->symbol))
1235 {
1236 if (prev_sc->symbol && sc->symbol)
1237 {
1238 if (!sc->symbol->Compare (prev_sc->symbol->GetName(), prev_sc->symbol->GetType()))
1239 {
1240 function_changed = true;
1241 }
1242 }
1243 else if (prev_sc->function && sc->function)
1244 {
1245 if (prev_sc->function->GetMangled() != sc->function->GetMangled())
1246 {
1247 function_changed = true;
1248 }
1249 }
1250 }
1251 }
1252 // The first context on a list of instructions will have a prev_sc that
1253 // has no Function or Symbol -- if SymbolContext had an IsValid() method, it
1254 // would return false. But we do get a prev_sc pointer.
1255 if ((sc && (sc->function || sc->symbol))
1256 && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL))
1257 {
1258 initial_function = true;
1259 }
Greg Clayton554f68d2015-02-04 22:00:53 +00001260 return FormatEntity::Format(*format, s, sc, exe_ctx, addr, NULL, function_changed, initial_function);
Jason Molendaaff1b352014-10-10 23:07:36 +00001261}
1262
1263
Jim Ingham228063c2012-02-21 02:23:08 +00001264void
1265Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1266{
Jim Ingham4f02b222012-02-22 22:49:20 +00001267 // For simplicity's sake, I am not going to deal with how to close down any
1268 // open logging streams, I just redirect everything from here on out to the
1269 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00001270 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
1271}
1272
1273bool
1274Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
1275{
Jim Ingham228063c2012-02-21 02:23:08 +00001276 StreamSP log_stream_sp;
Sean Callanan9a028512012-08-09 00:50:26 +00001277 if (m_log_callback_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001278 {
1279 log_stream_sp = m_log_callback_stream_sp;
1280 // For now when using the callback mode you always get thread & timestamp.
1281 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1282 }
1283 else if (log_file == NULL || *log_file == '\0')
1284 {
Greg Clayton44d93782014-01-27 23:43:24 +00001285 log_stream_sp = GetOutputFile();
Jim Ingham228063c2012-02-21 02:23:08 +00001286 }
1287 else
1288 {
1289 LogStreamMap::iterator pos = m_log_streams.find(log_file);
Greg Claytonc1b2ccf2013-01-08 00:01:36 +00001290 if (pos != m_log_streams.end())
1291 log_stream_sp = pos->second.lock();
1292 if (!log_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00001293 {
Pavel Labath8ac06992015-03-20 09:43:20 +00001294 uint32_t options = File::eOpenOptionWrite | File::eOpenOptionCanCreate
1295 | File::eOpenOptionCloseOnExec | File::eOpenOptionAppend;
1296 if (! (log_options & LLDB_LOG_OPTION_APPEND))
1297 options |= File::eOpenOptionTruncate;
1298
1299 log_stream_sp.reset (new StreamFile (log_file, options));
Jim Ingham228063c2012-02-21 02:23:08 +00001300 m_log_streams[log_file] = log_stream_sp;
1301 }
Jim Ingham228063c2012-02-21 02:23:08 +00001302 }
1303 assert (log_stream_sp.get());
1304
1305 if (log_options == 0)
1306 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
1307
Tamas Berghammer9c9ecce2015-05-27 13:34:04 +00001308 return Log::EnableLogChannel(log_stream_sp, log_options, channel, categories, error_stream);
Jim Ingham228063c2012-02-21 02:23:08 +00001309}
1310
Greg Clayton9585fbf2013-03-19 00:20:55 +00001311SourceManager &
1312Debugger::GetSourceManager ()
1313{
1314 if (m_source_manager_ap.get() == NULL)
1315 m_source_manager_ap.reset (new SourceManager (shared_from_this()));
1316 return *m_source_manager_ap;
1317}
1318
1319
Greg Clayton44d93782014-01-27 23:43:24 +00001320
1321// This function handles events that were broadcast by the process.
1322void
1323Debugger::HandleBreakpointEvent (const EventSP &event_sp)
1324{
1325 using namespace lldb;
1326 const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp);
1327
1328// if (event_type & eBreakpointEventTypeAdded
1329// || event_type & eBreakpointEventTypeRemoved
1330// || event_type & eBreakpointEventTypeEnabled
1331// || event_type & eBreakpointEventTypeDisabled
1332// || event_type & eBreakpointEventTypeCommandChanged
1333// || event_type & eBreakpointEventTypeConditionChanged
1334// || event_type & eBreakpointEventTypeIgnoreChanged
1335// || event_type & eBreakpointEventTypeLocationsResolved)
1336// {
1337// // Don't do anything about these events, since the breakpoint commands already echo these actions.
1338// }
1339//
1340 if (event_type & eBreakpointEventTypeLocationsAdded)
1341 {
1342 uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp);
1343 if (num_new_locations > 0)
1344 {
1345 BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
Pavel Labath44464872015-05-27 12:40:32 +00001346 StreamSP output_sp (GetAsyncOutputStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001347 if (output_sp)
1348 {
1349 output_sp->Printf("%d location%s added to breakpoint %d\n",
1350 num_new_locations,
1351 num_new_locations == 1 ? "" : "s",
1352 breakpoint->GetID());
Pavel Labath44464872015-05-27 12:40:32 +00001353 output_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001354 }
1355 }
1356 }
1357// else if (event_type & eBreakpointEventTypeLocationsRemoved)
1358// {
1359// // These locations just get disabled, not sure it is worth spamming folks about this on the command line.
1360// }
1361// else if (event_type & eBreakpointEventTypeLocationsResolved)
1362// {
1363// // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy.
1364// }
1365}
1366
1367size_t
1368Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
1369{
1370 size_t total_bytes = 0;
1371 if (stream == NULL)
1372 stream = GetOutputFile().get();
1373
1374 if (stream)
1375 {
1376 // The process has stuff waiting for stdout; get it and write it out to the appropriate place.
1377 if (process == NULL)
1378 {
1379 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1380 if (target_sp)
1381 process = target_sp->GetProcessSP().get();
1382 }
1383 if (process)
1384 {
1385 Error error;
1386 size_t len;
1387 char stdio_buffer[1024];
1388 while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1389 {
1390 stream->Write(stdio_buffer, len);
1391 total_bytes += len;
1392 }
1393 }
1394 stream->Flush();
1395 }
1396 return total_bytes;
1397}
1398
1399size_t
1400Debugger::GetProcessSTDERR (Process *process, Stream *stream)
1401{
1402 size_t total_bytes = 0;
1403 if (stream == NULL)
1404 stream = GetOutputFile().get();
1405
1406 if (stream)
1407 {
1408 // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
1409 if (process == NULL)
1410 {
1411 TargetSP target_sp = GetTargetList().GetSelectedTarget();
1412 if (target_sp)
1413 process = target_sp->GetProcessSP().get();
1414 }
1415 if (process)
1416 {
1417 Error error;
1418 size_t len;
1419 char stdio_buffer[1024];
1420 while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
1421 {
1422 stream->Write(stdio_buffer, len);
1423 total_bytes += len;
1424 }
1425 }
1426 stream->Flush();
1427 }
1428 return total_bytes;
1429}
1430
Greg Claytondc6224e2014-10-21 01:00:42 +00001431
Greg Clayton44d93782014-01-27 23:43:24 +00001432// This function handles events that were broadcast by the process.
1433void
1434Debugger::HandleProcessEvent (const EventSP &event_sp)
1435{
1436 using namespace lldb;
1437 const uint32_t event_type = event_sp->GetType();
1438 ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
Greg Claytondc6224e2014-10-21 01:00:42 +00001439
Pavel Labath44464872015-05-27 12:40:32 +00001440 StreamSP output_stream_sp = GetAsyncOutputStream();
1441 StreamSP error_stream_sp = GetAsyncErrorStream();
Greg Clayton44d93782014-01-27 23:43:24 +00001442 const bool gui_enabled = IsForwardingEvents();
Greg Clayton44d93782014-01-27 23:43:24 +00001443
Greg Claytonb4874f12014-02-28 18:22:24 +00001444 if (!gui_enabled)
1445 {
1446 bool pop_process_io_handler = false;
1447 assert (process_sp);
Greg Claytondc6224e2014-10-21 01:00:42 +00001448
Pavel Labath44464872015-05-27 12:40:32 +00001449 bool state_is_stopped = false;
1450 const bool got_state_changed = (event_type & Process::eBroadcastBitStateChanged) != 0;
1451 const bool got_stdout = (event_type & Process::eBroadcastBitSTDOUT) != 0;
1452 const bool got_stderr = (event_type & Process::eBroadcastBitSTDERR) != 0;
1453 if (got_state_changed)
Greg Clayton44d93782014-01-27 23:43:24 +00001454 {
Pavel Labath44464872015-05-27 12:40:32 +00001455 StateType event_state = Process::ProcessEventData::GetStateFromEvent (event_sp.get());
1456 state_is_stopped = StateIsStoppedState(event_state, false);
Greg Claytonb4874f12014-02-28 18:22:24 +00001457 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001458
Pavel Labath44464872015-05-27 12:40:32 +00001459 // Display running state changes first before any STDIO
1460 if (got_state_changed && !state_is_stopped)
Greg Claytonb4874f12014-02-28 18:22:24 +00001461 {
Pavel Labath44464872015-05-27 12:40:32 +00001462 Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler);
Greg Claytonb4874f12014-02-28 18:22:24 +00001463 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001464
Pavel Labath44464872015-05-27 12:40:32 +00001465 // Now display and STDOUT
1466 if (got_stdout || got_state_changed)
Greg Claytonb4874f12014-02-28 18:22:24 +00001467 {
Pavel Labath44464872015-05-27 12:40:32 +00001468 GetProcessSTDOUT (process_sp.get(), output_stream_sp.get());
Greg Clayton44d93782014-01-27 23:43:24 +00001469 }
Greg Claytondc6224e2014-10-21 01:00:42 +00001470
Pavel Labath44464872015-05-27 12:40:32 +00001471 // Now display and STDERR
1472 if (got_stderr || got_state_changed)
Greg Claytonb4874f12014-02-28 18:22:24 +00001473 {
Pavel Labath44464872015-05-27 12:40:32 +00001474 GetProcessSTDERR (process_sp.get(), error_stream_sp.get());
Greg Claytonb4874f12014-02-28 18:22:24 +00001475 }
1476
Pavel Labath44464872015-05-27 12:40:32 +00001477 // Now display any stopped state changes after any STDIO
1478 if (got_state_changed && state_is_stopped)
1479 {
1480 Process::HandleProcessStateChangedEvent (event_sp, output_stream_sp.get(), pop_process_io_handler);
1481 }
1482
1483 output_stream_sp->Flush();
1484 error_stream_sp->Flush();
1485
Greg Claytonb4874f12014-02-28 18:22:24 +00001486 if (pop_process_io_handler)
1487 process_sp->PopProcessIOHandler();
1488 }
Greg Clayton44d93782014-01-27 23:43:24 +00001489}
1490
1491void
1492Debugger::HandleThreadEvent (const EventSP &event_sp)
1493{
1494 // At present the only thread event we handle is the Frame Changed event,
1495 // and all we do for that is just reprint the thread status for that thread.
1496 using namespace lldb;
1497 const uint32_t event_type = event_sp->GetType();
1498 if (event_type == Thread::eBroadcastBitStackChanged ||
1499 event_type == Thread::eBroadcastBitThreadSelected )
1500 {
1501 ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get()));
1502 if (thread_sp)
1503 {
Pavel Labath44464872015-05-27 12:40:32 +00001504 thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1);
Greg Clayton44d93782014-01-27 23:43:24 +00001505 }
1506 }
1507}
1508
1509bool
1510Debugger::IsForwardingEvents ()
1511{
1512 return (bool)m_forward_listener_sp;
1513}
1514
1515void
1516Debugger::EnableForwardEvents (const ListenerSP &listener_sp)
1517{
1518 m_forward_listener_sp = listener_sp;
1519}
1520
1521void
1522Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
1523{
1524 m_forward_listener_sp.reset();
1525}
1526
1527
1528void
1529Debugger::DefaultEventHandler()
1530{
1531 Listener& listener(GetListener());
1532 ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
1533 ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
1534 ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
1535 BroadcastEventSpec target_event_spec (broadcaster_class_target,
1536 Target::eBroadcastBitBreakpointChanged);
1537
1538 BroadcastEventSpec process_event_spec (broadcaster_class_process,
1539 Process::eBroadcastBitStateChanged |
1540 Process::eBroadcastBitSTDOUT |
1541 Process::eBroadcastBitSTDERR);
1542
1543 BroadcastEventSpec thread_event_spec (broadcaster_class_thread,
1544 Thread::eBroadcastBitStackChanged |
1545 Thread::eBroadcastBitThreadSelected );
1546
1547 listener.StartListeningForEventSpec (*this, target_event_spec);
1548 listener.StartListeningForEventSpec (*this, process_event_spec);
1549 listener.StartListeningForEventSpec (*this, thread_event_spec);
1550 listener.StartListeningForEvents (m_command_interpreter_ap.get(),
1551 CommandInterpreter::eBroadcastBitQuitCommandReceived |
1552 CommandInterpreter::eBroadcastBitAsynchronousOutputData |
1553 CommandInterpreter::eBroadcastBitAsynchronousErrorData );
Greg Claytonafa91e332014-12-01 22:41:27 +00001554
1555 // Let the thread that spawned us know that we have started up and
1556 // that we are now listening to all required events so no events get missed
1557 m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening);
1558
Greg Clayton44d93782014-01-27 23:43:24 +00001559 bool done = false;
1560 while (!done)
1561 {
Greg Clayton44d93782014-01-27 23:43:24 +00001562 EventSP event_sp;
1563 if (listener.WaitForEvent(NULL, event_sp))
1564 {
1565 if (event_sp)
1566 {
1567 Broadcaster *broadcaster = event_sp->GetBroadcaster();
1568 if (broadcaster)
1569 {
1570 uint32_t event_type = event_sp->GetType();
1571 ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
1572 if (broadcaster_class == broadcaster_class_process)
1573 {
1574 HandleProcessEvent (event_sp);
1575 }
1576 else if (broadcaster_class == broadcaster_class_target)
1577 {
1578 if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get()))
1579 {
1580 HandleBreakpointEvent (event_sp);
1581 }
1582 }
1583 else if (broadcaster_class == broadcaster_class_thread)
1584 {
1585 HandleThreadEvent (event_sp);
1586 }
1587 else if (broadcaster == m_command_interpreter_ap.get())
1588 {
1589 if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived)
1590 {
1591 done = true;
1592 }
1593 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData)
1594 {
1595 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1596 if (data && data[0])
1597 {
Pavel Labath44464872015-05-27 12:40:32 +00001598 StreamSP error_sp (GetAsyncErrorStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001599 if (error_sp)
1600 {
Greg Clayton44d93782014-01-27 23:43:24 +00001601 error_sp->PutCString(data);
1602 error_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001603 }
1604 }
1605 }
1606 else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData)
1607 {
1608 const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
1609 if (data && data[0])
1610 {
Pavel Labath44464872015-05-27 12:40:32 +00001611 StreamSP output_sp (GetAsyncOutputStream());
Greg Clayton44d93782014-01-27 23:43:24 +00001612 if (output_sp)
1613 {
Greg Clayton44d93782014-01-27 23:43:24 +00001614 output_sp->PutCString(data);
1615 output_sp->Flush();
Greg Clayton44d93782014-01-27 23:43:24 +00001616 }
1617 }
1618 }
1619 }
1620 }
1621
1622 if (m_forward_listener_sp)
1623 m_forward_listener_sp->AddEvent(event_sp);
1624 }
1625 }
1626 }
1627}
1628
1629lldb::thread_result_t
1630Debugger::EventHandlerThread (lldb::thread_arg_t arg)
1631{
1632 ((Debugger *)arg)->DefaultEventHandler();
1633 return NULL;
1634}
1635
1636bool
1637Debugger::StartEventHandlerThread()
1638{
Zachary Turneracee96a2014-09-23 18:32:09 +00001639 if (!m_event_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001640 {
Greg Claytonafa91e332014-12-01 22:41:27 +00001641 // We must synchronize with the DefaultEventHandler() thread to ensure
1642 // it is up and running and listening to events before we return from
1643 // this function. We do this by listening to events for the
1644 // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
1645 Listener listener("lldb.debugger.event-handler");
1646 listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
1647
Zachary Turner7c2896a2014-10-24 22:06:29 +00001648 // Use larger 8MB stack for this thread
Greg Claytonafa91e332014-12-01 22:41:27 +00001649 m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread,
1650 this,
1651 NULL,
Zachary Turner7c2896a2014-10-24 22:06:29 +00001652 g_debugger_event_thread_stack_bytes);
Greg Claytonafa91e332014-12-01 22:41:27 +00001653
1654 // Make sure DefaultEventHandler() is running and listening to events before we return
1655 // from this function. We are only listening for events of type
1656 // eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
1657 // to wait an infinite amount of time for it (NULL timeout as the first parameter)
1658 lldb::EventSP event_sp;
1659 listener.WaitForEvent(NULL, event_sp);
Greg Clayton807b6b32014-10-15 18:03:59 +00001660 }
Zachary Turneracee96a2014-09-23 18:32:09 +00001661 return m_event_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001662}
1663
1664void
1665Debugger::StopEventHandlerThread()
1666{
Zachary Turneracee96a2014-09-23 18:32:09 +00001667 if (m_event_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001668 {
1669 GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
Zachary Turner39de3112014-09-09 20:54:56 +00001670 m_event_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001671 }
1672}
1673
1674
1675lldb::thread_result_t
1676Debugger::IOHandlerThread (lldb::thread_arg_t arg)
1677{
1678 Debugger *debugger = (Debugger *)arg;
Siva Chandra9aaab552015-02-26 19:26:36 +00001679 debugger->ExecuteIOHandlers();
Greg Clayton44d93782014-01-27 23:43:24 +00001680 debugger->StopEventHandlerThread();
1681 return NULL;
1682}
1683
1684bool
1685Debugger::StartIOHandlerThread()
1686{
Zachary Turneracee96a2014-09-23 18:32:09 +00001687 if (!m_io_handler_thread.IsJoinable())
Greg Clayton807b6b32014-10-15 18:03:59 +00001688 m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
1689 IOHandlerThread,
1690 this,
1691 NULL,
1692 8*1024*1024); // Use larger 8MB stack for this thread
Zachary Turneracee96a2014-09-23 18:32:09 +00001693 return m_io_handler_thread.IsJoinable();
Greg Clayton44d93782014-01-27 23:43:24 +00001694}
1695
1696void
1697Debugger::StopIOHandlerThread()
1698{
Zachary Turneracee96a2014-09-23 18:32:09 +00001699 if (m_io_handler_thread.IsJoinable())
Greg Clayton44d93782014-01-27 23:43:24 +00001700 {
1701 if (m_input_file_sp)
1702 m_input_file_sp->GetFile().Close();
Zachary Turner39de3112014-09-09 20:54:56 +00001703 m_io_handler_thread.Join(nullptr);
Greg Clayton44d93782014-01-27 23:43:24 +00001704 }
1705}
1706
Jim Ingham893c9322014-11-22 01:42:44 +00001707Target *
1708Debugger::GetDummyTarget()
1709{
1710 return m_target_list.GetDummyTarget (*this).get();
1711}
1712
1713Target *
Jim Ingham33df7cd2014-12-06 01:28:03 +00001714Debugger::GetSelectedOrDummyTarget(bool prefer_dummy)
Jim Ingham893c9322014-11-22 01:42:44 +00001715{
Jim Ingham33df7cd2014-12-06 01:28:03 +00001716 Target *target = nullptr;
1717 if (!prefer_dummy)
1718 {
1719 target = m_target_list.GetSelectedTarget().get();
1720 if (target)
1721 return target;
1722 }
1723
Jim Ingham893c9322014-11-22 01:42:44 +00001724 return GetDummyTarget();
1725}
Greg Clayton44d93782014-01-27 23:43:24 +00001726