Skip to content

Commit e27561f

Browse files
committed
[lldb] Move MD5 Checksum from FileSpec to SupportFile
When I added the MD5 checksum I was on the fence between storing it in FileSpec or creating a new SupportFile abstraction. The latter was deemed overkill for just the MD5 hashes, but support for inline sources in the DWARF 5 line table tipped the scales. This patch moves the MD5 checksum into the new SupportFile class.
1 parent dcba077 commit e27561f

File tree

5 files changed

+16
-44
lines changed

5 files changed

+16
-44
lines changed

lldb/include/lldb/Utility/FileSpec.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <optional>
1414
#include <string>
1515

16-
#include "lldb/Utility/Checksum.h"
1716
#include "lldb/Utility/ConstString.h"
1817

1918
#include "llvm/ADT/StringRef.h"
@@ -72,12 +71,8 @@ class FileSpec {
7271
/// \param[in] style
7372
/// The style of the path
7473
///
75-
/// \param[in] checksum
76-
/// The MD5 checksum of the path.
77-
///
7874
/// \see FileSpec::SetFile (const char *path)
79-
explicit FileSpec(llvm::StringRef path, Style style = Style::native,
80-
const Checksum &checksum = {});
75+
explicit FileSpec(llvm::StringRef path, Style style = Style::native);
8176

8277
explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple);
8378

@@ -367,11 +362,7 @@ class FileSpec {
367362
///
368363
/// \param[in] style
369364
/// The style for the given path.
370-
///
371-
/// \param[in] checksum
372-
/// The checksum for the given path.
373-
void SetFile(llvm::StringRef path, Style style,
374-
const Checksum &checksum = {});
365+
void SetFile(llvm::StringRef path, Style style);
375366

376367
/// Change the file specified with a new path.
377368
///
@@ -414,19 +405,13 @@ class FileSpec {
414405
/// The lifetime of the StringRefs is tied to the lifetime of the FileSpec.
415406
std::vector<llvm::StringRef> GetComponents() const;
416407

417-
/// Return the checksum for this FileSpec or all zeros if there is none.
418-
const Checksum &GetChecksum() const { return m_checksum; };
419-
420408
protected:
421409
// Convenience method for setting the file without changing the style.
422410
void SetFile(llvm::StringRef path);
423411

424412
/// Called anytime m_directory or m_filename is changed to clear any cached
425413
/// state in this object.
426-
void PathWasModified() {
427-
m_checksum = Checksum();
428-
m_absolute = Absolute::Calculate;
429-
}
414+
void PathWasModified() { m_absolute = Absolute::Calculate; }
430415

431416
enum class Absolute : uint8_t {
432417
Calculate,
@@ -440,9 +425,6 @@ class FileSpec {
440425
/// The unique'd filename path.
441426
ConstString m_filename;
442427

443-
/// The optional MD5 checksum of the file.
444-
Checksum m_checksum;
445-
446428
/// Cache whether this path is absolute.
447429
mutable Absolute m_absolute = Absolute::Calculate;
448430

lldb/include/lldb/Utility/FileSpecList.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLDB_CORE_FILESPECLIST_H
1010
#define LLDB_CORE_FILESPECLIST_H
1111

12+
#include "lldb/Utility/Checksum.h"
1213
#include "lldb/Utility/FileSpec.h"
1314

1415
#include <cstddef>
@@ -24,17 +25,22 @@ class Stream;
2425
class SupportFile {
2526
protected:
2627
FileSpec m_file_spec;
28+
Checksum m_checksum;
2729

2830
public:
29-
SupportFile(const FileSpec &spec) : m_file_spec(spec) {}
31+
SupportFile(const FileSpec &spec) : m_file_spec(spec), m_checksum() {}
32+
SupportFile(const FileSpec &spec, const Checksum &checksum)
33+
: m_file_spec(spec), m_checksum(checksum) {}
3034
SupportFile(const SupportFile &other) = delete;
3135
SupportFile(SupportFile &&other) = default;
3236
virtual ~SupportFile() = default;
3337
bool operator==(const SupportFile &other) {
34-
return m_file_spec == other.m_file_spec;
38+
return m_file_spec == other.m_file_spec && m_checksum == other.m_checksum;
3539
}
3640
/// Return the file name only. Useful for resolving breakpoints by file name.
3741
const FileSpec &GetSpecOnly() const { return m_file_spec; };
42+
/// Return the checksum or all zeros if there is none.
43+
const Checksum &GetChecksum() const { return m_checksum; };
3844
/// Materialize the file to disk and return the path to that temporary file.
3945
virtual const FileSpec &Materialize() { return m_file_spec; }
4046
};
@@ -90,7 +96,7 @@ class SupportFileList {
9096

9197
template <class... Args> void EmplaceBack(Args &&...args) {
9298
m_files.push_back(
93-
std::make_unique<SupportFile>(FileSpec(std::forward<Args>(args)...)));
99+
std::make_unique<SupportFile>(std::forward<Args>(args)...));
94100
}
95101

96102
protected:

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static void ParseSupportFilesFromPrologue(
294294
}
295295

296296
// Unconditionally add an entry, so the indices match up.
297-
support_files.EmplaceBack(remapped_file, style, checksum);
297+
support_files.EmplaceBack(FileSpec(remapped_file, style), checksum);
298298
}
299299
}
300300

lldb/source/Utility/FileSpec.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ void Denormalize(llvm::SmallVectorImpl<char> &path, FileSpec::Style style) {
6868
FileSpec::FileSpec() : m_style(GetNativeStyle()) {}
6969

7070
// Default constructor that can take an optional full path to a file on disk.
71-
FileSpec::FileSpec(llvm::StringRef path, Style style, const Checksum &checksum)
72-
: m_checksum(checksum), m_style(style) {
73-
SetFile(path, style, checksum);
71+
FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) {
72+
SetFile(path, style);
7473
}
7574

7675
FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple)
@@ -172,11 +171,9 @@ void FileSpec::SetFile(llvm::StringRef pathname) { SetFile(pathname, m_style); }
172171
// Update the contents of this object with a new path. The path will be split
173172
// up into a directory and filename and stored as uniqued string values for
174173
// quick comparison and efficient memory usage.
175-
void FileSpec::SetFile(llvm::StringRef pathname, Style style,
176-
const Checksum &checksum) {
174+
void FileSpec::SetFile(llvm::StringRef pathname, Style style) {
177175
Clear();
178176
m_style = (style == Style::native) ? GetNativeStyle() : style;
179-
m_checksum = checksum;
180177

181178
if (pathname.empty())
182179
return;

lldb/unittests/Utility/FileSpecTest.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,3 @@ TEST(FileSpecTest, TestGetComponents) {
534534
EXPECT_EQ(file_spec.GetComponents(), pair.second);
535535
}
536536
}
537-
538-
TEST(FileSpecTest, TestChecksum) {
539-
Checksum checksum(llvm::MD5::MD5Result{
540-
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}});
541-
FileSpec file_spec("/foo/bar", FileSpec::Style::posix, checksum);
542-
EXPECT_TRUE(static_cast<bool>(file_spec.GetChecksum()));
543-
EXPECT_EQ(file_spec.GetChecksum(), checksum);
544-
545-
FileSpec copy = file_spec;
546-
547-
EXPECT_TRUE(static_cast<bool>(copy.GetChecksum()));
548-
EXPECT_EQ(file_spec.GetChecksum(), copy.GetChecksum());
549-
}

0 commit comments

Comments
 (0)