Skip to content

Commit

Permalink
954: don't quit capturing a stacktrace when we encounter an invalid f…
Browse files Browse the repository at this point in the history
…rame (#955)

Don't abort stack trace when instructions can't be read at some frame.
  • Loading branch information
russelltg authored Sep 9, 2023
1 parent e2d01cf commit 63256ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
15 changes: 8 additions & 7 deletions adapter/src/debug_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions debuggee/cpp/debuggee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions tests/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down

0 comments on commit 63256ca

Please # to comment.