Skip to content

Commit 8d36aa6

Browse files
committed
Fix bugs with stack trace.
1 parent 24fdef2 commit 8d36aa6

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

assembly_interface.s

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ global interrupt
4545
; stack: [esp + 4] the software interrupt that should be generated (0-255)
4646
; [esp ] the return address
4747
interrupt:
48-
mov eax, [esp+4]
48+
mov eax, [esp+4] ; TODO: figure out how to pass this parameter to the int instruction
49+
push ebp ; make the caller show up in the stack trace
50+
mov ebp, esp
4951
int 49
52+
pop ebp
5053

5154
global enable_hardware_interrupts
5255
; enable_hardware_interrupts

interrupts.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#define INT_PAGE_FAULT 0x0000000E
1313
#define INT_SOFTWARE 0x00000031
1414

15+
void log_stack_trace_line(uint32_t eip) {
16+
print_uint32(LOG, eip);
17+
log(" : ");
18+
char * symbol_name = address_to_symbol_name(eip);
19+
fprintf(LOG, symbol_name);
20+
log("\n");
21+
}
22+
1523
void log_interrupt_details(char* int_name, uint32_t error_code, uint32_t eip, struct cpu_state* cpu) {
1624
if(cpu->ebp){}
1725
log("--------------------\n");
@@ -24,19 +32,12 @@ void log_interrupt_details(char* int_name, uint32_t error_code, uint32_t eip, st
2432
log("\n");
2533

2634
log("\nStack trace:\n");
27-
print_uint32(LOG, eip);
28-
log(" : ");
29-
char * symbol_name = address_to_symbol_name(eip);
30-
fprintf(LOG, symbol_name);
31-
log("\n");
35+
eip -= 4; // eip actually points one past the instruction that triggered interrupt
36+
log_stack_trace_line(eip);
3237
uint32_t ebp = cpu->ebp;
3338
while (ebp & 0xC0100000) {
3439
eip = ((uint32_t*) ebp)[1];
35-
print_uint32(LOG, eip);
36-
log(" : ");
37-
char * symbol_name = address_to_symbol_name(eip);
38-
fprintf(LOG, symbol_name);
39-
log("\n");
40+
log_stack_trace_line(eip);
4041

4142
ebp = *((uint32_t*)ebp);
4243
}

0 commit comments

Comments
 (0)