[Lldb-commits] [lldb] r182528 - Fixed a bug where persistent variables did not
Sean Callanan
scallanan at apple.com
Wed May 22 15:49:06 PDT 2013
Author: spyffe
Date: Wed May 22 17:49:06 2013
New Revision: 182528
URL: http://llvm.org/viewvc/llvm-project?rev=182528&view=rev
Log:
Fixed a bug where persistent variables did not
live as long as they needed to. This led to
equality tests involving persistent variables
often failing or succeeding when they had no
business doing so.
To do this, I introduced the ability for a
memory allocation to "leak" - that is, to
persist in the process beyond the lifetime of
the expression. Hand-declared persistent
variables do this now.
<rdar://problem/13956311>
Modified:
lldb/trunk/include/lldb/Expression/IRMemoryMap.h
lldb/trunk/source/Expression/IRMemoryMap.cpp
lldb/trunk/source/Expression/Materializer.cpp
lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py
lldb/trunk/test/expression_command/persistent_variables/main.c
Modified: lldb/trunk/include/lldb/Expression/IRMemoryMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRMemoryMap.h?rev=182528&r1=182527&r2=182528&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRMemoryMap.h (original)
+++ lldb/trunk/include/lldb/Expression/IRMemoryMap.h Wed May 22 17:49:06 2013
@@ -50,6 +50,7 @@ public:
};
lldb::addr_t Malloc (size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, Error &error);
+ void Leak (lldb::addr_t process_address, Error &error);
void Free (lldb::addr_t process_address, Error &error);
void WriteMemory (lldb::addr_t process_address, const uint8_t *bytes, size_t size, Error &error);
@@ -84,7 +85,10 @@ private:
uint32_t m_permissions; ///< The access permissions on the memory in the process. In the host, the memory is always read/write.
uint8_t m_alignment; ///< The alignment of the requested allocation
DataBufferHeap m_data;
- AllocationPolicy m_policy;
+
+ ///< Flags
+ AllocationPolicy m_policy : 2;
+ bool m_leak : 1;
public:
Allocation (lldb::addr_t process_alloc,
lldb::addr_t process_start,
@@ -100,7 +104,8 @@ private:
m_permissions (0),
m_alignment (0),
m_data (),
- m_policy (eAllocationPolicyInvalid)
+ m_policy (eAllocationPolicyInvalid),
+ m_leak (false)
{
}
};
Modified: lldb/trunk/source/Expression/IRMemoryMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRMemoryMap.cpp?rev=182528&r1=182527&r2=182528&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRMemoryMap.cpp (original)
+++ lldb/trunk/source/Expression/IRMemoryMap.cpp Wed May 22 17:49:06 2013
@@ -38,7 +38,10 @@ IRMemoryMap::~IRMemoryMap ()
while ((iter = m_allocations.begin()) != m_allocations.end())
{
err.Clear();
- Free(iter->first, err);
+ if (iter->second.m_leak)
+ m_allocations.erase(iter);
+ else
+ Free(iter->first, err);
}
}
}
@@ -369,6 +372,25 @@ IRMemoryMap::Malloc (size_t size, uint8_
}
void
+IRMemoryMap::Leak (lldb::addr_t process_address, Error &error)
+{
+ error.Clear();
+
+ AllocationMap::iterator iter = m_allocations.find(process_address);
+
+ if (iter == m_allocations.end())
+ {
+ error.SetErrorToGenericError();
+ error.SetErrorString("Couldn't leak: allocation doesn't exist");
+ return;
+ }
+
+ Allocation &allocation = iter->second;
+
+ allocation.m_leak = true;
+}
+
+void
IRMemoryMap::Free (lldb::addr_t process_address, Error &error)
{
error.Clear();
Modified: lldb/trunk/source/Expression/Materializer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/Materializer.cpp?rev=182528&r1=182527&r2=182528&view=diff
==============================================================================
--- lldb/trunk/source/Expression/Materializer.cpp (original)
+++ lldb/trunk/source/Expression/Materializer.cpp Wed May 22 17:49:06 2013
@@ -109,7 +109,11 @@ public:
// Clear the flag if the variable will never be deallocated.
if (m_persistent_variable_sp->m_flags & ClangExpressionVariable::EVKeepInTarget)
+ {
+ Error leak_error;
+ map.Leak(mem, leak_error);
m_persistent_variable_sp->m_flags &= ~ClangExpressionVariable::EVNeedsAllocation;
+ }
// Write the contents of the variable to the area.
Modified: lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py?rev=182528&r1=182527&r2=182528&view=diff
==============================================================================
--- lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py (original)
+++ lldb/trunk/test/expression_command/persistent_variables/TestPersistentVariables.py Wed May 22 17:49:06 2013
@@ -17,28 +17,33 @@ class PersistentVariablesTestCase(TestBa
self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
- self.runCmd("breakpoint set --name main")
+ self.runCmd("breakpoint set --source-pattern-regexp break")
self.runCmd("run", RUN_SUCCEEDED)
- self.expect("expression int $i = 5; $i + 1",
- startstr = "(int) $0 = 6")
+ self.runCmd("expression int $i = i")
+
+ self.expect("expression $i == i",
+ startstr = "(bool) $0 = true")
+
+ self.expect("expression $i + 1",
+ startstr = "(int) $1 = 6")
# (int) $0 = 6
self.expect("expression $i + 3",
- startstr = "(int) $1 = 8")
+ startstr = "(int) $2 = 8")
# (int) $1 = 8
- self.expect("expression $1 + $0",
- startstr = "(int) $2 = 14")
+ self.expect("expression $2 + $1",
+ startstr = "(int) $3 = 14")
# (int) $2 = 14
- self.expect("expression $2",
- startstr = "(int) $2 = 14")
+ self.expect("expression $3",
+ startstr = "(int) $3 = 14")
# (int) $2 = 14
- self.expect("expression $1",
- startstr = "(int) $1 = 8")
+ self.expect("expression $2",
+ startstr = "(int) $2 = 8")
# (int) $1 = 8
Modified: lldb/trunk/test/expression_command/persistent_variables/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/persistent_variables/main.c?rev=182528&r1=182527&r2=182528&view=diff
==============================================================================
--- lldb/trunk/test/expression_command/persistent_variables/main.c (original)
+++ lldb/trunk/test/expression_command/persistent_variables/main.c Wed May 22 17:49:06 2013
@@ -9,5 +9,6 @@
int main (int argc, char const *argv[])
{
- return 0;
+ int i = 5;
+ return 0; // Set breakpoint here
}
More information about the lldb-commits
mailing list