Skip to content

Commit da83e96

Browse files
committed
Fix a regression in macOS-style path remapping.
When we switched to the LLVM .debug_line parser, the .dSYM-style path remapping logic stopped working for relative paths because of how RemapSourceFile silently fails for relative paths. This patch both makes the code more readable and fixes this particular bug. One interesting thing I learned is that Module::RemapSourceFile() is a macOS-only code path that operates on on the lldb::Module level and is completely separate from target.source-map, which operates on a per-Target level. Differential Revision: https://reviews.llvm.org/D70037 rdar://problem/56924558
1 parent d24bce5 commit da83e96

File tree

5 files changed

+42
-25
lines changed

5 files changed

+42
-25
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
void stop() {}
1+
void relative();
22

33
int main()
44
{
5-
stop();
6-
// Hello World!
5+
relative();
6+
// Hello Absolute!
77
return 0;
88
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void stop() {}
2+
void relative() {
3+
stop();
4+
// Hello Relative!
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
BOTDIR = $(BUILDDIR)/buildbot
22
USERDIR = $(BUILDDIR)/user
33
C_SOURCES = $(BOTDIR)/main.c
4+
LD_EXTRAS = $(BOTDIR)/relative.o
45

56
include Makefile.rules
7+
8+
$(EXE): relative.o
9+
relative.o: $(BOTDIR)/relative.c
10+
cd $(BOTDIR) && $(CC) -c $(CFLAGS) -o $@ relative.c

lldb/packages/Python/lldbsuite/test/macosx/DBGSourcePathRemapping/TestDSYMSourcePathRemapping.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def build(self):
1717
lldbutil.mkdir_p(botdir)
1818
lldbutil.mkdir_p(userdir)
1919
import shutil
20-
for f in ['main.c']:
20+
for f in ['main.c', 'relative.c']:
2121
shutil.copyfile(os.path.join(inputs, f), os.path.join(botdir, f))
2222
shutil.copyfile(os.path.join(inputs, f), os.path.join(userdir, f))
2323

@@ -52,5 +52,10 @@ def build(self):
5252
@skipIf(debug_info=no_match("dsym"))
5353
def test(self):
5454
self.build()
55-
lldbutil.run_to_name_breakpoint(self, 'main')
56-
self.expect("source list", substrs=["Hello World"])
55+
56+
target, process, _, _ = lldbutil.run_to_name_breakpoint(
57+
self, 'main')
58+
self.expect("source list -n main", substrs=["Hello Absolute"])
59+
bkpt = target.BreakpointCreateByName('relative')
60+
lldbutil.continue_to_breakpoint(process, bkpt)
61+
self.expect("source list -n relative", substrs=["Hello Relative"])

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ ParseLLVMLineTable(lldb_private::DWARFContext &context,
179179
return *line_table;
180180
}
181181

182+
static llvm::Optional<std::string>
183+
GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx,
184+
llvm::StringRef compile_dir, FileSpec::Style style) {
185+
// Try to get an absolute path first.
186+
std::string abs_path;
187+
auto absolute = llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
188+
if (prologue.getFileNameByIndex(idx, compile_dir, absolute, abs_path, style))
189+
return std::move(abs_path);
190+
191+
// Otherwise ask for a relative path.
192+
std::string rel_path;
193+
auto relative = llvm::DILineInfoSpecifier::FileLineInfoKind::Default;
194+
if (!prologue.getFileNameByIndex(idx, compile_dir, relative, rel_path, style))
195+
return {};
196+
return std::move(rel_path);
197+
}
198+
182199
static FileSpecList ParseSupportFilesFromPrologue(
183200
const lldb::ModuleSP &module,
184201
const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style,
@@ -188,27 +205,12 @@ static FileSpecList ParseSupportFilesFromPrologue(
188205

189206
const size_t number_of_files = prologue.FileNames.size();
190207
for (size_t idx = 1; idx <= number_of_files; ++idx) {
191-
std::string original_file;
192-
if (!prologue.getFileNameByIndex(
193-
idx, compile_dir,
194-
llvm::DILineInfoSpecifier::FileLineInfoKind::Default, original_file,
195-
style)) {
196-
// Always add an entry so the indexes remain correct.
197-
support_files.EmplaceBack();
198-
continue;
199-
}
200-
201208
std::string remapped_file;
202-
if (!prologue.getFileNameByIndex(
203-
idx, compile_dir,
204-
llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
205-
remapped_file, style)) {
206-
// Always add an entry so the indexes remain correct.
207-
support_files.EmplaceBack(original_file, style);
208-
continue;
209-
}
209+
if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style))
210+
if (!module->RemapSourceFile(llvm::StringRef(*file_path), remapped_file))
211+
remapped_file = std::move(*file_path);
210212

211-
module->RemapSourceFile(llvm::StringRef(original_file), remapped_file);
213+
// Unconditionally add an entry, so the indices match up.
212214
support_files.EmplaceBack(remapped_file, style);
213215
}
214216

0 commit comments

Comments
 (0)