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
This commit is contained in:
Enrico Granata 2016-03-15 21:50:51 +00:00
parent 298516ffa9
commit 592afe73ad
3 changed files with 52 additions and 2 deletions

View File

@ -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
//------------------------------------------------------------------

View File

@ -11,6 +11,7 @@
// C Includes
// C++ Includes
#include <algorithm>
#include <cctype>
#include <functional>
@ -3344,7 +3345,9 @@ public:
std::vector<Language*> 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;
}
}

View File

@ -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 ()
{