[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
Matthew Weingarten via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 24 08:26:09 PDT 2024
================
@@ -96,19 +102,63 @@ llvm::SmallVector<SegmentEntry> readSegmentEntries(const char *Ptr) {
}
llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>>
-readMemInfoBlocks(const char *Ptr) {
+readMemInfoBlocksV3(const char *Ptr) {
using namespace support;
const uint64_t NumItemsToRead =
- endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
+ endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr);
+
llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>> Items;
for (uint64_t I = 0; I < NumItemsToRead; I++) {
const uint64_t Id =
- endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
- const MemInfoBlock MIB = *reinterpret_cast<const MemInfoBlock *>(Ptr);
+ endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr);
+
+ // We cheat a bit here and remove the const from cast to set the
+ // Histogram Pointer to newly allocated buffer. We also cheat, since V3 and
+ // V4 do not have the same fields. V3 is missing AccessHistogramSize and
+ // AccessHistogram. This means we read "dirty" data in here, but it should
+ // not segfault, since there will be callstack data placed after this in the
+ // binary format.
+ MemInfoBlock MIB = *reinterpret_cast<const MemInfoBlock *>(Ptr);
+ // Overwrite dirty data.
----------------
mattweingarten wrote:
My thought process is that the MemInfoBlock MIB is a allocated on the stack, since its a local variable and not a pointer. Meaning the reinterpret_cast copies the information from the data-buffer into the stack variable. Correct me if I am wrong
https://github.com/llvm/llvm-project/pull/94264
More information about the lldb-commits
mailing list