#include "lldb/lldb-forward.h"
#include "lldb/lldb-private.h"
#include "lldb/Core/ClangForward.h"
+#include "lldb/Core/DataBufferHeap.h"
#include "llvm/ExecutionEngine/JITMemoryManager.h"
#include "lldb/Expression/ClangExpression.h"
#include "lldb/Expression/ClangExpressionParser.h"
{
lldb::addr_t m_remote_allocation;///< The (unaligned) base for the remote allocation
lldb::addr_t m_remote_start; ///< The base address of the remote allocation
- uintptr_t m_local_start; ///< The base address of the local allocation - LLDB_INVALID_ADDRESS means it was allocated with WriteNow
+ uintptr_t m_local_start; ///< The base address of the local allocation
uintptr_t m_size; ///< The size of the allocation
unsigned m_section_id; ///< The ID of the section
unsigned m_alignment; ///< The required alignment for the allocation
bool m_executable; ///< True <=> the allocation must be executable in the target
bool m_allocated; ///< True <=> the allocation has been propagated to the target
+ std::unique_ptr<DataBufferHeap> m_data; ///< If non-NULL, a local data buffer containing the written bytes. Only populated by WriteNow.
+
static const unsigned eSectionIDNone = (unsigned)-1;
//------------------------------------------------------------------
m_process_wp(process_sp),
m_module_ap(module_ap),
m_module(m_module_ap.get()),
- m_cpu_features(),
+ m_cpu_features(cpu_features),
m_name(name),
m_did_jit(false),
m_function_load_addr(LLDB_INVALID_ADDRESS),
m_function_end_load_addr(LLDB_INVALID_ADDRESS)
{
- for (std::string &feature : cpu_features)
- {
- m_cpu_features.push_back(std::string(feature.c_str()));
- }
}
lldb::addr_t
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- Allocation allocation;
+ auto iter = m_allocations.insert(m_allocations.end(), Allocation());
+
+ Allocation &allocation(*iter);
+
allocation.m_size = size;
allocation.m_alignment = 8;
- allocation.m_local_start = LLDB_INVALID_ADDRESS;
+ allocation.m_data.reset(new DataBufferHeap(bytes, size));
+ allocation.m_local_start = (uintptr_t)allocation.m_data->GetBytes();
allocation.m_section_id = Allocation::eSectionIDNone;
lldb_private::Error err;
{
err.SetErrorToGenericError();
err.SetErrorString("Couldn't find the process");
+ return LLDB_INVALID_ADDRESS;
}
allocation.m_remote_allocation = process_sp->AllocateMemory(allocation_size,
log->Printf("IRExecutionUnit::WriteNow() wrote to 0x%llx", allocation.m_remote_start);
allocation.dump(log);
}
-
- m_allocations.push_back(allocation);
-
+
return allocation.m_remote_start;
}
uint8_t *return_value = m_default_mm_ap->allocateStub(F, StubSize, Alignment);
- Allocation allocation;
+ auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+
+ Allocation &allocation(*iter);
+
allocation.m_size = StubSize;
allocation.m_alignment = Alignment;
allocation.m_local_start = (uintptr_t)return_value;
F, StubSize, Alignment, return_value);
allocation.dump(log);
}
-
- m_parent.m_allocations.push_back(allocation);
-
+
return return_value;
}
uint8_t *return_value = m_default_mm_ap->allocateSpace(Size, Alignment);
- Allocation allocation;
+ auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+
+ Allocation &allocation(*iter);
+
allocation.m_size = Size;
allocation.m_alignment = Alignment;
allocation.m_local_start = (uintptr_t)return_value;
(uint64_t)Size, Alignment, return_value);
allocation.dump(log);
}
-
- m_parent.m_allocations.push_back(allocation);
-
+
return return_value;
}
uint8_t *return_value = m_default_mm_ap->allocateCodeSection(Size, Alignment, SectionID);
- Allocation allocation;
+ auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+
+ Allocation &allocation(*iter);
+
allocation.m_size = Size;
allocation.m_alignment = Alignment;
allocation.m_local_start = (uintptr_t)return_value;
(uint64_t)Size, Alignment, SectionID, return_value);
allocation.dump(log);
}
-
- m_parent.m_allocations.push_back(allocation);
-
+
return return_value;
}
uint8_t *return_value = m_default_mm_ap->allocateDataSection(Size, Alignment, SectionID, IsReadOnly);
- Allocation allocation;
+ auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+
+ Allocation &allocation(*iter);
+
allocation.m_size = Size;
allocation.m_alignment = Alignment;
allocation.m_local_start = (uintptr_t)return_value;
(uint64_t)Size, Alignment, SectionID, return_value);
allocation.dump(log);
}
-
- m_parent.m_allocations.push_back(allocation);
-
+
return return_value;
}
uint8_t *return_value = m_default_mm_ap->allocateGlobal(Size, Alignment);
- Allocation allocation;
+ auto iter = m_parent.m_allocations.insert(m_parent.m_allocations.end(), Allocation());
+
+ Allocation &allocation(*iter);
+
allocation.m_size = Size;
allocation.m_alignment = Alignment;
allocation.m_local_start = (uintptr_t)return_value;
allocation.dump(log);
}
- m_parent.m_allocations.push_back(allocation);
-
return return_value;
}
if (!allocation.m_allocated)
continue;
- if (allocation.m_local_start == LLDB_INVALID_ADDRESS)
+ if (allocation.m_section_id == Allocation::eSectionIDNone)
continue;
engine.mapSectionAddress((void*)allocation.m_local_start, allocation.m_remote_start);