From 592afe73ada21856f908a42486378b2860037ebd Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Tue, 15 Mar 2016 21:50:51 +0000 Subject: [PATCH] Improve the 'type lookup' command such that it guesses to use the current's frame language as the one to start searching from. llvm-svn: 263592 --- lldb/include/lldb/Target/StackFrame.h | 5 +++++ lldb/source/Commands/CommandObjectType.cpp | 29 ++++++++++++++++++++++++++++- lldb/source/Target/StackFrame.cpp | 20 +++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Target/StackFrame.h b/lldb/include/lldb/Target/StackFrame.h index b65b018..f021cba 100644 --- a/lldb/include/lldb/Target/StackFrame.h +++ b/lldb/include/lldb/Target/StackFrame.h @@ -478,6 +478,11 @@ public: lldb::LanguageType GetLanguage (); + // similar to GetLanguage(), but is allowed to take a potentially incorrect guess + // if exact information is not available + lldb::LanguageType + GuessLanguage (); + //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 971506b..f291f11 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -11,6 +11,7 @@ // C Includes // C++ Includes +#include #include #include @@ -3344,7 +3345,9 @@ public: std::vector languages; - if (m_command_options.m_language == eLanguageTypeUnknown) + bool is_global_search = false; + + if ( (is_global_search = (m_command_options.m_language == eLanguageTypeUnknown)) ) { // FIXME: hardcoding languages is not good languages.push_back(Language::FindPlugin(eLanguageTypeObjC)); @@ -3355,6 +3358,27 @@ public: languages.push_back(Language::FindPlugin(m_command_options.m_language)); } + // This is not the most efficient way to do this, but we support very few languages + // so the cost of the sort is going to be dwarfed by the actual lookup anyway + if (StackFrame* frame = m_exe_ctx.GetFramePtr()) + { + LanguageType lang = frame->GuessLanguage(); + if (lang != eLanguageTypeUnknown) + { + std::sort(languages.begin(), + languages.end(), + [lang] (Language* lang1, + Language* lang2) -> bool { + if (!lang1 || !lang2) return false; + LanguageType lt1 = lang1->GetLanguageType(); + LanguageType lt2 = lang2->GetLanguageType(); + if (lt1 == lang) return true; // make the selected frame's language come first + if (lt2 == lang) return false; // make the selected frame's language come first + return (lt1 < lt2); // normal comparison otherwise + }); + } + } + for (Language* language : languages) { if (!language) @@ -3374,6 +3398,9 @@ public: } } } + // this is "type lookup SomeName" and we did find a match, so get out + if (any_found && is_global_search) + break; } } diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp index 1d1a68f..37dc67b 100644 --- a/lldb/source/Target/StackFrame.cpp +++ b/lldb/source/Target/StackFrame.cpp @@ -12,10 +12,11 @@ // Other libraries and framework includes // Project includes #include "lldb/Target/StackFrame.h" -#include "lldb/Core/Module.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Disassembler.h" #include "lldb/Core/FormatEntity.h" +#include "lldb/Core/Mangled.h" +#include "lldb/Core/Module.h" #include "lldb/Core/Value.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Core/ValueObjectConstResult.h" @@ -1356,6 +1357,23 @@ StackFrame::GetLanguage () return lldb::eLanguageTypeUnknown; } +lldb::LanguageType +StackFrame::GuessLanguage () +{ + LanguageType lang_type = GetLanguage(); + + if (lang_type == eLanguageTypeUnknown) + { + Function *f = GetSymbolContext(eSymbolContextFunction).function; + if (f) + { + lang_type = f->GetMangled().GuessLanguage(); + } + } + + return lang_type; +} + TargetSP StackFrame::CalculateTarget () { -- 2.7.4