1- use dap:: events:: { Event , StoppedEventBody } ;
2- use dap:: prelude:: { Command , Request , ResponseBody } ;
3- use dap:: responses:: {
4- EvaluateResponse , ScopesResponse , SetBreakpointsResponse , StackTraceResponse , ThreadsResponse ,
5- VariablesResponse ,
6- } ;
7- use dap:: types:: { Breakpoint , Capabilities , Source , StackFrame , StoppedEventReason , Thread } ;
8- use tracing:: trace;
1+ use dap:: events:: Event ;
2+ use dap:: prelude:: ResponseBody ;
93
104use crate :: connection:: Connection ;
115
6+ mod handler;
7+
128pub struct CairoDebugger {
139 connection : Connection ,
1410}
@@ -28,7 +24,7 @@ impl CairoDebugger {
2824
2925 pub fn run ( & mut self ) -> anyhow:: Result < ( ) > {
3026 while let Ok ( req) = self . connection . next_request ( ) {
31- match handle_request ( & req) {
27+ match handler :: handle_request ( & req) {
3228 ServerResponse :: Success ( body) => self . connection . send_success ( req, body) ?,
3329 ServerResponse :: Error ( msg) => self . connection . send_error ( req, & msg) ?,
3430 ServerResponse :: Event ( event) => self . connection . send_event ( event) ?,
@@ -42,153 +38,3 @@ impl CairoDebugger {
4238 Ok ( ( ) )
4339 }
4440}
45-
46- fn handle_request ( request : & Request ) -> ServerResponse {
47- match & request. command {
48- // We have not yet decided if we want to support these.
49- Command :: BreakpointLocations ( _)
50- | Command :: Cancel ( _)
51- | Command :: Completions ( _)
52- | Command :: DataBreakpointInfo ( _)
53- | Command :: Disassemble ( _)
54- | Command :: Disconnect ( _)
55- | Command :: Goto ( _)
56- | Command :: ExceptionInfo ( _)
57- | Command :: GotoTargets ( _)
58- | Command :: LoadedSources
59- | Command :: Modules ( _)
60- | Command :: ReadMemory ( _)
61- | Command :: RestartFrame ( _)
62- | Command :: SetDataBreakpoints ( _)
63- | Command :: Restart ( _)
64- | Command :: SetExceptionBreakpoints ( _)
65- | Command :: TerminateThreads ( _)
66- | Command :: Terminate ( _)
67- | Command :: StepInTargets ( _)
68- | Command :: SetVariable ( _)
69- | Command :: SetInstructionBreakpoints ( _)
70- | Command :: SetExpression ( _)
71- | Command :: WriteMemory ( _) => {
72- // If we receive these with current capabilities, it is the client's fault.
73- let msg = format ! ( "Received an unsupported request: {request:?}" ) ;
74- ServerResponse :: Error ( msg)
75- }
76-
77- // These may be supported after the MVP.
78- // Nonetheless, if we receive these with current capabilities,
79- // it is the client's fault.
80- Command :: ReverseContinue ( _) => {
81- ServerResponse :: Error ( "Step back is not yet supported" . into ( ) )
82- }
83- Command :: StepBack ( _) => ServerResponse :: Error ( "Step back is not yet supported" . into ( ) ) ,
84- Command :: SetFunctionBreakpoints ( _) => {
85- ServerResponse :: Error ( "Set function breakpoints is not yet supported" . into ( ) )
86- }
87-
88- // It makes no sense to send `attach` in the current architecture.
89- Command :: Attach ( _) => ServerResponse :: Error ( "Attach is not supported" . into ( ) ) ,
90-
91- // Supported requests.
92- Command :: Initialize ( args) => {
93- trace ! ( "Initialized a client: {:?}" , args. client_name) ;
94-
95- ServerResponse :: Success ( ResponseBody :: Initialize ( Capabilities {
96- supports_configuration_done_request : Some ( true ) ,
97- ..Default :: default ( )
98- } ) )
99- }
100- Command :: ConfigurationDone => {
101- trace ! ( "Configuration done" ) ;
102- ServerResponse :: Success ( ResponseBody :: ConfigurationDone )
103- }
104- Command :: Continue ( _) => {
105- todo ! ( )
106- }
107- Command :: Launch ( _) => {
108- // Start running the Cairo program here.
109- ServerResponse :: SuccessThenEvent ( ResponseBody :: Launch , Event :: Initialized )
110- }
111- Command :: Next ( _) => {
112- todo ! ( )
113- }
114- Command :: Pause ( _) => ServerResponse :: Event ( Event :: Stopped ( StoppedEventBody {
115- reason : StoppedEventReason :: Pause ,
116- thread_id : Some ( 0 ) ,
117- description : None ,
118- preserve_focus_hint : None ,
119- text : None ,
120- all_threads_stopped : Some ( true ) ,
121- hit_breakpoint_ids : None ,
122- } ) ) ,
123- Command :: SetBreakpoints ( args) => {
124- let mut response_bps = Vec :: new ( ) ;
125- if let Some ( requested_bps) = & args. breakpoints {
126- for bp in requested_bps {
127- // For now accept every breakpoint as valid
128- response_bps. push ( Breakpoint {
129- verified : true ,
130- source : Some ( args. source . clone ( ) ) ,
131- line : Some ( bp. line ) ,
132- ..Default :: default ( )
133- } ) ;
134- }
135- }
136- ServerResponse :: Success ( ResponseBody :: SetBreakpoints ( SetBreakpointsResponse {
137- breakpoints : response_bps,
138- } ) )
139- }
140- Command :: Source ( _) => {
141- todo ! ( )
142- }
143- Command :: StackTrace ( _) => {
144- ServerResponse :: Success ( ResponseBody :: StackTrace ( StackTraceResponse {
145- stack_frames : vec ! [ StackFrame {
146- id: 1 ,
147- name: "test" . to_string( ) ,
148- // Replace it with the actual source path.
149- // Otherwise, the debugger will crush after returning this response.
150- source: Some ( Source { name: None , path: None , ..Default :: default ( ) } ) ,
151- line: 1 ,
152- column: 1 ,
153- ..Default :: default ( )
154- } ] ,
155- total_frames : Some ( 1 ) ,
156- } ) )
157- }
158- Command :: StepIn ( _) => {
159- todo ! ( )
160- }
161- Command :: StepOut ( _) => {
162- todo ! ( )
163- }
164-
165- Command :: Evaluate ( _) => {
166- ServerResponse :: Success ( ResponseBody :: Evaluate ( EvaluateResponse {
167- // Return whatever since we cannot opt out of supporting this request.
168- result : "" . to_string ( ) ,
169- type_field : None ,
170- presentation_hint : None ,
171- variables_reference : 0 ,
172- named_variables : None ,
173- indexed_variables : None ,
174- memory_reference : None ,
175- } ) )
176- }
177- Command :: Threads => {
178- ServerResponse :: Success ( ResponseBody :: Threads ( ThreadsResponse {
179- // Return a single thread.
180- threads : vec ! [ Thread { id: 0 , name: "" . to_string( ) } ] ,
181- } ) )
182- }
183- Command :: Variables ( _) => {
184- ServerResponse :: Success ( ResponseBody :: Variables ( VariablesResponse {
185- // Return no variables.
186- variables : vec ! [ ] ,
187- } ) )
188- }
189- Command :: Scopes ( _) => {
190- // Return no scopes.
191- ServerResponse :: Success ( ResponseBody :: Scopes ( ScopesResponse { scopes : vec ! [ ] } ) )
192- }
193- }
194- }
0 commit comments