diff options
| -rw-r--r-- | lldb/include/lldb/Target/StackFrame.h | 5 | ||||
| -rw-r--r-- | lldb/source/Commands/CommandObjectType.cpp | 29 | ||||
| -rw-r--r-- | 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 b65b0181017..f021cbac606 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 971506bd9e0..f291f115e45 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -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; } } diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp index 1d1a68fd334..37dc67bed0c 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 () { |

