dawn created this revision.
dawn added a reviewer: jingham.
dawn added a subscriber: lldb-commits.
dawn set the repository for this revision to rL LLVM.

This patch reworks the breakpoint filter-by-language patch to use the symbol 
context instead of trying to guess the language solely from the symbol's name.  
This has the advantage that symbols compiled with debug info will have their 
actual language known.  Symbols without debug info will still do the same 
"guess"ing because Symbol::GetLanguage() is implemented using 
Mangled::GuessLanguage().  The recognition of ObjC names was merged into 
Mangled::GuessLanguage.

Repository:
  rL LLVM

http://reviews.llvm.org/D15326

Files:
  include/lldb/Symbol/SymbolContext.h
  include/lldb/Target/Language.h
  include/lldb/Target/LanguageRuntime.h
  source/Breakpoint/BreakpointResolverName.cpp
  source/Core/Mangled.cpp
  source/Symbol/SymbolContext.cpp
  source/Target/Language.cpp
  source/Target/LanguageRuntime.cpp

Index: source/Target/LanguageRuntime.cpp
===================================================================
--- source/Target/LanguageRuntime.cpp
+++ source/Target/LanguageRuntime.cpp
@@ -345,28 +345,3 @@
 {
     return m_process->GetTarget().GetSearchFilterForModule(NULL);
 }
-
-lldb::LanguageType
-LanguageRuntime::GuessLanguageForSymbolByName (Target &target, const char *symbol_name)
-{
-    // We "guess" the language because we can't determine a symbol's language from it's name.
-    // For example, a Pascal symbol can be mangled using the C++ Itanium scheme, and defined
-    // in a compilation unit within the same module as other C++ units.
-    //
-    // In addition, different targets could have different ways of mangling names from a given
-    // language, likewise compilation units within those targets.  It would help to be able to
-    // ask the various LanguageRuntime plugin instances for this target to recognize the name,
-    // but right now the plugin instances depend on the process, not the target.  That is
-    // unfortunate, because to use this for filtering breakpoints by language, we need to know
-    // the "language for symbol-name" prior to running.  So we'd have to make a
-    // "LanguageRuntimeTarget" and "LanguageRuntimeProcess", and direct the questions that don't
-    // need a running process to the former, and that do to the latter.
-    //
-    // That's more work than I want to do for this feature.
-    if (CPlusPlusLanguage::IsCPPMangledName (symbol_name))
-        return eLanguageTypeC_plus_plus;
-    else if (ObjCLanguage::IsPossibleObjCMethodName (symbol_name))
-        return eLanguageTypeObjC;
-    else
-        return eLanguageTypeUnknown;
-}
Index: source/Target/Language.cpp
===================================================================
--- source/Target/Language.cpp
+++ source/Target/Language.cpp
@@ -287,6 +287,57 @@
     }
 }
 
+LanguageType
+Language::GetPrimaryLanguage (LanguageType language)
+{
+    switch (language)
+    {
+        case eLanguageTypeC_plus_plus:
+        case eLanguageTypeC_plus_plus_03:
+        case eLanguageTypeC_plus_plus_11:
+        case eLanguageTypeC_plus_plus_14:
+            return eLanguageTypeC_plus_plus;
+        case eLanguageTypeC:
+        case eLanguageTypeC89:
+        case eLanguageTypeC99:
+        case eLanguageTypeC11:
+            return eLanguageTypeC;
+        case eLanguageTypeObjC:
+        case eLanguageTypeObjC_plus_plus:
+            return eLanguageTypeObjC;
+        case eLanguageTypePascal83:
+        case eLanguageTypeCobol74:
+        case eLanguageTypeCobol85:
+        case eLanguageTypeFortran77:
+        case eLanguageTypeFortran90:
+        case eLanguageTypeFortran95:
+        case eLanguageTypeFortran03:
+        case eLanguageTypeFortran08:
+        case eLanguageTypeAda83:
+        case eLanguageTypeAda95:
+        case eLanguageTypeModula2:
+        case eLanguageTypeJava:
+        case eLanguageTypePLI:
+        case eLanguageTypeUPC:
+        case eLanguageTypeD:
+        case eLanguageTypePython:
+        case eLanguageTypeOpenCL:
+        case eLanguageTypeGo:
+        case eLanguageTypeModula3:
+        case eLanguageTypeHaskell:
+        case eLanguageTypeOCaml:
+        case eLanguageTypeRust:
+        case eLanguageTypeSwift:
+        case eLanguageTypeJulia:
+        case eLanguageTypeDylan:
+        case eLanguageTypeMipsAssembler:
+        case eLanguageTypeExtRenderScript:
+        case eLanguageTypeUnknown:
+        default:
+            return language;
+    }
+}
+
 void
 Language::GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages,
                                              std::set<lldb::LanguageType> &languages_for_expressions)
Index: source/Symbol/SymbolContext.cpp
===================================================================
--- source/Symbol/SymbolContext.cpp
+++ source/Symbol/SymbolContext.cpp
@@ -525,6 +525,38 @@
     return false;
 }
 
+LanguageType
+SymbolContext::GetLanguage () const
+{
+    LanguageType lang;
+    if (function &&
+        (lang = function->GetLanguage()) != eLanguageTypeUnknown)
+    {
+        return lang;
+    }
+    else if (variable &&
+             (lang = variable->GetLanguage()) != eLanguageTypeUnknown)
+    {
+        return lang;
+    }
+    else if (symbol &&
+             (lang = symbol->GetLanguage()) != eLanguageTypeUnknown)
+    {
+        return lang;
+    }
+    else if (comp_unit &&
+             (lang = comp_unit->GetLanguage()) != eLanguageTypeUnknown)
+    {
+        return lang;
+    }
+    else if (symbol)
+    {
+        // If all else fails, try to guess the language from the name.
+        return symbol->GetMangled().GuessLanguage();
+    }
+    return eLanguageTypeUnknown;
+}
+
 bool
 SymbolContext::GetParentOfInlinedScope (const Address &curr_frame_pc, 
                                         SymbolContext &next_frame_sc, 
Index: source/Core/Mangled.cpp
===================================================================
--- source/Core/Mangled.cpp
+++ source/Core/Mangled.cpp
@@ -39,6 +39,7 @@
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/Timer.h"
 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
+#include "Plugins/Language/ObjC/ObjCLanguage.h"
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
@@ -426,6 +427,14 @@
     return m_mangled.MemorySize() + m_demangled.MemorySize();
 }
 
+//----------------------------------------------------------------------
+// We "guess" the language because we can't determine a symbol's language
+// from it's name.  For example, a Pascal symbol can be mangled using the
+// C++ Itanium scheme, and defined in a compilation unit within the same
+// module as other C++ units.  In addition, different targets could have
+// different ways of mangling names from a given language, likewise the
+// compilation units within those targets.
+//----------------------------------------------------------------------
 lldb::LanguageType
 Mangled::GuessLanguage () const
 {
@@ -434,11 +443,14 @@
     {
         if (GetDemangledName(lldb::eLanguageTypeUnknown))
         {
-            if (cstring_is_mangled(mangled.GetCString()))
+            const char *mangled_name = mangled.GetCString();
+            if (cstring_is_mangled(mangled_name))
                 return lldb::eLanguageTypeC_plus_plus;
+            else if (ObjCLanguage::IsPossibleObjCMethodName(mangled_name))
+                return lldb::eLanguageTypeObjC;
         }
     }
-    return  lldb::eLanguageTypeUnknown;
+    return lldb::eLanguageTypeUnknown;
 }
 
 //----------------------------------------------------------------------
Index: source/Breakpoint/BreakpointResolverName.cpp
===================================================================
--- source/Breakpoint/BreakpointResolverName.cpp
+++ source/Breakpoint/BreakpointResolverName.cpp
@@ -21,7 +21,6 @@
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContext.h"
-#include "lldb/Target/LanguageRuntime.h"
 #include "Plugins/Language/ObjC/ObjCLanguage.h"
 
 using namespace lldb;
@@ -259,8 +258,6 @@
     // If the filter specifies a Compilation Unit, remove the ones that don't pass at this point.
     if (filter_by_cu || filter_by_language)
     {
-        Target &target = m_breakpoint->GetTarget();
-        
         uint32_t num_functions = func_list.GetSize();
         
         for (size_t idx = 0; idx < num_functions; idx++)
@@ -276,32 +273,12 @@
             
             if (filter_by_language)
             {
-                const char *name = sc.GetFunctionName(Mangled::ePreferMangled).AsCString();
-                if (name)
+                LanguageType sym_language = sc.GetLanguage();
+                if ((Language::GetPrimaryLanguage(sym_language) !=
+                     Language::GetPrimaryLanguage(m_language)) &&
+                    (sym_language != eLanguageTypeUnknown))
                 {
-                    LanguageType sym_language = LanguageRuntime::GuessLanguageForSymbolByName(target, name);
-                    if (Language::LanguageIsC(m_language) ||
-                        Language::LanguageIsPascal(m_language))
-                    {
-                        // We don't currently have a way to say "This symbol name is C" so for now, C means
-                        // not ObjC and not C++, etc...
-                        if (sym_language == eLanguageTypeC_plus_plus
-                            || sym_language == eLanguageTypeObjC
-                            || sym_language == eLanguageTypeSwift)
-                        {
-                            remove_it = true;
-                        }
-                    }
-                    else if (sym_language != m_language)
-                    {
-                        // Note: This code prevents us from being able to find symbols
-                        // like 'printf' if the target language's option is set.  It
-                        // would be better to limit this filtering to only when the
-                        // breakpoint's language option is set (and not the target's),
-                        // but we can't know if m_language was set from the target or
-                        // breakpoint option.
-                        remove_it = true;
-                    }
+                    remove_it = true;
                 }
             }
             
Index: include/lldb/Target/LanguageRuntime.h
===================================================================
--- include/lldb/Target/LanguageRuntime.h
+++ include/lldb/Target/LanguageRuntime.h
@@ -117,9 +117,6 @@
         return m_process;
     }
     
-    static lldb::LanguageType
-    GuessLanguageForSymbolByName (Target &target, const char *symbol_name);
-    
     Target&
     GetTargetRef()
     {
Index: include/lldb/Target/Language.h
===================================================================
--- include/lldb/Target/Language.h
+++ include/lldb/Target/Language.h
@@ -173,6 +173,10 @@
     static bool
     LanguageIsPascal (lldb::LanguageType language);
     
+    // return the primary language, so if LanguageIsC(l), return eLanguageTypeC, etc.
+    static lldb::LanguageType
+    GetPrimaryLanguage (lldb::LanguageType language);
+
     static void
     GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages,
                                        std::set<lldb::LanguageType> &languages_for_expressions);
Index: include/lldb/Symbol/SymbolContext.h
===================================================================
--- include/lldb/Symbol/SymbolContext.h
+++ include/lldb/Symbol/SymbolContext.h
@@ -253,6 +253,9 @@
     uint32_t
     GetResolvedMask () const;
 
+    lldb::LanguageType
+    GetLanguage () const;
+
     //------------------------------------------------------------------
     /// Find a block that defines the function represented by this
     /// symbol context.
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to