This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Core] Don't crash in GetSoftwareBreakpointTrapOpcode for unknown triples
ClosedPublic

Authored by JDevlieghere on Apr 21 2020, 1:46 PM.

Details

Summary

A reproducer replay hit an llvm_unreachable in Target.cpp because the architecture was not set and therefore the ArchSpec was invalid.

Unhandled architecture in Platform::GetSoftwareBreakpointTrapOpcode
UNREACHABLE executed at /Users/jonas/llvm/llvm-project/lldb/source/Target/Platform.cpp:1922!

The unhandled case is llvm::Triple::UnknownArch. Alternatively we can add a case for it to the switch statement, but checking IsValid seemed more canonical.

Diff Detail

Event Timeline

JDevlieghere created this revision.Apr 21 2020, 1:46 PM
davide added a subscriber: davide.Apr 21 2020, 3:56 PM

What's exactly the testcase doing?

None of this is exposed through SBPlatform right? No way to test this?

lldb/source/Target/Platform.cpp
1825–1826

would be nice to log something here on the "lldb break" log channel?

The presence of llvm_unreachable here is questionable, but I am surprised that this comes up in the context of reproducers. If the reproducers cause this function to be called with a different ArchSpec, then it sounds like there are bigger problems that need to be solved..

If we do want to do something about the crash, then I think we ought to just remove the llvm_unreachable. I don't think it makes sense to bail out on invalid ArchSpecs, but blow up on not-yet-supported architectures. If anything, I would say it should be the opposite -- I don't think it makes sense for anyone to call this function with an invalid/empty ArchSpec, but it may be reasonable to enable some degraded behavior for architectures which are not fully supported.

The presence of llvm_unreachable here is questionable, but I am surprised that this comes up in the context of reproducers. If the reproducers cause this function to be called with a different ArchSpec, then it sounds like there are bigger problems that need to be solved..

I only mentioned the reproducers to show that we can reach this code with an invalid ArchSpec and that this is not just a speculative fix. Since you're interested in what triggered this: TestRecognizeBreakpoint.py is a GDBRemoteTestBase, which starts with an empty Target (hence the invalid ArchSpec later on) and then connects to the test's GDB remote. It does so through ConnectRemote which for ProcessGDBRemote calls ConnectToDebugserver, which bypasses redirecting the connection to the GDB replay server. Fixing the reproducers issue is just a matter of moving that code down, so we connect to the replay server instead of the test's gdb server (which isn't there during active replay).

If we do want to do something about the crash, then I think we ought to just remove the llvm_unreachable. I don't think it makes sense to bail out on invalid ArchSpecs, but blow up on not-yet-supported architectures. If anything, I would say it should be the opposite -- I don't think it makes sense for anyone to call this function with an invalid/empty ArchSpec, but it may be reasonable to enable some degraded behavior for architectures which are not fully supported.

Sounds reasonable to me. We can add an assert arch.IsValid() to enforce that precondition and have the default case return 0.

JDevlieghere retitled this revision from [lldb/Core] Check that ArchSpec is valid. to [lldb/Core] Don't crash in GetSoftwareBreakpointTrapOpcode for unknown triples.
labath accepted this revision.Apr 24 2020, 4:35 AM

This makes sense to me.

(If we are able to reach this deep into the code with an invalid archspec by just issuing (sb or cli) commands, it sounds like there should be some check (and a bail out) very early on in the call stack.)

This revision is now accepted and ready to land.Apr 24 2020, 4:35 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2020, 9:11 AM