fix(dap): validate key and index exist when requesting vars (#5628)

Check if the stack frames contain the thread id and the frame before
trying to get the frame id. If case any of the two fails to be
found, provide the user with messages to inform them of the issue and
gracefully return.

Closes: #5625

Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
pull/5651/head
Filip Dutescu 2 years ago committed by GitHub
parent e3765ac6d2
commit 44729fbaf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -475,19 +475,36 @@ pub fn dap_variables(cx: &mut Context) {
if debugger.thread_id.is_none() { if debugger.thread_id.is_none() {
cx.editor cx.editor
.set_status("Cannot access variables while target is running"); .set_status("Cannot access variables while target is running.");
return; return;
} }
let (frame, thread_id) = match (debugger.active_frame, debugger.thread_id) { let (frame, thread_id) = match (debugger.active_frame, debugger.thread_id) {
(Some(frame), Some(thread_id)) => (frame, thread_id), (Some(frame), Some(thread_id)) => (frame, thread_id),
_ => { _ => {
cx.editor cx.editor
.set_status("Cannot find current stack frame to access variables"); .set_status("Cannot find current stack frame to access variables.");
return; return;
} }
}; };
let frame_id = debugger.stack_frames[&thread_id][frame].id; let thread_frame = match debugger.stack_frames.get(&thread_id) {
Some(thread_frame) => thread_frame,
None => {
cx.editor
.set_error("Failed to get stack frame for thread: {thread_id}");
return;
}
};
let stack_frame = match thread_frame.get(frame) {
Some(stack_frame) => stack_frame,
None => {
cx.editor
.set_error("Failed to get stack frame for thread {thread_id} and frame {frame}.");
return;
}
};
let frame_id = stack_frame.id;
let scopes = match block_on(debugger.scopes(frame_id)) { let scopes = match block_on(debugger.scopes(frame_id)) {
Ok(s) => s, Ok(s) => s,
Err(e) => { Err(e) => {

Loading…
Cancel
Save