Skip to content

Commit 6011b7e

Browse files
committed
Address most of Jim's comments
1 parent b99ced0 commit 6011b7e

File tree

9 files changed

+32
-28
lines changed

9 files changed

+32
-28
lines changed

lldb/include/lldb/Symbol/CompileUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
#include "lldb/Utility/Stream.h"
2020
#include "lldb/Utility/UserID.h"
2121
#include "lldb/lldb-enumerations.h"
22+
#include "lldb/lldb-forward.h"
2223

2324
#include "llvm/ADT/DenseMap.h"
2425
#include "llvm/ADT/DenseSet.h"
2526

2627
namespace lldb_private {
27-
class RealpathPrefixes;
2828

2929
/// \class CompileUnit CompileUnit.h "lldb/Symbol/CompileUnit.h"
3030
/// A class that describes a compilation unit.

lldb/include/lldb/Target/Statistics.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_TARGET_STATISTICS_H
1111

1212
#include "lldb/Utility/ConstString.h"
13+
#include "lldb/Utility/RealpathPrefixes.h"
1314
#include "lldb/Utility/Stream.h"
1415
#include "lldb/lldb-forward.h"
1516
#include "llvm/ADT/StringMap.h"
@@ -175,7 +176,7 @@ struct StatisticsOptions {
175176
};
176177

177178
/// A class that represents statistics for a since lldb_private::Target.
178-
class TargetStats {
179+
class TargetStats : public RealpathPrefixesStats {
179180
public:
180181
llvm::json::Value ToJSON(Target &target,
181182
const lldb_private::StatisticsOptions &options);
@@ -184,8 +185,8 @@ class TargetStats {
184185
void SetFirstPrivateStopTime();
185186
void SetFirstPublicStopTime();
186187
void IncreaseSourceMapDeduceCount();
187-
void IncreaseSourceRealpathAttemptCount();
188-
void IncreaseSourceRealpathCompatibleCount();
188+
virtual void IncreaseSourceRealpathAttemptCount() override;
189+
virtual void IncreaseSourceRealpathCompatibleCount() override;
189190

190191
StatsDuration &GetCreateTime() { return m_create_time; }
191192
StatsSuccessFail &GetExpressionStats() { return m_expr_eval; }

lldb/include/lldb/Utility/FileSpecList.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <vector>
1818

1919
namespace lldb_private {
20-
class RealpathPrefixes;
2120
class Stream;
2221

2322
/// A list of support files for a CompileUnit.

lldb/include/lldb/Utility/RealpathPrefixes.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99
#ifndef LLDB_CORE_REALPATHPREFIXES_H
1010
#define LLDB_CORE_REALPATHPREFIXES_H
1111

12+
#include "lldb/lldb-forward.h"
1213
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1314
#include "llvm/Support/VirtualFileSystem.h"
1415

1516
#include <optional>
1617
#include <string>
1718
#include <vector>
1819

19-
namespace lldb_private {
20-
class FileSpec;
21-
class FileSpecList;
22-
class Target;
23-
} // namespace lldb_private
24-
2520
namespace lldb_private {
2621

2722
class RealpathPrefixes {
@@ -37,8 +32,8 @@ class RealpathPrefixes {
3732
void SetFileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs);
3833

3934
// Sets an optional Target instance to gather statistics.
40-
void SetTarget(Target *target) { m_target = target; }
41-
Target *GetTarget() const { return m_target; }
35+
void SetTarget(const lldb::TargetSP& target) { m_target = target; }
36+
lldb::TargetSP GetTarget() const { return m_target.lock(); }
4237

4338
std::optional<FileSpec> ResolveSymlinks(const FileSpec &file_spec) const;
4439

@@ -55,7 +50,15 @@ class RealpathPrefixes {
5550
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
5651

5752
// The optional Target instance to gather statistics.
58-
Target *m_target;
53+
lldb::TargetWP m_target;
54+
};
55+
56+
class RealpathPrefixesStats {
57+
public:
58+
virtual ~RealpathPrefixesStats() = default;
59+
60+
virtual void IncreaseSourceRealpathAttemptCount() = 0;
61+
virtual void IncreaseSourceRealpathCompatibleCount() = 0;
5962
};
6063

6164
} // namespace lldb_private

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class Queue;
175175
class QueueImpl;
176176
class QueueItem;
177177
class REPL;
178+
class RealpathPrefixes;
178179
class RecognizedStackFrame;
179180
class RegisterCheckpoint;
180181
class RegisterContext;

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4360,7 +4360,7 @@ InlineStrategy TargetProperties::GetInlineStrategy() const {
43604360
RealpathPrefixes TargetProperties::GetSourceRealpathPrefixes() const {
43614361
const uint32_t idx = ePropertySourceRealpathPrefixes;
43624362
auto prefixes = RealpathPrefixes(GetPropertyAtIndexAs<FileSpecList>(idx, {}));
4363-
prefixes.SetTarget(this->m_target);
4363+
prefixes.SetTarget(this->m_target->shared_from_this());
43644364
return prefixes;
43654365
}
43664366

lldb/source/Target/TargetProperties.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ let Definition = "target" in {
152152
Desc<"The strategy to use when settings breakpoints by file and line. Breakpoint locations can end up being inlined by the compiler, so that a compile unit 'a.c' might contain an inlined function from another source file. Usually this is limited to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. Always checking for inlined breakpoint locations can be expensive (memory and time), so if you have a project with many headers and find that setting breakpoints is slow, then you can change this setting to headers. This setting allows you to control exactly which strategy is used when setting file and line breakpoints.">;
153153
def SourceRealpathPrefixes: Property<"source-realpath-prefixes", "FileSpecList">,
154154
DefaultStringValue<"">,
155-
Desc<"Realpath any source paths that start with one of these prefixes. If the debug info contains symlinks that don't match the original source file locations that the user will use to set breakpoints, then this setting can help resolve breakpoints correctly.">;
155+
Desc<"Realpath any source paths that start with one of these prefixes. If the debug info contains symlinks which match the original source file's basename but don't match its location that the user will use to set breakpoints, then this setting can help resolve breakpoints correctly. This handles both symlinked files and directories. Wild card prefixes: An empty string matches all paths. A forward slash matches absolute paths.">;
156156
def DisassemblyFlavor: Property<"x86-disassembly-flavor", "Enum">,
157157
DefaultEnumValue<"eX86DisFlavorDefault">,
158158
EnumValues<"OptionEnumValues(g_x86_dis_flavor_value_types)">,

lldb/source/Utility/FileSpecList.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ size_t SupportFileList::FindFileIndex(size_t start_idx,
116116
enum IsCompatibleResult {
117117
kNoMatch = 0,
118118
kOnlyFileMatch = 1,
119-
kCompatible = 2,
119+
kBothDirectoryAndFileMatch = 2,
120120
};
121121

122122
IsCompatibleResult IsCompatible(const FileSpec &curr_file,
@@ -132,15 +132,15 @@ IsCompatibleResult IsCompatible(const FileSpec &curr_file,
132132
return IsCompatibleResult::kNoMatch;
133133

134134
// Only compare the full name if the we were asked to and if the current
135-
// file entry has the a directory. If it doesn't have a directory then we
136-
// only compare the filename.
135+
// file entry has a directory. If it doesn't have a directory then we only
136+
// compare the filename.
137137
if (FileSpec::Equal(curr_file, file_spec, full)) {
138-
return IsCompatibleResult::kCompatible;
138+
return IsCompatibleResult::kBothDirectoryAndFileMatch;
139139
} else if (curr_file.IsRelative() || file_spec_relative) {
140140
llvm::StringRef curr_file_dir = curr_file.GetDirectory().GetStringRef();
141141
if (curr_file_dir.empty())
142-
return IsCompatibleResult::kCompatible; // Basename match only for this
143-
// file in the list
142+
// Basename match only for this file in the list
143+
return IsCompatibleResult::kBothDirectoryAndFileMatch;
144144

145145
// Check if we have a relative path in our file list, or if "file_spec" is
146146
// relative, if so, check if either ends with the other.
@@ -158,7 +158,7 @@ IsCompatibleResult IsCompatible(const FileSpec &curr_file,
158158
file_spec_case_sensitive || curr_file.IsCaseSensitive();
159159
if (is_suffix(curr_file_dir, file_spec_dir, case_sensitive) ||
160160
is_suffix(file_spec_dir, curr_file_dir, case_sensitive))
161-
return IsCompatibleResult::kCompatible;
161+
return IsCompatibleResult::kBothDirectoryAndFileMatch;
162162
}
163163
return IsCompatibleResult::kOnlyFileMatch;
164164
}
@@ -174,15 +174,15 @@ size_t SupportFileList::FindCompatibleIndex(
174174
const FileSpec &curr_file = m_files[idx]->GetSpecOnly();
175175

176176
IsCompatibleResult result = IsCompatible(curr_file, file_spec);
177-
if (result == IsCompatibleResult::kCompatible)
177+
if (result == IsCompatibleResult::kBothDirectoryAndFileMatch)
178178
return idx;
179179

180180
if (realpath_prefixes && result == IsCompatibleResult::kOnlyFileMatch) {
181181
if (std::optional<FileSpec> resolved_curr_file =
182182
realpath_prefixes->ResolveSymlinks(curr_file)) {
183183
if (IsCompatible(*resolved_curr_file, file_spec)) {
184184
// Stats and logging.
185-
if (Target *target = realpath_prefixes->GetTarget())
185+
if (lldb::TargetSP target = realpath_prefixes->GetTarget())
186186
target->GetStatistics().IncreaseSourceRealpathCompatibleCount();
187187
Log *log = GetLog(LLDBLog::Source);
188188
LLDB_LOGF(log,

lldb/source/Utility/RealpathPrefixes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using namespace lldb_private;
1919

2020
RealpathPrefixes::RealpathPrefixes(const FileSpecList &file_spec_list)
21-
: m_fs(llvm::vfs::getRealFileSystem()), m_target(nullptr) {
21+
: m_fs(llvm::vfs::getRealFileSystem()) {
2222
m_prefixes.reserve(file_spec_list.GetSize());
2323
for (const FileSpec &file_spec : file_spec_list) {
2424
m_prefixes.emplace_back(file_spec.GetPath());
@@ -43,8 +43,8 @@ RealpathPrefixes::ResolveSymlinks(const FileSpec &file_spec) const {
4343
for (const std::string &prefix : m_prefixes) {
4444
if (is_prefix(file_spec_path, prefix, file_spec.IsCaseSensitive())) {
4545
// Stats and logging.
46-
if (m_target)
47-
m_target->GetStatistics().IncreaseSourceRealpathAttemptCount();
46+
if (lldb::TargetSP target = m_target.lock())
47+
target->GetStatistics().IncreaseSourceRealpathAttemptCount();
4848
Log *log = GetLog(LLDBLog::Source);
4949
LLDB_LOGF(log, "Realpath'ing support file %s", file_spec_path.c_str());
5050

0 commit comments

Comments
 (0)