OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: TrapFlag ignored
PostPosted: Wed Jan 11, 2017 1:27 pm 
Offline
Member
Member

Joined: Fri May 16, 2014 2:40 pm
Posts: 36
I'm currently writing a gdb stub for 64bit to make debugging of my kernel easier on real hardware (Since some issues only occur on actual hardware, and not on a simulator).
The stub seems to work (I can read/write memory, registers and I can step through the code), except that stepping stops working at the moment I call a function in the code being debugged. I tried debugging my debugger through qemu, and it shows that indeed my interrupt handler is not being triggered anymore, while the TF flag is still set in the EFLAGS register.

My ISR assembly:
Code:
%macro isr 2
align 8
global _isr_%1
_isr_%1:
        push 0
        pushaq
        mov rdi, %2
        mov rsi, rsp
        call fault_handler
        popaq
        add rsp,8
        iretq
%endmacro

section .text

extern fault_handler;

isr         divide_error, 0
isr         debug, 1
isr         nmi_interrupt, 2
isr         breakpoint, 3


My c fault handler:
Code:
struct interrupt_state {
    uint64_t r15,r14,r13,r12,r11,r10;
    uint64_t r9,r8,rsi,rdi,rdx,rcx;
    uint64_t rbx,rax,rbp,errorCode;
    uint64_t rip, cs, rflags, rsp;
} __attribute__((packed));

void fault_handler(int num, struct interrupt_state* state) {
    if(gdbDebugInitialized) {
        gdbHandleException(num, state);
        return;
    }
//Left out some code here since it will never be called while the stub is active
}


My gdb stub stepping code:
Code:
void gdbHandleException(int num, struct interrupt_state* state) {
    if(gdbInMemoryRoutine) {
        gdbErrorOccurred = true;
        return;
    }

    int sigval = computeSignal(num);
...
//Left out all code starting the loop and reading packages since the debug packages themselves are being read correctly
...

        case 's':
            stepping = true;
        case 'c':
            /* try to read optional parameter, pc unchanged if no parm */
            if (hexToInt (&ptr, &addr)) {
                state->rip = addr;
            }

            /* clear the trace bit */
            state->rflags &= 0xfffffeff;

            /* set the trace bit if we're stepping */
            //if (stepping) //Commented out so that we are always setting the flag after breakpoint (To see whether it still stops after each instruction)
                state->rflags |= 0x100;

            return;


Am I making some obvious mistake, or does someone know how this can happen?

Any help is appreciated!


Top
 Profile  
 
 Post subject: Re: TrapFlag ignored
PostPosted: Mon Jan 16, 2017 6:15 am 
Offline
Member
Member

Joined: Fri May 16, 2014 2:40 pm
Posts: 36
Anyone has a clue how this could happen?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot] and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group