LLDB mainline
SupportFile.h
Go to the documentation of this file.
1//===-- SupportFile.h -------------------------------------------*- 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//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_UTILITY_SUPPORTFILE_H
10#define LLDB_UTILITY_SUPPORTFILE_H
11
14
15namespace lldb_private {
16
17/// Wraps a FileSpec and an optional Checksum. The FileSpec represents either a
18/// path to a file or a source file whose contents is known (for example because
19/// it can be reconstructed from debug info), but that hasn't been written to a
20/// file yet.
22public:
24 SupportFile(const FileSpec &spec) : m_file_spec(spec), m_checksum() {}
25 SupportFile(const FileSpec &spec, const Checksum &checksum)
26 : m_file_spec(spec), m_checksum(checksum) {}
27
28 SupportFile(const SupportFile &other) = delete;
29 SupportFile(SupportFile &&other) = default;
30
31 virtual ~SupportFile() = default;
32
33 enum SupportFileEquality : uint8_t {
34 eEqualFileSpec = (1u << 1),
35 eEqualChecksum = (1u << 2),
39 };
40
41 bool Equal(const SupportFile &other,
43 assert(!(equality & eEqualChecksum & eEqualChecksumIfSet) &&
44 "eEqualChecksum and eEqualChecksumIfSet are mutually exclusive");
45
46 if (equality & eEqualFileSpec) {
47 if (m_file_spec != other.m_file_spec)
48 return false;
49 }
50
51 if (equality & eEqualChecksum) {
52 if (m_checksum != other.m_checksum)
53 return false;
54 }
55
56 if (equality & eEqualChecksumIfSet) {
57 if (m_checksum && other.m_checksum)
58 if (m_checksum != other.m_checksum)
59 return false;
60 }
61
62 return true;
63 }
64
65 /// Return the file name only. Useful for resolving breakpoints by file name.
66 const FileSpec &GetSpecOnly() const { return m_file_spec; };
67
68 /// Return the checksum or all zeros if there is none.
69 const Checksum &GetChecksum() const { return m_checksum; };
70
71 /// Materialize the file to disk and return the path to that temporary file.
72 virtual const FileSpec &Materialize() { return m_file_spec; }
73
74protected:
77};
78
79} // namespace lldb_private
80
81#endif // LLDB_UTILITY_SUPPORTFILE_H
A file utility class.
Definition: FileSpec.h:56
Wraps a FileSpec and an optional Checksum.
Definition: SupportFile.h:21
const Checksum m_checksum
Definition: SupportFile.h:76
SupportFile(const SupportFile &other)=delete
virtual ~SupportFile()=default
SupportFile(const FileSpec &spec, const Checksum &checksum)
Definition: SupportFile.h:25
SupportFile(SupportFile &&other)=default
const FileSpec & GetSpecOnly() const
Return the file name only. Useful for resolving breakpoints by file name.
Definition: SupportFile.h:66
bool Equal(const SupportFile &other, SupportFileEquality equality=eEqualFileSpecAndChecksum) const
Definition: SupportFile.h:41
const FileSpec m_file_spec
Definition: SupportFile.h:75
virtual const FileSpec & Materialize()
Materialize the file to disk and return the path to that temporary file.
Definition: SupportFile.h:72
const Checksum & GetChecksum() const
Return the checksum or all zeros if there is none.
Definition: SupportFile.h:69
SupportFile(const FileSpec &spec)
Definition: SupportFile.h:24
A class that represents a running process on the host machine.