This is an archive of the discontinued LLVM Phabricator instance.

Improve error logging when xcrun fails to execute successfully
ClosedPublic

Authored by aprantl on Nov 15 2022, 1:37 PM.

Details

Summary

Because Host::RunShellCommand runs commands through $SHELL there is an opportunity for this to fail spectacularly on systems that use custom shells with odd behaviors. This patch makes these situations easier to debug by at least logging the result of the failed xcrun invocation.

rdar://102389438

Diff Detail

Event Timeline

aprantl created this revision.Nov 15 2022, 1:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 1:37 PM
aprantl requested review of this revision.Nov 15 2022, 1:37 PM
kastiglione added inline comments.Nov 15 2022, 2:04 PM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
397

Maybe a comment explaining how this is useful in the Types category.

406–407

Why is the timeout increased?

407–414

Should this produce a diagnostic? Seems like failure here should be surfaced to the user.

aprantl updated this revision to Diff 475630.Nov 15 2022, 4:49 PM
aprantl edited the summary of this revision. (Show Details)

Implemented error handling of sorts. Because the computation result is cached and most uses are nested deep in places that have no proper error handling themselves I'm logging to the global error stream.

JDevlieghere requested changes to this revision.Nov 15 2022, 6:49 PM
JDevlieghere added inline comments.
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
420

Why not return an Error?

424

Same question.

509

Here too, why not return a StringError with the log message from the live above?

This revision now requires changes to proceed.Nov 15 2022, 6:49 PM
labath added a subscriber: labath.Nov 16 2022, 4:49 AM
labath added inline comments.
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
14

We shouldn't have Host->Core dependencies. Could you report the error in the caller?

411

why not just pass run_in_shell=false (the optional argument coming after the timeout)?

542

ReportError(toString(path_or_err.takeError())) ?

lldb/unittests/Host/HostTest.cpp
40 ↗(On Diff #475630)

On one (linux) machine I have access to, this is present in /bin/true. A different one has the same file in both paths.

aprantl updated this revision to Diff 475857.Nov 16 2022, 10:01 AM

Address feedback

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
420

For the caller of this lambda "there is no such SDK" is not an error that should be surfaced to the user. There's a loop that will try multiple alternate spellings until it finds a matching SDK.

aprantl added inline comments.Nov 16 2022, 3:09 PM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
14

How strong to you fell about this?
It would be an odd interface. GetXcodeSDKPath also caches negative results because negative lookups are really slow. This means we would only raise an error on the first call and not on the subsequent ones. I can do that, but it also feels weird. I guess we could cache the error string as well?

JDevlieghere added inline comments.Nov 17 2022, 9:57 AM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
14

I would say pretty strongly. While we still have cycles in LLDB, we haven't introduced new one, at least not that I'm aware off. The diagnostics can be fixed by percolating the error up further and dealing with the errors at the call site, which presumably can depend on Host. Caching the error sounds reasonable to me.

That approach doesn't work for the progress updates though. I can imagine that there's more places in LLDB that don't rely on Core from where we'd like to report progress. One potential solution to that is moving Progress to Utility and replacing the dependency on Core with a callback. Similar to the diagnostics we could make it something that follows the Initialize/Terminate patter and then keeps a static list of callbacks for reporting progress. Definitely not the most elegant solution, but it could work for both Progress and Diagnostics if we wanted to.

aprantl updated this revision to Diff 478762.Nov 29 2022, 5:07 PM

Don't introduce a Host->Core dependency. Cache the errors and remove Progress reports (since they also depend on Core).

JDevlieghere accepted this revision.Nov 30 2022, 4:23 PM

LGTM

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
10
342–344
This revision is now accepted and ready to land.Nov 30 2022, 4:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 4:22 PM