[Lldb-commits] [lldb] r248960 - Introudce a IsTopLevelFunction() API on Language and Function

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 30 16:12:23 PDT 2015


Author: enrico
Date: Wed Sep 30 18:12:22 2015
New Revision: 248960

URL: http://llvm.org/viewvc/llvm-project?rev=248960&view=rev
Log:
Introudce a IsTopLevelFunction() API on Language and Function

This is meant to support languages that have a scripting mode with top-level code that acts as global

For now, this flag only controls whether 'frame variable' will attempt to treat globals as locals when within such a function


Modified:
    lldb/trunk/include/lldb/Symbol/Function.h
    lldb/trunk/include/lldb/Target/Language.h
    lldb/trunk/source/Commands/CommandObjectFrame.cpp
    lldb/trunk/source/Symbol/Function.cpp
    lldb/trunk/source/Target/Language.cpp

Modified: lldb/trunk/include/lldb/Symbol/Function.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=248960&r1=248959&r2=248960&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Function.h (original)
+++ lldb/trunk/include/lldb/Symbol/Function.h Wed Sep 30 18:12:22 2015
@@ -631,6 +631,24 @@ public:
     //------------------------------------------------------------------
     bool
     GetIsOptimized ();
+    
+    //------------------------------------------------------------------
+    /// Get whether this function represents a 'top-level' function
+    ///
+    /// The concept of a top-level function is language-specific, mostly
+    /// meant to represent the notion of scripting-style code that has
+    /// global visibility of the variables/symbols/functions/...
+    /// defined within the containing file/module
+    ///
+    /// If stopped in a top-level function, LLDB will expose global variables
+    /// as-if locals in the 'frame variable' command
+    ///
+    /// @return
+    ///     Returns 'true' if this function is a top-level function,
+    ///     'false' otherwise.
+    //------------------------------------------------------------------
+    bool
+    IsTopLevelFunction ();
 
     lldb::DisassemblerSP
     GetInstructions (const ExecutionContext &exe_ctx,

Modified: lldb/trunk/include/lldb/Target/Language.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Language.h?rev=248960&r1=248959&r2=248960&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Language.h (original)
+++ lldb/trunk/include/lldb/Target/Language.h Wed Sep 30 18:12:22 2015
@@ -41,6 +41,9 @@ public:
     virtual lldb::LanguageType
     GetLanguageType () const = 0;
     
+    bool
+    IsTopLevelFunction (Function& function);
+    
     virtual lldb::TypeCategoryImplSP
     GetFormatters ();
     

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=248960&r1=248959&r2=248960&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Wed Sep 30 18:12:22 2015
@@ -35,6 +35,7 @@
 #include "lldb/Interpreter/OptionGroupVariable.h"
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Type.h"
@@ -409,6 +410,10 @@ protected:
         
         DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(eLanguageRuntimeDescriptionDisplayVerbosityFull,eFormatDefault,summary_format_sp));
         
+        const SymbolContext& sym_ctx = frame->GetSymbolContext(eSymbolContextFunction);
+        if (sym_ctx.function && sym_ctx.function->IsTopLevelFunction())
+            m_option_variable.show_globals = true;
+        
         if (variable_list)
         {
             const Format format = m_option_format.GetFormat();

Modified: lldb/trunk/source/Symbol/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Function.cpp?rev=248960&r1=248959&r2=248960&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Function.cpp (original)
+++ lldb/trunk/source/Symbol/Function.cpp Wed Sep 30 18:12:22 2015
@@ -17,6 +17,7 @@
 #include "lldb/Symbol/LineTable.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Target/Language.h"
 #include "llvm/Support/Casting.h"
 
 using namespace lldb;
@@ -481,6 +482,17 @@ Function::GetIsOptimized ()
     return result;
 }
 
+bool
+Function::IsTopLevelFunction ()
+{
+    bool result = false;
+    
+    if (Language* language = Language::FindPlugin(GetLanguage()))
+        result = language->IsTopLevelFunction(*this);
+    
+    return result;
+}
+
 ConstString
 Function::GetDisplayName () const
 {

Modified: lldb/trunk/source/Target/Language.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Language.cpp?rev=248960&r1=248959&r2=248960&view=diff
==============================================================================
--- lldb/trunk/source/Target/Language.cpp (original)
+++ lldb/trunk/source/Target/Language.cpp Wed Sep 30 18:12:22 2015
@@ -89,6 +89,12 @@ Language::ForEach (std::function<bool(La
     }
 }
 
+bool
+Language::IsTopLevelFunction (Function& function)
+{
+    return false;
+}
+
 lldb::TypeCategoryImplSP
 Language::GetFormatters ()
 {




More information about the lldb-commits mailing list