Skip to content

Commit 7cdd3ef

Browse files
jasonmolendayuxuanchen1997
authored andcommitted
[lldb] Don't crash when attaching to pid and no binaries found (#100287)
Summary: There is a narrow window during process launch on macOS where lldb can attach and no binaries will be seen as loaded in the process (none reported by libdyld SPI). A year ago I made changes to set the new-binary-loaded breakpoint correctly despite this. But we've seen a crash when this combination is seen, where CommandObjectProcessAttach::DoExecute assumed there was at least one binary registered in the Target. Fix that. Also fix two FileSpec API uses from when we didn't have a GetPath() method that returned a std::string, and was copying the filepaths into fixed length buffers. All of this code was from ~14 years ago when we didn't have that API. rdar://131631627 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250573
1 parent f5f19b7 commit 7cdd3ef

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,25 +369,23 @@ class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach {
369369

370370
// Okay, we're done. Last step is to warn if the executable module has
371371
// changed:
372-
char new_path[PATH_MAX];
373372
ModuleSP new_exec_module_sp(target->GetExecutableModule());
374373
if (!old_exec_module_sp) {
375374
// We might not have a module if we attached to a raw pid...
376375
if (new_exec_module_sp) {
377-
new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
378-
result.AppendMessageWithFormat("Executable module set to \"%s\".\n",
379-
new_path);
376+
result.AppendMessageWithFormat(
377+
"Executable binary set to \"%s\".\n",
378+
new_exec_module_sp->GetFileSpec().GetPath().c_str());
380379
}
380+
} else if (!new_exec_module_sp) {
381+
result.AppendWarningWithFormat("No executable binary.");
381382
} else if (old_exec_module_sp->GetFileSpec() !=
382383
new_exec_module_sp->GetFileSpec()) {
383-
char old_path[PATH_MAX];
384-
385-
old_exec_module_sp->GetFileSpec().GetPath(old_path, PATH_MAX);
386-
new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
387384

388385
result.AppendWarningWithFormat(
389-
"Executable module changed from \"%s\" to \"%s\".\n", old_path,
390-
new_path);
386+
"Executable binary changed from \"%s\" to \"%s\".\n",
387+
old_exec_module_sp->GetFileSpec().GetPath().c_str(),
388+
new_exec_module_sp->GetFileSpec().GetPath().c_str());
391389
}
392390

393391
if (!old_arch_spec.IsValid()) {

0 commit comments

Comments
 (0)