summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Expression/IRMemoryMap.h9
-rw-r--r--lldb/source/Expression/IRMemoryMap.cpp24
-rw-r--r--lldb/source/Expression/Materializer.cpp4
-rw-r--r--lldb/test/expression_command/persistent_variables/TestPersistentVariables.py25
-rw-r--r--lldb/test/expression_command/persistent_variables/main.c3
5 files changed, 51 insertions, 14 deletions
diff --git a/lldb/include/lldb/Expression/IRMemoryMap.h b/lldb/include/lldb/Expression/IRMemoryMap.h
index 2e8bdb43cf7..e2a3f07ad8d 100644
--- a/lldb/include/lldb/Expression/IRMemoryMap.h
+++ b/lldb/include/lldb/Expression/IRMemoryMap.h
@@ -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)
{
}
};
diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp
index 4c4cef41572..9a0f034dc62 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -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_t alignment, uint32_t permissions, Alloc
}
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();
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index f41a6134e12..897065fd315 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -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.
diff --git a/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py b/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py
index 47d1631d7c2..51c22aa9c52 100644
--- a/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py
+++ b/lldb/test/expression_command/persistent_variables/TestPersistentVariables.py
@@ -17,28 +17,33 @@ class PersistentVariablesTestCase(TestBase):
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
diff --git a/lldb/test/expression_command/persistent_variables/main.c b/lldb/test/expression_command/persistent_variables/main.c
index 343eac7e554..fd41471df8e 100644
--- a/lldb/test/expression_command/persistent_variables/main.c
+++ b/lldb/test/expression_command/persistent_variables/main.c
@@ -9,5 +9,6 @@
int main (int argc, char const *argv[])
{
- return 0;
+ int i = 5;
+ return 0; // Set breakpoint here
}
OpenPOWER on IntegriCloud