Skip to content

Commit ea57365

Browse files
rmacnak-googleCommit Queue
authored and
Commit Queue
committed
[standalone] Fix finding symbols when argv[0] is not an absolute path or relative to CWD.
TEST=vm/dart/symbolized_crash_test Change-Id: I941045db6ab78b24bd529e775380be80c1d71121 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339782 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 73e2aa4 commit ea57365

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

runtime/bin/exe_utils.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,22 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
122122
}
123123

124124
#if !defined(DART_HOST_OS_WINDOWS)
125-
void EXEUtils::LoadDartProfilerSymbols(const char* exepath) {
126-
int len = strlen(exepath);
127-
char* sympath = reinterpret_cast<char*>(malloc(len + 5));
128-
memcpy(sympath, exepath, len); // NOLINT
129-
memcpy(sympath + len, ".sym", 5); // NOLINT
130-
File* file = File::Open(nullptr, sympath, File::kRead);
131-
free(sympath);
132-
if (file != nullptr) {
133-
int64_t size = file->Length();
134-
MappedMemory* mapping = file->Map(File::kReadOnly, 0, size);
135-
Dart_AddSymbols(exepath, mapping->address(), size);
136-
mapping->Leak(); // Let us delete the object but keep the mapping.
137-
delete mapping;
138-
file->Release();
139-
}
125+
void EXEUtils::LoadDartProfilerSymbols(const char* argv0) {
126+
char* path = reinterpret_cast<char*>(malloc(PATH_MAX + 5));
127+
if (Platform::ResolveExecutablePathInto(path, PATH_MAX) <= 0) return;
128+
129+
int len = strlen(path);
130+
memcpy(path + len, ".sym", 5); // NOLINT
131+
File* file = File::Open(nullptr, path, File::kRead);
132+
free(path);
133+
if (file == nullptr) return;
134+
135+
int64_t size = file->Length();
136+
MappedMemory* mapping = file->Map(File::kReadOnly, 0, size);
137+
Dart_AddSymbols(argv0, mapping->address(), size);
138+
mapping->Leak(); // Let us delete the object but keep the mapping.
139+
delete mapping;
140+
file->Release();
140141
}
141142
#endif // !defined(DART_HOST_OS_WINDOWS)
142143

runtime/tests/vm/dart/symbolized_crash_test.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ main() {
1111
if (Platform.isWindows) return; // posix exit codes
1212
if (Platform.isAndroid) return; // run_vm_tests not available on test device
1313

14-
var run_vm_tests =
15-
path.join(path.dirname(Platform.resolvedExecutable), "run_vm_tests");
16-
var result = Process.runSync(run_vm_tests, ["Fatal"]);
14+
// Run such that "cwd/argv[0].sym" does not exist to check .sym properly
15+
// resolves against the executable.
16+
var dir = path.dirname(Platform.resolvedExecutable);
17+
var result = Process.runSync(
18+
"/bin/sh",
19+
["-c", "PATH=$dir run_vm_tests Fatal"],
20+
);
1721
print(result.exitCode);
1822
print(result.stdout);
1923
print(result.stderr);

0 commit comments

Comments
 (0)