This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix bug to update process public run lock with process state
ClosedPublic

Authored by mib on Apr 14 2023, 5:06 PM.

Details

Summary

This patch should address an issue that caused the process public run
lock to not be updated during a process launch/attach when the process
stops.

That caused the public run lock to report its state as running while the
process state is stopped. This prevents the users to interact with the
process (through the command line or via the SBAPI) since it's
considered still running.

To address that, this patch refactors the name of the internal hijack
listeners to a specific pattern lldb.internal.<action>.hijack that
are used to ensure that we've attached to or launched a process successfully.

Then, when updating the process public state, after updating the state
value, if the process is not hijacked externally, meaning if the process
doens't have a hijack listener that matches the internal hijack
listeners pattern, we can update the public run lock accordingly.

rdar://108283017

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Apr 14 2023, 5:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 5:06 PM
mib requested review of this revision.Apr 14 2023, 5:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 5:06 PM
mib removed a project: Restricted Project.Apr 14 2023, 5:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 5:06 PM
mib removed a project: Restricted Project.Apr 14 2023, 5:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 5:06 PM
bulbazord requested changes to this revision.Apr 17 2023, 1:03 PM
bulbazord added a subscriber: bulbazord.

Idea is good, few concerns about the implementation.

lldb/source/Target/Process.cpp
404–419

Do these need to be ConstStrings? They will live in the string pool forever, and it looks like in the code below you're just manipulating const char * anyway.

Could be something like:

llvm::StringRef Process::GetAttachSynchronousHijackListenerName() {
  return "lldb.internal.Process.AttachSynchronous.hijack";
}
1394–1395

Instead of using the strstr function directly, I would at least do strnstr to ensure that we're not touching memory we don't have. Especially if we could get hijacking_name to be shorter than "lldb.internal" somehow...

We could also change this to use StringRefs and use the starts_with/startswith methods instead.

1403–1405

First, I would probably avoid strcmp directly and use strncmp instead. We know the length of the HijackListener name, that would be a good choice for n here.

But you could probably simplify this even further. You can compare GetResumeSynchronousHijackListenerName to hijacking_name with StringRef's operator==.

This revision now requires changes to proceed.Apr 17 2023, 1:03 PM
mib updated this revision to Diff 514792.Apr 18 2023, 5:18 PM
mib marked 3 inline comments as done.

Address @bulbazord comments

This revision is now accepted and ready to land.Apr 18 2023, 5:32 PM
JDevlieghere added inline comments.Apr 18 2023, 9:22 PM
lldb/source/Target/Process.cpp
404–414

Do these actually need to be methods? Can't these be public static StringRefs instead?

mib updated this revision to Diff 514832.Apr 18 2023, 11:38 PM

Turning hijack listener name getters into public static constexpr llvmStringRef as @JDevlieghere suggested.

This revision was landed with ongoing or failed builds.Apr 19 2023, 10:05 AM
This revision was automatically updated to reflect the committed changes.
mib added a comment.Apr 19 2023, 11:48 AM

Reverting this because it introduced some failures on the linux bot: https://lab.llvm.org/buildbot/#/builders/68/builds/51397/steps/6/logs/stdio

mib added inline comments.Apr 19 2023, 4:29 PM
lldb/source/Target/Process.cpp
1395

I think I forgot to negate this: if hijacking_name DOES NOT start with "lldb.internal", then it mean that the process state change is externally hijacked.

mib updated this revision to Diff 515137.Apr 19 2023, 4:54 PM
mib edited the summary of this revision. (Show Details)

Fix condition typo

mib reopened this revision.Apr 19 2023, 4:54 PM
This revision is now accepted and ready to land.Apr 19 2023, 4:54 PM
This revision was landed with ongoing or failed builds.Apr 19 2023, 4:55 PM
This revision was automatically updated to reflect the committed changes.
mib edited the summary of this revision. (Show Details)Apr 19 2023, 5:14 PM