180814287SRaphael Isemann //===-- SBFileSpecList.cpp ------------------------------------------------===// 2969795f1SJim Ingham // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6969795f1SJim Ingham // 7969795f1SJim Ingham //===----------------------------------------------------------------------===// 8969795f1SJim Ingham 9baf5664fSJonas Devlieghere #include "lldb/API/SBFileSpecList.h" 10d51402acSJonas Devlieghere #include "lldb/Utility/ReproducerInstrumentation.h" 11bd4bf82aSJonas Devlieghere #include "Utils.h" 12969795f1SJim Ingham #include "lldb/API/SBFileSpec.h" 13969795f1SJim Ingham #include "lldb/API/SBStream.h" 14969795f1SJim Ingham #include "lldb/Core/FileSpecList.h" 158d48cd60SZachary Turner #include "lldb/Host/PosixApi.h" 165713a05bSZachary Turner #include "lldb/Utility/FileSpec.h" 17bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 18969795f1SJim Ingham 1976e47d48SRaphael Isemann #include <climits> 20baf5664fSJonas Devlieghere 21969795f1SJim Ingham using namespace lldb; 22969795f1SJim Ingham using namespace lldb_private; 23969795f1SJim Ingham 24baf5664fSJonas Devlieghere SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) { 25baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFileSpecList); 26baf5664fSJonas Devlieghere } 27969795f1SJim Ingham 28a3436f73SKazu Hirata SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) { 29baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR(SBFileSpecList, (const lldb::SBFileSpecList &), rhs); 30baf5664fSJonas Devlieghere 31bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up); 32969795f1SJim Ingham } 33969795f1SJim Ingham 34866b7a65SJonas Devlieghere SBFileSpecList::~SBFileSpecList() = default; 35969795f1SJim Ingham 36b9c1b51eSKate Stone const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) { 37baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(const lldb::SBFileSpecList &, 38baf5664fSJonas Devlieghere SBFileSpecList, operator=,(const lldb::SBFileSpecList &), 39baf5664fSJonas Devlieghere rhs); 40baf5664fSJonas Devlieghere 41bd4bf82aSJonas Devlieghere if (this != &rhs) 42bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up); 43*d232abc3SJonas Devlieghere return *this; 44969795f1SJim Ingham } 45969795f1SJim Ingham 46baf5664fSJonas Devlieghere uint32_t SBFileSpecList::GetSize() const { 47baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBFileSpecList, GetSize); 48baf5664fSJonas Devlieghere 49baf5664fSJonas Devlieghere return m_opaque_up->GetSize(); 50baf5664fSJonas Devlieghere } 51969795f1SJim Ingham 52b9c1b51eSKate Stone void SBFileSpecList::Append(const SBFileSpec &sb_file) { 53baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBFileSpecList, Append, (const lldb::SBFileSpec &), 54baf5664fSJonas Devlieghere sb_file); 55baf5664fSJonas Devlieghere 56d5b44036SJonas Devlieghere m_opaque_up->Append(sb_file.ref()); 57969795f1SJim Ingham } 58969795f1SJim Ingham 59b9c1b51eSKate Stone bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) { 60baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(bool, SBFileSpecList, AppendIfUnique, 61baf5664fSJonas Devlieghere (const lldb::SBFileSpec &), sb_file); 62baf5664fSJonas Devlieghere 63d5b44036SJonas Devlieghere return m_opaque_up->AppendIfUnique(sb_file.ref()); 64969795f1SJim Ingham } 65969795f1SJim Ingham 66baf5664fSJonas Devlieghere void SBFileSpecList::Clear() { 67baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(void, SBFileSpecList, Clear); 68baf5664fSJonas Devlieghere 69baf5664fSJonas Devlieghere m_opaque_up->Clear(); 70baf5664fSJonas Devlieghere } 71969795f1SJim Ingham 72b9c1b51eSKate Stone uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file, 73b9c1b51eSKate Stone bool full) { 74baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(uint32_t, SBFileSpecList, FindFileIndex, 75baf5664fSJonas Devlieghere (uint32_t, const lldb::SBFileSpec &, bool), idx, sb_file, 76baf5664fSJonas Devlieghere full); 77baf5664fSJonas Devlieghere 78d5b44036SJonas Devlieghere return m_opaque_up->FindFileIndex(idx, sb_file.ref(), full); 79969795f1SJim Ingham } 80969795f1SJim Ingham 81b9c1b51eSKate Stone const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const { 82baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST(const lldb::SBFileSpec, SBFileSpecList, 83baf5664fSJonas Devlieghere GetFileSpecAtIndex, (uint32_t), idx); 84baf5664fSJonas Devlieghere 85969795f1SJim Ingham SBFileSpec new_spec; 86d5b44036SJonas Devlieghere new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx)); 87*d232abc3SJonas Devlieghere return new_spec; 88969795f1SJim Ingham } 89969795f1SJim Ingham 90b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::operator->() const { 91d5b44036SJonas Devlieghere return m_opaque_up.get(); 92969795f1SJim Ingham } 93969795f1SJim Ingham 94b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::get() const { 95d5b44036SJonas Devlieghere return m_opaque_up.get(); 96969795f1SJim Ingham } 97969795f1SJim Ingham 98b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::operator*() const { 99d5b44036SJonas Devlieghere return *m_opaque_up; 100969795f1SJim Ingham } 101969795f1SJim Ingham 102b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::ref() const { 103d5b44036SJonas Devlieghere return *m_opaque_up; 104969795f1SJim Ingham } 105969795f1SJim Ingham 106b9c1b51eSKate Stone bool SBFileSpecList::GetDescription(SBStream &description) const { 107baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST(bool, SBFileSpecList, GetDescription, 108baf5664fSJonas Devlieghere (lldb::SBStream &), description); 109baf5664fSJonas Devlieghere 110da7bc7d0SGreg Clayton Stream &strm = description.ref(); 111da7bc7d0SGreg Clayton 112d5b44036SJonas Devlieghere if (m_opaque_up) { 113d5b44036SJonas Devlieghere uint32_t num_files = m_opaque_up->GetSize(); 114da7bc7d0SGreg Clayton strm.Printf("%d files: ", num_files); 115b9c1b51eSKate Stone for (uint32_t i = 0; i < num_files; i++) { 116969795f1SJim Ingham char path[PATH_MAX]; 117d5b44036SJonas Devlieghere if (m_opaque_up->GetFileSpecAtIndex(i).GetPath(path, sizeof(path))) 118da7bc7d0SGreg Clayton strm.Printf("\n %s", path); 119969795f1SJim Ingham } 120b9c1b51eSKate Stone } else 121da7bc7d0SGreg Clayton strm.PutCString("No value"); 122969795f1SJim Ingham 123969795f1SJim Ingham return true; 124969795f1SJim Ingham } 125