1 //===-- SBFileSpecList.cpp ------------------------------------------------===// 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 //===----------------------------------------------------------------------===// 8 9 #include "lldb/API/SBFileSpecList.h" 10 #include "SBReproducerPrivate.h" 11 #include "Utils.h" 12 #include "lldb/API/SBFileSpec.h" 13 #include "lldb/API/SBStream.h" 14 #include "lldb/Core/FileSpecList.h" 15 #include "lldb/Host/PosixApi.h" 16 #include "lldb/Utility/FileSpec.h" 17 #include "lldb/Utility/Stream.h" 18 19 #include <limits.h> 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) { 25 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFileSpecList); 26 } 27 28 SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_up() { 29 LLDB_RECORD_CONSTRUCTOR(SBFileSpecList, (const lldb::SBFileSpecList &), rhs); 30 31 32 m_opaque_up = clone(rhs.m_opaque_up); 33 } 34 35 SBFileSpecList::~SBFileSpecList() = default; 36 37 const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) { 38 LLDB_RECORD_METHOD(const lldb::SBFileSpecList &, 39 SBFileSpecList, operator=,(const lldb::SBFileSpecList &), 40 rhs); 41 42 if (this != &rhs) 43 m_opaque_up = clone(rhs.m_opaque_up); 44 return LLDB_RECORD_RESULT(*this); 45 } 46 47 uint32_t SBFileSpecList::GetSize() const { 48 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBFileSpecList, GetSize); 49 50 return m_opaque_up->GetSize(); 51 } 52 53 void SBFileSpecList::Append(const SBFileSpec &sb_file) { 54 LLDB_RECORD_METHOD(void, SBFileSpecList, Append, (const lldb::SBFileSpec &), 55 sb_file); 56 57 m_opaque_up->Append(sb_file.ref()); 58 } 59 60 bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) { 61 LLDB_RECORD_METHOD(bool, SBFileSpecList, AppendIfUnique, 62 (const lldb::SBFileSpec &), sb_file); 63 64 return m_opaque_up->AppendIfUnique(sb_file.ref()); 65 } 66 67 void SBFileSpecList::Clear() { 68 LLDB_RECORD_METHOD_NO_ARGS(void, SBFileSpecList, Clear); 69 70 m_opaque_up->Clear(); 71 } 72 73 uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file, 74 bool full) { 75 LLDB_RECORD_METHOD(uint32_t, SBFileSpecList, FindFileIndex, 76 (uint32_t, const lldb::SBFileSpec &, bool), idx, sb_file, 77 full); 78 79 return m_opaque_up->FindFileIndex(idx, sb_file.ref(), full); 80 } 81 82 const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const { 83 LLDB_RECORD_METHOD_CONST(const lldb::SBFileSpec, SBFileSpecList, 84 GetFileSpecAtIndex, (uint32_t), idx); 85 86 SBFileSpec new_spec; 87 new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx)); 88 return LLDB_RECORD_RESULT(new_spec); 89 } 90 91 const lldb_private::FileSpecList *SBFileSpecList::operator->() const { 92 return m_opaque_up.get(); 93 } 94 95 const lldb_private::FileSpecList *SBFileSpecList::get() const { 96 return m_opaque_up.get(); 97 } 98 99 const lldb_private::FileSpecList &SBFileSpecList::operator*() const { 100 return *m_opaque_up; 101 } 102 103 const lldb_private::FileSpecList &SBFileSpecList::ref() const { 104 return *m_opaque_up; 105 } 106 107 bool SBFileSpecList::GetDescription(SBStream &description) const { 108 LLDB_RECORD_METHOD_CONST(bool, SBFileSpecList, GetDescription, 109 (lldb::SBStream &), description); 110 111 Stream &strm = description.ref(); 112 113 if (m_opaque_up) { 114 uint32_t num_files = m_opaque_up->GetSize(); 115 strm.Printf("%d files: ", num_files); 116 for (uint32_t i = 0; i < num_files; i++) { 117 char path[PATH_MAX]; 118 if (m_opaque_up->GetFileSpecAtIndex(i).GetPath(path, sizeof(path))) 119 strm.Printf("\n %s", path); 120 } 121 } else 122 strm.PutCString("No value"); 123 124 return true; 125 } 126 127 namespace lldb_private { 128 namespace repro { 129 130 template <> 131 void RegisterMethods<SBFileSpecList>(Registry &R) { 132 LLDB_REGISTER_CONSTRUCTOR(SBFileSpecList, ()); 133 LLDB_REGISTER_CONSTRUCTOR(SBFileSpecList, (const lldb::SBFileSpecList &)); 134 LLDB_REGISTER_METHOD( 135 const lldb::SBFileSpecList &, 136 SBFileSpecList, operator=,(const lldb::SBFileSpecList &)); 137 LLDB_REGISTER_METHOD_CONST(uint32_t, SBFileSpecList, GetSize, ()); 138 LLDB_REGISTER_METHOD(void, SBFileSpecList, Append, 139 (const lldb::SBFileSpec &)); 140 LLDB_REGISTER_METHOD(bool, SBFileSpecList, AppendIfUnique, 141 (const lldb::SBFileSpec &)); 142 LLDB_REGISTER_METHOD(void, SBFileSpecList, Clear, ()); 143 LLDB_REGISTER_METHOD(uint32_t, SBFileSpecList, FindFileIndex, 144 (uint32_t, const lldb::SBFileSpec &, bool)); 145 LLDB_REGISTER_METHOD_CONST(const lldb::SBFileSpec, SBFileSpecList, 146 GetFileSpecAtIndex, (uint32_t)); 147 LLDB_REGISTER_METHOD_CONST(bool, SBFileSpecList, GetDescription, 148 (lldb::SBStream &)); 149 } 150 151 } 152 } 153