[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBFile.cpp
blob277402f31abf7d68c5330f305a489896e907c2e2
1 //===-- SBFile.cpp ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBFile.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBError.h"
12 #include "lldb/Host/File.h"
14 using namespace lldb;
15 using namespace lldb_private;
17 SBFile::~SBFile() {}
19 SBFile::SBFile(FileSP file_sp) : m_opaque_sp(file_sp) {
20 LLDB_RECORD_DUMMY(void, SBfile, SBFile, (FileSP), file_sp);
23 SBFile::SBFile() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFile); }
25 SBFile::SBFile(FILE *file, bool transfer_ownership) {
26 LLDB_RECORD_DUMMY(void, SBFile, (FILE *, bool), file, transfer_ownership);
27 m_opaque_sp = std::make_shared<NativeFile>(file, transfer_ownership);
30 SBFile::SBFile(int fd, const char *mode, bool transfer_owndership) {
31 LLDB_RECORD_DUMMY(void, SBFile, (int, const char *, bool), fd, mode,
32 transfer_owndership);
33 auto options = File::GetOptionsFromMode(mode);
34 if (!options) {
35 llvm::consumeError(options.takeError());
36 return;
38 m_opaque_sp =
39 std::make_shared<NativeFile>(fd, options.get(), transfer_owndership);
42 SBError SBFile::Read(uint8_t *buf, size_t num_bytes, size_t *bytes_read) {
43 LLDB_RECORD_DUMMY(lldb::SBError, SBFile, Read, (uint8_t *, size_t, size_t *),
44 buf, num_bytes, bytes_read);
45 SBError error;
46 if (!m_opaque_sp) {
47 error.SetErrorString("invalid SBFile");
48 *bytes_read = 0;
49 } else {
50 Status status = m_opaque_sp->Read(buf, num_bytes);
51 error.SetError(status);
52 *bytes_read = num_bytes;
54 return LLDB_RECORD_RESULT(error);
57 SBError SBFile::Write(const uint8_t *buf, size_t num_bytes,
58 size_t *bytes_written) {
59 LLDB_RECORD_DUMMY(lldb::SBError, SBFile, Write,
60 (const uint8_t *, size_t, size_t *), buf, num_bytes,
61 bytes_written);
62 SBError error;
63 if (!m_opaque_sp) {
64 error.SetErrorString("invalid SBFile");
65 *bytes_written = 0;
66 } else {
67 Status status = m_opaque_sp->Write(buf, num_bytes);
68 error.SetError(status);
69 *bytes_written = num_bytes;
71 return LLDB_RECORD_RESULT(error);
74 SBError SBFile::Flush() {
75 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBFile, Flush);
76 SBError error;
77 if (!m_opaque_sp) {
78 error.SetErrorString("invalid SBFile");
79 } else {
80 Status status = m_opaque_sp->Flush();
81 error.SetError(status);
83 return LLDB_RECORD_RESULT(error);
86 bool SBFile::IsValid() const {
87 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFile, IsValid);
88 return m_opaque_sp && m_opaque_sp->IsValid();
91 SBError SBFile::Close() {
92 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBFile, Close);
93 SBError error;
94 if (m_opaque_sp) {
95 Status status = m_opaque_sp->Close();
96 error.SetError(status);
98 return LLDB_RECORD_RESULT(error);
101 SBFile::operator bool() const {
102 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFile, operator bool);
103 return IsValid();
106 bool SBFile::operator!() const {
107 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFile, operator!);
108 return !IsValid();
111 FileSP SBFile::GetFile() const {
112 LLDB_RECORD_METHOD_CONST_NO_ARGS(FileSP, SBFile, GetFile);
113 return LLDB_RECORD_RESULT(m_opaque_sp);
116 namespace lldb_private {
117 namespace repro {
119 template <> void RegisterMethods<SBFile>(Registry &R) {
120 LLDB_REGISTER_CONSTRUCTOR(SBFile, ());
121 LLDB_REGISTER_CONSTRUCTOR(SBFile, (FileSP));
122 LLDB_REGISTER_CONSTRUCTOR(SBFile, (FILE *, bool));
123 LLDB_REGISTER_CONSTRUCTOR(SBFile, (int, const char *, bool));
124 LLDB_REGISTER_METHOD(lldb::SBError, SBFile, Flush, ());
125 LLDB_REGISTER_METHOD_CONST(bool, SBFile, IsValid, ());
126 LLDB_REGISTER_METHOD_CONST(bool, SBFile, operator bool,());
127 LLDB_REGISTER_METHOD_CONST(bool, SBFile, operator!,());
128 LLDB_REGISTER_METHOD_CONST(FileSP, SBFile, GetFile, ());
129 LLDB_REGISTER_METHOD(lldb::SBError, SBFile, Close, ());
131 } // namespace repro
132 } // namespace lldb_private