[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
================
@@ -307,6 +307,34 @@ class GDBRemoteCommunicationServerLLGS
private:
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml();
+ /// Helper struct for the Execute{Set,Remove}Breakpoint methods.
+ struct BreakpointResult {
+ enum class Kind { OK, Error, IllFormed };
+
+ Kind kind;
+ uint8_t error_code = 0; // Only meaningful when kind == Error.
+ std::string message; // Only meaningful when kind == IllFormed.
----------------
DavidSpickett wrote:
This feels like a discriminated union but without the union, and C++ has discriminated union with std::variant. Only problem is the OK state which doesn't have a type as such, which I think is what https://en.cppreference.com/cpp/utility/variant/monostate is for? (first time I've come across that myself)
Does std::variant fit here or is it awkward to handle? You could use a variant as a member of this class and then you still have the `Create...` which are more intuitive than knowing what type to set. Then the variant handles the enum/union part for you.
Your `switch (result.kind) {` above would become std::visit.
https://github.com/llvm/llvm-project/pull/192915
More information about the llvm-branch-commits
mailing list