-
Notifications
You must be signed in to change notification settings - Fork 0
Make handle_request method of debugger
#29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ddoktorski
wants to merge
2
commits into
move-debugger-from-lib
Choose a base branch
from
handle-requests
base: move-debugger-from-lib
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||
| use anyhow::{Result, bail}; | ||||||
| use dap::events::{Event, StoppedEventBody}; | ||||||
| use dap::prelude::{Command, Request, ResponseBody}; | ||||||
| use dap::responses::{ | ||||||
|
|
@@ -7,154 +8,205 @@ use dap::responses::{ | |||||
| use dap::types::{Breakpoint, Capabilities, Source, StackFrame, StoppedEventReason, Thread}; | ||||||
| use tracing::trace; | ||||||
|
|
||||||
| use crate::debugger::ServerResponse; | ||||||
| use crate::CairoDebugger; | ||||||
|
|
||||||
| pub fn handle_request(request: &Request) -> ServerResponse { | ||||||
| match &request.command { | ||||||
| // We have not yet decided if we want to support these. | ||||||
| Command::BreakpointLocations(_) | ||||||
| | Command::Cancel(_) | ||||||
| | Command::Completions(_) | ||||||
| | Command::DataBreakpointInfo(_) | ||||||
| | Command::Disassemble(_) | ||||||
| | Command::Disconnect(_) | ||||||
| | Command::Goto(_) | ||||||
| | Command::ExceptionInfo(_) | ||||||
| | Command::GotoTargets(_) | ||||||
| | Command::LoadedSources | ||||||
| | Command::Modules(_) | ||||||
| | Command::ReadMemory(_) | ||||||
| | Command::RestartFrame(_) | ||||||
| | Command::SetDataBreakpoints(_) | ||||||
| | Command::Restart(_) | ||||||
| | Command::SetExceptionBreakpoints(_) | ||||||
| | Command::TerminateThreads(_) | ||||||
| | Command::Terminate(_) | ||||||
| | Command::StepInTargets(_) | ||||||
| | Command::SetVariable(_) | ||||||
| | Command::SetInstructionBreakpoints(_) | ||||||
| | Command::SetExpression(_) | ||||||
| | Command::WriteMemory(_) => { | ||||||
| // If we receive these with current capabilities, it is the client's fault. | ||||||
| let msg = format!("Received an unsupported request: {request:?}"); | ||||||
| ServerResponse::Error(msg) | ||||||
| } | ||||||
| pub enum HandleResult { | ||||||
| Handled, | ||||||
| } | ||||||
|
|
||||||
| // These may be supported after the MVP. | ||||||
| // Nonetheless, if we receive these with current capabilities, | ||||||
| // it is the client's fault. | ||||||
| Command::ReverseContinue(_) => { | ||||||
| ServerResponse::Error("Step back is not yet supported".into()) | ||||||
| } | ||||||
| Command::StepBack(_) => ServerResponse::Error("Step back is not yet supported".into()), | ||||||
| Command::SetFunctionBreakpoints(_) => { | ||||||
| ServerResponse::Error("Set function breakpoints is not yet supported".into()) | ||||||
| } | ||||||
| impl CairoDebugger { | ||||||
| pub(crate) fn handle_request(&self, request: Request) -> Result<HandleResult> { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This module is not visible from lib.rs anyways |
||||||
| match &request.command { | ||||||
| // We have not yet decided if we want to support these. | ||||||
| Command::BreakpointLocations(_) | ||||||
| | Command::Cancel(_) | ||||||
| | Command::Completions(_) | ||||||
| | Command::DataBreakpointInfo(_) | ||||||
| | Command::Disassemble(_) | ||||||
| | Command::Disconnect(_) | ||||||
| | Command::Goto(_) | ||||||
| | Command::ExceptionInfo(_) | ||||||
| | Command::GotoTargets(_) | ||||||
| | Command::LoadedSources | ||||||
| | Command::Modules(_) | ||||||
| | Command::ReadMemory(_) | ||||||
| | Command::RestartFrame(_) | ||||||
| | Command::SetDataBreakpoints(_) | ||||||
| | Command::Restart(_) | ||||||
| | Command::SetExceptionBreakpoints(_) | ||||||
| | Command::TerminateThreads(_) | ||||||
| | Command::Terminate(_) | ||||||
| | Command::StepInTargets(_) | ||||||
| | Command::SetVariable(_) | ||||||
| | Command::SetInstructionBreakpoints(_) | ||||||
| | Command::SetExpression(_) | ||||||
| | Command::WriteMemory(_) => { | ||||||
| // If we receive these with current capabilities, it is the client's fault. | ||||||
| let msg = format!("Received an unsupported request: {request:?}"); | ||||||
| self.connection.send_error(request, &msg)?; | ||||||
| bail!("Unsupported request"); | ||||||
| } | ||||||
|
|
||||||
| // It makes no sense to send `attach` in the current architecture. | ||||||
| Command::Attach(_) => ServerResponse::Error("Attach is not supported".into()), | ||||||
| // These may be supported after the MVP. | ||||||
| // Nonetheless, if we receive these with current capabilities, | ||||||
| // it is the client's fault. | ||||||
| Command::ReverseContinue(_) => { | ||||||
| self.connection.send_error(request, "Reverse continue is not yet supported")?; | ||||||
| bail!("Reverse continue is not yet supported"); | ||||||
| } | ||||||
| Command::StepBack(_) => { | ||||||
| self.connection.send_error(request, "Step back is not yet supported")?; | ||||||
| bail!("Step back is not yet supported"); | ||||||
| } | ||||||
| Command::SetFunctionBreakpoints(_) => { | ||||||
| self.connection | ||||||
| .send_error(request, "Set function breakpoints is not yet supported")?; | ||||||
| bail!("Set function breakpoints is not yet supported"); | ||||||
| } | ||||||
|
|
||||||
| // Supported requests. | ||||||
| Command::Initialize(args) => { | ||||||
| trace!("Initialized a client: {:?}", args.client_name); | ||||||
| // It makes no sense to send `attach` in the current architecture. | ||||||
| Command::Attach(_) => { | ||||||
| self.connection.send_error(request, "Attach is not supported")?; | ||||||
| bail!("Unsupported request"); | ||||||
| } | ||||||
|
|
||||||
| ServerResponse::Success(ResponseBody::Initialize(Capabilities { | ||||||
| supports_configuration_done_request: Some(true), | ||||||
| ..Default::default() | ||||||
| })) | ||||||
| } | ||||||
| Command::ConfigurationDone => { | ||||||
| trace!("Configuration done"); | ||||||
| ServerResponse::Success(ResponseBody::ConfigurationDone) | ||||||
| } | ||||||
| Command::Continue(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::Launch(_) => { | ||||||
| // Start running the Cairo program here. | ||||||
| ServerResponse::SuccessThenEvent(ResponseBody::Launch, Event::Initialized) | ||||||
| } | ||||||
| Command::Next(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::Pause(_) => ServerResponse::Event(Event::Stopped(StoppedEventBody { | ||||||
| reason: StoppedEventReason::Pause, | ||||||
| thread_id: Some(0), | ||||||
| description: None, | ||||||
| preserve_focus_hint: None, | ||||||
| text: None, | ||||||
| all_threads_stopped: Some(true), | ||||||
| hit_breakpoint_ids: None, | ||||||
| })), | ||||||
| Command::SetBreakpoints(args) => { | ||||||
| let mut response_bps = Vec::new(); | ||||||
| if let Some(requested_bps) = &args.breakpoints { | ||||||
| for bp in requested_bps { | ||||||
| // For now accept every breakpoint as valid | ||||||
| response_bps.push(Breakpoint { | ||||||
| verified: true, | ||||||
| source: Some(args.source.clone()), | ||||||
| line: Some(bp.line), | ||||||
| // Supported requests. | ||||||
| Command::Initialize(args) => { | ||||||
| trace!("Initialized a client: {:?}", args.client_name); | ||||||
| self.connection.send_success( | ||||||
| request, | ||||||
| ResponseBody::Initialize(Capabilities { | ||||||
| supports_configuration_done_request: Some(true), | ||||||
| ..Default::default() | ||||||
| }); | ||||||
| }), | ||||||
| )?; | ||||||
| self.connection.send_event(Event::Initialized)?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::ConfigurationDone => { | ||||||
| trace!("Configuration done"); | ||||||
| self.connection.send_success(request, ResponseBody::ConfigurationDone)?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::Continue(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::Launch(_) => { | ||||||
| // Start running the Cairo program here. | ||||||
| self.connection.send_success(request, ResponseBody::Launch)?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::Next(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::Pause(_) => { | ||||||
| self.connection.send_event(Event::Stopped(StoppedEventBody { | ||||||
| reason: StoppedEventReason::Pause, | ||||||
| thread_id: Some(0), | ||||||
| description: None, | ||||||
| preserve_focus_hint: None, | ||||||
| text: None, | ||||||
| all_threads_stopped: Some(true), | ||||||
| hit_breakpoint_ids: None, | ||||||
| }))?; | ||||||
| self.connection.send_success(request, ResponseBody::Pause)?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::SetBreakpoints(args) => { | ||||||
| let mut response_bps = Vec::new(); | ||||||
| if let Some(requested_bps) = &args.breakpoints { | ||||||
| for bp in requested_bps { | ||||||
| // For now accept every breakpoint as valid | ||||||
| response_bps.push(Breakpoint { | ||||||
| verified: true, | ||||||
| source: Some(args.source.clone()), | ||||||
| line: Some(bp.line), | ||||||
| ..Default::default() | ||||||
| }); | ||||||
| } | ||||||
| } | ||||||
| self.connection.send_success( | ||||||
| request, | ||||||
| ResponseBody::SetBreakpoints(SetBreakpointsResponse { | ||||||
| breakpoints: response_bps, | ||||||
| }), | ||||||
| )?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::Source(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::StackTrace(_) => { | ||||||
| self.connection.send_success( | ||||||
| request, | ||||||
| ResponseBody::StackTrace(StackTraceResponse { | ||||||
| stack_frames: vec![StackFrame { | ||||||
| id: 1, | ||||||
| name: "test".to_string(), | ||||||
| // Replace it with the actual source path. | ||||||
| // Otherwise, the debugger will crush after returning this response. | ||||||
| source: Some(Source { name: None, path: None, ..Default::default() }), | ||||||
| line: 1, | ||||||
| column: 1, | ||||||
| ..Default::default() | ||||||
| }], | ||||||
| total_frames: Some(1), | ||||||
| }), | ||||||
| )?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::StepIn(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::StepOut(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| ServerResponse::Success(ResponseBody::SetBreakpoints(SetBreakpointsResponse { | ||||||
| breakpoints: response_bps, | ||||||
| })) | ||||||
| } | ||||||
| Command::Source(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::StackTrace(_) => { | ||||||
| ServerResponse::Success(ResponseBody::StackTrace(StackTraceResponse { | ||||||
| stack_frames: vec![StackFrame { | ||||||
| id: 1, | ||||||
| name: "test".to_string(), | ||||||
| // Replace it with the actual source path. | ||||||
| // Otherwise, the debugger will crush after returning this response. | ||||||
| source: Some(Source { name: None, path: None, ..Default::default() }), | ||||||
| line: 1, | ||||||
| column: 1, | ||||||
| ..Default::default() | ||||||
| }], | ||||||
| total_frames: Some(1), | ||||||
| })) | ||||||
| } | ||||||
| Command::StepIn(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
| Command::StepOut(_) => { | ||||||
| todo!() | ||||||
| } | ||||||
|
|
||||||
| Command::Evaluate(_) => { | ||||||
| ServerResponse::Success(ResponseBody::Evaluate(EvaluateResponse { | ||||||
| // Return whatever since we cannot opt out of supporting this request. | ||||||
| result: "".to_string(), | ||||||
| type_field: None, | ||||||
| presentation_hint: None, | ||||||
| variables_reference: 0, | ||||||
| named_variables: None, | ||||||
| indexed_variables: None, | ||||||
| memory_reference: None, | ||||||
| })) | ||||||
| } | ||||||
| Command::Threads => { | ||||||
| ServerResponse::Success(ResponseBody::Threads(ThreadsResponse { | ||||||
| // Return a single thread. | ||||||
| threads: vec![Thread { id: 0, name: "".to_string() }], | ||||||
| })) | ||||||
| } | ||||||
| Command::Variables(_) => { | ||||||
| ServerResponse::Success(ResponseBody::Variables(VariablesResponse { | ||||||
| // Return no variables. | ||||||
| variables: vec![], | ||||||
| })) | ||||||
| } | ||||||
| Command::Scopes(_) => { | ||||||
| // Return no scopes. | ||||||
| ServerResponse::Success(ResponseBody::Scopes(ScopesResponse { scopes: vec![] })) | ||||||
| Command::Evaluate(_) => { | ||||||
| self.connection.send_success( | ||||||
| request, | ||||||
| ResponseBody::Evaluate(EvaluateResponse { | ||||||
| // Return whatever since we cannot opt out of supporting this request. | ||||||
| result: "".to_string(), | ||||||
| type_field: None, | ||||||
| presentation_hint: None, | ||||||
| variables_reference: 0, | ||||||
| named_variables: None, | ||||||
| indexed_variables: None, | ||||||
| memory_reference: None, | ||||||
| }), | ||||||
| )?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::Threads => { | ||||||
| self.connection.send_success( | ||||||
| request, | ||||||
| ResponseBody::Threads(ThreadsResponse { | ||||||
| // Return a single thread. | ||||||
| threads: vec![Thread { id: 0, name: "".to_string() }], | ||||||
| }), | ||||||
| )?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::Variables(_) => { | ||||||
| self.connection.send_success( | ||||||
| request, | ||||||
| ResponseBody::Variables(VariablesResponse { | ||||||
| // Return no variables. | ||||||
| variables: vec![], | ||||||
| }), | ||||||
| )?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| Command::Scopes(_) => { | ||||||
| // Return no scopes. | ||||||
| // Return no scopes. | ||||||
| self.connection.send_success( | ||||||
| request, | ||||||
| ResponseBody::Scopes(ScopesResponse { scopes: vec![] }), | ||||||
| )?; | ||||||
| Ok(HandleResult::Handled) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we could somehow return sth from
handle_requestthat is an info for the server about what it should do next (send request/event/halt and wait for continue etc.), like it was before. This way we give the control back to the server event loop, which results in clearer code. And we don't need server state in this function anymore