2017-02-25 02:56:49 +08:00
|
|
|
//===--- DataBufferLLVM.cpp -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "lldb/Utility/DataBufferLLVM.h"
|
2017-02-25 02:56:49 +08:00
|
|
|
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-02-25 02:56:49 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <assert.h>
|
|
|
|
#include <type_traits>
|
2017-04-07 02:12:24 +08:00
|
|
|
|
2017-02-25 02:56:49 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
Make sure DataBufferLLVM contents are writable
Summary:
We sometimes need to write to the object file we've mapped into memory,
generally to apply relocations to debug info sections. We've had that
ability before, but with the introduction of DataBufferLLVM, we have
lost it, as the underlying llvm class (MemoryBuffer) only supports
read-only mappings.
This switches DataBufferLLVM to use the new llvm::WritableMemoryBuffer
class as a back-end, as this one guarantees to return a writable buffer.
This removes the need for the "Private" flag to the DataBufferLLVM
creation functions, as it was really used to mean "writable". The LLVM
function also does not have the NullTerminate flag, so I've modified our
clients to not require this feature and removed that flag as well.
Reviewers: zturner, clayborg, jingham
Subscribers: emaste, aprantl, arichardson, krytarowski, lldb-commits
Differential Revision: https://reviews.llvm.org/D40079
llvm-svn: 321255
2017-12-21 18:54:30 +08:00
|
|
|
DataBufferLLVM::DataBufferLLVM(
|
|
|
|
std::unique_ptr<llvm::WritableMemoryBuffer> MemBuffer)
|
2017-02-25 02:56:49 +08:00
|
|
|
: Buffer(std::move(MemBuffer)) {
|
|
|
|
assert(Buffer != nullptr &&
|
|
|
|
"Cannot construct a DataBufferLLVM with a null buffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
DataBufferLLVM::~DataBufferLLVM() {}
|
|
|
|
|
|
|
|
uint8_t *DataBufferLLVM::GetBytes() {
|
Make sure DataBufferLLVM contents are writable
Summary:
We sometimes need to write to the object file we've mapped into memory,
generally to apply relocations to debug info sections. We've had that
ability before, but with the introduction of DataBufferLLVM, we have
lost it, as the underlying llvm class (MemoryBuffer) only supports
read-only mappings.
This switches DataBufferLLVM to use the new llvm::WritableMemoryBuffer
class as a back-end, as this one guarantees to return a writable buffer.
This removes the need for the "Private" flag to the DataBufferLLVM
creation functions, as it was really used to mean "writable". The LLVM
function also does not have the NullTerminate flag, so I've modified our
clients to not require this feature and removed that flag as well.
Reviewers: zturner, clayborg, jingham
Subscribers: emaste, aprantl, arichardson, krytarowski, lldb-commits
Differential Revision: https://reviews.llvm.org/D40079
llvm-svn: 321255
2017-12-21 18:54:30 +08:00
|
|
|
return reinterpret_cast<uint8_t *>(Buffer->getBufferStart());
|
2017-02-25 02:56:49 +08:00
|
|
|
}
|
|
|
|
|
Make sure DataBufferLLVM contents are writable
Summary:
We sometimes need to write to the object file we've mapped into memory,
generally to apply relocations to debug info sections. We've had that
ability before, but with the introduction of DataBufferLLVM, we have
lost it, as the underlying llvm class (MemoryBuffer) only supports
read-only mappings.
This switches DataBufferLLVM to use the new llvm::WritableMemoryBuffer
class as a back-end, as this one guarantees to return a writable buffer.
This removes the need for the "Private" flag to the DataBufferLLVM
creation functions, as it was really used to mean "writable". The LLVM
function also does not have the NullTerminate flag, so I've modified our
clients to not require this feature and removed that flag as well.
Reviewers: zturner, clayborg, jingham
Subscribers: emaste, aprantl, arichardson, krytarowski, lldb-commits
Differential Revision: https://reviews.llvm.org/D40079
llvm-svn: 321255
2017-12-21 18:54:30 +08:00
|
|
|
const uint8_t *DataBufferLLVM::GetBytes() const {
|
|
|
|
return reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
|
|
|
|
}
|
2017-02-25 02:56:49 +08:00
|
|
|
|
|
|
|
lldb::offset_t DataBufferLLVM::GetByteSize() const {
|
|
|
|
return Buffer->getBufferSize();
|
|
|
|
}
|