aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Utility/DataBufferLLVM.h
blob: 737e2d019044ec07b3d1032e98d379e3cda087e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//===--- 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/Utility/DataBuffer.h"
#include "lldb/lldb-types.h" // for offset_t

#include <memory>
#include <stdint.h> // for uint8_t, uint64_t

namespace llvm {
class MemoryBuffer;
class Twine;
}

namespace lldb_private {

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

  static std::shared_ptr<DataBufferLLVM>
  CreateSliceFromPath(const llvm::Twine &Path, uint64_t Size, uint64_t Offset, bool Private = false);

  static std::shared_ptr<DataBufferLLVM>
  CreateFromPath(const llvm::Twine &Path, bool NullTerminate = false, bool Private = false);

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

  char *GetChars() { return reinterpret_cast<char *>(GetBytes()); }

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