[llvm-branch-commits] [lldb] [lldbremote][NFC] Factor out code handling breakpoint packets (PR #192915)
David Spickett via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Apr 24 08:36:37 PDT 2026
================
@@ -2900,155 +2900,172 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
return SendPacketNoLock(response.GetString());
}
-GDBRemoteCommunication::PacketResult
-GDBRemoteCommunicationServerLLGS::Handle_Z(StringExtractorGDBRemote &packet) {
+namespace {
+/// Helper struct to expand a GDBStoppointType into flags.
+struct BreakpointKind {
+ bool want_hardware;
+ bool want_breakpoint;
+ uint32_t watch_flags;
+
+ /// Invalid types must be handled prior to calling this.
+ BreakpointKind(GDBStoppointType stoppoint_type) {
+ switch (stoppoint_type) {
+ case eBreakpointSoftware:
+ want_hardware = false;
+ want_breakpoint = true;
+ break;
+ case eBreakpointHardware:
+ want_hardware = true;
+ want_breakpoint = true;
+ break;
+ case eWatchpointWrite:
+ watch_flags = 1;
+ want_hardware = true;
+ want_breakpoint = false;
+ break;
+ case eWatchpointRead:
+ watch_flags = 2;
+ want_hardware = true;
+ want_breakpoint = false;
+ break;
+ case eWatchpointReadWrite:
+ watch_flags = 3;
+ want_hardware = true;
+ want_breakpoint = false;
+ break;
+ default:
+ llvm_unreachable("unhandled GDBStoppointType");
+ }
+ }
+};
+
+/// If stoppoint_type is a valid type, create a BreakpointKind, otherwise
+/// returns nullopt.
+std::optional<BreakpointKind>
+getBreakpointKind(GDBStoppointType stoppoint_type) {
+ switch (stoppoint_type) {
+ case eBreakpointSoftware:
+ case eBreakpointHardware:
+ case eWatchpointWrite:
+ case eWatchpointRead:
+ case eWatchpointReadWrite:
+ return BreakpointKind(stoppoint_type);
+ case eStoppointInvalid:
+ break;
+ }
+ return std::nullopt;
----------------
DavidSpickett wrote:
I'd have put the return in place of the break personally.
Side note: I thought about making the default `return BreakpointKind`. But you might have written it like this so we get a warning if a new kind is added, which is a good idea.
https://github.com/llvm/llvm-project/pull/192915
More information about the llvm-branch-commits
mailing list