Preserving gdb backtraces

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
cptroot
Posts: 4
Joined: Wed Apr 13, 2016 10:23 pm
Libera.chat IRC: cptroot

Preserving gdb backtraces

Post by cptroot »

I'm currently trying to use gdb to debug my interrupt handlers. I'm trying to copy %rip from the interrupt stack push and push on %rbp, doing the standard mov %rsp, %rbp

So the assembly looks like this:

Code: Select all

push %rsp
push %rax
mov 0x10(%rsp), %rax                                      
push %rax
push %rbp
At the end of this, I have the following stack:

Code: Select all

0x676d528:	0x000000000676d580	0x0000008000008c59
0x676d538:	0x0000008000066828	0x000000000676d548
0x676d548:	0x0000008000008c59	0x0000000000000028
And the registers are

Code: Select all

rax            0x8000008c59	549755849817
rbx            0x7f21f18	133308184
rcx            0x0	0
rdx            0x8000000000	549755813888
rsi            0xfffffffffffffffd	-3
rdi            0x676e7f8	108455928
rbp            0x676d528	0x676d528
rsp            0x676d528	0x676d528
r8             0x800005fc78	549756206200
r9             0x676d508	108451080
r10            0x800005fc78	549756206200
r11            0x0	0
r12            0x0	0
r13            0x0	0
r14            0x0	0
r15            0x0	0
rip            0x800000969c	0x800000969c <kernel::divide_by_zero_handler+12>
eflags         0x2	[ ]
cs             0x28	40
ss             0x8	8
ds             0x8	8
es             0x8	8
fs             0x8	8
gs             0x8	8
So why is it that my backtrace doesn't catch these values on the stack and correctly follow the backtrace out to the function that triggered the divide by zero exception?

Code: Select all

#0  0x000000800000969c in kernel::divide_by_zero_handler ()
    at /media/sf_CS_81/rusty_pintos/uefi_booter/kernel/src/lib.rs:322
#1  0x000000000676d580 in ?? ()
#2  0x0000008000008c59 in kernel::divide_by_zero ()
    at /media/sf_CS_81/rusty_pintos/uefi_booter/kernel/src/lib.rs:199
Backtrace stopped: frame did not save the PC
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: Preserving gdb backtraces

Post by Boris »

Hi,

Basically after an interrupt, your stack looks like
[ Whatever , undefined ( usually the stack starts at tss.rsp0 if the interrupt happened from outside the kernel )
[ Interrupted SS ]
[ interrupted RSP ]
[ Interrupted RFLAGS ]
[ Interrupted CS ]
[ Interrupted RIP ] <-- RSP points to this

But ! You have an untouched RBP. If it is valid ( check if it points to another rbp )
You just have here to do immediately after the beginning of your interrupt handler,
Pushq ℅RBP; Movq %RBP,%RSP
Post Reply