Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick bugfixes for SR-1161 #272

Merged
merged 4 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
void relative();

int main()
{
relative();
// Hello Absolute!
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void stop() {}
void relative() {
stop();
// Hello Relative!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BOTDIR = $(BUILDDIR)/buildbot
USERDIR = $(BUILDDIR)/user
C_SOURCES = $(BOTDIR)/main.c
LD_EXTRAS = $(BOTDIR)/relative.o

include Makefile.rules

$(EXE): relative.o
relative.o: $(BOTDIR)/relative.c
cd $(BOTDIR) && $(CC) -c $(CFLAGS) -o $@ relative.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil
import os
import unittest2


class TestDSYMSourcePathRemapping(lldbtest.TestBase):

mydir = lldbtest.TestBase.compute_mydir(__file__)

def build(self):
botdir = self.getBuildArtifact('buildbot')
userdir = self.getBuildArtifact('user')
inputs = self.getSourcePath('Inputs')
lldbutil.mkdir_p(botdir)
lldbutil.mkdir_p(userdir)
import shutil
for f in ['main.c', 'relative.c']:
shutil.copyfile(os.path.join(inputs, f), os.path.join(botdir, f))
shutil.copyfile(os.path.join(inputs, f), os.path.join(userdir, f))

super(TestDSYMSourcePathRemapping, self).build()

# Remove the build sources.
self.assertTrue(os.path.isdir(botdir))
shutil.rmtree(botdir)

# Create a plist.
import subprocess
dsym = self.getBuildArtifact('a.out.dSYM')
uuid = subprocess.check_output(["/usr/bin/dwarfdump", "--uuid", dsym]
).decode("utf-8").split(" ")[1]
import re
self.assertTrue(re.match(r'[0-9a-fA-F-]+', uuid))
plist = os.path.join(dsym, 'Contents', 'Resources', uuid + '.plist')
with open(plist, 'w') as f:
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write('<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n')
f.write('<plist version="1.0">\n')
f.write('<dict>\n')
f.write(' <key>DBGSourcePathRemapping</key>\n')
f.write(' <dict>\n')
f.write(' <key>' + botdir + '</key>\n')
f.write(' <string>' + userdir + '</string>\n')
f.write(' </dict>\n')
f.write('</dict>\n')
f.write('</plist>\n')


@skipIf(debug_info=no_match("dsym"))
def test(self):
self.build()

target, process, _, _ = lldbutil.run_to_name_breakpoint(
self, 'main')
self.expect("source list -n main", substrs=["Hello Absolute"])
bkpt = target.BreakpointCreateByName('relative')
lldbutil.continue_to_breakpoint(process, bkpt)
self.expect("source list -n relative", substrs=["Hello Relative"])
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ class ObjCRuntimeMethodType {

const bool isInstance = instance;
const bool isVariadic = false;
const bool isSynthesized = false;
const bool isPropertyAccessor = false;
const bool isSynthesizedAccessorStub = false;
const bool isImplicitlyDeclared = true;
const bool isDefined = false;
const clang::ObjCMethodDecl::ImplementationControl impControl =
Expand Down Expand Up @@ -377,8 +378,8 @@ class ObjCRuntimeMethodType {
clang::ObjCMethodDecl *ret = clang::ObjCMethodDecl::Create(
ast_ctx, clang::SourceLocation(), clang::SourceLocation(), sel,
ret_type, nullptr, interface_decl, isInstance, isVariadic,
isSynthesized, isImplicitlyDeclared, isDefined, impControl,
HasRelatedResultType);
isPropertyAccessor, isSynthesizedAccessorStub, isImplicitlyDeclared,
isDefined, impControl, HasRelatedResultType);

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

Expand Down
48 changes: 21 additions & 27 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ ParseLLVMLineTable(lldb_private::DWARFContext &context,
return *line_table;
}

static llvm::Optional<std::string>
GetFileByIndex(const llvm::DWARFDebugLine::Prologue &prologue, size_t idx,
llvm::StringRef compile_dir, FileSpec::Style style) {
// Try to get an absolute path first.
std::string abs_path;
auto absolute = llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
if (prologue.getFileNameByIndex(idx, compile_dir, absolute, abs_path, style))
return std::move(abs_path);

// Otherwise ask for a relative path.
std::string rel_path;
auto relative = llvm::DILineInfoSpecifier::FileLineInfoKind::Default;
if (!prologue.getFileNameByIndex(idx, compile_dir, relative, rel_path, style))
return {};
return std::move(rel_path);
}

static FileSpecList ParseSupportFilesFromPrologue(
const lldb::ModuleSP &module,
const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style,
Expand All @@ -189,35 +206,12 @@ static FileSpecList ParseSupportFilesFromPrologue(
FileSpec::GuessPathStyle(compile_dir);
const size_t number_of_files = prologue.FileNames.size();
for (size_t idx = 1; idx <= number_of_files; ++idx) {
std::string original_file;
if (!prologue.getFileNameByIndex(
idx, compile_dir,
llvm::DILineInfoSpecifier::FileLineInfoKind::Default, original_file,
style)) {
// Always add an entry so the indexes remain correct.
support_files.EmplaceBack();
continue;
}

FileSpec::Style style = FileSpec::Style::native;
if (compile_dir_style) {
style = *compile_dir_style;
} else if (llvm::Optional<FileSpec::Style> file_style =
FileSpec::GuessPathStyle(original_file)) {
style = *file_style;
}

std::string remapped_file;
if (!prologue.getFileNameByIndex(
idx, compile_dir,
llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
remapped_file, style)) {
// Always add an entry so the indexes remain correct.
support_files.EmplaceBack(original_file, style);
continue;
}
if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style))
if (!module->RemapSourceFile(llvm::StringRef(*file_path), remapped_file))
remapped_file = std::move(*file_path);

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

Expand Down
32 changes: 20 additions & 12 deletions lldb/source/Symbol/ClangASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8528,7 +8528,8 @@ bool ClangASTContext::AddObjCClassProperty(
? class_interface_decl->lookupInstanceMethod(getter_sel)
: class_interface_decl->lookupClassMethod(getter_sel))) {
const bool isVariadic = false;
const bool isSynthesized = false;
const bool isPropertyAccessor = false;
const bool isSynthesizedAccessorStub = false;
const bool isImplicitlyDeclared = true;
const bool isDefined = false;
const clang::ObjCMethodDecl::ImplementationControl impControl =
Expand All @@ -8539,7 +8540,8 @@ bool ClangASTContext::AddObjCClassProperty(
*clang_ast, clang::SourceLocation(), clang::SourceLocation(),
getter_sel, ClangUtil::GetQualType(property_clang_type_to_access),
nullptr, class_interface_decl, isInstance, isVariadic,
isSynthesized, isImplicitlyDeclared, isDefined, impControl,
isPropertyAccessor, isSynthesizedAccessorStub,
isImplicitlyDeclared, isDefined, impControl,
HasRelatedResultType);

if (getter && metadata)
Expand All @@ -8560,7 +8562,8 @@ bool ClangASTContext::AddObjCClassProperty(
: class_interface_decl->lookupClassMethod(setter_sel))) {
clang::QualType result_type = clang_ast->VoidTy;
const bool isVariadic = false;
const bool isSynthesized = false;
const bool isPropertyAccessor = true;
const bool isSynthesizedAccessorStub = false;
const bool isImplicitlyDeclared = true;
const bool isDefined = false;
const clang::ObjCMethodDecl::ImplementationControl impControl =
Expand All @@ -8570,8 +8573,9 @@ bool ClangASTContext::AddObjCClassProperty(
clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create(
*clang_ast, clang::SourceLocation(), clang::SourceLocation(),
setter_sel, result_type, nullptr, class_interface_decl,
isInstance, isVariadic, isSynthesized, isImplicitlyDeclared,
isDefined, impControl, HasRelatedResultType);
isInstance, isVariadic, isPropertyAccessor,
isSynthesizedAccessorStub, isImplicitlyDeclared, isDefined,
impControl, HasRelatedResultType);

if (setter && metadata)
ClangASTContext::SetMetadata(clang_ast, setter, *metadata);
Expand Down Expand Up @@ -8673,10 +8677,16 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
if (!method_function_prototype)
return nullptr;

bool is_synthesized = false;
bool is_defined = false;
clang::ObjCMethodDecl::ImplementationControl imp_control =
const bool isInstance = (name[0] == '-');
const bool isVariadic = false;
const bool isPropertyAccessor = false;
const bool isSynthesizedAccessorStub = false;
/// Force this to true because we don't have source locations.
const bool isImplicitlyDeclared = true;
const bool isDefined = false;
const clang::ObjCMethodDecl::ImplementationControl impControl =
clang::ObjCMethodDecl::None;
const bool HasRelatedResultType = false;

const unsigned num_args = method_function_prototype->getNumParams();

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

if (objc_method_decl == nullptr)
return nullptr;
Expand Down