[Lldb-commits] [lldb] r263592 - Improve the 'type lookup' command such that it guesses to use the current's frame language as the one to start searching from.

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 15 14:50:52 PDT 2016


Author: enrico
Date: Tue Mar 15 16:50:51 2016
New Revision: 263592

URL: http://llvm.org/viewvc/llvm-project?rev=263592&view=rev
Log:
Improve the 'type lookup' command such that it guesses to use the current's frame language as the one to start searching from.

Modified:
    lldb/trunk/include/lldb/Target/StackFrame.h
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Target/StackFrame.cpp

Modified: lldb/trunk/include/lldb/Target/StackFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackFrame.h?rev=263592&r1=263591&r2=263592&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/StackFrame.h (original)
+++ lldb/trunk/include/lldb/Target/StackFrame.h Tue Mar 15 16:50:51 2016
@@ -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
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=263592&r1=263591&r2=263592&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Tue Mar 15 16:50:51 2016
@@ -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;
             }
         }
         

Modified: lldb/trunk/source/Target/StackFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=263592&r1=263591&r2=263592&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrame.cpp (original)
+++ lldb/trunk/source/Target/StackFrame.cpp Tue Mar 15 16:50:51 2016
@@ -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 ()
 {




More information about the lldb-commits mailing list