Author: ldrumm Date: Wed Aug 3 12:31:58 2016 New Revision: 277613 URL: http://llvm.org/viewvc/llvm-project?rev=277613&view=rev Log: [RenderScript] Always create a new allocation ID in CaptureAllocationInit hook
Due to internal reuse of buffers in the RenderScript runtime by the system allocator, comparing pointers is not a safe way to check whether an allocation is tracked by lldb. This change updates the lldb RenderScript internal hook callback to properly identify and remove old allocations that had have an address that is currently being tracked. This change also removes the need for `lldb_private::renderscript::LookupAllocation` to take a `create` flag, as this is now always the case. Original Author: <d...@codeplay.com> Subscribers: lldb-commits Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp?rev=277613&r1=277612&r2=277613&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp Wed Aug 3 12:31:58 2016 @@ -1091,7 +1091,10 @@ RenderScriptRuntime::CaptureScriptInvoke // for all allocations we have found for (const uint64_t alloc_addr : allocs) { - AllocationDetails* alloc = LookUpAllocation(alloc_addr, true); + AllocationDetails *alloc = LookUpAllocation(alloc_addr); + if (!alloc) + alloc = CreateAllocation(alloc_addr); + if (alloc) { // save the allocation address @@ -1207,7 +1210,7 @@ RenderScriptRuntime::CaptureAllocationIn log->Printf("%s - 0x%" PRIx64 ",0x%" PRIx64 ",0x%" PRIx64 " .", __FUNCTION__, uint64_t(args[eRsContext]), uint64_t(args[eRsAlloc]), uint64_t(args[eRsForceZero])); - AllocationDetails *alloc = LookUpAllocation(uint64_t(args[eRsAlloc]), true); + AllocationDetails *alloc = CreateAllocation(uint64_t(args[eRsAlloc])); if (alloc) alloc->context = uint64_t(args[eRsContext]); } @@ -3467,7 +3470,7 @@ RenderScriptRuntime::LookUpScript(addr_t } RenderScriptRuntime::AllocationDetails * -RenderScriptRuntime::LookUpAllocation(addr_t address, bool create) +RenderScriptRuntime::LookUpAllocation(addr_t address) { for (const auto &a : m_allocations) { @@ -3475,14 +3478,35 @@ RenderScriptRuntime::LookUpAllocation(ad if (*a->address == address) return a.get(); } - if (create) + return nullptr; +} + +RenderScriptRuntime::AllocationDetails * +RenderScriptRuntime::CreateAllocation(addr_t address) +{ + Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); + + // Remove any previous allocation which contains the same address + auto it = m_allocations.begin(); + while (it != m_allocations.end()) { - std::unique_ptr<AllocationDetails> a(new AllocationDetails); - a->address = address; - m_allocations.push_back(std::move(a)); - return m_allocations.back().get(); + if (*((*it)->address) == address) + { + if (log) + log->Printf("%s - Removing allocation id: %d, address: 0x%" PRIx64, __FUNCTION__, (*it)->id, address); + + it = m_allocations.erase(it); + } + else + { + it++; + } } - return nullptr; + + std::unique_ptr<AllocationDetails> a(new AllocationDetails); + a->address = address; + m_allocations.push_back(std::move(a)); + return m_allocations.back().get(); } void Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h?rev=277613&r1=277612&r2=277613&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h Wed Aug 3 12:31:58 2016 @@ -408,10 +408,13 @@ private: // Search for a previously saved allocation detail object using a target address. // If an allocation does not exist for this address then nullptr will be returned. - // If 'create' is true and there is no previous allocation then a new allocation - // detail object will be created for this address and returned. AllocationDetails * - LookUpAllocation(lldb::addr_t address, bool create); + LookUpAllocation(lldb::addr_t address); + + // Creates a new allocation with the specified address assigning a new ID and removes + // any previous stored allocation which has the same address. + AllocationDetails * + CreateAllocation(lldb::addr_t address); bool GetOverrideExprOptions(clang::TargetOptions &prototype) override; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits