From 63256ca8f9e01034aa714448f6acc263095f9bff Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Fri, 8 Sep 2023 22:31:48 -0500 Subject: [PATCH] 954: don't quit capturing a stacktrace when we encounter an invalid frame (#955) Don't abort stack trace when instructions can't be read at some frame. --- adapter/src/debug_session.rs | 15 ++++++++------- debuggee/cpp/debuggee.cpp | 5 +++++ tests/adapter.test.ts | 9 +++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/adapter/src/debug_session.rs b/adapter/src/debug_session.rs index d4cdef1d..c324580a 100644 --- a/adapter/src/debug_session.rs +++ b/adapter/src/debug_session.rs @@ -691,14 +691,15 @@ impl DebugSession { } } else { let pc_addr = frame.pc(); - let dasm = self.disassembly.from_address(pc_addr)?; - stack_frame.line = dasm.line_num_by_address(pc_addr) as i64; + if let Ok(dasm) = self.disassembly.from_address(pc_addr) { + stack_frame.line = dasm.line_num_by_address(pc_addr) as i64; + stack_frame.source = Some(Source { + name: Some(dasm.source_name().to_owned()), + source_reference: Some(handles::to_i64(Some(dasm.handle()))), + ..Default::default() + }); + } stack_frame.column = 0; - stack_frame.source = Some(Source { - name: Some(dasm.source_name().to_owned()), - source_reference: Some(handles::to_i64(Some(dasm.handle()))), - ..Default::default() - }); stack_frame.presentation_hint = Some("subtle".to_owned()); } stack_frames.push(stack_frame); diff --git a/debuggee/cpp/debuggee.cpp b/debuggee/cpp/debuggee.cpp index e9dfa65a..67e8fbf8 100644 --- a/debuggee/cpp/debuggee.cpp +++ b/debuggee/cpp/debuggee.cpp @@ -169,6 +169,11 @@ int main(int argc, char *argv[]) { *(volatile int *)0 = 42; } + else if (testcase == "crash_invalid_call") + { + using call_t = void(*)(); + ((call_t)(nullptr))(); + } else if (testcase == "throw") { throw std::runtime_error("error"); diff --git a/tests/adapter.test.ts b/tests/adapter.test.ts index 187d4906..88f16ef3 100644 --- a/tests/adapter.test.ts +++ b/tests/adapter.test.ts @@ -307,6 +307,15 @@ function generateSuite(triple: string) { assert.equal(response4.body.variables[0].value, '20'); }); + test('invalid jump crash', async function () { + let stoppedEvent = await ds.launchAndWaitForStop({ name: 'invalid jump crash', program: debuggee, args: ['crash_invalid_call'] }); + let response = await ds.stackTraceRequest({ threadId: stoppedEvent.body.threadId, levels: 2 }); + assert.equal(response.body.stackFrames.length, 2) + assert.equal(response.body.stackFrames[0].instructionPointerReference, '0x0'); + assert.notEqual(response.body.stackFrames[1].instructionPointerReference, '0x0'); + assert.equal(response.body.stackFrames[1].name, 'main'); + }); + test('variables', async function () { let bpLine = findMarker(debuggeeTypes, '#BP3'); let stoppedEvent = await ds.launchAndWaitForStop({ name: 'variables', program: debuggee, args: ['vars'] },