This is an archive of the discontinued LLVM Phabricator instance.

change debugserver to return an empty platform name for unknown platforms, instead of crashing
ClosedPublic

Authored by jasonmolenda on Oct 25 2022, 4:29 PM.

Details

Summary

debugserver is sometimes run in bringup environments, where debugserver doesn't yet recognize its platform code. debugserver will crash shortly after when strlen() is run on the nullptr returned, creating a std::string.

Instead, have debugserver return an empty platform name back up to lldb. lldb is in a better position to handle a triple with a missing component and surface an error message to the user, instead of having debugserver cease to be running.

Diff Detail

Event Timeline

jasonmolenda created this revision.Oct 25 2022, 4:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2022, 4:29 PM
jasonmolenda requested review of this revision.Oct 25 2022, 4:29 PM

Ah, one minute on this one. Going over the testsuite, there's a change in behavior of TestMacCatalyst.py and I'm not positive if it's a bug or the test case being overly sensitive.

Update patch to also update the loop in HandlePacket_qProcessInfo() which iterates over the binaries, looking for a binary that declares its platform. The first binary in the list is dyld, and this binary does not have a platform, but the loop would get back an empty string and terminate its search. Update this to recognize an empty platform name and continue searching, to preserve its original intended behavior for qProcessInfo.

How about an optional instead, if GetPlatformString is fallible.

How about an optional instead, if GetPlatformString is fallible.

Ah, interesting idea. debugserver doesn't use any llvm, but I believe we're building with C++17 these days so I could do it with std::optional.

How about an optional instead, if GetPlatformString is fallible.

Ah, interesting idea. debugserver doesn't use any llvm, but I believe we're building with C++17 these days so I could do it with std::optional.

Yep.

Update MachProcess::GetPlatformString to return a std::optional platform string, if the platform enumeration is recognized. Update callers to handle the absence of a value appropriately.

Looks great, but I would have expected std::optional<std::string> and a nullopt.

Looks great, but I would have expected std::optional<std::string> and a nullopt.

Yeah I'm fine with that, it does seems more natural. In this case we're returning the address of a half-dozen const strings in the text section, so there wasn't any lifetime worries or anything, I left it as a char* after thinking about it for a few seconds. I'll update to use a std::string, this is not a hot code path, a small object allocation doesn't matter.

Update patch to pass std::string's in the optionals, and use std::nullopt. Thanks for all the feedback on this one, Thorsten.

tschuett added inline comments.Oct 26 2022, 11:50 PM
lldb/tools/debugserver/source/RNBRemote.cpp
6264

Nit: the has_value()is redundant. optional has boolean conversion.

6266

Maybe *platform works.

Incorporate Thorsten's suggestions for more idiomatic use of the std::optional result.

JDevlieghere accepted this revision.Oct 27 2022, 1:06 PM

Nice use of std::optional. LGTM.

This revision is now accepted and ready to land.Oct 27 2022, 1:06 PM
JDevlieghere added inline comments.Oct 27 2022, 1:09 PM
lldb/tools/debugserver/source/MacOSX/MachProcess.mm
725

This is unused