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"
10bd4bf82aSJonas Devlieghere #include "Utils.h"
11969795f1SJim Ingham #include "lldb/API/SBFileSpec.h"
12969795f1SJim Ingham #include "lldb/API/SBStream.h"
13969795f1SJim Ingham #include "lldb/Core/FileSpecList.h"
148d48cd60SZachary Turner #include "lldb/Host/PosixApi.h"
155713a05bSZachary Turner #include "lldb/Utility/FileSpec.h"
16*1755f5b1SJonas Devlieghere #include "lldb/Utility/Instrumentation.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
SBFileSpecList()24baf5664fSJonas Devlieghere SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) {
25*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
26baf5664fSJonas Devlieghere }
27969795f1SJim Ingham
SBFileSpecList(const SBFileSpecList & rhs)28a3436f73SKazu Hirata SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) {
29*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
30baf5664fSJonas Devlieghere
31bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up);
32969795f1SJim Ingham }
33969795f1SJim Ingham
34866b7a65SJonas Devlieghere SBFileSpecList::~SBFileSpecList() = default;
35969795f1SJim Ingham
operator =(const SBFileSpecList & rhs)36b9c1b51eSKate Stone const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
37*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
38baf5664fSJonas Devlieghere
39bd4bf82aSJonas Devlieghere if (this != &rhs)
40bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up);
41d232abc3SJonas Devlieghere return *this;
42969795f1SJim Ingham }
43969795f1SJim Ingham
GetSize() const44baf5664fSJonas Devlieghere uint32_t SBFileSpecList::GetSize() const {
45*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
46baf5664fSJonas Devlieghere
47baf5664fSJonas Devlieghere return m_opaque_up->GetSize();
48baf5664fSJonas Devlieghere }
49969795f1SJim Ingham
Append(const SBFileSpec & sb_file)50b9c1b51eSKate Stone void SBFileSpecList::Append(const SBFileSpec &sb_file) {
51*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, sb_file);
52baf5664fSJonas Devlieghere
53d5b44036SJonas Devlieghere m_opaque_up->Append(sb_file.ref());
54969795f1SJim Ingham }
55969795f1SJim Ingham
AppendIfUnique(const SBFileSpec & sb_file)56b9c1b51eSKate Stone bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
57*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, sb_file);
58baf5664fSJonas Devlieghere
59d5b44036SJonas Devlieghere return m_opaque_up->AppendIfUnique(sb_file.ref());
60969795f1SJim Ingham }
61969795f1SJim Ingham
Clear()62baf5664fSJonas Devlieghere void SBFileSpecList::Clear() {
63*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
64baf5664fSJonas Devlieghere
65baf5664fSJonas Devlieghere m_opaque_up->Clear();
66baf5664fSJonas Devlieghere }
67969795f1SJim Ingham
FindFileIndex(uint32_t idx,const SBFileSpec & sb_file,bool full)68b9c1b51eSKate Stone uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
69b9c1b51eSKate Stone bool full) {
70*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, idx, sb_file, full);
71baf5664fSJonas Devlieghere
72d5b44036SJonas Devlieghere return m_opaque_up->FindFileIndex(idx, sb_file.ref(), full);
73969795f1SJim Ingham }
74969795f1SJim Ingham
GetFileSpecAtIndex(uint32_t idx) const75b9c1b51eSKate Stone const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
76*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, idx);
77baf5664fSJonas Devlieghere
78969795f1SJim Ingham SBFileSpec new_spec;
79d5b44036SJonas Devlieghere new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx));
80d232abc3SJonas Devlieghere return new_spec;
81969795f1SJim Ingham }
82969795f1SJim Ingham
operator ->() const83b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::operator->() const {
84d5b44036SJonas Devlieghere return m_opaque_up.get();
85969795f1SJim Ingham }
86969795f1SJim Ingham
get() const87b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::get() const {
88d5b44036SJonas Devlieghere return m_opaque_up.get();
89969795f1SJim Ingham }
90969795f1SJim Ingham
operator *() const91b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::operator*() const {
92d5b44036SJonas Devlieghere return *m_opaque_up;
93969795f1SJim Ingham }
94969795f1SJim Ingham
ref() const95b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::ref() const {
96d5b44036SJonas Devlieghere return *m_opaque_up;
97969795f1SJim Ingham }
98969795f1SJim Ingham
GetDescription(SBStream & description) const99b9c1b51eSKate Stone bool SBFileSpecList::GetDescription(SBStream &description) const {
100*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, description);
101baf5664fSJonas Devlieghere
102da7bc7d0SGreg Clayton Stream &strm = description.ref();
103da7bc7d0SGreg Clayton
104d5b44036SJonas Devlieghere if (m_opaque_up) {
105d5b44036SJonas Devlieghere uint32_t num_files = m_opaque_up->GetSize();
106da7bc7d0SGreg Clayton strm.Printf("%d files: ", num_files);
107b9c1b51eSKate Stone for (uint32_t i = 0; i < num_files; i++) {
108969795f1SJim Ingham char path[PATH_MAX];
109d5b44036SJonas Devlieghere if (m_opaque_up->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
110da7bc7d0SGreg Clayton strm.Printf("\n %s", path);
111969795f1SJim Ingham }
112b9c1b51eSKate Stone } else
113da7bc7d0SGreg Clayton strm.PutCString("No value");
114969795f1SJim Ingham
115969795f1SJim Ingham return true;
116969795f1SJim Ingham }
117