[Lldb-commits] [lldb] r123694 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h include/lldb/Expression/ClangExpressionParser.h include/lldb/Expression/IRForTarget.h source/Expression/ClangExpressionDeclMap.cpp source/Expression/ClangExpressionParser.cpp source/Expression/ClangFunction.cpp source/Expression/ClangUserExpression.cpp source/Expression/ClangUtilityFunction.cpp source/Expression/IRForTarget.cpp

Sean Callanan scallanan at apple.com
Mon Jan 17 15:42:46 PST 2011


Author: spyffe
Date: Mon Jan 17 17:42:46 2011
New Revision: 123694

URL: http://llvm.org/viewvc/llvm-project?rev=123694&view=rev
Log:
Added support for the fragile ivars provided by
Apple's Objective-C 2.0 runtime.  They are enabled
if the Objective-C runtime has the proper version.

Modified:
    lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
    lldb/trunk/include/lldb/Expression/ClangExpressionParser.h
    lldb/trunk/include/lldb/Expression/IRForTarget.h
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Expression/ClangFunction.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp
    lldb/trunk/source/Expression/ClangUtilityFunction.cpp
    lldb/trunk/source/Expression/IRForTarget.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Mon Jan 17 17:42:46 2011
@@ -290,6 +290,23 @@
                         uint64_t &ptr);
     
     //------------------------------------------------------------------
+    /// [Used by IRForTarget] Get the address of a symbol given nothing
+    /// but its name.
+    ///
+    /// @param[in] name
+    ///     The name of the symbol.  
+    ///
+    /// @param[out] ptr
+    ///     The absolute address of the function in the target.
+    ///
+    /// @return
+    ///     True if the address could be retrieved; false otherwise.
+    //------------------------------------------------------------------
+    bool 
+    GetSymbolAddress (const ConstString &name,
+                      uint64_t &ptr);
+    
+    //------------------------------------------------------------------
     /// [Used by CommandObjectExpression] Materialize the entire struct
     /// at a given address, which should be aligned as specified by 
     /// GetStructInfo().

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionParser.h?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionParser.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionParser.h Mon Jan 17 17:42:46 2011
@@ -25,6 +25,7 @@
 namespace lldb_private
 {
 
+class Process;
 class RecordingMemoryManager;
     
 //----------------------------------------------------------------------
@@ -49,10 +50,15 @@
     ///     The LLVM-friendly target triple for use in initializing the
     ///     compiler.
     ///
+    /// @param[in process
+    ///     If non-NULL, the process to customize the expression for
+    ///     (e.g., by tuning Objective-C runtime support).  May be NULL.
+    ///
     /// @param[in] expr
     ///     The expression to be parsed.
     //------------------------------------------------------------------
     ClangExpressionParser (const char *target_triple,
+                           Process *process,
                            ClangExpression &expr);
     
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (original)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Mon Jan 17 17:42:46 2011
@@ -322,12 +322,9 @@
     /// @param[in] llvm_module
     ///     The module currently being processed.
     ///
-    /// @param[in] V
+    /// @param[in] value
     ///     The variable.
     ///
-    /// @param[in] Store
-    ///     True if the access is a store.
-    ///
     /// @return
     ///     True on success; false otherwise
     //------------------------------------------------------------------
@@ -336,6 +333,22 @@
                          llvm::Value *value);
     
     //------------------------------------------------------------------
+    /// Handle a single externally-defined symbol
+    ///
+    /// @param[in] llvm_module
+    ///     The module currently being processed.
+    ///
+    /// @param[in] symbol
+    ///     The symbol.
+    ///
+    /// @return
+    ///     True on success; false otherwise
+    //------------------------------------------------------------------
+    bool
+    HandleSymbol (llvm::Module &llvm_module,
+                  llvm::Value *symbol);
+
+    //------------------------------------------------------------------
     /// Handle all the arguments to a function call
     ///
     /// @param[in] llvm_module

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Mon Jan 17 17:42:46 2011
@@ -452,6 +452,36 @@
     return true;
 }
 
+bool 
+ClangExpressionDeclMap::GetSymbolAddress
+(
+    const ConstString &name,
+    uint64_t &ptr
+)
+{
+    assert (m_parser_vars.get());
+    
+    // Back out in all cases where we're not fully initialized
+    if (m_parser_vars->m_exe_ctx->target == NULL)
+        return false;
+    
+    SymbolContextList sc_list;
+    
+    m_parser_vars->m_exe_ctx->target->GetImages().FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, sc_list);
+    
+    if (!sc_list.GetSize())
+        return false;
+    
+    SymbolContext sym_ctx;
+    sc_list.GetContextAtIndex(0, sym_ctx);
+    
+    const Address *sym_address = &sym_ctx.symbol->GetAddressRangeRef().GetBaseAddress();
+    
+    ptr = sym_address->GetLoadAddress (m_parser_vars->m_exe_ctx->target);
+    
+    return true;
+}
+
 // Interface for CommandObjectExpression
 
 bool 

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Mon Jan 17 17:42:46 2011
@@ -21,6 +21,7 @@
 #include "lldb/Expression/IRToDWARF.h"
 #include "lldb/Expression/RecordingMemoryManager.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ObjCLanguageRuntime.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 
@@ -177,6 +178,7 @@
 //===----------------------------------------------------------------------===//
 
 ClangExpressionParser::ClangExpressionParser(const char *target_triple,
+                                             Process *process,
                                              ClangExpression &expr) :
     m_expr(expr),
     m_target_triple (),
@@ -211,10 +213,18 @@
     // Setup objective C
     m_compiler->getLangOpts().ObjC1 = true;
     m_compiler->getLangOpts().ObjC2 = true;
-    // We need to enable the fragile ABI for things target triples that
-    // support it. 
-//    m_compiler->getLangOpts().ObjCNonFragileABI = true;     // NOT i386
-//    m_compiler->getLangOpts().ObjCNonFragileABI2 = true;    // NOT i386
+    
+    if (process)
+    {
+        if (process->GetObjCLanguageRuntime())
+        {
+            if (process->GetObjCLanguageRuntime()->GetRuntimeVersion() == lldb::eAppleObjC_V2)
+            {
+                m_compiler->getLangOpts().ObjCNonFragileABI = true;     // NOT i386
+                m_compiler->getLangOpts().ObjCNonFragileABI2 = true;    // NOT i386
+            }
+        }
+    }
 
     m_compiler->getLangOpts().ThreadsafeStatics = false;
     m_compiler->getLangOpts().AccessControl = false; // Debuggers get universal access

Modified: lldb/trunk/source/Expression/ClangFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangFunction.cpp Mon Jan 17 17:42:46 2011
@@ -214,7 +214,7 @@
         
     // Okay, now compile this expression
     
-    m_parser.reset(new ClangExpressionParser(m_target_triple.c_str(), *this));
+    m_parser.reset(new ClangExpressionParser(m_target_triple.c_str(), NULL, *this));
     
     num_errors = m_parser->Parse (errors);
     

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Jan 17 17:42:46 2011
@@ -253,7 +253,7 @@
     
     m_expr_decl_map->WillParse(exe_ctx);
     
-    ClangExpressionParser parser(target_triple.GetCString(), *this);
+    ClangExpressionParser parser(target_triple.GetCString(), exe_ctx.process, *this);
     
     unsigned num_errors = parser.Parse (error_stream);
     

Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Mon Jan 17 17:42:46 2011
@@ -105,7 +105,7 @@
     
     m_expr_decl_map->WillParse(exe_ctx);
         
-    ClangExpressionParser parser(target_triple.GetCString(), *this);
+    ClangExpressionParser parser(target_triple.GetCString(), exe_ctx.process, *this);
     
     unsigned num_errors = parser.Parse (error_stream);
     

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=123694&r1=123693&r2=123694&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Mon Jan 17 17:42:46 2011
@@ -1070,6 +1070,44 @@
 }
 
 bool
+IRForTarget::HandleSymbol (Module &llvm_module,
+                           Value *symbol)
+{
+    lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+    
+    lldb_private::ConstString name(symbol->getName().str().c_str());
+    
+    uint64_t symbol_addr;
+    
+    if (!m_decl_map->GetSymbolAddress (name, symbol_addr))
+    {
+        if (log)
+            log->Printf ("Symbol \"%s\" had no address", name.GetCString());
+        
+        return false;
+    }
+
+    if (log)
+        log->Printf("Found \"%s\" at 0x%llx", name.GetCString(), symbol_addr);
+    
+    const Type *symbol_type = symbol->getType();
+    
+    const IntegerType *intptr_ty = Type::getIntNTy(llvm_module.getContext(),
+                                                   (llvm_module.getPointerSize() == Module::Pointer64) ? 64 : 32);
+    
+    Constant *symbol_addr_int = ConstantInt::get(intptr_ty, symbol_addr, false);
+    
+    Value *symbol_addr_ptr = ConstantExpr::getIntToPtr(symbol_addr_int, symbol_type);
+    
+    if (log)
+        log->Printf("Replacing %s with %s", PrintValue(symbol).c_str(), PrintValue(symbol_addr_ptr).c_str());
+    
+    symbol->replaceAllUsesWith(symbol_addr_ptr);
+    
+    return true;
+}
+
+bool
 IRForTarget::MaybeHandleCallArguments (Module &llvm_module, CallInst *Old)
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -1250,9 +1288,16 @@
                         (*global).getName().str().c_str(),
                         DeclForGlobalValue(llvm_module, global));
     
-        if (DeclForGlobalValue(llvm_module, global) &&
-            !MaybeHandleVariable (llvm_module, global))
-            return false;
+        if ((*global).getName().str().find("OBJC_IVAR") == 0)
+        {
+            if (!HandleSymbol(llvm_module, global))
+                return false;
+        }
+        else if (DeclForGlobalValue(llvm_module, global))
+        {
+            if (!MaybeHandleVariable (llvm_module, global))
+                return false;
+        }
     }
         
     return true;





More information about the lldb-commits mailing list