[Lldb-commits] [lldb] r131370 - in /lldb/trunk: include/lldb/ include/lldb/Core/ include/lldb/Target/ source/Expression/ source/Plugins/ABI/SysV-x86_64/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/ source/Plugins/Process/gdb-remote/ source/Plugins/UnwindAssembly/InstEmulation/ source/Target/

Greg Clayton gclayton at apple.com
Sat May 14 18:25:55 PDT 2011


Author: gclayton
Date: Sat May 14 20:25:55 2011
New Revision: 131370

URL: http://llvm.org/viewvc/llvm-project?rev=131370&view=rev
Log:
Added the ability to get the return value from a ThreadPlanCallFunction
thread plan. In order to get the return value, you can call:

        void
        ThreadPlanCallFunction::RequestReturnValue (lldb::ValueSP &return_value_sp);
        
This registers a shared pointer to a return value that will get filled in if
everything goes well. After the thread plan is run the return value will be
extracted for you.

Added an ifdef to be able to switch between the LLVM MCJIT and the standand JIT.
We currently have the standard JIT selected because we have some work to do to
get the MCJIT fuctioning properly.

Added the ability to call functions with 6 argument in the x86_64 ABI.

Added the ability for GDBRemoteCommunicationClient to detect if the allocate
and deallocate memory packets are supported and to not call allocate memory 
("_M") or deallocate ("_m") if we find they aren't supported.

Modified the ProcessGDBRemote::DoAllocateMemory(...) and ProcessGDBRemote::DoDeallocateMemory(...) 
to be able to deal with the allocate and deallocate memory packets not being 
supported. If they are not supported, ProcessGDBRemote will switch to calling
"mmap" and "munmap" to allocate and deallocate memory instead using our 
trivial function call support.

Modified the "void ProcessGDBRemote::DidLaunchOrAttach()" to correctly ignore 
the qHostInfo triple information if any was specified in the target. Currently 
if the target only specifies an architecture when creating the target:

(lldb) target create --arch i386 a.out

Then the vendor, os and environemnt will be adopted by the target.

If the target was created with any triple that specifies more than the arch:

(lldb) target create --arch i386-unknown-unknown a.out

Then the target will maintain its triple and not adopt any new values. This
can be used to help force bare board debugging where the dynamic loader for
static files will get used and users can then use "target modules load ..."
to set addressses for any files that are desired.

Added back some convenience functions to the lldb_private::RegisterContext class
for writing registers with unsigned values. Also made all RegisterContext
constructors explicit to make sure we know when an integer is being converted
to a RegisterValue. 


Modified:
    lldb/trunk/include/lldb/Core/RegisterValue.h
    lldb/trunk/include/lldb/Target/RegisterContext.h
    lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h
    lldb/trunk/include/lldb/lldb-forward-rtti.h
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
    lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
    lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
    lldb/trunk/source/Target/RegisterContext.cpp
    lldb/trunk/source/Target/ThreadPlanCallFunction.cpp

Modified: lldb/trunk/include/lldb/Core/RegisterValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RegisterValue.h?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/RegisterValue.h (original)
+++ lldb/trunk/include/lldb/Core/RegisterValue.h Sat May 14 20:25:55 2011
@@ -51,24 +51,28 @@
         {
         }
 
+        explicit 
         RegisterValue (uint8_t inst) : 
             m_type (eTypeUInt8)
         {
             m_data.uint8 = inst;
         }
 
+        explicit 
         RegisterValue (uint16_t inst) : 
             m_type (eTypeUInt16)
         {
             m_data.uint16 = inst;
         }
 
+        explicit 
         RegisterValue (uint32_t inst) : 
             m_type (eTypeUInt32)
         {
             m_data.uint32 = inst;
         }
 
+        explicit 
         RegisterValue (uint64_t inst) : 
             m_type (eTypeUInt64)
         {
@@ -76,30 +80,35 @@
         }
 
 #if defined (ENABLE_128_BIT_SUPPORT)
+        explicit 
         RegisterValue (__uint128_t inst) : 
             m_type (eTypeUInt128)
         {
             m_data.uint128 = inst;
         }
 #endif        
+        explicit 
         RegisterValue (float value) : 
             m_type (eTypeFloat)
         {
             m_data.ieee_float = value;
         }
 
+        explicit 
         RegisterValue (double value) : 
             m_type (eTypeDouble)
         {
             m_data.ieee_double = value;
         }
 
+        explicit 
         RegisterValue (long double value) : 
             m_type (eTypeLongDouble)
         {
             m_data.ieee_long_double = value;
         }
 
+        explicit 
         RegisterValue (uint8_t *bytes, size_t length, lldb::ByteOrder byte_order)
         {
             SetBytes (bytes, length, byte_order);

Modified: lldb/trunk/include/lldb/Target/RegisterContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/RegisterContext.h?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/RegisterContext.h (original)
+++ lldb/trunk/include/lldb/Target/RegisterContext.h Sat May 14 20:25:55 2011
@@ -142,10 +142,15 @@
     uint64_t
     ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value);
 
+    uint64_t
+    ReadRegisterAsUnsigned (const RegisterInfo *reg_info, uint64_t fail_value);
+    
     bool
     WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval);
 
     bool
+    WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval);
+    bool
     ConvertBetweenRegisterKinds (int source_rk, uint32_t source_regnum, int target_rk, uint32_t& target_regnum);
 
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h (original)
+++ lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Sat May 14 20:25:55 2011
@@ -80,7 +80,28 @@
     {
         return true;
     }
-    
+
+    // To get the return value from a function call you must create a 
+    // lldb::ValueSP that contains a valid clang type in its context and call
+    // RequestReturnValue. The ValueSP will be stored and when the function is
+    // done executing, the object will check if there is a requested return 
+    // value. If there is, the return value will be retrieved using the 
+    // ABI::GetReturnValue() for the ABI in the process. Then after the thread
+    // plan is complete, you can call "GetReturnValue()" to retrieve the value
+    // that was extracted.
+
+    const lldb::ValueSP &
+    GetReturnValue ()
+    {
+        return m_return_value_sp;
+    }
+
+    void
+    RequestReturnValue (lldb::ValueSP &return_value_sp)
+    {
+        m_return_value_sp = return_value_sp;
+    }
+
     // Return the stack pointer that the function received
     // on entry.  Any stack address below this should be 
     // considered invalid after the function has been
@@ -112,7 +133,6 @@
     bool
     BreakpointsExplainStop ();
     
-    bool                                            m_use_abi;
     bool                                            m_valid;
     bool                                            m_stop_other_threads;
     Address                                         m_function_addr;
@@ -125,6 +145,7 @@
     LanguageRuntime                                *m_cxx_language_runtime;
     LanguageRuntime                                *m_objc_language_runtime;
     Thread::ThreadStateCheckpoint                   m_stored_thread_state;
+    lldb::ValueSP                                   m_return_value_sp;  // If this contains a valid pointer, use the ABI to extract values when complete
     bool                                            m_takedown_done;    // We want to ensure we only do the takedown once.  This ensures that.
 
     DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction);

Modified: lldb/trunk/include/lldb/lldb-forward-rtti.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward-rtti.h?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward-rtti.h (original)
+++ lldb/trunk/include/lldb/lldb-forward-rtti.h Sat May 14 20:25:55 2011
@@ -71,6 +71,8 @@
     typedef SharedPtr<lldb_private::UserSettingsController>::Type UserSettingsControllerSP;
     typedef SharedPtr<lldb_private::UnwindPlan>::Type UnwindPlanSP;
     typedef SharedPtr<lldb_private::ValueObject>::Type ValueObjectSP;
+    typedef SharedPtr<lldb_private::Value>::Type ValueSP;
+    typedef SharedPtr<lldb_private::ValueList>::Type ValueListSP;
     typedef SharedPtr<lldb_private::Variable>::Type VariableSP;
     typedef SharedPtr<lldb_private::VariableList>::Type VariableListSP;
     typedef SharedPtr<lldb_private::ValueObjectList>::Type ValueObjectListSP;

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Sat May 14 20:25:55 2011
@@ -52,7 +52,13 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+
+#define USE_STANDARD_JIT
+#if defined (USE_STANDARD_JIT)
 #include "llvm/ExecutionEngine/JIT.h"
+#else
+#include "llvm/ExecutionEngine/MCJIT.h"
+#endif
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -550,12 +556,24 @@
         
     llvm::TargetMachine::setRelocationModel(llvm::Reloc::PIC_);
     
+#if defined (USE_STANDARD_JIT)
     m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module, 
                                                                &error_string, 
                                                                jit_memory_manager,
                                                                CodeGenOpt::Less,
                                                                true,
                                                                CodeModel::Small));
+#else
+    EngineBuilder builder(module);
+    builder.setEngineKind(EngineKind::JIT)
+        .setErrorStr(&error_string)
+        .setJITMemoryManager(jit_memory_manager)
+        .setOptLevel(CodeGenOpt::Less)
+        .setAllocateGVsWithCode(true)
+        .setCodeModel(CodeModel::Small)
+        .setUseMCJIT(true);
+    m_execution_engine.reset(builder.create());
+#endif
         
     if (!m_execution_engine.get())
     {

Modified: lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp Sat May 14 20:25:55 2011
@@ -70,9 +70,6 @@
                                     addr_t *arg5_ptr,
                                     addr_t *arg6_ptr) const
 {
-    if (arg4_ptr || arg5_ptr || arg6_ptr)
-        return false;
-    
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
     if (log)
@@ -89,32 +86,58 @@
     if (!reg_ctx)
         return false;
     
-    RegisterValue reg_value;
+    const RegisterInfo *reg_info = NULL;
     if (arg1_ptr)
     {
+        reg_info = reg_ctx->GetRegisterInfoByName("rdi", 0);
         if (log)
-            log->Printf("About to write arg1 (0x%llx) into RDI", (uint64_t)*arg1_ptr);
+            log->Printf("About to write arg1 (0x%llx) into %s", (uint64_t)*arg1_ptr, reg_info->name);
 
-        reg_value.SetUInt64(*arg1_ptr);
-        if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName("rdi", 0), reg_value))
+        if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg1_ptr))
             return false;
 
         if (arg2_ptr)
         {
+            reg_info = reg_ctx->GetRegisterInfoByName("rsi", 0);
             if (log)
-                log->Printf("About to write arg2 (0x%llx) into RSI", (uint64_t)*arg2_ptr);
-            
-            reg_value.SetUInt64(*arg2_ptr);
-            if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName("rsi", 0), reg_value))
+                log->Printf("About to write arg2 (0x%llx) into %s", (uint64_t)*arg2_ptr, reg_info->name);
+            if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg2_ptr))
                 return false;
 
             if (arg3_ptr)
             {
+                reg_info = reg_ctx->GetRegisterInfoByName("rdx", 0);
                 if (log)
-                    log->Printf("About to write arg3 (0x%llx) into RDX", (uint64_t)*arg3_ptr);
-                reg_value.SetUInt64(*arg3_ptr);
-                if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName("rdx", 0), reg_value))
+                    log->Printf("About to write arg3 (0x%llx) into %s", (uint64_t)*arg3_ptr, reg_info->name);
+                if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg3_ptr))
                     return false;
+
+                if (arg4_ptr)
+                {
+                    reg_info = reg_ctx->GetRegisterInfoByName("rcx", 0);
+                    if (log)
+                        log->Printf("About to write arg4 (0x%llx) into %s", (uint64_t)*arg4_ptr, reg_info->name);
+                    if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg4_ptr))
+                        return false;
+
+                    if (arg5_ptr)
+                    {
+                        reg_info = reg_ctx->GetRegisterInfoByName("r8", 0);
+                        if (log)
+                            log->Printf("About to write arg5 (0x%llx) into %s", (uint64_t)*arg5_ptr, reg_info->name);
+                        if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg5_ptr))
+                            return false;
+
+                        if (arg6_ptr)
+                        {
+                            reg_info = reg_ctx->GetRegisterInfoByName("r9", 0);
+                            if (log)
+                                log->Printf("About to write arg6 (0x%llx) into %s", (uint64_t)*arg6_ptr, reg_info->name);
+                            if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg6_ptr))
+                                return false;
+                        }
+                    }
+                }
             }
         }
     }
@@ -130,6 +153,7 @@
     // The return address is pushed onto the stack (yes after the alignment...)
     sp -= 8;
 
+    RegisterValue reg_value;
     reg_value.SetUInt64 (return_addr);
 
     if (log)
@@ -145,8 +169,7 @@
     if (log)
         log->Printf("Writing SP (0x%llx) down", (uint64_t)sp);
     
-    reg_value.SetUInt64(sp);
-    if (!reg_ctx->WriteRegister (reg_ctx->GetRegisterInfoByName("rsp"), reg_value))
+    if (!reg_ctx->WriteRegisterFromUnsigned (reg_ctx->GetRegisterInfoByName("rsp"), sp))
         return false;
 
     // %rip is set to the address of the called function.
@@ -154,9 +177,7 @@
     if (log)
         log->Printf("Writing new IP (0x%llx) down", (uint64_t)func_addr);
 
-    reg_value.SetUInt64(func_addr);
-
-    if (!reg_ctx->WriteRegister(pc_reg_info, func_addr))
+    if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_info, func_addr))
         return false;
 
     return true;
@@ -222,13 +243,13 @@
         default:
             return false;
         case 8:
-            scalar = (uint8_t)(arg_contents & 0xff);
+            scalar = (uint8_t)(arg_contents & 0xffu);
             break;
         case 16:
-            scalar = (uint16_t)(arg_contents & 0xffff);
+            scalar = (uint16_t)(arg_contents & 0xffffu);
             break;
         case 32:
-            scalar = (uint32_t)(arg_contents & 0xffffffff);
+            scalar = (uint32_t)(arg_contents & 0xffffffffu);
             break;
         case 64:
             scalar = (uint64_t)arg_contents;

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp Sat May 14 20:25:55 2011
@@ -381,9 +381,9 @@
     
 bool 
 AppleObjCTrampolineHandler::AppleObjCVTables::RefreshTrampolines (void *baton, 
-                                    StoppointCallbackContext *context, 
-                                    lldb::user_id_t break_id, 
-                                    lldb::user_id_t break_loc_id)
+                                                                  StoppointCallbackContext *context, 
+                                                                  lldb::user_id_t break_id, 
+                                                                  lldb::user_id_t break_loc_id)
 {
     AppleObjCVTables *vtable_handler = (AppleObjCVTables *) baton;
     if (vtable_handler->InitializeVTableSymbols())

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Sat May 14 20:25:55 2011
@@ -45,8 +45,7 @@
     m_supports_vCont_s (eLazyBoolCalculate),
     m_supports_vCont_S (eLazyBoolCalculate),
     m_qHostInfo_is_valid (eLazyBoolCalculate),
-    m_supports__m (eLazyBoolCalculate),
-    m_supports__M (eLazyBoolCalculate),
+    m_supports_alloc_dealloc_memory (eLazyBoolCalculate),
     m_supports_qProcessInfoPID (true),
     m_supports_qfProcessInfo (true),
     m_supports_qUserName (true),
@@ -132,8 +131,7 @@
     m_supports_vCont_s = eLazyBoolCalculate;
     m_supports_vCont_S = eLazyBoolCalculate;
     m_qHostInfo_is_valid = eLazyBoolCalculate;
-    m_supports__m = eLazyBoolCalculate;
-    m_supports__M = eLazyBoolCalculate;
+    m_supports_alloc_dealloc_memory = eLazyBoolCalculate;
 
     m_supports_qProcessInfoPID = true;
     m_supports_qfProcessInfo = true;
@@ -1021,9 +1019,9 @@
 addr_t
 GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions)
 {
-    if (m_supports__M != eLazyBoolNo)
+    if (m_supports_alloc_dealloc_memory != eLazyBoolNo)
     {
-        m_supports__M = eLazyBoolYes;
+        m_supports_alloc_dealloc_memory = eLazyBoolYes;
         char packet[64];
         const int packet_len = ::snprintf (packet, sizeof(packet), "_M%zx,%s%s%s", size,
                                            permissions & lldb::ePermissionsReadable ? "r" : "",
@@ -1034,7 +1032,7 @@
         if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
         {
             if (response.IsUnsupportedResponse())
-                m_supports__M = eLazyBoolNo;
+                m_supports_alloc_dealloc_memory = eLazyBoolNo;
             else if (!response.IsErrorResponse())
                 return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
         }
@@ -1045,9 +1043,9 @@
 bool
 GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr)
 {
-    if (m_supports__m != eLazyBoolNo)
+    if (m_supports_alloc_dealloc_memory != eLazyBoolNo)
     {
-        m_supports__m = eLazyBoolYes;
+        m_supports_alloc_dealloc_memory = eLazyBoolYes;
         char packet[64];
         const int packet_len = ::snprintf(packet, sizeof(packet), "_m%llx", (uint64_t)addr);
         assert (packet_len < sizeof(packet));
@@ -1057,7 +1055,7 @@
             if (response.IsOKResponse())
                 return true;
             else if (response.IsUnsupportedResponse())
-                m_supports__m = eLazyBoolNo;
+                m_supports_alloc_dealloc_memory = eLazyBoolNo;
         }
     }
     return false;

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Sat May 14 20:25:55 2011
@@ -306,15 +306,9 @@
     SetCurrentThreadForRun (int tid);
 
     lldb_private::LazyBool
-    SupportsAllocateMemory () const
+    SupportsAllocDeallocMemory () const
     {
-        return m_supports__M;
-    }
-
-    lldb_private::LazyBool
-    SupportsDeallocateMemory () const
-    {
-        return m_supports__m;
+        return m_supports_alloc_dealloc_memory;
     }
 
 protected:
@@ -331,8 +325,7 @@
     lldb_private::LazyBool m_supports_vCont_s;
     lldb_private::LazyBool m_supports_vCont_S;
     lldb_private::LazyBool m_qHostInfo_is_valid;
-    lldb_private::LazyBool m_supports__m;
-    lldb_private::LazyBool m_supports__M;
+    lldb_private::LazyBool m_supports_alloc_dealloc_memory;
 
     bool
         m_supports_qProcessInfoPID:1,

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Sat May 14 20:25:55 2011
@@ -34,6 +34,7 @@
 #include "lldb/Core/State.h"
 #include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
+#include "lldb/Core/Value.h"
 #include "lldb/Host/TimeValue.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Target/DynamicLoader.h"
@@ -654,14 +655,18 @@
                     // Fill in what is missing in the triple
                     const llvm::Triple &remote_triple = gdb_remote_arch.GetTriple();
                     llvm::Triple &target_triple = target_arch.GetTriple();
-                    if (target_triple.getVendor() == llvm::Triple::UnknownVendor)
+                    if (target_triple.getVendorName().size() == 0)
+                    {
                         target_triple.setVendor (remote_triple.getVendor());
 
-                    if (target_triple.getOS() == llvm::Triple::UnknownOS)
-                        target_triple.setOS (remote_triple.getOS());
+                        if (target_triple.getOSName().size() == 0)
+                        {
+                            target_triple.setOS (remote_triple.getOS());
 
-                    if (target_triple.getEnvironment() == llvm::Triple::UnknownEnvironment)
-                        target_triple.setEnvironment (remote_triple.getEnvironment());
+                            if (target_triple.getEnvironmentName().size() == 0)
+                                target_triple.setEnvironment (remote_triple.getEnvironment());
+                        }
+                    }
                 }
             }
             else
@@ -1545,7 +1550,7 @@
 {
     addr_t allocated_addr = LLDB_INVALID_ADDRESS;
     
-    LazyBool supported = m_gdb_comm.SupportsAllocateMemory();
+    LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory();
     switch (supported)
     {
         case eLazyBoolCalculate:
@@ -1596,31 +1601,44 @@
                         AddressRange mmap_range;
                         if (sc.GetAddressRange(range_scope, 0, use_inline_block_range, mmap_range))
                         {
-                            lldb::ThreadPlanSP call_plan_sp (new ThreadPlanCallFunction (*thread,
-                                                                                         mmap_range.GetBaseAddress(),
-                                                                                         stop_other_threads,
-                                                                                         discard_on_error,
-                                                                                         &arg1_addr,
-                                                                                         &arg2_len,
-                                                                                         &arg3_prot,
-                                                                                         &arg4_flags,
-                                                                                         &arg5_fd,
-                                                                                         &arg6_offset));
+                            ThreadPlanCallFunction *call_function_thread_plan = new ThreadPlanCallFunction (*thread,
+                                                                                                            mmap_range.GetBaseAddress(),
+                                                                                                            stop_other_threads,
+                                                                                                            discard_on_error,
+                                                                                                            &arg1_addr,
+                                                                                                            &arg2_len,
+                                                                                                            &arg3_prot,
+                                                                                                            &arg4_flags,
+                                                                                                            &arg5_fd,
+                                                                                                            &arg6_offset);
+                            lldb::ThreadPlanSP call_plan_sp (call_function_thread_plan);
                             if (call_plan_sp)
                             {
+                                ValueSP return_value_sp (new Value);
+                                ClangASTContext *clang_ast_context = m_target.GetScratchClangASTContext();
+                                lldb::clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false);
+                                return_value_sp->SetValueType (Value::eValueTypeScalar);
+                                return_value_sp->SetContext (Value::eContextTypeClangType, clang_void_ptr_type);
+                                call_function_thread_plan->RequestReturnValue (return_value_sp);
+    
                                 StreamFile error_strm;
                                 StackFrame *frame = thread->GetStackFrameAtIndex (0).get();
                                 if (frame)
                                 {
                                     ExecutionContext exe_ctx;
                                     frame->CalculateExecutionContext (exe_ctx);
-                                    ExecutionResults results = RunThreadPlan (exe_ctx,
-                                                                              call_plan_sp,        
-                                                                              stop_other_threads,
-                                                                              try_all_threads,
-                                                                              discard_on_error,
-                                                                              single_thread_timeout_usec,
-                                                                              error_strm);
+                                    ExecutionResults result = RunThreadPlan (exe_ctx,
+                                                                             call_plan_sp,        
+                                                                             stop_other_threads,
+                                                                             try_all_threads,
+                                                                             discard_on_error,
+                                                                             single_thread_timeout_usec,
+                                                                             error_strm);
+                                    if (result == eExecutionCompleted)
+                                    {
+                                        allocated_addr = return_value_sp->GetScalar().ULongLong();
+                                        m_addr_to_mmap_size[allocated_addr] = size;
+                                    }
                                 }
                             }
                         }
@@ -1641,8 +1659,91 @@
 ProcessGDBRemote::DoDeallocateMemory (lldb::addr_t addr)
 {
     Error error; 
-    if (!m_gdb_comm.DeallocateMemory (addr))
-        error.SetErrorStringWithFormat("unable to deallocate memory at 0x%llx", addr);
+    LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory();
+
+    switch (supported)
+    {
+        case eLazyBoolCalculate:
+            // We should never be deallocating memory without allocating memory 
+            // first so we should never get eLazyBoolCalculate
+            error.SetErrorString ("tried to deallocate memory without ever allocating memory");
+            break;
+
+        case eLazyBoolYes:
+            if (!m_gdb_comm.DeallocateMemory (addr))
+                error.SetErrorStringWithFormat("unable to deallocate memory at 0x%llx", addr);
+            break;
+            
+        case eLazyBoolNo:
+            // Call munmap() to create executable memory in the inferior..
+            {
+                MMapMap::iterator pos = m_addr_to_mmap_size.find(addr);
+                if (pos != m_addr_to_mmap_size.end())
+                {
+                    Thread *thread = GetThreadList().GetSelectedThread().get();
+                    if (thread == NULL)
+                        thread = GetThreadList().GetThreadAtIndex(0).get();
+                    
+                    const bool append = true;
+                    const bool include_symbols = true;
+                    SymbolContextList sc_list;
+                    const uint32_t count = m_target.GetImages().FindFunctions (ConstString ("munmap"), 
+                                                                               eFunctionNameTypeFull,
+                                                                               include_symbols, 
+                                                                               append, 
+                                                                               sc_list);
+                    if (count > 0)
+                    {
+                        SymbolContext sc;
+                        if (sc_list.GetContextAtIndex(0, sc))
+                        {
+                            const uint32_t range_scope = eSymbolContextFunction | eSymbolContextSymbol;
+                            const bool use_inline_block_range = false;
+                            const bool stop_other_threads = true;
+                            const bool discard_on_error = true;
+                            const bool try_all_threads = true;
+                            const uint32_t single_thread_timeout_usec = 500000;
+                            addr_t arg1_addr = addr;
+                            addr_t arg2_len = pos->second;
+                            
+                            AddressRange munmap_range;
+                            if (sc.GetAddressRange(range_scope, 0, use_inline_block_range, munmap_range))
+                            {
+                                lldb::ThreadPlanSP call_plan_sp (new ThreadPlanCallFunction (*thread,
+                                                                                             munmap_range.GetBaseAddress(),
+                                                                                             stop_other_threads,
+                                                                                             discard_on_error,
+                                                                                             &arg1_addr,
+                                                                                             &arg2_len));
+                                if (call_plan_sp)
+                                {
+                                    StreamFile error_strm;
+                                    StackFrame *frame = thread->GetStackFrameAtIndex (0).get();
+                                    if (frame)
+                                    {
+                                        ExecutionContext exe_ctx;
+                                        frame->CalculateExecutionContext (exe_ctx);
+                                        ExecutionResults result = RunThreadPlan (exe_ctx,
+                                                                                 call_plan_sp,        
+                                                                                 stop_other_threads,
+                                                                                 try_all_threads,
+                                                                                 discard_on_error,
+                                                                                 single_thread_timeout_usec,
+                                                                                 error_strm);
+                                        if (result == eExecutionCompleted)
+                                        {
+                                            m_addr_to_mmap_size.erase (pos);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            break;
+    }
+
     return error;
 }
 

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Sat May 14 20:25:55 2011
@@ -303,6 +303,7 @@
     lldb::thread_t m_async_thread;
     typedef std::vector<lldb::tid_t> tid_collection;
     typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
+    typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
     tid_collection m_continue_c_tids;                  // 'c' for continue
     tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
     tid_collection m_continue_s_tids;                  // 's' for step
@@ -312,7 +313,7 @@
     bool m_waiting_for_attach;
     bool m_local_debugserver;  // Is the debugserver process we are talking to local or on another machine.
     std::vector<lldb::user_id_t>  m_thread_observation_bps;
-
+    MMapMap m_addr_to_mmap_size;
     bool
     StartAsyncThread ();
 

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp Sat May 14 20:25:55 2011
@@ -43,7 +43,6 @@
     m_dispatch_queue_name (),
     m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS)
 {
-//    ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD | GDBR_LOG_VERBOSE, "ThreadGDBRemote::ThreadGDBRemote ( pid = %i, tid = 0x%4.4x, )", m_process.GetID(), GetID());
     ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID());
 }
 

Modified: lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp (original)
+++ lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp Sat May 14 20:25:55 2011
@@ -84,7 +84,9 @@
             m_pushed_regs.clear();
 
             m_initial_sp = (1ull << ((addr_byte_size * 8) - 1));
-            SetRegisterValue (m_cfa_reg_info, m_initial_sp);
+            RegisterValue cfa_reg_value;
+            cfa_reg_value.SetUInt (m_initial_sp, m_cfa_reg_info.byte_size);
+            SetRegisterValue (m_cfa_reg_info, cfa_reg_value);
                 
             const InstructionList &inst_list = disasm_sp->GetInstructionList ();
             const size_t num_instructions = inst_list.GetSize();

Modified: lldb/trunk/source/Target/RegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/RegisterContext.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Target/RegisterContext.cpp (original)
+++ lldb/trunk/source/Target/RegisterContext.cpp Sat May 14 20:25:55 2011
@@ -150,14 +150,18 @@
 RegisterContext::ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value)
 {
     if (reg != LLDB_INVALID_REGNUM)
+        return ReadRegisterAsUnsigned (GetRegisterInfoAtIndex (reg), fail_value);
+    return fail_value;
+}
+
+uint64_t
+RegisterContext::ReadRegisterAsUnsigned (const RegisterInfo *reg_info, uint64_t fail_value)
+{
+    if (reg_info)
     {
-        const RegisterInfo *reg_info = GetRegisterInfoAtIndex (reg);
-        if (reg_info)
-        {
-            RegisterValue value;
-            if (ReadRegister (reg_info, value))
-                return value.GetAsUInt64();
-        }
+        RegisterValue value;
+        if (ReadRegister (reg_info, value))
+            return value.GetAsUInt64();
     }
     return fail_value;
 }
@@ -167,7 +171,12 @@
 {
     if (reg == LLDB_INVALID_REGNUM)
         return false;
-    const RegisterInfo *reg_info = GetRegisterInfoAtIndex (reg);
+    return WriteRegisterFromUnsigned (GetRegisterInfoAtIndex (reg), uval);
+}
+
+bool
+RegisterContext::WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval)
+{
     if (reg_info)
     {
         RegisterValue value;

Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=131370&r1=131369&r2=131370&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Sat May 14 20:25:55 2011
@@ -272,6 +272,13 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
     if (!m_takedown_done)
     {
+        // TODO: how do we tell if all went well?
+        if (m_return_value_sp)
+        {
+            const ABI *abi = m_thread.GetProcess().GetABI().get();
+            if (abi)
+                abi->GetReturnValue(m_thread, *m_return_value_sp);
+        }
         if (log)
             log->Printf ("DoTakedown called for thread 0x%4.4x, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete());
         m_takedown_done = true;





More information about the lldb-commits mailing list