Skip to content

Commit

Permalink
Delete DataBufferMemoryMap.
Browse files Browse the repository at this point in the history
After a series of patches on the LLVM side to get the mmaping
code up to compatibility with LLDB's needs, it is now ready
to go, which means LLDB's custom mmapping code is redundant.
So this patch deletes it all and uses LLVM's code instead.

In the future, we could take this one step further and delete
even the lldb DataBuffer base class and rely entirely on
LLVM's facilities, but this is a job for another day.

Differential Revision: https://reviews.llvm.org/D30054

llvm-svn: 296159
  • Loading branch information
Zachary Turner committed Feb 24, 2017
1 parent bb361fc commit 3f4a4b3
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 760 deletions.
3 changes: 2 additions & 1 deletion lldb/include/lldb/Core/DataBufferHeap.h
Expand Up @@ -25,7 +25,8 @@ namespace lldb_private {
/// the object. This class is best used to store chunks of data that
/// are created or read from sources that can't intelligently and lazily
/// fault new data pages in. Large amounts of data that comes from files
/// should probably use the DataBufferMemoryMap class.
/// should probably use DataBufferLLVM, which can intelligently determine
/// when memory mapping is optimal.
//----------------------------------------------------------------------
class DataBufferHeap : public DataBuffer {
public:
Expand Down
46 changes: 46 additions & 0 deletions lldb/include/lldb/Core/DataBufferLLVM.h
@@ -0,0 +1,46 @@
//===--- DataBufferLLVM.h ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_CORE_DATABUFFERLLVM_H
#define LLDB_CORE_DATABUFFERLLVM_H

#include "lldb/Core/DataBuffer.h"

#include <memory>

namespace llvm {
class MemoryBuffer;
}

namespace lldb_private {

class DataBufferLLVM : public DataBuffer {
public:
~DataBufferLLVM();

static std::shared_ptr<DataBufferLLVM>
CreateFromPath(llvm::StringRef Path, uint64_t Size, uint64_t Offset);
static std::shared_ptr<DataBufferLLVM>
CreateFromFileSpec(const FileSpec &F, uint64_t Size, uint64_t Offset);

uint8_t *GetBytes() override;
const uint8_t *GetBytes() const override;
lldb::offset_t GetByteSize() const override;

private:
/// \brief Construct a DataBufferLLVM from \p Buffer. \p Buffer must be a
/// valid pointer.
explicit DataBufferLLVM(std::unique_ptr<llvm::MemoryBuffer> Buffer);
const uint8_t *GetBuffer() const;

std::unique_ptr<llvm::MemoryBuffer> Buffer;
};
}

#endif
154 changes: 0 additions & 154 deletions lldb/include/lldb/Core/DataBufferMemoryMap.h

This file was deleted.

69 changes: 0 additions & 69 deletions lldb/include/lldb/Host/FileSpec.h
Expand Up @@ -498,75 +498,6 @@ class FileSpec {
//------------------------------------------------------------------
size_t MemorySize() const;

//------------------------------------------------------------------
/// Memory map part of, or the entire contents of, a file.
///
/// Returns a shared pointer to a data buffer that contains all or
/// part of the contents of a file. The data is memory mapped and
/// will lazily page in data from the file as memory is accessed.
/// The data that is mapped will start \a offset bytes into the
/// file, and \a length bytes will be mapped. If \a length is
/// greater than the number of bytes available in the file starting
/// at \a offset, the number of bytes will be appropriately
/// truncated. The final number of bytes that get mapped can be
/// verified using the DataBuffer::GetByteSize() function on the return
/// shared data pointer object contents.
///
/// @param[in] offset
/// The offset in bytes from the beginning of the file where
/// memory mapping should begin.
///
/// @param[in] length
/// The size in bytes that should be mapped starting \a offset
/// bytes into the file. If \a length is \c SIZE_MAX, map
/// as many bytes as possible.
///
/// @return
/// A shared pointer to the memory mapped data. This shared
/// pointer can contain a nullptr DataBuffer pointer, so the contained
/// pointer must be checked prior to using it.
//------------------------------------------------------------------
lldb::DataBufferSP MemoryMapFileContents(off_t offset = 0,
size_t length = SIZE_MAX) const;

//------------------------------------------------------------------
/// Memory map part of, or the entire contents of, a file only if
/// the file is local (not on a network mount).
///
/// Returns a shared pointer to a data buffer that contains all or
/// part of the contents of a file. The data will be memory mapped
/// if the file is local and will lazily page in data from the file
/// as memory is accessed. If the data is memory mapped, the data
/// that is mapped will start \a offset bytes into the file, and
/// \a length bytes will be mapped. If \a length is
/// greater than the number of bytes available in the file starting
/// at \a offset, the number of bytes will be appropriately
/// truncated. The final number of bytes that get mapped can be
/// verified using the DataBuffer::GetByteSize() function on the return
/// shared data pointer object contents.
///
/// If the file is on a network mount the data will be read into a
/// heap buffer immediately so that accesses to the data won't later
/// cause a crash if we touch a page that isn't paged in and the
/// network mount has been disconnected or gone away.
///
/// @param[in] offset
/// The offset in bytes from the beginning of the file where
/// memory mapping should begin.
///
/// @param[in] length
/// The size in bytes that should be mapped starting \a offset
/// bytes into the file. If \a length is \c SIZE_MAX, map
/// as many bytes as possible.
///
/// @return
/// A shared pointer to the memory mapped data. This shared
/// pointer can contain a nullptr DataBuffer pointer, so the contained
/// pointer must be checked prior to using it.
//------------------------------------------------------------------
lldb::DataBufferSP MemoryMapFileContentsIfLocal(off_t file_offset,
size_t file_size) const;

//------------------------------------------------------------------
/// Read part of, or the entire contents of, a file into a heap based data
/// buffer.
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/CMakeLists.txt
Expand Up @@ -10,7 +10,7 @@ add_lldb_library(lldbCore
Communication.cpp
Connection.cpp
DataBufferHeap.cpp
DataBufferMemoryMap.cpp
DataBufferLLVM.cpp
DataEncoder.cpp
DataExtractor.cpp
Debugger.cpp
Expand Down
58 changes: 58 additions & 0 deletions lldb/source/Core/DataBufferLLVM.cpp
@@ -0,0 +1,58 @@
//===--- DataBufferLLVM.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/DataBufferLLVM.h"

#include "lldb/Host/FileSpec.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"

using namespace lldb_private;

DataBufferLLVM::DataBufferLLVM(std::unique_ptr<llvm::MemoryBuffer> MemBuffer)
: Buffer(std::move(MemBuffer)) {
assert(Buffer != nullptr &&
"Cannot construct a DataBufferLLVM with a null buffer");
}

DataBufferLLVM::~DataBufferLLVM() {}

std::shared_ptr<DataBufferLLVM>
DataBufferLLVM::CreateFromPath(llvm::StringRef Path, uint64_t Size,
uint64_t Offset) {
// If the file resides non-locally, pass the volatile flag so that we don't
// mmap it.
bool Volatile = !llvm::sys::fs::is_local(Path);

auto Buffer = llvm::MemoryBuffer::getFileSlice(Path, Size, Offset, Volatile);
if (!Buffer)
return nullptr;
return std::shared_ptr<DataBufferLLVM>(
new DataBufferLLVM(std::move(*Buffer)));
}

std::shared_ptr<DataBufferLLVM>
DataBufferLLVM::CreateFromFileSpec(const FileSpec &F, uint64_t Size,
uint64_t Offset) {
return CreateFromPath(F.GetPath(), Size, Offset);
}

uint8_t *DataBufferLLVM::GetBytes() {
return const_cast<uint8_t *>(GetBuffer());
}

const uint8_t *DataBufferLLVM::GetBytes() const { return GetBuffer(); }

lldb::offset_t DataBufferLLVM::GetByteSize() const {
return Buffer->getBufferSize();
}

const uint8_t *DataBufferLLVM::GetBuffer() const {
return reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
}

0 comments on commit 3f4a4b3

Please sign in to comment.