Skip to content

[pull] swiftwasm-release/5.3 from swift/release/5.3 #8

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

Merged
merged 26 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9af1072
[lldb] Update for removal of SourceFile::addImports
hamishknight Apr 13, 2020
f53d12b
[lldb] Resolve imports before manipulating AST
hamishknight Apr 14, 2020
05f5e2a
[AArch64][GlobalISel] Fixup <32b heterogeneous regbanks of G_PHIs jus…
aemerson Feb 24, 2020
750e49c
Revert "[InstCombine] fold zext of masked bit set/clear"
kadircet Jan 8, 2020
803d1b1
[lldb] Update for removal of SourceFile::addImports (#1079)
hamishknight Apr 20, 2020
ca0260d
Merge commit '7733347fca02' from apple/stable/20200108 into swift/master
Apr 21, 2020
7733347
Merge pull request #1086 from apple/pr-61468474
aemerson Apr 21, 2020
e038c78
Merge commit 'b7867f6ff1ec' from apple/stable/20200108 into swift/master
Apr 21, 2020
b7867f6
Merge pull request #1100 from apple/PR-59994008
ahatanaka Apr 21, 2020
87b6ab2
[lldb/Test] Decode stdout and stderr in case it contains Unicode.
JDevlieghere Apr 21, 2020
07e680a
[lldb/Test] XFAIL TestDataFormatterObjCNSError except for gmodules.
JDevlieghere Mar 26, 2020
715aa78
[VirtualFileSystem] Support directory entries in the YAMLVFSWriter
JDevlieghere Mar 27, 2020
83dca65
Re-land "[FileCollector] Add a method to add a whole directory and it…
JDevlieghere Mar 30, 2020
1d9a5be
[lldb/Reproducers] Always collect the whole dSYM in the reproducer
JDevlieghere Mar 30, 2020
a9abe89
Merge commit '150d68ed3f9c' from apple/stable/20200108 into swift/master
Apr 21, 2020
150d68e
Merge pull request #1101 from JDevlieghere/🍒/20200108/2de52422acf0466…
JDevlieghere Apr 21, 2020
724a15c
Implement TypeSystemSwiftTypeRef::GetArrayElementType() (NFC)
adrian-prantl Apr 17, 2020
3666548
Merge pull request #1090 from adrian-prantl/GetArrayElementType
adrian-prantl Apr 21, 2020
c9e31f7
[apple/stable/20200108] Fix ambiguity
JDevlieghere Apr 21, 2020
e8a928d
Unbreak ASan runtime in the simulators.
delcypher Apr 21, 2020
b574910
Add missing call to `Symbolizer::LateInitialize()` in UBSan's standal…
delcypher Apr 21, 2020
c1aa619
Merge pull request #1102 from JDevlieghere/🍒/20200108/1d9a5bea33c6b9b…
JDevlieghere Apr 22, 2020
de1720d
Merge commit 'c1aa61938dd2' from apple/stable/20200108 into swift/master
Apr 22, 2020
c94d846
Merge pull request #1103 from danliew-apple/cherry-pick-62067724
danliew-apple Apr 22, 2020
4ee92ef
Merge pull request #1104 from danliew-apple/cherry-pick-62083617
danliew-apple Apr 22, 2020
dcc89a2
Merge commit '4ee92ef9e7a0' from apple/stable/20200108 into swift/master
Apr 22, 2020
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
Prev Previous commit
Next Next commit
[lldb/Reproducers] Always collect the whole dSYM in the reproducer
The FileCollector in LLDB collects every files that's used during a
debug session when capture is enabled. This ensures that the reproducer
only contains the files necessary to reproduce. This approach is not a
good fit for the dSYM bundle, which is a directory on disk, but should
be treated as a single unit.

On macOS LLDB have automatically find the matching dSYM for a binary by
its UUID. Having a incomplete dSYM in a reproducer can break debugging
even when reproducers are disabled.

This patch adds a was to specify a directory of interest to the
reproducers. It is called from SymbolVendorMacOSX with the path of the
dSYMs used by LLDB.

Differential revision: https://reviews.llvm.org/D76672

(cherry picked from commit 38ddb49)
  • Loading branch information
JDevlieghere committed Apr 21, 2020
commit 1d9a5bea33c6b9b94bb1a930df1655e3dd4188e7
2 changes: 2 additions & 0 deletions lldb/include/lldb/Utility/Reproducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class FileProvider : public Provider<FileProvider> {
return m_collector;
}

void recordInterestingDirectory(const llvm::Twine &dir);

void Keep() override {
auto mapping = GetRoot().CopyByAppendingPathComponent(Info::file);
// Temporary files that are removed during execution can cause copy errors.
Expand Down
247 changes: 127 additions & 120 deletions lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "lldb/Symbol/LocateSymbolFile.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/Reproducer.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/Timer.h"

Expand Down Expand Up @@ -143,6 +144,11 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
}

if (dsym_fspec) {
// Compute dSYM root.
std::string dsym_root = dsym_fspec.GetPath();
const size_t pos = dsym_root.find("/Contents/Resources/");
dsym_root = pos != std::string::npos ? dsym_root.substr(0, pos) : "";

DataBufferSP dsym_file_data_sp;
lldb::offset_t dsym_file_data_offset = 0;
dsym_objfile_sp =
Expand All @@ -152,136 +158,132 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
if (UUIDsMatch(module_sp.get(), dsym_objfile_sp.get(), feedback_strm)) {
// We need a XML parser if we hope to parse a plist...
if (XMLDocument::XMLEnabled()) {
char dsym_path[PATH_MAX];
if (module_sp->GetSourceMappingList().IsEmpty() &&
dsym_fspec.GetPath(dsym_path, sizeof(dsym_path))) {
if (module_sp->GetSourceMappingList().IsEmpty()) {
lldb_private::UUID dsym_uuid = dsym_objfile_sp->GetUUID();
if (dsym_uuid) {
std::string uuid_str = dsym_uuid.GetAsString();
if (!uuid_str.empty()) {
char *resources = strstr(dsym_path, "/Contents/Resources/");
if (resources) {
char dsym_uuid_plist_path[PATH_MAX];
resources[strlen("/Contents/Resources/")] = '\0';
snprintf(dsym_uuid_plist_path, sizeof(dsym_uuid_plist_path),
"%s%s.plist", dsym_path, uuid_str.c_str());
FileSpec dsym_uuid_plist_spec(dsym_uuid_plist_path);
if (FileSystem::Instance().Exists(dsym_uuid_plist_spec)) {
ApplePropertyList plist(dsym_uuid_plist_path);
if (plist) {
std::string DBGBuildSourcePath;
std::string DBGSourcePath;

// DBGSourcePathRemapping is a dictionary in the plist
// with keys which are DBGBuildSourcePath file paths and
// values which are DBGSourcePath file paths

StructuredData::ObjectSP plist_sp =
plist.GetStructuredData();
if (plist_sp.get() && plist_sp->GetAsDictionary() &&
plist_sp->GetAsDictionary()->HasKey(
"DBGSourcePathRemapping") &&
plist_sp->GetAsDictionary()
->GetValueForKey("DBGSourcePathRemapping")
->GetAsDictionary()) {

// If DBGVersion 1 or DBGVersion missing, ignore DBGSourcePathRemapping.
// If DBGVersion 2, strip last two components of path remappings from
// entries to fix an issue with a specific set of
// DBGSourcePathRemapping entries that lldb worked
// with.
// If DBGVersion 3, trust & use the source path remappings as-is.
//

bool new_style_source_remapping_dictionary = false;
bool do_truncate_remapping_names = false;
std::string original_DBGSourcePath_value =
DBGSourcePath;
if (plist_sp->GetAsDictionary()->HasKey("DBGVersion")) {
std::string version_string =
plist_sp->GetAsDictionary()
->GetValueForKey("DBGVersion")
->GetStringValue("");
if (!version_string.empty() &&
isdigit(version_string[0])) {
int version_number = atoi(version_string.c_str());
if (version_number > 1) {
new_style_source_remapping_dictionary = true;
}
if (version_number == 2) {
do_truncate_remapping_names = true;
}
if (!uuid_str.empty() && !dsym_root.empty()) {
char dsym_uuid_plist_path[PATH_MAX];
snprintf(dsym_uuid_plist_path, sizeof(dsym_uuid_plist_path),
"%s/Contents/Resources/%s.plist", dsym_root.c_str(),
uuid_str.c_str());
FileSpec dsym_uuid_plist_spec(dsym_uuid_plist_path);
if (FileSystem::Instance().Exists(dsym_uuid_plist_spec)) {
ApplePropertyList plist(dsym_uuid_plist_path);
if (plist) {
std::string DBGBuildSourcePath;
std::string DBGSourcePath;

// DBGSourcePathRemapping is a dictionary in the plist
// with keys which are DBGBuildSourcePath file paths and
// values which are DBGSourcePath file paths

StructuredData::ObjectSP plist_sp =
plist.GetStructuredData();
if (plist_sp.get() && plist_sp->GetAsDictionary() &&
plist_sp->GetAsDictionary()->HasKey(
"DBGSourcePathRemapping") &&
plist_sp->GetAsDictionary()
->GetValueForKey("DBGSourcePathRemapping")
->GetAsDictionary()) {

// If DBGVersion 1 or DBGVersion missing, ignore
// DBGSourcePathRemapping. If DBGVersion 2, strip last two
// components of path remappings from
// entries to fix an issue with a
// specific set of DBGSourcePathRemapping
// entries that lldb worked with.
// If DBGVersion 3, trust & use the source path remappings
// as-is.
//

bool new_style_source_remapping_dictionary = false;
bool do_truncate_remapping_names = false;
std::string original_DBGSourcePath_value = DBGSourcePath;
if (plist_sp->GetAsDictionary()->HasKey("DBGVersion")) {
std::string version_string =
std::string(plist_sp->GetAsDictionary()
->GetValueForKey("DBGVersion")
->GetStringValue(""));
if (!version_string.empty() &&
isdigit(version_string[0])) {
int version_number = atoi(version_string.c_str());
if (version_number > 1) {
new_style_source_remapping_dictionary = true;
}
if (version_number == 2) {
do_truncate_remapping_names = true;
}
}
}

StructuredData::Dictionary *remappings_dict =
plist_sp->GetAsDictionary()
->GetValueForKey("DBGSourcePathRemapping")
->GetAsDictionary();
remappings_dict->ForEach(
[&module_sp, new_style_source_remapping_dictionary,
original_DBGSourcePath_value, do_truncate_remapping_names](
ConstString key,
StructuredData::Object *object) -> bool {
if (object && object->GetAsString()) {

// key is DBGBuildSourcePath
// object is DBGSourcePath
std::string DBGSourcePath =
object->GetStringValue();
if (!new_style_source_remapping_dictionary &&
!original_DBGSourcePath_value.empty()) {
DBGSourcePath = original_DBGSourcePath_value;
}
if (DBGSourcePath[0] == '~') {
FileSpec resolved_source_path(
DBGSourcePath.c_str());
FileSystem::Instance().Resolve(
resolved_source_path);
DBGSourcePath =
resolved_source_path.GetPath();
}
StructuredData::Dictionary *remappings_dict =
plist_sp->GetAsDictionary()
->GetValueForKey("DBGSourcePathRemapping")
->GetAsDictionary();
remappings_dict->ForEach(
[&module_sp, new_style_source_remapping_dictionary,
original_DBGSourcePath_value,
do_truncate_remapping_names](
ConstString key,
StructuredData::Object *object) -> bool {
if (object && object->GetAsString()) {

// key is DBGBuildSourcePath
// object is DBGSourcePath
std::string DBGSourcePath =
std::string(object->GetStringValue());
if (!new_style_source_remapping_dictionary &&
!original_DBGSourcePath_value.empty()) {
DBGSourcePath = original_DBGSourcePath_value;
}
if (DBGSourcePath[0] == '~') {
FileSpec resolved_source_path(
DBGSourcePath.c_str());
FileSystem::Instance().Resolve(
resolved_source_path);
DBGSourcePath = resolved_source_path.GetPath();
}
module_sp->GetSourceMappingList().Append(
key, ConstString(DBGSourcePath), true);
// With version 2 of DBGSourcePathRemapping, we
// can chop off the last two filename parts
// from the source remapping and get a more
// general source remapping that still works.
// Add this as another option in addition to
// the full source path remap.
if (do_truncate_remapping_names) {
FileSpec build_path(key.AsCString());
FileSpec source_path(DBGSourcePath.c_str());
build_path.RemoveLastPathComponent();
build_path.RemoveLastPathComponent();
source_path.RemoveLastPathComponent();
source_path.RemoveLastPathComponent();
module_sp->GetSourceMappingList().Append(
key, ConstString(DBGSourcePath), true);
// With version 2 of DBGSourcePathRemapping, we
// can chop off the last two filename parts
// from the source remapping and get a more
// general source remapping that still works.
// Add this as another option in addition to
// the full source path remap.
if (do_truncate_remapping_names) {
FileSpec build_path(key.AsCString());
FileSpec source_path(DBGSourcePath.c_str());
build_path.RemoveLastPathComponent();
build_path.RemoveLastPathComponent();
source_path.RemoveLastPathComponent();
source_path.RemoveLastPathComponent();
module_sp->GetSourceMappingList().Append(
ConstString(build_path.GetPath().c_str()),
ConstString(source_path.GetPath().c_str()), true);
}
ConstString(build_path.GetPath().c_str()),
ConstString(source_path.GetPath().c_str()),
true);
}
return true;
});
}
}
return true;
});
}

// If we have a DBGBuildSourcePath + DBGSourcePath pair,
// append those to the source path remappings.

plist.GetValueAsString("DBGBuildSourcePath",
DBGBuildSourcePath);
plist.GetValueAsString("DBGSourcePath", DBGSourcePath);
if (!DBGBuildSourcePath.empty() &&
!DBGSourcePath.empty()) {
if (DBGSourcePath[0] == '~') {
FileSpec resolved_source_path(DBGSourcePath.c_str());
FileSystem::Instance().Resolve(resolved_source_path);
DBGSourcePath = resolved_source_path.GetPath();
}
module_sp->GetSourceMappingList().Append(
ConstString(DBGBuildSourcePath),
ConstString(DBGSourcePath), true);
// If we have a DBGBuildSourcePath + DBGSourcePath pair,
// append those to the source path remappings.

plist.GetValueAsString("DBGBuildSourcePath",
DBGBuildSourcePath);
plist.GetValueAsString("DBGSourcePath", DBGSourcePath);
if (!DBGBuildSourcePath.empty() && !DBGSourcePath.empty()) {
if (DBGSourcePath[0] == '~') {
FileSpec resolved_source_path(DBGSourcePath.c_str());
FileSystem::Instance().Resolve(resolved_source_path);
DBGSourcePath = resolved_source_path.GetPath();
}
module_sp->GetSourceMappingList().Append(
ConstString(DBGBuildSourcePath),
ConstString(DBGSourcePath), true);
}
}
}
Expand All @@ -291,6 +293,11 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
}

symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp);
if (repro::Generator *g =
repro::Reproducer::Instance().GetGenerator()) {
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
fp.recordInterestingDirectory(dsym_root);
}
return symbol_vendor;
}
}
Expand Down
5 changes: 5 additions & 0 deletions lldb/source/Utility/Reproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ void WorkingDirectoryProvider::Keep() {
os << m_cwd << "\n";
}

void FileProvider::recordInterestingDirectory(const llvm::Twine &dir) {
if (m_collector)
m_collector->addDirectory(dir);
}

void ProviderBase::anchor() {}
char CommandProvider::ID = 0;
char FileProvider::ID = 0;
Expand Down
11 changes: 11 additions & 0 deletions lldb/test/Shell/Reproducer/TestDSYM.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# REQUIRES: system-darwin
# Ensure that the reproducers captures the whole dSYM bundle.

# RUN: rm -rf %t.repro
# RUN: %clang_host %S/Inputs/simple.c -g -o %t.out
# RUN: touch %t.out.dSYM/foo.bar

# RUN: %lldb -x -b --capture --capture-path %t.repro %t.out -o 'b main' -o 'run' -o 'reproducer generate'

# RUN: %lldb -b -o 'reproducer dump -p files -f %t.repro' | FileCheck %s --check-prefix FILES
# FILES: foo.bar