1 //===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/API/SBDebugger.h"
14 #include "lldb/Core/Debugger.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/Type.h"
21 #include "lldb/lldb-private.h"
22 #include "lldb/Core/ConnectionFileDescriptor.h"
23 #include "lldb/Core/InputReader.h"
24 #include "lldb/Core/Module.h"
25 #include "lldb/Core/PluginManager.h"
26 #include "lldb/Core/RegisterValue.h"
27 #include "lldb/Core/State.h"
28 #include "lldb/Core/StreamAsynchronousIO.h"
29 #include "lldb/Core/StreamCallback.h"
30 #include "lldb/Core/StreamString.h"
31 #include "lldb/Core/Timer.h"
32 #include "lldb/Core/ValueObject.h"
33 #include "lldb/Core/ValueObjectVariable.h"
34 #include "lldb/DataFormatters/DataVisualization.h"
35 #include "lldb/DataFormatters/FormatManager.h"
36 #include "lldb/Host/DynamicLibrary.h"
37 #include "lldb/Host/Terminal.h"
38 #include "lldb/Interpreter/CommandInterpreter.h"
39 #include "lldb/Interpreter/OptionValueSInt64.h"
40 #include "lldb/Interpreter/OptionValueString.h"
41 #include "lldb/Symbol/ClangASTContext.h"
42 #include "lldb/Symbol/CompileUnit.h"
43 #include "lldb/Symbol/Function.h"
44 #include "lldb/Symbol/Symbol.h"
45 #include "lldb/Symbol/VariableList.h"
46 #include "lldb/Target/TargetList.h"
47 #include "lldb/Target/Process.h"
48 #include "lldb/Target/RegisterContext.h"
49 #include "lldb/Target/StopInfo.h"
50 #include "lldb/Target/Target.h"
51 #include "lldb/Target/Thread.h"
52 #include "lldb/Utility/AnsiTerminal.h"
55 using namespace lldb_private;
58 static uint32_t g_shared_debugger_refcount = 0;
59 static lldb::user_id_t g_unique_id = 1;
61 #pragma mark Static Functions
64 GetDebuggerListMutex ()
66 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
70 typedef std::vector<DebuggerSP> DebuggerList;
75 // hide the static debugger list inside a singleton accessor to avoid
76 // global init contructors
77 static DebuggerList g_list;
81 OptionEnumValueElement
82 g_show_disassembly_enum_values[] =
84 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
85 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
86 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
90 OptionEnumValueElement
91 g_language_enumerators[] =
93 { eScriptLanguageNone, "none", "Disable scripting languages."},
94 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
95 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
99 #define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
100 #define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
102 #define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id%tid}"\
106 "{, name = '${thread.name}'}"\
107 "{, queue = '${thread.queue}'}"\
108 "{, stop reason = ${thread.stop-reason}}"\
109 "{\\nReturn value: ${thread.return-value}}"\
112 #define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
119 static PropertyDefinition
122 { "auto-confirm", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
123 { "frame-format", OptionValue::eTypeString , true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
124 { "notify-void", OptionValue::eTypeBoolean, true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
125 { "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
126 { "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
127 { "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
128 { "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
129 { "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." },
130 { "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." },
131 { "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
132 { "thread-format", OptionValue::eTypeString , true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
133 { "use-external-editor", OptionValue::eTypeBoolean, true, false, NULL, NULL, "Whether to use an external editor or not." },
134 { "use-color", OptionValue::eTypeBoolean, true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
135 { "auto-one-line-summaries", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
137 { NULL, OptionValue::eTypeInvalid, true, 0 , NULL, NULL, NULL }
142 ePropertyAutoConfirm = 0,
143 ePropertyFrameFormat,
146 ePropertyScriptLanguage,
147 ePropertyStopDisassemblyCount,
148 ePropertyStopDisassemblyDisplay,
149 ePropertyStopLineCountAfter,
150 ePropertyStopLineCountBefore,
151 ePropertyTerminalWidth,
152 ePropertyThreadFormat,
153 ePropertyUseExternalEditor,
155 ePropertyAutoOneLineSummaries
160 //Debugger::GetFrameFormat() const
162 // return m_properties_sp->GetFrameFormat();
165 //Debugger::GetThreadFormat() const
167 // return m_properties_sp->GetThreadFormat();
173 Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
174 VarSetOperationType op,
175 const char *property_path,
178 bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
180 LoadScriptFromSymFile load_script_old_value;
181 if (is_load_script && exe_ctx->GetTargetSP())
183 target_sp = exe_ctx->GetTargetSP();
184 load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile();
186 Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value));
189 // FIXME it would be nice to have "on-change" callbacks for properties
190 if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0)
192 const char *new_prompt = GetPrompt();
193 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
195 new_prompt = str.c_str();
196 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
197 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
199 else if (strcmp(property_path, g_properties[ePropertyUseColor].name) == 0)
201 // use-color changed. Ping the prompt so it can reset the ansi terminal codes.
202 SetPrompt (GetPrompt());
204 else if (is_load_script && target_sp && load_script_old_value == eLoadScriptFromSymFileWarn)
206 if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == eLoadScriptFromSymFileTrue)
208 std::list<Error> errors;
209 StreamString feedback_stream;
210 if (!target_sp->LoadScriptingResources(errors,&feedback_stream))
212 for (auto error : errors)
214 GetErrorStream().Printf("%s\n",error.AsCString());
216 if (feedback_stream.GetSize())
217 GetErrorStream().Printf("%s",feedback_stream.GetData());
226 Debugger::GetAutoConfirm () const
228 const uint32_t idx = ePropertyAutoConfirm;
229 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
233 Debugger::GetFrameFormat() const
235 const uint32_t idx = ePropertyFrameFormat;
236 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
240 Debugger::GetNotifyVoid () const
242 const uint32_t idx = ePropertyNotiftVoid;
243 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
247 Debugger::GetPrompt() const
249 const uint32_t idx = ePropertyPrompt;
250 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
254 Debugger::SetPrompt(const char *p)
256 const uint32_t idx = ePropertyPrompt;
257 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
258 const char *new_prompt = GetPrompt();
259 std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
261 new_prompt = str.c_str();
262 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));;
263 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
267 Debugger::GetThreadFormat() const
269 const uint32_t idx = ePropertyThreadFormat;
270 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
274 Debugger::GetScriptLanguage() const
276 const uint32_t idx = ePropertyScriptLanguage;
277 return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
281 Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
283 const uint32_t idx = ePropertyScriptLanguage;
284 return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
288 Debugger::GetTerminalWidth () const
290 const uint32_t idx = ePropertyTerminalWidth;
291 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
295 Debugger::SetTerminalWidth (uint32_t term_width)
297 const uint32_t idx = ePropertyTerminalWidth;
298 return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
302 Debugger::GetUseExternalEditor () const
304 const uint32_t idx = ePropertyUseExternalEditor;
305 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
309 Debugger::SetUseExternalEditor (bool b)
311 const uint32_t idx = ePropertyUseExternalEditor;
312 return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
316 Debugger::GetUseColor () const
318 const uint32_t idx = ePropertyUseColor;
319 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
323 Debugger::SetUseColor (bool b)
325 const uint32_t idx = ePropertyUseColor;
326 bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
327 SetPrompt (GetPrompt());
332 Debugger::GetStopSourceLineCount (bool before) const
334 const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
335 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
338 Debugger::StopDisassemblyType
339 Debugger::GetStopDisassemblyDisplay () const
341 const uint32_t idx = ePropertyStopDisassemblyDisplay;
342 return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
346 Debugger::GetDisassemblyLineCount () const
348 const uint32_t idx = ePropertyStopDisassemblyCount;
349 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
353 Debugger::GetAutoOneLineSummaries () const
355 const uint32_t idx = ePropertyAutoOneLineSummaries;
356 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
360 #pragma mark Debugger
362 //const DebuggerPropertiesSP &
363 //Debugger::GetSettings() const
365 // return m_properties_sp;
370 Debugger::TestDebuggerRefCount ()
372 return g_shared_debugger_refcount;
376 Debugger::Initialize ()
378 if (g_shared_debugger_refcount++ == 0)
379 lldb_private::Initialize();
383 Debugger::Terminate ()
385 if (g_shared_debugger_refcount > 0)
387 g_shared_debugger_refcount--;
388 if (g_shared_debugger_refcount == 0)
390 lldb_private::WillTerminate();
391 lldb_private::Terminate();
393 // Clear our master list of debugger objects
394 Mutex::Locker locker (GetDebuggerListMutex ());
395 GetDebuggerList().clear();
401 Debugger::SettingsInitialize ()
403 Target::SettingsInitialize ();
407 Debugger::SettingsTerminate ()
409 Target::SettingsTerminate ();
413 Debugger::LoadPlugin (const FileSpec& spec, Error& error)
415 lldb::DynamicLibrarySP dynlib_sp(new lldb_private::DynamicLibrary(spec));
416 if (!dynlib_sp || dynlib_sp->IsValid() == false)
419 error.SetErrorString("this file does not represent a loadable dylib");
421 error.SetErrorString("no such file");
424 lldb::DebuggerSP debugger_sp(shared_from_this());
425 lldb::SBDebugger debugger_sb(debugger_sp);
426 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
427 // TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays
428 LLDBCommandPluginInit init_func = dynlib_sp->GetSymbol<LLDBCommandPluginInit>("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
431 error.SetErrorString("cannot find the initialization function lldb::PluginInitialize(lldb::SBDebugger)");
434 if (init_func(debugger_sb))
436 m_loaded_plugins.push_back(dynlib_sp);
439 error.SetErrorString("dylib refused to be loaded");
443 static FileSpec::EnumerateDirectoryResult
447 FileSpec::FileType file_type,
448 const FileSpec &file_spec
453 static ConstString g_dylibext("dylib");
454 static ConstString g_solibext("so");
457 return FileSpec::eEnumerateDirectoryResultQuit;
459 Debugger *debugger = (Debugger*)baton;
461 // If we have a regular file, a symbolic link or unknown file type, try
462 // and process the file. We must handle unknown as sometimes the directory
463 // enumeration might be enumerating a file system that doesn't have correct
464 // file type information.
465 if (file_type == FileSpec::eFileTypeRegular ||
466 file_type == FileSpec::eFileTypeSymbolicLink ||
467 file_type == FileSpec::eFileTypeUnknown )
469 FileSpec plugin_file_spec (file_spec);
470 plugin_file_spec.ResolvePath ();
472 if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
473 plugin_file_spec.GetFileNameExtension() != g_solibext)
475 return FileSpec::eEnumerateDirectoryResultNext;
478 Error plugin_load_error;
479 debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
481 return FileSpec::eEnumerateDirectoryResultNext;
484 else if (file_type == FileSpec::eFileTypeUnknown ||
485 file_type == FileSpec::eFileTypeDirectory ||
486 file_type == FileSpec::eFileTypeSymbolicLink )
488 // Try and recurse into anything that a directory or symbolic link.
489 // We must also do this for unknown as sometimes the directory enumeration
490 // might be enurating a file system that doesn't have correct file type
492 return FileSpec::eEnumerateDirectoryResultEnter;
495 return FileSpec::eEnumerateDirectoryResultNext;
499 Debugger::InstanceInitialize ()
502 const bool find_directories = true;
503 const bool find_files = true;
504 const bool find_other = true;
505 char dir_path[PATH_MAX];
506 if (Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec))
508 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
510 FileSpec::EnumerateDirectory (dir_path,
519 if (Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec))
521 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
523 FileSpec::EnumerateDirectory (dir_path,
532 PluginManager::DebuggerInitialize (*this);
536 Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
538 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
539 if (g_shared_debugger_refcount > 0)
541 Mutex::Locker locker (GetDebuggerListMutex ());
542 GetDebuggerList().push_back(debugger_sp);
544 debugger_sp->InstanceInitialize ();
549 Debugger::Destroy (DebuggerSP &debugger_sp)
551 if (debugger_sp.get() == NULL)
554 debugger_sp->Clear();
556 if (g_shared_debugger_refcount > 0)
558 Mutex::Locker locker (GetDebuggerListMutex ());
559 DebuggerList &debugger_list = GetDebuggerList ();
560 DebuggerList::iterator pos, end = debugger_list.end();
561 for (pos = debugger_list.begin (); pos != end; ++pos)
563 if ((*pos).get() == debugger_sp.get())
565 debugger_list.erase (pos);
573 Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
575 DebuggerSP debugger_sp;
576 if (g_shared_debugger_refcount > 0)
578 Mutex::Locker locker (GetDebuggerListMutex ());
579 DebuggerList &debugger_list = GetDebuggerList();
580 DebuggerList::iterator pos, end = debugger_list.end();
582 for (pos = debugger_list.begin(); pos != end; ++pos)
584 if ((*pos).get()->m_instance_name == instance_name)
595 Debugger::FindTargetWithProcessID (lldb::pid_t pid)
598 if (g_shared_debugger_refcount > 0)
600 Mutex::Locker locker (GetDebuggerListMutex ());
601 DebuggerList &debugger_list = GetDebuggerList();
602 DebuggerList::iterator pos, end = debugger_list.end();
603 for (pos = debugger_list.begin(); pos != end; ++pos)
605 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
614 Debugger::FindTargetWithProcess (Process *process)
617 if (g_shared_debugger_refcount > 0)
619 Mutex::Locker locker (GetDebuggerListMutex ());
620 DebuggerList &debugger_list = GetDebuggerList();
621 DebuggerList::iterator pos, end = debugger_list.end();
622 for (pos = debugger_list.begin(); pos != end; ++pos)
624 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
632 Debugger::Debugger (lldb::LogOutputCallback log_callback, void *baton) :
633 UserID (g_unique_id++),
634 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
635 m_input_comm("debugger.input"),
640 m_target_list (*this),
642 m_listener ("lldb.Debugger"),
643 m_source_manager_ap(),
644 m_source_file_cache(),
645 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
646 m_input_reader_stack (),
647 m_input_reader_data (),
650 char instance_cstr[256];
651 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
652 m_instance_name.SetCString(instance_cstr);
654 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
655 m_command_interpreter_ap->Initialize ();
656 // Always add our default platform to the platform list
657 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
658 assert (default_platform_sp.get());
659 m_platform_list.Append (default_platform_sp, true);
661 m_collection_sp->Initialize (g_properties);
662 m_collection_sp->AppendProperty (ConstString("target"),
663 ConstString("Settings specify to debugging targets."),
665 Target::GetGlobalProperties()->GetValueProperties());
666 if (m_command_interpreter_ap.get())
668 m_collection_sp->AppendProperty (ConstString("interpreter"),
669 ConstString("Settings specify to the debugger's command interpreter."),
671 m_command_interpreter_ap->GetValueProperties());
673 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
674 term_width->SetMinimumValue(10);
675 term_width->SetMaximumValue(1024);
677 // Turn off use-color if this is a dumb terminal.
678 const char *term = getenv ("TERM");
679 if (term && !strcmp (term, "dumb"))
683 Debugger::~Debugger ()
691 CleanUpInputReaders();
693 int num_targets = m_target_list.GetNumTargets();
694 for (int i = 0; i < num_targets; i++)
696 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
699 ProcessSP process_sp (target_sp->GetProcessSP());
701 process_sp->Finalize();
702 target_sp->Destroy();
705 BroadcasterManager::Clear ();
707 // Close the input file _before_ we close the input read communications class
708 // as it does NOT own the input file, our m_input_file does.
709 m_terminal_state.Clear();
710 GetInputFile().Close ();
711 // Now that we have closed m_input_file, we can now tell our input communication
712 // class to close down. Its read thread should quickly exit after we close
713 // the input file handle above.
714 m_input_comm.Clear ();
718 Debugger::GetCloseInputOnEOF () const
720 return m_input_comm.GetCloseOnEOF();
724 Debugger::SetCloseInputOnEOF (bool b)
726 m_input_comm.SetCloseOnEOF(b);
730 Debugger::GetAsyncExecution ()
732 return !m_command_interpreter_ap->GetSynchronous();
736 Debugger::SetAsyncExecution (bool async_execution)
738 m_command_interpreter_ap->SetSynchronous (!async_execution);
743 Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
745 File &in_file = GetInputFile();
746 in_file.SetStream (fh, tranfer_ownership);
747 if (in_file.IsValid() == false)
748 in_file.SetStream (stdin, true);
750 // Disconnect from any old connection if we had one
751 m_input_comm.Disconnect ();
752 // Pass false as the second argument to ConnectionFileDescriptor below because
753 // our "in_file" above will already take ownership if requested and we don't
754 // want to objects trying to own and close a file descriptor.
755 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
756 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
758 // Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
759 SaveInputTerminalState ();
762 if (m_input_comm.StartReadThread (&error) == false)
764 File &err_file = GetErrorFile();
766 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
772 Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
774 File &out_file = GetOutputFile();
775 out_file.SetStream (fh, tranfer_ownership);
776 if (out_file.IsValid() == false)
777 out_file.SetStream (stdout, false);
779 // do not create the ScriptInterpreter just for setting the output file handle
780 // as the constructor will know how to do the right thing on its own
781 const bool can_create = false;
782 ScriptInterpreter* script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create);
783 if (script_interpreter)
784 script_interpreter->ResetOutputFileHandle (fh);
788 Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
790 File &err_file = GetErrorFile();
791 err_file.SetStream (fh, tranfer_ownership);
792 if (err_file.IsValid() == false)
793 err_file.SetStream (stderr, false);
797 Debugger::SaveInputTerminalState ()
799 File &in_file = GetInputFile();
800 if (in_file.GetDescriptor() != File::kInvalidDescriptor)
801 m_terminal_state.Save(in_file.GetDescriptor(), true);
805 Debugger::RestoreInputTerminalState ()
807 m_terminal_state.Restore();
811 Debugger::GetSelectedExecutionContext ()
813 ExecutionContext exe_ctx;
814 TargetSP target_sp(GetSelectedTarget());
815 exe_ctx.SetTargetSP (target_sp);
819 ProcessSP process_sp (target_sp->GetProcessSP());
820 exe_ctx.SetProcessSP (process_sp);
821 if (process_sp && process_sp->IsRunning() == false)
823 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
826 exe_ctx.SetThreadSP (thread_sp);
827 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
828 if (exe_ctx.GetFramePtr() == NULL)
829 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
837 Debugger::GetCurrentInputReader ()
839 InputReaderSP reader_sp;
841 if (!m_input_reader_stack.IsEmpty())
843 // Clear any finished readers from the stack
844 while (CheckIfTopInputReaderIsDone()) ;
846 if (!m_input_reader_stack.IsEmpty())
847 reader_sp = m_input_reader_stack.Top();
854 Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
857 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
859 ((Debugger *)baton)->DispatchInputEndOfFile ();
864 Debugger::DispatchInput (const char *bytes, size_t bytes_len)
866 if (bytes == NULL || bytes_len == 0)
869 WriteToDefaultReader (bytes, bytes_len);
873 Debugger::DispatchInputInterrupt ()
875 m_input_reader_data.clear();
877 InputReaderSP reader_sp (GetCurrentInputReader ());
880 reader_sp->Notify (eInputReaderInterrupt);
882 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
883 while (CheckIfTopInputReaderIsDone ()) ;
888 Debugger::DispatchInputEndOfFile ()
890 m_input_reader_data.clear();
892 InputReaderSP reader_sp (GetCurrentInputReader ());
895 reader_sp->Notify (eInputReaderEndOfFile);
897 // If notifying the reader of the end-of-file finished the reader, we should pop it off the stack.
898 while (CheckIfTopInputReaderIsDone ()) ;
903 Debugger::CleanUpInputReaders ()
905 m_input_reader_data.clear();
907 // The bottom input reader should be the main debugger input reader. We do not want to close that one here.
908 while (m_input_reader_stack.GetSize() > 1)
910 InputReaderSP reader_sp (GetCurrentInputReader ());
913 reader_sp->Notify (eInputReaderEndOfFile);
914 reader_sp->SetIsDone (true);
920 Debugger::NotifyTopInputReader (InputReaderAction notification)
922 InputReaderSP reader_sp (GetCurrentInputReader());
925 reader_sp->Notify (notification);
927 // Flush out any input readers that are done.
928 while (CheckIfTopInputReaderIsDone ())
934 Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
936 InputReaderSP top_reader_sp (GetCurrentInputReader());
938 return (reader_sp.get() == top_reader_sp.get());
943 Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
945 if (bytes && bytes_len)
946 m_input_reader_data.append (bytes, bytes_len);
948 if (m_input_reader_data.empty())
951 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
953 // Get the input reader from the top of the stack
954 InputReaderSP reader_sp (GetCurrentInputReader ());
958 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
959 m_input_reader_data.size());
962 m_input_reader_data.erase (0, bytes_handled);
966 // No bytes were handled, we might not have reached our
967 // granularity, just return and wait for more data
972 // Flush out any input readers that are done.
973 while (CheckIfTopInputReaderIsDone ())
979 Debugger::PushInputReader (const InputReaderSP& reader_sp)
984 // Deactivate the old top reader
985 InputReaderSP top_reader_sp (GetCurrentInputReader ());
988 top_reader_sp->Notify (eInputReaderDeactivate);
990 m_input_reader_stack.Push (reader_sp);
991 reader_sp->Notify (eInputReaderActivate);
992 ActivateInputReader (reader_sp);
996 Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
1000 // The reader on the stop of the stack is done, so let the next
1001 // read on the stack referesh its prompt and if there is one...
1002 if (!m_input_reader_stack.IsEmpty())
1004 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
1005 InputReaderSP reader_sp(m_input_reader_stack.Top());
1007 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
1009 m_input_reader_stack.Pop ();
1010 reader_sp->Notify (eInputReaderDeactivate);
1011 reader_sp->Notify (eInputReaderDone);
1014 if (!m_input_reader_stack.IsEmpty())
1016 reader_sp = m_input_reader_stack.Top();
1019 ActivateInputReader (reader_sp);
1020 reader_sp->Notify (eInputReaderReactivate);
1029 Debugger::CheckIfTopInputReaderIsDone ()
1031 bool result = false;
1032 if (!m_input_reader_stack.IsEmpty())
1034 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
1035 InputReaderSP reader_sp(m_input_reader_stack.Top());
1037 if (reader_sp && reader_sp->IsDone())
1040 PopInputReader (reader_sp);
1047 Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
1049 int input_fd = m_input_file.GetFile().GetDescriptor();
1053 Terminal tty(input_fd);
1055 tty.SetEcho(reader_sp->GetEcho());
1057 switch (reader_sp->GetGranularity())
1059 case eInputReaderGranularityByte:
1060 case eInputReaderGranularityWord:
1061 tty.SetCanonical (false);
1064 case eInputReaderGranularityLine:
1065 case eInputReaderGranularityAll:
1066 tty.SetCanonical (true);
1076 Debugger::GetAsyncOutputStream ()
1078 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1079 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
1083 Debugger::GetAsyncErrorStream ()
1085 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
1086 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
1090 Debugger::GetNumDebuggers()
1092 if (g_shared_debugger_refcount > 0)
1094 Mutex::Locker locker (GetDebuggerListMutex ());
1095 return GetDebuggerList().size();
1101 Debugger::GetDebuggerAtIndex (size_t index)
1103 DebuggerSP debugger_sp;
1105 if (g_shared_debugger_refcount > 0)
1107 Mutex::Locker locker (GetDebuggerListMutex ());
1108 DebuggerList &debugger_list = GetDebuggerList();
1110 if (index < debugger_list.size())
1111 debugger_sp = debugger_list[index];
1118 Debugger::FindDebuggerWithID (lldb::user_id_t id)
1120 DebuggerSP debugger_sp;
1122 if (g_shared_debugger_refcount > 0)
1124 Mutex::Locker locker (GetDebuggerListMutex ());
1125 DebuggerList &debugger_list = GetDebuggerList();
1126 DebuggerList::iterator pos, end = debugger_list.end();
1127 for (pos = debugger_list.begin(); pos != end; ++pos)
1129 if ((*pos).get()->GetID() == id)
1140 TestPromptFormats (StackFrame *frame)
1146 const char *prompt_format =
1147 "{addr = '${addr}'\n}"
1148 "{process.id = '${process.id}'\n}"
1149 "{process.name = '${process.name}'\n}"
1150 "{process.file.basename = '${process.file.basename}'\n}"
1151 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1152 "{thread.id = '${thread.id}'\n}"
1153 "{thread.index = '${thread.index}'\n}"
1154 "{thread.name = '${thread.name}'\n}"
1155 "{thread.queue = '${thread.queue}'\n}"
1156 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1157 "{target.arch = '${target.arch}'\n}"
1158 "{module.file.basename = '${module.file.basename}'\n}"
1159 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1160 "{file.basename = '${file.basename}'\n}"
1161 "{file.fullpath = '${file.fullpath}'\n}"
1162 "{frame.index = '${frame.index}'\n}"
1163 "{frame.pc = '${frame.pc}'\n}"
1164 "{frame.sp = '${frame.sp}'\n}"
1165 "{frame.fp = '${frame.fp}'\n}"
1166 "{frame.flags = '${frame.flags}'\n}"
1167 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1168 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1169 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1170 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1171 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1172 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1173 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1174 "{function.id = '${function.id}'\n}"
1175 "{function.name = '${function.name}'\n}"
1176 "{function.name-with-args = '${function.name-with-args}'\n}"
1177 "{function.addr-offset = '${function.addr-offset}'\n}"
1178 "{function.line-offset = '${function.line-offset}'\n}"
1179 "{function.pc-offset = '${function.pc-offset}'\n}"
1180 "{line.file.basename = '${line.file.basename}'\n}"
1181 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1182 "{line.number = '${line.number}'\n}"
1183 "{line.start-addr = '${line.start-addr}'\n}"
1184 "{line.end-addr = '${line.end-addr}'\n}"
1187 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1188 ExecutionContext exe_ctx;
1189 frame->CalculateExecutionContext(exe_ctx);
1190 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s))
1192 printf("%s\n", s.GetData());
1196 printf ("what we got: %s\n", s.GetData());
1201 ScanFormatDescriptor (const char* var_name_begin,
1202 const char* var_name_end,
1203 const char** var_name_final,
1204 const char** percent_position,
1205 Format* custom_format,
1206 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
1208 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
1209 *percent_position = ::strchr(var_name_begin,'%');
1210 if (!*percent_position || *percent_position > var_name_end)
1213 log->Printf("[ScanFormatDescriptor] no format descriptor in string, skipping");
1214 *var_name_final = var_name_end;
1218 *var_name_final = *percent_position;
1219 std::string format_name(*var_name_final+1, var_name_end-*var_name_final-1);
1221 log->Printf("[ScanFormatDescriptor] parsing %s as a format descriptor", format_name.c_str());
1222 if ( !FormatManager::GetFormatFromCString(format_name.c_str(),
1227 log->Printf("[ScanFormatDescriptor] %s is an unknown format", format_name.c_str());
1229 switch (format_name.front())
1231 case '@': // if this is an @ sign, print ObjC description
1232 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLanguageSpecific;
1234 case 'V': // if this is a V, print the value using the default format
1235 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
1237 case 'L': // if this is an L, print the location of the value
1238 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLocation;
1240 case 'S': // if this is an S, print the summary after all
1241 *val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
1243 case '#': // if this is a '#', print the number of children
1244 *val_obj_display = ValueObject::eValueObjectRepresentationStyleChildrenCount;
1246 case 'T': // if this is a 'T', print the type
1247 *val_obj_display = ValueObject::eValueObjectRepresentationStyleType;
1249 case 'N': // if this is a 'N', print the name
1250 *val_obj_display = ValueObject::eValueObjectRepresentationStyleName;
1252 case '>': // if this is a '>', print the name
1253 *val_obj_display = ValueObject::eValueObjectRepresentationStyleExpressionPath;
1257 log->Printf("ScanFormatDescriptor] %s is an error, leaving the previous value alone", format_name.c_str());
1261 // a good custom format tells us to print the value using it
1265 log->Printf("[ScanFormatDescriptor] will display value for this VO");
1266 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
1270 log->Printf("[ScanFormatDescriptor] final format description outcome: custom_format = %d, val_obj_display = %d",
1277 ScanBracketedRange (const char* var_name_begin,
1278 const char* var_name_end,
1279 const char* var_name_final,
1280 const char** open_bracket_position,
1281 const char** separator_position,
1282 const char** close_bracket_position,
1283 const char** var_name_final_if_array_range,
1284 int64_t* index_lower,
1285 int64_t* index_higher)
1287 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
1288 *open_bracket_position = ::strchr(var_name_begin,'[');
1289 if (*open_bracket_position && *open_bracket_position < var_name_final)
1291 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
1292 *close_bracket_position = ::strchr(*open_bracket_position,']');
1293 // as usual, we assume that [] will come before %
1294 //printf("trying to expand a []\n");
1295 *var_name_final_if_array_range = *open_bracket_position;
1296 if (*close_bracket_position - *open_bracket_position == 1)
1299 log->Printf("[ScanBracketedRange] '[]' detected.. going from 0 to end of data");
1302 else if (*separator_position == NULL || *separator_position > var_name_end)
1305 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
1306 *index_higher = *index_lower;
1308 log->Printf("[ScanBracketedRange] [%" PRId64 "] detected, high index is same", *index_lower);
1310 else if (*close_bracket_position && *close_bracket_position < var_name_end)
1313 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
1314 *index_higher = ::strtoul (*separator_position+1, &end, 0);
1316 log->Printf("[ScanBracketedRange] [%" PRId64 "-%" PRId64 "] detected", *index_lower, *index_higher);
1321 log->Printf("[ScanBracketedRange] expression is erroneous, cannot extract indices out of it");
1324 if (*index_lower > *index_higher && *index_higher > 0)
1327 log->Printf("[ScanBracketedRange] swapping indices");
1328 int64_t temp = *index_lower;
1329 *index_lower = *index_higher;
1330 *index_higher = temp;
1334 log->Printf("[ScanBracketedRange] no bracketed range, skipping entirely");
1338 template <typename T>
1339 static bool RunScriptFormatKeyword(Stream &s, ScriptInterpreter *script_interpreter, T t, const std::string& script_name)
1341 if (script_interpreter)
1344 std::string script_output;
1346 if (script_interpreter->RunScriptFormatKeyword(script_name.c_str(), t, script_output, script_error) && script_error.Success())
1348 s.Printf("%s", script_output.c_str());
1353 s.Printf("<error: %s>",script_error.AsCString());
1359 static ValueObjectSP
1360 ExpandIndexedExpression (ValueObject* valobj,
1365 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
1366 const char* ptr_deref_format = "[%d]";
1367 std::string ptr_deref_buffer(10,0);
1368 ::sprintf(&ptr_deref_buffer[0], ptr_deref_format, index);
1370 log->Printf("[ExpandIndexedExpression] name to deref: %s",ptr_deref_buffer.c_str());
1371 const char* first_unparsed;
1372 ValueObject::GetValueForExpressionPathOptions options;
1373 ValueObject::ExpressionPathEndResultType final_value_type;
1374 ValueObject::ExpressionPathScanEndReason reason_to_stop;
1375 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
1376 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.c_str(),
1385 log->Printf("[ExpandIndexedExpression] ERROR: unparsed portion = %s, why stopping = %d,"
1386 " final_value_type %d",
1387 first_unparsed, reason_to_stop, final_value_type);
1392 log->Printf("[ExpandIndexedExpression] ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1393 " final_value_type %d",
1394 first_unparsed, reason_to_stop, final_value_type);
1400 IsToken(const char *var_name_begin, const char *var)
1402 return (::strncmp (var_name_begin, var, strlen(var)) == 0);
1406 IsTokenWithFormat(const char *var_name_begin, const char *var, std::string &format, const char *default_format,
1407 const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1409 int var_len = strlen(var);
1410 if (::strncmp (var_name_begin, var, var_len) == 0)
1412 var_name_begin += var_len;
1413 if (*var_name_begin == '}')
1415 format = default_format;
1418 else if (*var_name_begin == '%')
1420 // Allow format specifiers: x|X|u with optional width specifiers.
1421 // ${thread.id%x} ; hex
1422 // ${thread.id%X} ; uppercase hex
1423 // ${thread.id%u} ; unsigned decimal
1424 // ${thread.id%8.8X} ; width.precision + specifier
1425 // ${thread.id%tid} ; unsigned on FreeBSD/Linux, otherwise default_format (0x%4.4x for thread.id)
1427 const char *specifier = NULL;
1428 int width_precision_length = 0;
1429 const char *width_precision = ++var_name_begin;
1430 while (isdigit(*var_name_begin) || *var_name_begin == '.')
1432 dot_count += (*var_name_begin == '.');
1436 width_precision_length++;
1439 if (IsToken (var_name_begin, "tid}"))
1441 Target *target = Target::GetTargetFromContexts (exe_ctx_ptr, sc_ptr);
1444 ArchSpec arch (target->GetArchitecture ());
1445 llvm::Triple::OSType ostype = arch.IsValid() ? arch.GetTriple().getOS() : llvm::Triple::UnknownOS;
1446 if ((ostype == llvm::Triple::FreeBSD) || (ostype == llvm::Triple::Linux))
1451 format = default_format;
1455 else if (IsToken (var_name_begin, "x}"))
1457 else if (IsToken (var_name_begin, "X}"))
1459 else if (IsToken (var_name_begin, "u}"))
1465 if (width_precision_length)
1466 format += std::string(width_precision, width_precision_length);
1467 format += specifier;
1479 const SymbolContext *sc,
1480 const ExecutionContext *exe_ctx,
1481 const Address *addr,
1487 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
1488 bool success = true;
1490 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
1492 for (p = format; *p != '\0'; ++p)
1496 valobj = realvalobj;
1499 size_t non_special_chars = ::strcspn (p, "${}\\");
1500 if (non_special_chars > 0)
1503 s.Write (p, non_special_chars);
1504 p += non_special_chars;
1513 // Start a new scope that must have everything it needs if it is to
1514 // to make it into the final output stream "s". If you want to make
1515 // a format that only prints out the function or symbol name if there
1516 // is one in the symbol context you can use:
1517 // "{function =${function.name}}"
1518 // The first '{' starts a new scope that end with the matching '}' at
1519 // the end of the string. The contents "function =${function.name}"
1520 // will then be evaluated and only be output if there is a function
1521 // or symbol with a valid name.
1522 StreamString sub_strm;
1524 ++p; // Skip the '{'
1526 if (FormatPromptRecurse (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
1528 // The stream had all it needed
1529 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1539 // End of a enclosing scope
1544 // We have a prompt variable to print
1549 const char *var_name_begin = p;
1550 const char *var_name_end = ::strchr (p, '}');
1552 if (var_name_end && var_name_begin < var_name_end)
1554 // if we have already failed to parse, skip this variable
1557 const char *cstr = NULL;
1558 std::string token_format;
1559 Address format_addr;
1560 bool calculate_format_addr_function_offset = false;
1561 // Set reg_kind and reg_num to invalid values
1562 RegisterKind reg_kind = kNumRegisterKinds;
1563 uint32_t reg_num = LLDB_INVALID_REGNUM;
1564 FileSpec format_file_spec;
1565 const RegisterInfo *reg_info = NULL;
1566 RegisterContext *reg_ctx = NULL;
1567 bool do_deref_pointer = false;
1568 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
1569 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain;
1571 // Each variable must set success to true below...
1572 bool var_success = false;
1573 switch (var_name_begin[0])
1583 log->Printf("[Debugger::FormatPrompt] initial string: %s",var_name_begin);
1585 // check for *var and *svar
1586 if (*var_name_begin == '*')
1588 do_deref_pointer = true;
1591 log->Printf("[Debugger::FormatPrompt] found a deref, new string is: %s",var_name_begin);
1594 if (*var_name_begin == 's')
1596 if (!valobj->IsSynthetic())
1597 valobj = valobj->GetSyntheticValue().get();
1602 log->Printf("[Debugger::FormatPrompt] found a synthetic, new string is: %s",var_name_begin);
1605 // should be a 'v' by now
1606 if (*var_name_begin != 'v')
1610 log->Printf("[Debugger::FormatPrompt] string I am working with: %s",var_name_begin);
1612 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
1613 ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
1614 ValueObject::GetValueForExpressionPathOptions options;
1615 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
1616 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
1617 ValueObject* target = NULL;
1618 Format custom_format = eFormatInvalid;
1619 const char* var_name_final = NULL;
1620 const char* var_name_final_if_array_range = NULL;
1621 const char* close_bracket_position = NULL;
1622 int64_t index_lower = -1;
1623 int64_t index_higher = -1;
1624 bool is_array_range = false;
1625 const char* first_unparsed;
1626 bool was_plain_var = false;
1627 bool was_var_format = false;
1628 bool was_var_indexed = false;
1631 // simplest case ${var}, just print valobj's value
1632 if (IsToken (var_name_begin, "var}"))
1634 was_plain_var = true;
1636 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
1638 else if (IsToken (var_name_begin,"var%"))
1640 was_var_format = true;
1641 // this is a variable with some custom format applied to it
1642 const char* percent_position;
1644 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
1645 ScanFormatDescriptor (var_name_begin,
1652 // this is ${var.something} or multiple .something nested
1653 else if (IsToken (var_name_begin, "var"))
1655 if (IsToken (var_name_begin, "var["))
1656 was_var_indexed = true;
1657 const char* percent_position;
1658 ScanFormatDescriptor (var_name_begin,
1665 const char* open_bracket_position;
1666 const char* separator_position;
1667 ScanBracketedRange (var_name_begin,
1670 &open_bracket_position,
1671 &separator_position,
1672 &close_bracket_position,
1673 &var_name_final_if_array_range,
1679 std::string expr_path(var_name_final-var_name_begin-1,0);
1680 memcpy(&expr_path[0], var_name_begin+3,var_name_final-var_name_begin-3);
1683 log->Printf("[Debugger::FormatPrompt] symbol to expand: %s",expr_path.c_str());
1685 target = valobj->GetValueForExpressionPath(expr_path.c_str(),
1695 log->Printf("[Debugger::FormatPrompt] ERROR: unparsed portion = %s, why stopping = %d,"
1696 " final_value_type %d",
1697 first_unparsed, reason_to_stop, final_value_type);
1703 log->Printf("[Debugger::FormatPrompt] ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1704 " final_value_type %d",
1705 first_unparsed, reason_to_stop, final_value_type);
1711 is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange ||
1712 final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange);
1714 do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference);
1716 if (do_deref_pointer && !is_array_range)
1718 // I have not deref-ed yet, let's do it
1719 // this happens when we are not going through GetValueForVariableExpressionPath
1720 // to get to the target ValueObject
1722 target = target->Dereference(error).get();
1726 log->Printf("[Debugger::FormatPrompt] ERROR: %s\n", error.AsCString("unknown")); \
1729 do_deref_pointer = false;
1732 // we do not want to use the summary for a bitfield of type T:n
1733 // if we were originally dealing with just a T - that would get
1734 // us into an endless recursion
1735 if (target->IsBitfield() && was_var_indexed)
1737 // TODO: check for a (T:n)-specific summary - we should still obey that
1738 StreamString bitfield_name;
1739 bitfield_name.Printf("%s:%d", target->GetTypeName().AsCString(), target->GetBitfieldBitSize());
1740 lldb::TypeNameSpecifierImplSP type_sp(new TypeNameSpecifierImpl(bitfield_name.GetData(),false));
1741 if (!DataVisualization::GetSummaryForType(type_sp))
1742 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
1745 // TODO use flags for these
1746 const uint32_t type_info_flags = target->GetClangType().GetTypeInfo(NULL);
1747 bool is_array = (type_info_flags & ClangASTType::eTypeIsArray) != 0;
1748 bool is_pointer = (type_info_flags & ClangASTType::eTypeIsPointer) != 0;
1749 bool is_aggregate = target->GetClangType().IsAggregateType();
1751 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) // this should be wrong, but there are some exceptions
1753 StreamString str_temp;
1755 log->Printf("[Debugger::FormatPrompt] I am into array || pointer && !range");
1757 if (target->HasSpecialPrintableRepresentation(val_obj_display, custom_format))
1759 // try to use the special cases
1760 var_success = target->DumpPrintableRepresentation(str_temp,
1764 log->Printf("[Debugger::FormatPrompt] special cases did%s match", var_success ? "" : "n't");
1766 // should not happen
1768 s << str_temp.GetData();
1774 if (was_plain_var) // if ${var}
1776 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1778 else if (is_pointer) // if pointer, value is the address stored
1780 target->DumpPrintableRepresentation (s,
1783 ValueObject::ePrintableRepresentationSpecialCasesDisable);
1790 // if directly trying to print ${var}, and this is an aggregate, display a nice
1791 // type @ location message
1792 if (is_aggregate && was_plain_var)
1794 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1799 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
1800 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)))
1802 s << "<invalid use of aggregate type>";
1807 if (!is_array_range)
1810 log->Printf("[Debugger::FormatPrompt] dumping ordinary printable output");
1811 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1816 log->Printf("[Debugger::FormatPrompt] checking if I can handle as array");
1817 if (!is_array && !is_pointer)
1820 log->Printf("[Debugger::FormatPrompt] handle as array");
1821 const char* special_directions = NULL;
1822 StreamString special_directions_writer;
1823 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1825 ConstString additional_data;
1826 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1827 special_directions_writer.Printf("${%svar%s}",
1828 do_deref_pointer ? "*" : "",
1829 additional_data.GetCString());
1830 special_directions = special_directions_writer.GetData();
1833 // let us display items index_lower thru index_higher of this array
1837 if (index_higher < 0)
1838 index_higher = valobj->GetNumChildren() - 1;
1840 uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1842 for (;index_lower<=index_higher;index_lower++)
1844 ValueObject* item = ExpandIndexedExpression (target,
1846 exe_ctx->GetFramePtr(),
1852 log->Printf("[Debugger::FormatPrompt] ERROR in getting child item at index %" PRId64, index_lower);
1857 log->Printf("[Debugger::FormatPrompt] special_directions for child item: %s",special_directions);
1860 if (!special_directions)
1861 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1863 var_success &= FormatPromptRecurse(special_directions, sc, exe_ctx, addr, s, NULL, item);
1865 if (--max_num_children == 0)
1867 s.PutCString(", ...");
1871 if (index_lower < index_higher)
1879 if (IsToken (var_name_begin, "addr}"))
1881 if (addr && addr->IsValid())
1884 format_addr = *addr;
1890 if (IsToken (var_name_begin, "process."))
1894 Process *process = exe_ctx->GetProcessPtr();
1897 var_name_begin += ::strlen ("process.");
1898 if (IsTokenWithFormat (var_name_begin, "id", token_format, "%" PRIu64, exe_ctx, sc))
1900 s.Printf(token_format.c_str(), process->GetID());
1903 else if ((IsToken (var_name_begin, "name}")) ||
1904 (IsToken (var_name_begin, "file.basename}")) ||
1905 (IsToken (var_name_begin, "file.fullpath}")))
1907 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1910 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1912 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1913 var_success = (bool)format_file_spec;
1917 format_file_spec = exe_module->GetFileSpec();
1918 var_success = (bool)format_file_spec;
1922 else if (IsToken (var_name_begin, "script:"))
1924 var_name_begin += ::strlen("script:");
1925 std::string script_name(var_name_begin,var_name_end);
1926 ScriptInterpreter* script_interpreter = process->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
1927 if (RunScriptFormatKeyword (s, script_interpreter, process, script_name))
1936 if (IsToken (var_name_begin, "thread."))
1940 Thread *thread = exe_ctx->GetThreadPtr();
1943 var_name_begin += ::strlen ("thread.");
1944 if (IsTokenWithFormat (var_name_begin, "id", token_format, "0x%4.4" PRIx64, exe_ctx, sc))
1946 s.Printf(token_format.c_str(), thread->GetID());
1949 else if (IsTokenWithFormat (var_name_begin, "protocol_id", token_format, "0x%4.4" PRIx64, exe_ctx, sc))
1951 s.Printf(token_format.c_str(), thread->GetProtocolID());
1954 else if (IsTokenWithFormat (var_name_begin, "index", token_format, "%" PRIu64, exe_ctx, sc))
1956 s.Printf(token_format.c_str(), (uint64_t)thread->GetIndexID());
1959 else if (IsToken (var_name_begin, "name}"))
1961 cstr = thread->GetName();
1962 var_success = cstr && cstr[0];
1966 else if (IsToken (var_name_begin, "queue}"))
1968 cstr = thread->GetQueueName();
1969 var_success = cstr && cstr[0];
1973 else if (IsToken (var_name_begin, "stop-reason}"))
1975 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1976 if (stop_info_sp && stop_info_sp->IsValid())
1978 cstr = stop_info_sp->GetDescription();
1979 if (cstr && cstr[0])
1986 else if (IsToken (var_name_begin, "return-value}"))
1988 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1989 if (stop_info_sp && stop_info_sp->IsValid())
1991 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1992 if (return_valobj_sp)
1994 return_valobj_sp->Dump(s);
1999 else if (IsToken (var_name_begin, "script:"))
2001 var_name_begin += ::strlen("script:");
2002 std::string script_name(var_name_begin,var_name_end);
2003 ScriptInterpreter* script_interpreter = thread->GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
2004 if (RunScriptFormatKeyword (s, script_interpreter, thread, script_name))
2010 else if (IsToken (var_name_begin, "target."))
2012 // TODO: hookup properties
2013 // if (!target_properties_sp)
2015 // Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2017 // target_properties_sp = target->GetProperties();
2020 // if (target_properties_sp)
2022 // var_name_begin += ::strlen ("target.");
2023 // const char *end_property = strchr(var_name_begin, '}');
2024 // if (end_property)
2026 // ConstString property_name(var_name_begin, end_property - var_name_begin);
2027 // std::string property_value (target_properties_sp->GetPropertyValue(property_name));
2028 // if (!property_value.empty())
2030 // s.PutCString (property_value.c_str());
2031 // var_success = true;
2035 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2038 var_name_begin += ::strlen ("target.");
2039 if (IsToken (var_name_begin, "arch}"))
2041 ArchSpec arch (target->GetArchitecture ());
2044 s.PutCString (arch.GetArchitectureName());
2048 else if (IsToken (var_name_begin, "script:"))
2050 var_name_begin += ::strlen("script:");
2051 std::string script_name(var_name_begin,var_name_end);
2052 ScriptInterpreter* script_interpreter = target->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
2053 if (RunScriptFormatKeyword (s, script_interpreter, target, script_name))
2062 if (IsToken (var_name_begin, "module."))
2064 if (sc && sc->module_sp.get())
2066 Module *module = sc->module_sp.get();
2067 var_name_begin += ::strlen ("module.");
2069 if (IsToken (var_name_begin, "file."))
2071 if (module->GetFileSpec())
2073 var_name_begin += ::strlen ("file.");
2075 if (IsToken (var_name_begin, "basename}"))
2077 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
2078 var_success = (bool)format_file_spec;
2080 else if (IsToken (var_name_begin, "fullpath}"))
2082 format_file_spec = module->GetFileSpec();
2083 var_success = (bool)format_file_spec;
2093 if (IsToken (var_name_begin, "file."))
2095 if (sc && sc->comp_unit != NULL)
2097 var_name_begin += ::strlen ("file.");
2099 if (IsToken (var_name_begin, "basename}"))
2101 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
2102 var_success = (bool)format_file_spec;
2104 else if (IsToken (var_name_begin, "fullpath}"))
2106 format_file_spec = *sc->comp_unit;
2107 var_success = (bool)format_file_spec;
2111 else if (IsToken (var_name_begin, "frame."))
2115 StackFrame *frame = exe_ctx->GetFramePtr();
2118 var_name_begin += ::strlen ("frame.");
2119 if (IsToken (var_name_begin, "index}"))
2121 s.Printf("%u", frame->GetFrameIndex());
2124 else if (IsToken (var_name_begin, "pc}"))
2126 reg_kind = eRegisterKindGeneric;
2127 reg_num = LLDB_REGNUM_GENERIC_PC;
2130 else if (IsToken (var_name_begin, "sp}"))
2132 reg_kind = eRegisterKindGeneric;
2133 reg_num = LLDB_REGNUM_GENERIC_SP;
2136 else if (IsToken (var_name_begin, "fp}"))
2138 reg_kind = eRegisterKindGeneric;
2139 reg_num = LLDB_REGNUM_GENERIC_FP;
2142 else if (IsToken (var_name_begin, "flags}"))
2144 reg_kind = eRegisterKindGeneric;
2145 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
2148 else if (IsToken (var_name_begin, "reg."))
2150 reg_ctx = frame->GetRegisterContext().get();
2153 var_name_begin += ::strlen ("reg.");
2154 if (var_name_begin < var_name_end)
2156 std::string reg_name (var_name_begin, var_name_end);
2157 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
2163 else if (IsToken (var_name_begin, "script:"))
2165 var_name_begin += ::strlen("script:");
2166 std::string script_name(var_name_begin,var_name_end);
2167 ScriptInterpreter* script_interpreter = frame->GetThread()->GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
2168 if (RunScriptFormatKeyword (s, script_interpreter, frame, script_name))
2174 else if (IsToken (var_name_begin, "function."))
2176 if (sc && (sc->function != NULL || sc->symbol != NULL))
2178 var_name_begin += ::strlen ("function.");
2179 if (IsToken (var_name_begin, "id}"))
2182 s.Printf("function{0x%8.8" PRIx64 "}", sc->function->GetID());
2184 s.Printf("symbol[%u]", sc->symbol->GetID());
2188 else if (IsToken (var_name_begin, "name}"))
2191 cstr = sc->function->GetName().AsCString (NULL);
2192 else if (sc->symbol)
2193 cstr = sc->symbol->GetName().AsCString (NULL);
2200 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2203 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
2206 s.PutCString(" [inlined] ");
2207 inline_info->GetName().Dump(&s);
2214 else if (IsToken (var_name_begin, "name-with-args}"))
2216 // Print the function name with arguments in it
2221 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
2222 cstr = sc->function->GetName().AsCString (NULL);
2225 const InlineFunctionInfo *inline_info = NULL;
2226 VariableListSP variable_list_sp;
2227 bool get_function_vars = true;
2230 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2234 get_function_vars = false;
2235 inline_info = sc->block->GetInlinedFunctionInfo();
2237 variable_list_sp = inline_block->GetBlockVariableList (true);
2241 if (get_function_vars)
2243 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
2248 s.PutCString (cstr);
2249 s.PutCString (" [inlined] ");
2250 cstr = inline_info->GetName().GetCString();
2254 if (variable_list_sp)
2255 variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument, args);
2256 if (args.GetSize() > 0)
2258 const char *open_paren = strchr (cstr, '(');
2259 const char *close_paren = NULL;
2262 if (IsToken (open_paren, "(anonymous namespace)"))
2264 open_paren = strchr (open_paren + strlen("(anonymous namespace)"), '(');
2266 close_paren = strchr (open_paren, ')');
2269 close_paren = strchr (open_paren, ')');
2273 s.Write(cstr, open_paren - cstr + 1);
2276 s.PutCString (cstr);
2279 const size_t num_args = args.GetSize();
2280 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
2282 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
2283 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
2284 const char *var_name = var_value_sp->GetName().GetCString();
2285 const char *var_value = var_value_sp->GetValueAsCString();
2287 s.PutCString (", ");
2288 if (var_value_sp->GetError().Success())
2291 s.Printf ("%s=%s", var_name, var_value);
2293 s.Printf ("%s=%s at %s", var_name, var_value_sp->GetTypeName().GetCString(), var_value_sp->GetLocationAsCString());
2296 s.Printf ("%s=<unavailable>", var_name);
2300 s.PutCString (close_paren);
2311 else if (sc->symbol)
2313 cstr = sc->symbol->GetName().AsCString (NULL);
2321 else if (IsToken (var_name_begin, "addr-offset}"))
2323 var_success = addr != NULL;
2326 format_addr = *addr;
2327 calculate_format_addr_function_offset = true;
2330 else if (IsToken (var_name_begin, "line-offset}"))
2332 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2335 format_addr = sc->line_entry.range.GetBaseAddress();
2336 calculate_format_addr_function_offset = true;
2339 else if (IsToken (var_name_begin, "pc-offset}"))
2341 StackFrame *frame = exe_ctx->GetFramePtr();
2342 var_success = frame != NULL;
2345 format_addr = frame->GetFrameCodeAddress();
2346 calculate_format_addr_function_offset = true;
2354 if (IsToken (var_name_begin, "line."))
2356 if (sc && sc->line_entry.IsValid())
2358 var_name_begin += ::strlen ("line.");
2359 if (IsToken (var_name_begin, "file."))
2361 var_name_begin += ::strlen ("file.");
2363 if (IsToken (var_name_begin, "basename}"))
2365 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2366 var_success = (bool)format_file_spec;
2368 else if (IsToken (var_name_begin, "fullpath}"))
2370 format_file_spec = sc->line_entry.file;
2371 var_success = (bool)format_file_spec;
2374 else if (IsTokenWithFormat (var_name_begin, "number", token_format, "%" PRIu64, exe_ctx, sc))
2377 s.Printf(token_format.c_str(), (uint64_t)sc->line_entry.line);
2379 else if ((IsToken (var_name_begin, "start-addr}")) ||
2380 (IsToken (var_name_begin, "end-addr}")))
2382 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2385 format_addr = sc->line_entry.range.GetBaseAddress();
2386 if (var_name_begin[0] == 'e')
2387 format_addr.Slide (sc->line_entry.range.GetByteSize());
2397 // If format addr is valid, then we need to print an address
2398 if (reg_num != LLDB_INVALID_REGNUM)
2400 StackFrame *frame = exe_ctx->GetFramePtr();
2401 // We have a register value to display...
2402 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2404 format_addr = frame->GetFrameCodeAddress();
2408 if (reg_ctx == NULL)
2409 reg_ctx = frame->GetRegisterContext().get();
2413 if (reg_kind != kNumRegisterKinds)
2414 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2415 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2416 var_success = reg_info != NULL;
2421 if (reg_info != NULL)
2423 RegisterValue reg_value;
2424 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2427 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
2431 if (format_file_spec)
2433 s << format_file_spec;
2436 // If format addr is valid, then we need to print an address
2437 if (format_addr.IsValid())
2439 var_success = false;
2441 if (calculate_format_addr_function_offset)
2449 func_addr = sc->function->GetAddressRange().GetBaseAddress();
2452 // Check to make sure we aren't in an inline
2453 // function. If we are, use the inline block
2454 // range that contains "format_addr" since
2455 // blocks can be discontiguous.
2456 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2457 AddressRange inline_range;
2458 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2459 func_addr = inline_range.GetBaseAddress();
2462 else if (sc->symbol && sc->symbol->ValueIsAddress())
2463 func_addr = sc->symbol->GetAddress();
2466 if (func_addr.IsValid())
2468 if (func_addr.GetSection() == format_addr.GetSection())
2470 addr_t func_file_addr = func_addr.GetFileAddress();
2471 addr_t addr_file_addr = format_addr.GetFileAddress();
2472 if (addr_file_addr > func_file_addr)
2473 s.Printf(" + %" PRIu64, addr_file_addr - func_file_addr);
2474 else if (addr_file_addr < func_file_addr)
2475 s.Printf(" - %" PRIu64, func_file_addr - addr_file_addr);
2480 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2483 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2484 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2485 if (addr_load_addr > func_load_addr)
2486 s.Printf(" + %" PRIu64, addr_load_addr - func_load_addr);
2487 else if (addr_load_addr < func_load_addr)
2488 s.Printf(" - %" PRIu64, func_load_addr - addr_load_addr);
2496 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2497 addr_t vaddr = LLDB_INVALID_ADDRESS;
2498 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2499 vaddr = format_addr.GetLoadAddress (target);
2500 if (vaddr == LLDB_INVALID_ADDRESS)
2501 vaddr = format_addr.GetFileAddress ();
2503 if (vaddr != LLDB_INVALID_ADDRESS)
2505 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
2506 if (addr_width == 0)
2508 s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr);
2515 if (var_success == false)
2525 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2529 else if (*p == '\\')
2531 ++p; // skip the slash
2534 case 'a': s.PutChar ('\a'); break;
2535 case 'b': s.PutChar ('\b'); break;
2536 case 'f': s.PutChar ('\f'); break;
2537 case 'n': s.PutChar ('\n'); break;
2538 case 'r': s.PutChar ('\r'); break;
2539 case 't': s.PutChar ('\t'); break;
2540 case 'v': s.PutChar ('\v'); break;
2541 case '\'': s.PutChar ('\''); break;
2542 case '\\': s.PutChar ('\\'); break;
2544 // 1 to 3 octal chars
2546 // Make a string that can hold onto the initial zero char,
2547 // up to 3 octal digits, and a terminating NULL.
2548 char oct_str[5] = { 0, 0, 0, 0, 0 };
2551 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2554 // We don't want to consume the last octal character since
2555 // the main for loop will do this for us, so we advance p by
2556 // one less than i (even if i is zero)
2558 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2559 if (octal_value <= UINT8_MAX)
2561 s.PutChar((char)octal_value);
2567 // hex number in the format
2570 ++p; // Skip the 'x'
2572 // Make a string that can hold onto two hex chars plus a
2574 char hex_str[3] = { 0,0,0 };
2578 ++p; // Skip the first of the two hex chars
2582 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2583 if (hex_value <= UINT8_MAX)
2584 s.PutChar ((char)hex_value);
2593 // Just desensitize any other character by just printing what
2594 // came after the '\'
2608 Debugger::FormatPrompt
2611 const SymbolContext *sc,
2612 const ExecutionContext *exe_ctx,
2613 const Address *addr,
2618 bool use_color = exe_ctx ? exe_ctx->GetTargetRef().GetDebugger().GetUseColor() : true;
2619 std::string format_str = lldb_utility::ansi::FormatAnsiTerminalCodes (format, use_color);
2620 if (format_str.length())
2621 format = format_str.c_str();
2622 return FormatPromptRecurse (format, sc, exe_ctx, addr, s, NULL, valobj);
2626 Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
2628 // For simplicity's sake, I am not going to deal with how to close down any
2629 // open logging streams, I just redirect everything from here on out to the
2631 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
2635 Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
2637 Log::Callbacks log_callbacks;
2639 StreamSP log_stream_sp;
2640 if (m_log_callback_stream_sp)
2642 log_stream_sp = m_log_callback_stream_sp;
2643 // For now when using the callback mode you always get thread & timestamp.
2644 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
2646 else if (log_file == NULL || *log_file == '\0')
2648 log_stream_sp.reset(new StreamFile(GetOutputFile().GetDescriptor(), false));
2652 LogStreamMap::iterator pos = m_log_streams.find(log_file);
2653 if (pos != m_log_streams.end())
2654 log_stream_sp = pos->second.lock();
2657 log_stream_sp.reset (new StreamFile (log_file));
2658 m_log_streams[log_file] = log_stream_sp;
2661 assert (log_stream_sp.get());
2663 if (log_options == 0)
2664 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
2666 if (Log::GetLogChannelCallbacks (ConstString(channel), log_callbacks))
2668 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
2673 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
2676 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
2682 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2688 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2696 Debugger::GetSourceManager ()
2698 if (m_source_manager_ap.get() == NULL)
2699 m_source_manager_ap.reset (new SourceManager (shared_from_this()));
2700 return *m_source_manager_ap;