Skip to content

Commit 5b6386d

Browse files
authored
[lldb-dap] Swapping to not use FLAG_ENUM and just defining typed enums. (#133622)
Small tweak to the previous patch to make the enums in `lldb_dap::protocol` typed to work with types like `llvm::DenseSet` found by ubsan.
1 parent 3acccf0 commit 5b6386d

File tree

4 files changed

+148
-141
lines changed

4 files changed

+148
-141
lines changed

lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Protocol/ProtocolBase.h"
10-
#include "lldb/lldb-enumerations.h"
1110
#include "llvm/ADT/StringRef.h"
1211
#include "llvm/ADT/StringSwitch.h"
1312
#include "llvm/Support/ErrorHandling.h"
@@ -32,8 +31,11 @@ static bool mapRaw(const json::Value &Params, StringLiteral Prop,
3231

3332
namespace lldb_dap::protocol {
3433

35-
FLAGS_ENUM(MessageType){eMessageTypeRequest, eMessageTypeResponse,
36-
eMessageTypeEvent};
34+
enum MessageType : unsigned {
35+
eMessageTypeRequest,
36+
eMessageTypeResponse,
37+
eMessageTypeEvent
38+
};
3739

3840
bool fromJSON(const json::Value &Params, MessageType &M, json::Path P) {
3941
auto rawType = Params.getAsString();

lldb/tools/lldb-dap/Protocol/ProtocolBase.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#ifndef LLDB_TOOLS_LLDB_DAP_PROTOCOL_H
2121
#define LLDB_TOOLS_LLDB_DAP_PROTOCOL_H
2222

23-
#include "lldb/lldb-enumerations.h"
2423
#include "llvm/Support/JSON.h"
2524
#include <cstdint>
2625
#include <optional>
@@ -65,11 +64,11 @@ struct Event {
6564
llvm::json::Value toJSON(const Event &);
6665
bool fromJSON(const llvm::json::Value &, Event &, llvm::json::Path);
6766

68-
FLAGS_ENUM(ResponseMessage){
69-
/// The request was cancelled
70-
eResponseMessageCancelled,
71-
/// The request may be retried once the adapter is in a 'stopped' state
72-
eResponseMessageNotStopped,
67+
enum ResponseMessage : unsigned {
68+
/// The request was cancelled
69+
eResponseMessageCancelled,
70+
/// The request may be retried once the adapter is in a 'stopped' state
71+
eResponseMessageNotStopped,
7372
};
7473

7574
/// Response for a request.

lldb/tools/lldb-dap/Protocol/ProtocolRequests.h

+17-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include "Protocol/ProtocolBase.h"
2424
#include "Protocol/ProtocolTypes.h"
25-
#include "lldb/lldb-enumerations.h"
2625
#include "llvm/ADT/DenseSet.h"
2726
#include "llvm/Support/JSON.h"
2827
#include <cstdint>
@@ -57,26 +56,26 @@ bool fromJSON(const llvm::json::Value &, DisconnectArguments &,
5756
using DisconnectResponse = VoidResponse;
5857

5958
/// Features supported by DAP clients.
60-
FLAGS_ENUM(ClientFeature){
61-
eClientFeatureVariableType,
62-
eClientFeatureVariablePaging,
63-
eClientFeatureRunInTerminalRequest,
64-
eClientFeatureMemoryReferences,
65-
eClientFeatureProgressReporting,
66-
eClientFeatureInvalidatedEvent,
67-
eClientFeatureMemoryEvent,
68-
/// Client supports the `argsCanBeInterpretedByShell` attribute on the
69-
/// `runInTerminal` request.
70-
eClientFeatureArgsCanBeInterpretedByShell,
71-
eClientFeatureStartDebuggingRequest,
72-
/// The client will interpret ANSI escape sequences in the display of
73-
/// `OutputEvent.output` and `Variable.value` fields when
74-
/// `Capabilities.supportsANSIStyling` is also enabled.
75-
eClientFeatureANSIStyling,
59+
enum ClientFeature : unsigned {
60+
eClientFeatureVariableType,
61+
eClientFeatureVariablePaging,
62+
eClientFeatureRunInTerminalRequest,
63+
eClientFeatureMemoryReferences,
64+
eClientFeatureProgressReporting,
65+
eClientFeatureInvalidatedEvent,
66+
eClientFeatureMemoryEvent,
67+
/// Client supports the `argsCanBeInterpretedByShell` attribute on the
68+
/// `runInTerminal` request.
69+
eClientFeatureArgsCanBeInterpretedByShell,
70+
eClientFeatureStartDebuggingRequest,
71+
/// The client will interpret ANSI escape sequences in the display of
72+
/// `OutputEvent.output` and `Variable.value` fields when
73+
/// `Capabilities.supportsANSIStyling` is also enabled.
74+
eClientFeatureANSIStyling,
7675
};
7776

7877
/// Format of paths reported by the debug adapter.
79-
FLAGS_ENUM(PathFormat){ePatFormatPath, ePathFormatURI};
78+
enum PathFormat : unsigned { ePatFormatPath, ePathFormatURI };
8079

8180
/// Arguments for `initialize` request.
8281
struct InitializeRequestArguments {

lldb/tools/lldb-dap/Protocol/ProtocolTypes.h

+121-114
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#ifndef LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_TYPES_H
2121
#define LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_TYPES_H
2222

23-
#include "lldb/lldb-enumerations.h"
2423
#include "llvm/ADT/DenseSet.h"
2524
#include "llvm/Support/JSON.h"
2625
#include <cstdint>
@@ -57,8 +56,12 @@ struct ExceptionBreakpointsFilter {
5756
};
5857
llvm::json::Value toJSON(const ExceptionBreakpointsFilter &);
5958

60-
FLAGS_ENUM(ColumnType){eColumnTypeString, eColumnTypeNumber, eColumnTypeBoolean,
61-
eColumnTypeTimestamp};
59+
enum ColumnType : unsigned {
60+
eColumnTypeString,
61+
eColumnTypeNumber,
62+
eColumnTypeBoolean,
63+
eColumnTypeTimestamp
64+
};
6265

6366
/// A ColumnDescriptor specifies what module attribute to show in a column of
6467
/// the modules view, how to format it, and what the column’s label should be.
@@ -87,23 +90,27 @@ llvm::json::Value toJSON(const ColumnDescriptor &);
8790

8891
/// Names of checksum algorithms that may be supported by a debug adapter.
8992
/// Values: ‘MD5’, ‘SHA1’, ‘SHA256’, ‘timestamp’.
90-
FLAGS_ENUM(ChecksumAlgorithm){eChecksumAlgorithmMD5, eChecksumAlgorithmSHA1,
91-
eChecksumAlgorithmSHA256,
92-
eChecksumAlgorithmTimestamp};
93+
enum ChecksumAlgorithm : unsigned {
94+
eChecksumAlgorithmMD5,
95+
eChecksumAlgorithmSHA1,
96+
eChecksumAlgorithmSHA256,
97+
eChecksumAlgorithmTimestamp
98+
};
9399
llvm::json::Value toJSON(const ChecksumAlgorithm &);
94100

95101
/// Describes one or more type of breakpoint a BreakpointMode applies to. This
96102
/// is a non-exhaustive enumeration and may expand as future breakpoint types
97103
/// are added.
98-
FLAGS_ENUM(BreakpointModeApplicability){
99-
/// In `SourceBreakpoint`'s.
100-
eBreakpointModeApplicabilitySource,
101-
/// In exception breakpoints applied in the `ExceptionFilterOptions`.
102-
eBreakpointModeApplicabilityException,
103-
/// In data breakpoints requested in the `DataBreakpointInfo` request.
104-
eBreakpointModeApplicabilityData,
105-
/// In `InstructionBreakpoint`'s.
106-
eBreakpointModeApplicabilityInstruction};
104+
enum BreakpointModeApplicability : unsigned {
105+
/// In `SourceBreakpoint`'s.
106+
eBreakpointModeApplicabilitySource,
107+
/// In exception breakpoints applied in the `ExceptionFilterOptions`.
108+
eBreakpointModeApplicabilityException,
109+
/// In data breakpoints requested in the `DataBreakpointInfo` request.
110+
eBreakpointModeApplicabilityData,
111+
/// In `InstructionBreakpoint`'s.
112+
eBreakpointModeApplicabilityInstruction
113+
};
107114
llvm::json::Value toJSON(const BreakpointModeApplicability &);
108115

109116
/// A `BreakpointMode` is provided as a option when setting breakpoints on
@@ -126,101 +133,101 @@ struct BreakpointMode {
126133
llvm::json::Value toJSON(const BreakpointMode &);
127134

128135
/// Debug Adapter Features flags supported by lldb-dap.
129-
FLAGS_ENUM(AdapterFeature){
130-
/// The debug adapter supports ANSI escape sequences in styling of
131-
/// `OutputEvent.output` and `Variable.value` fields.
132-
eAdapterFeatureANSIStyling,
133-
/// The debug adapter supports the `breakpointLocations` request.
134-
eAdapterFeatureBreakpointLocationsRequest,
135-
/// The debug adapter supports the `cancel` request.
136-
eAdapterFeatureCancelRequest,
137-
/// The debug adapter supports the `clipboard` context value in the
138-
/// `evaluate` request.
139-
eAdapterFeatureClipboardContext,
140-
/// The debug adapter supports the `completions` request.
141-
eAdapterFeatureCompletionsRequest,
142-
/// The debug adapter supports conditional breakpoints.
143-
eAdapterFeatureConditionalBreakpoints,
144-
/// The debug adapter supports the `configurationDone` request.
145-
eAdapterFeatureConfigurationDoneRequest,
146-
/// The debug adapter supports the `asAddress` and `bytes` fields in the
147-
/// `dataBreakpointInfo` request.
148-
eAdapterFeatureDataBreakpointBytes,
149-
/// The debug adapter supports data breakpoints.
150-
eAdapterFeatureDataBreakpoints,
151-
/// The debug adapter supports the delayed loading of parts of the stack,
152-
/// which requires that both the `startFrame` and `levels` arguments and the
153-
/// `totalFrames` result of the `stackTrace` request are supported.
154-
eAdapterFeatureDelayedStackTraceLoading,
155-
/// The debug adapter supports the `disassemble` request.
156-
eAdapterFeatureDisassembleRequest,
157-
/// The debug adapter supports a (side effect free) `evaluate` request for
158-
/// data hovers.
159-
eAdapterFeatureEvaluateForHovers,
160-
/// The debug adapter supports `filterOptions` as an argument on the
161-
/// `setExceptionBreakpoints` request.
162-
eAdapterFeatureExceptionFilterOptions,
163-
/// The debug adapter supports the `exceptionInfo` request.
164-
eAdapterFeatureExceptionInfoRequest,
165-
/// The debug adapter supports `exceptionOptions` on the
166-
/// `setExceptionBreakpoints` request.
167-
eAdapterFeatureExceptionOptions,
168-
/// The debug adapter supports function breakpoints.
169-
eAdapterFeatureFunctionBreakpoints,
170-
/// The debug adapter supports the `gotoTargets` request.
171-
eAdapterFeatureGotoTargetsRequest,
172-
/// The debug adapter supports breakpoints that break execution after a
173-
/// specified number of hits.
174-
eAdapterFeatureHitConditionalBreakpoints,
175-
/// The debug adapter supports adding breakpoints based on instruction
176-
/// references.
177-
eAdapterFeatureInstructionBreakpoints,
178-
/// The debug adapter supports the `loadedSources` request.
179-
eAdapterFeatureLoadedSourcesRequest,
180-
/// The debug adapter supports log points by interpreting the `logMessage`
181-
/// attribute of the `SourceBreakpoint`.
182-
eAdapterFeatureLogPoints,
183-
/// The debug adapter supports the `modules` request.
184-
eAdapterFeatureModulesRequest,
185-
/// The debug adapter supports the `readMemory` request.
186-
eAdapterFeatureReadMemoryRequest,
187-
/// The debug adapter supports restarting a frame.
188-
eAdapterFeatureRestartFrame,
189-
/// The debug adapter supports the `restart` request. In this case a client
190-
/// should not implement `restart` by terminating and relaunching the
191-
/// adapter but by calling the `restart` request.
192-
eAdapterFeatureRestartRequest,
193-
/// The debug adapter supports the `setExpression` request.
194-
eAdapterFeatureSetExpression,
195-
/// The debug adapter supports setting a variable to a value.
196-
eAdapterFeatureSetVariable,
197-
/// The debug adapter supports the `singleThread` property on the execution
198-
/// requests (`continue`, `next`, `stepIn`, `stepOut`, `reverseContinue`,
199-
/// `stepBack`).
200-
eAdapterFeatureSingleThreadExecutionRequests,
201-
/// The debug adapter supports stepping back via the `stepBack` and
202-
/// `reverseContinue` requests.
203-
eAdapterFeatureStepBack,
204-
/// The debug adapter supports the `stepInTargets` request.
205-
eAdapterFeatureStepInTargetsRequest,
206-
/// The debug adapter supports stepping granularities (argument
207-
/// `granularity`) for the stepping requests.
208-
eAdapterFeatureSteppingGranularity,
209-
/// The debug adapter supports the `terminate` request.
210-
eAdapterFeatureTerminateRequest,
211-
/// The debug adapter supports the `terminateThreads` request.
212-
eAdapterFeatureTerminateThreadsRequest,
213-
/// The debug adapter supports the `suspendDebuggee` attribute on the
214-
/// `disconnect` request.
215-
eAdapterFeatureSuspendDebuggee,
216-
/// The debug adapter supports a `format` attribute on the `stackTrace`,
217-
/// `variables`, and `evaluate` requests.
218-
eAdapterFeatureValueFormattingOptions,
219-
/// The debug adapter supports the `writeMemory` request.
220-
eAdapterFeatureWriteMemoryRequest,
221-
/// The debug adapter supports the `terminateDebuggee` attribute on the
222-
/// `disconnect` request.
223-
eAdapterFeatureTerminateDebuggee,
136+
enum AdapterFeature : unsigned {
137+
/// The debug adapter supports ANSI escape sequences in styling of
138+
/// `OutputEvent.output` and `Variable.value` fields.
139+
eAdapterFeatureANSIStyling,
140+
/// The debug adapter supports the `breakpointLocations` request.
141+
eAdapterFeatureBreakpointLocationsRequest,
142+
/// The debug adapter supports the `cancel` request.
143+
eAdapterFeatureCancelRequest,
144+
/// The debug adapter supports the `clipboard` context value in the
145+
/// `evaluate` request.
146+
eAdapterFeatureClipboardContext,
147+
/// The debug adapter supports the `completions` request.
148+
eAdapterFeatureCompletionsRequest,
149+
/// The debug adapter supports conditional breakpoints.
150+
eAdapterFeatureConditionalBreakpoints,
151+
/// The debug adapter supports the `configurationDone` request.
152+
eAdapterFeatureConfigurationDoneRequest,
153+
/// The debug adapter supports the `asAddress` and `bytes` fields in the
154+
/// `dataBreakpointInfo` request.
155+
eAdapterFeatureDataBreakpointBytes,
156+
/// The debug adapter supports data breakpoints.
157+
eAdapterFeatureDataBreakpoints,
158+
/// The debug adapter supports the delayed loading of parts of the stack,
159+
/// which requires that both the `startFrame` and `levels` arguments and the
160+
/// `totalFrames` result of the `stackTrace` request are supported.
161+
eAdapterFeatureDelayedStackTraceLoading,
162+
/// The debug adapter supports the `disassemble` request.
163+
eAdapterFeatureDisassembleRequest,
164+
/// The debug adapter supports a (side effect free) `evaluate` request for
165+
/// data hovers.
166+
eAdapterFeatureEvaluateForHovers,
167+
/// The debug adapter supports `filterOptions` as an argument on the
168+
/// `setExceptionBreakpoints` request.
169+
eAdapterFeatureExceptionFilterOptions,
170+
/// The debug adapter supports the `exceptionInfo` request.
171+
eAdapterFeatureExceptionInfoRequest,
172+
/// The debug adapter supports `exceptionOptions` on the
173+
/// `setExceptionBreakpoints` request.
174+
eAdapterFeatureExceptionOptions,
175+
/// The debug adapter supports function breakpoints.
176+
eAdapterFeatureFunctionBreakpoints,
177+
/// The debug adapter supports the `gotoTargets` request.
178+
eAdapterFeatureGotoTargetsRequest,
179+
/// The debug adapter supports breakpoints that break execution after a
180+
/// specified number of hits.
181+
eAdapterFeatureHitConditionalBreakpoints,
182+
/// The debug adapter supports adding breakpoints based on instruction
183+
/// references.
184+
eAdapterFeatureInstructionBreakpoints,
185+
/// The debug adapter supports the `loadedSources` request.
186+
eAdapterFeatureLoadedSourcesRequest,
187+
/// The debug adapter supports log points by interpreting the `logMessage`
188+
/// attribute of the `SourceBreakpoint`.
189+
eAdapterFeatureLogPoints,
190+
/// The debug adapter supports the `modules` request.
191+
eAdapterFeatureModulesRequest,
192+
/// The debug adapter supports the `readMemory` request.
193+
eAdapterFeatureReadMemoryRequest,
194+
/// The debug adapter supports restarting a frame.
195+
eAdapterFeatureRestartFrame,
196+
/// The debug adapter supports the `restart` request. In this case a client
197+
/// should not implement `restart` by terminating and relaunching the
198+
/// adapter but by calling the `restart` request.
199+
eAdapterFeatureRestartRequest,
200+
/// The debug adapter supports the `setExpression` request.
201+
eAdapterFeatureSetExpression,
202+
/// The debug adapter supports setting a variable to a value.
203+
eAdapterFeatureSetVariable,
204+
/// The debug adapter supports the `singleThread` property on the execution
205+
/// requests (`continue`, `next`, `stepIn`, `stepOut`, `reverseContinue`,
206+
/// `stepBack`).
207+
eAdapterFeatureSingleThreadExecutionRequests,
208+
/// The debug adapter supports stepping back via the `stepBack` and
209+
/// `reverseContinue` requests.
210+
eAdapterFeatureStepBack,
211+
/// The debug adapter supports the `stepInTargets` request.
212+
eAdapterFeatureStepInTargetsRequest,
213+
/// The debug adapter supports stepping granularities (argument
214+
/// `granularity`) for the stepping requests.
215+
eAdapterFeatureSteppingGranularity,
216+
/// The debug adapter supports the `terminate` request.
217+
eAdapterFeatureTerminateRequest,
218+
/// The debug adapter supports the `terminateThreads` request.
219+
eAdapterFeatureTerminateThreadsRequest,
220+
/// The debug adapter supports the `suspendDebuggee` attribute on the
221+
/// `disconnect` request.
222+
eAdapterFeatureSuspendDebuggee,
223+
/// The debug adapter supports a `format` attribute on the `stackTrace`,
224+
/// `variables`, and `evaluate` requests.
225+
eAdapterFeatureValueFormattingOptions,
226+
/// The debug adapter supports the `writeMemory` request.
227+
eAdapterFeatureWriteMemoryRequest,
228+
/// The debug adapter supports the `terminateDebuggee` attribute on the
229+
/// `disconnect` request.
230+
eAdapterFeatureTerminateDebuggee,
224231
};
225232

226233
/// Information about the capabilities of a debug adapter.
@@ -261,10 +268,10 @@ struct Capabilities {
261268
};
262269
llvm::json::Value toJSON(const Capabilities &);
263270

264-
FLAGS_ENUM(PresentationHint){
265-
ePresentationHintNormal,
266-
ePresentationHintEmphasize,
267-
ePresentationHintDeemphasize,
271+
enum PresentationHint : unsigned {
272+
ePresentationHintNormal,
273+
ePresentationHintEmphasize,
274+
ePresentationHintDeemphasize,
268275
};
269276

270277
/// A `Source` is a descriptor for source code. It is returned from the debug

0 commit comments

Comments
 (0)