Skip to content

Commit e12c7c2

Browse files
Merge pull request #272 from adrian-prantl/56924558
cherry-pick bugfixes for SR-1161
2 parents a721fbb + 952413c commit e12c7c2

File tree

7 files changed

+129
-42
lines changed

7 files changed

+129
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
void relative();
2+
3+
int main()
4+
{
5+
relative();
6+
// Hello Absolute!
7+
return 0;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void stop() {}
2+
void relative() {
3+
stop();
4+
// Hello Relative!
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
BOTDIR = $(BUILDDIR)/buildbot
2+
USERDIR = $(BUILDDIR)/user
3+
C_SOURCES = $(BOTDIR)/main.c
4+
LD_EXTRAS = $(BOTDIR)/relative.o
5+
6+
include Makefile.rules
7+
8+
$(EXE): relative.o
9+
relative.o: $(BOTDIR)/relative.c
10+
cd $(BOTDIR) && $(CC) -c $(CFLAGS) -o $@ relative.c
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import os
6+
import unittest2
7+
8+
9+
class TestDSYMSourcePathRemapping(lldbtest.TestBase):
10+
11+
mydir = lldbtest.TestBase.compute_mydir(__file__)
12+
13+
def build(self):
14+
botdir = self.getBuildArtifact('buildbot')
15+
userdir = self.getBuildArtifact('user')
16+
inputs = self.getSourcePath('Inputs')
17+
lldbutil.mkdir_p(botdir)
18+
lldbutil.mkdir_p(userdir)
19+
import shutil
20+
for f in ['main.c', 'relative.c']:
21+
shutil.copyfile(os.path.join(inputs, f), os.path.join(botdir, f))
22+
shutil.copyfile(os.path.join(inputs, f), os.path.join(userdir, f))
23+
24+
super(TestDSYMSourcePathRemapping, self).build()
25+
26+
# Remove the build sources.
27+
self.assertTrue(os.path.isdir(botdir))
28+
shutil.rmtree(botdir)
29+
30+
# Create a plist.
31+
import subprocess
32+
dsym = self.getBuildArtifact('a.out.dSYM')
33+
uuid = subprocess.check_output(["/usr/bin/dwarfdump", "--uuid", dsym]
34+
).decode("utf-8").split(" ")[1]
35+
import re
36+
self.assertTrue(re.match(r'[0-9a-fA-F-]+', uuid))
37+
plist = os.path.join(dsym, 'Contents', 'Resources', uuid + '.plist')
38+
with open(plist, 'w') as f:
39+
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
40+
f.write('<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n')
41+
f.write('<plist version="1.0">\n')
42+
f.write('<dict>\n')
43+
f.write(' <key>DBGSourcePathRemapping</key>\n')
44+
f.write(' <dict>\n')
45+
f.write(' <key>' + botdir + '</key>\n')
46+
f.write(' <string>' + userdir + '</string>\n')
47+
f.write(' </dict>\n')
48+
f.write('</dict>\n')
49+
f.write('</plist>\n')
50+
51+
52+
@skipIf(debug_info=no_match("dsym"))
53+
def test(self):
54+
self.build()
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/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ class ObjCRuntimeMethodType {
330330

331331
const bool isInstance = instance;
332332
const bool isVariadic = false;
333-
const bool isSynthesized = false;
333+
const bool isPropertyAccessor = false;
334+
const bool isSynthesizedAccessorStub = false;
334335
const bool isImplicitlyDeclared = true;
335336
const bool isDefined = false;
336337
const clang::ObjCMethodDecl::ImplementationControl impControl =
@@ -377,8 +378,8 @@ class ObjCRuntimeMethodType {
377378
clang::ObjCMethodDecl *ret = clang::ObjCMethodDecl::Create(
378379
ast_ctx, clang::SourceLocation(), clang::SourceLocation(), sel,
379380
ret_type, nullptr, interface_decl, isInstance, isVariadic,
380-
isSynthesized, isImplicitlyDeclared, isDefined, impControl,
381-
HasRelatedResultType);
381+
isPropertyAccessor, isSynthesizedAccessorStub, isImplicitlyDeclared,
382+
isDefined, impControl, HasRelatedResultType);
382383

383384
std::vector<clang::ParmVarDecl *> parm_vars;
384385

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

+21-27
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ ParseLLVMLineTable(lldb_private::DWARFContext &context,
178178
return *line_table;
179179
}
180180

181+
static llvm::Optional<std::string>
182+
GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx,
183+
llvm::StringRef compile_dir, FileSpec::Style style) {
184+
// Try to get an absolute path first.
185+
std::string abs_path;
186+
auto absolute = llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
187+
if (prologue.getFileNameByIndex(idx, compile_dir, absolute, abs_path, style))
188+
return std::move(abs_path);
189+
190+
// Otherwise ask for a relative path.
191+
std::string rel_path;
192+
auto relative = llvm::DILineInfoSpecifier::FileLineInfoKind::Default;
193+
if (!prologue.getFileNameByIndex(idx, compile_dir, relative, rel_path, style))
194+
return {};
195+
return std::move(rel_path);
196+
}
197+
181198
static FileSpecList ParseSupportFilesFromPrologue(
182199
const lldb::ModuleSP &module,
183200
const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style,
@@ -189,35 +206,12 @@ static FileSpecList ParseSupportFilesFromPrologue(
189206
FileSpec::GuessPathStyle(compile_dir);
190207
const size_t number_of_files = prologue.FileNames.size();
191208
for (size_t idx = 1; idx <= number_of_files; ++idx) {
192-
std::string original_file;
193-
if (!prologue.getFileNameByIndex(
194-
idx, compile_dir,
195-
llvm::DILineInfoSpecifier::FileLineInfoKind::Default, original_file,
196-
style)) {
197-
// Always add an entry so the indexes remain correct.
198-
support_files.EmplaceBack();
199-
continue;
200-
}
201-
202-
FileSpec::Style style = FileSpec::Style::native;
203-
if (compile_dir_style) {
204-
style = *compile_dir_style;
205-
} else if (llvm::Optional<FileSpec::Style> file_style =
206-
FileSpec::GuessPathStyle(original_file)) {
207-
style = *file_style;
208-
}
209-
210209
std::string remapped_file;
211-
if (!prologue.getFileNameByIndex(
212-
idx, compile_dir,
213-
llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
214-
remapped_file, style)) {
215-
// Always add an entry so the indexes remain correct.
216-
support_files.EmplaceBack(original_file, style);
217-
continue;
218-
}
210+
if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style))
211+
if (!module->RemapSourceFile(llvm::StringRef(*file_path), remapped_file))
212+
remapped_file = std::move(*file_path);
219213

220-
module->RemapSourceFile(llvm::StringRef(original_file), remapped_file);
214+
// Unconditionally add an entry, so the indices match up.
221215
support_files.EmplaceBack(remapped_file, style);
222216
}
223217

lldb/source/Symbol/ClangASTContext.cpp

+20-12
Original file line numberDiff line numberDiff line change
@@ -8528,7 +8528,8 @@ bool ClangASTContext::AddObjCClassProperty(
85288528
? class_interface_decl->lookupInstanceMethod(getter_sel)
85298529
: class_interface_decl->lookupClassMethod(getter_sel))) {
85308530
const bool isVariadic = false;
8531-
const bool isSynthesized = false;
8531+
const bool isPropertyAccessor = false;
8532+
const bool isSynthesizedAccessorStub = false;
85328533
const bool isImplicitlyDeclared = true;
85338534
const bool isDefined = false;
85348535
const clang::ObjCMethodDecl::ImplementationControl impControl =
@@ -8539,7 +8540,8 @@ bool ClangASTContext::AddObjCClassProperty(
85398540
*clang_ast, clang::SourceLocation(), clang::SourceLocation(),
85408541
getter_sel, ClangUtil::GetQualType(property_clang_type_to_access),
85418542
nullptr, class_interface_decl, isInstance, isVariadic,
8542-
isSynthesized, isImplicitlyDeclared, isDefined, impControl,
8543+
isPropertyAccessor, isSynthesizedAccessorStub,
8544+
isImplicitlyDeclared, isDefined, impControl,
85438545
HasRelatedResultType);
85448546

85458547
if (getter && metadata)
@@ -8560,7 +8562,8 @@ bool ClangASTContext::AddObjCClassProperty(
85608562
: class_interface_decl->lookupClassMethod(setter_sel))) {
85618563
clang::QualType result_type = clang_ast->VoidTy;
85628564
const bool isVariadic = false;
8563-
const bool isSynthesized = false;
8565+
const bool isPropertyAccessor = true;
8566+
const bool isSynthesizedAccessorStub = false;
85648567
const bool isImplicitlyDeclared = true;
85658568
const bool isDefined = false;
85668569
const clang::ObjCMethodDecl::ImplementationControl impControl =
@@ -8570,8 +8573,9 @@ bool ClangASTContext::AddObjCClassProperty(
85708573
clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create(
85718574
*clang_ast, clang::SourceLocation(), clang::SourceLocation(),
85728575
setter_sel, result_type, nullptr, class_interface_decl,
8573-
isInstance, isVariadic, isSynthesized, isImplicitlyDeclared,
8574-
isDefined, impControl, HasRelatedResultType);
8576+
isInstance, isVariadic, isPropertyAccessor,
8577+
isSynthesizedAccessorStub, isImplicitlyDeclared, isDefined,
8578+
impControl, HasRelatedResultType);
85758579

85768580
if (setter && metadata)
85778581
ClangASTContext::SetMetadata(clang_ast, setter, *metadata);
@@ -8673,10 +8677,16 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
86738677
if (!method_function_prototype)
86748678
return nullptr;
86758679

8676-
bool is_synthesized = false;
8677-
bool is_defined = false;
8678-
clang::ObjCMethodDecl::ImplementationControl imp_control =
8680+
const bool isInstance = (name[0] == '-');
8681+
const bool isVariadic = false;
8682+
const bool isPropertyAccessor = false;
8683+
const bool isSynthesizedAccessorStub = false;
8684+
/// Force this to true because we don't have source locations.
8685+
const bool isImplicitlyDeclared = true;
8686+
const bool isDefined = false;
8687+
const clang::ObjCMethodDecl::ImplementationControl impControl =
86798688
clang::ObjCMethodDecl::None;
8689+
const bool HasRelatedResultType = false;
86808690

86818691
const unsigned num_args = method_function_prototype->getNumParams();
86828692

@@ -8692,10 +8702,8 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
86928702
nullptr, // TypeSourceInfo *ResultTInfo,
86938703
ClangASTContext::GetASTContext(ast)->GetDeclContextForType(
86948704
ClangUtil::GetQualType(type)),
8695-
name[0] == '-', is_variadic, is_synthesized,
8696-
true, // is_implicitly_declared; we force this to true because we don't
8697-
// have source locations
8698-
is_defined, imp_control, false /*has_related_result_type*/);
8705+
isInstance, isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
8706+
isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType);
86998707

87008708
if (objc_method_decl == nullptr)
87018709
return nullptr;

0 commit comments

Comments
 (0)