Thanks for your answer!
First of all: turns out debugging in bochs doesn't work either. Not sure what's going on there, but I put that on halt to get back to qemu using your method.
Unfortunately, it doesn't work for me. Part of my code looks as follows:
# Setup paging for long mode
# ...
# Setup the long mode gdt
lgdt gdt_long
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
ljmp $0x08, $.long_mode
.code64
.long_mode:
jmp kernel_main
The 'kernel_main' code runs fine (prints some stuff to the terminal). So all looks good. However, I tried this (gdb 7.7.1, cross compiled, qemu from macports):
(gdb) file ../.bin/kernel
Reading symbols from ../.bin/kernel...done.
(gdb) b .long_mode
Breakpoint 1 at 0x100116: file bootstrap/boot.s, line 174.
(gdb) tar rem :1234
Remote debugging using :1234
0x0000fff0 in ?? ()
(gdb) c
Continuing.
Remote 'g' packet reply is too long: 10000080...801f0000
(gdb) info reg
Target is executing.
(gdb) set arch i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) set arch i386:x86-64:intel
The target architecture is assumed to be i386:x86-64:intel
The break address seems to be correct. This is what objdump -d displays:
00100116 <.long_mode>:
100116: e9 e9 07 00 00 jmp 100904 <kernel_main>
The same 'Target is executing.' is displayed after running the set arch commands several times. Of course, I can't continue either:
(gdb) c
Continuing.
Cannot execute this command while the selected thread is running.
So nothing I can do except for killing the app, it seems. Without setting the breakpoint it does work fine, though. Until I press ctrl+c, that is:
^CRemote 'g' packet reply is too long: 00000000...1f0000
Remote 'g' packet reply is too long: 0000000...1f0000
Remote 'g' packet reply is too long: 000000...0801f0000
(gdb) info reg
../../gdb-7.7.1/gdb/findvar.c:292: internal-error: value_of_register_lazy: Assertion `frame_id_p (get_frame_id (frame))' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
I also tried this (where boot.s:116 is the long jump to long mode):
(gdb) b bootstrap/boot.s:116
Breakpoint 1 at 0x1000bc: file bootstrap/boot.s, line 116.
(gdb) tar rem :1234
Remote debugging using :1234
0x0000fff0 in ?? ()
(gdb) c
Continuing.
Breakpoint 1, .loop_page_table () at bootstrap/boot.s:116
116 ljmp $0x08, $.long_mode
(gdb) b .long_mode
Breakpoint 2 at 0x100116: file bootstrap/boot.s, line 174.
(gdb) stepi
Remote 'g' packet reply is too long: 10000080...1f0000
(gdb) info reg
Target is executing.
Again, it's left in a state executing... And nothing I can do.
Also:
(gdb) b bootstrap/boot.s:116
Breakpoint 1 at 0x1000bc: file bootstrap/boot.s, line 116.
(gdb) tar rem :1234
Remote debugging using :1234
0x0000fff0 in ?? ()
(gdb) c
Continuing.
Breakpoint 1, .loop_page_table () at bootstrap/boot.s:116
116 ljmp $0x08, $.long_mode
(gdb) info reg
eax 0x80000010 -2147483632
ecx 0xc0000080 -1073741696
edx 0x0 0
ebx 0x3001 12289
esp 0x3f8 0x3f8
ebp 0x67e5c 0x67e5c
esi 0x56bfa 355322
edi 0x1001 4097
eip 0x1000bc 0x1000bc <.loop_page_table+103>
eflags 0x86 [ PF SF ]
cs 0x8 8
ss 0x10 16
ds 0x10 16
es 0x10 16
fs 0x10 16
gs 0x10 16
(gdb) set arch i386:x86-64:intel
The target architecture is assumed to be i386:x86-64:intel
(gdb) info reg
(gdb) info reg
rax 0xc000008080000010 -4611685466524090352
rbx 0x300100000000 52780853100544
rcx 0x67e5c000003f8 1827783462355960
rdx 0x100100056bfa 17596481367034
rsi 0x86001000bc 575526666428
rdi 0x1000000008 68719476744
rbp 0x1000000010 0x1000000010
rsp 0x1000000010 0x1000000010
r8 0x0 0
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0x0 0
r13 0x0 0
r14 0x0 0
r15 0x0 0
rip 0x0 0x0
eflags 0x0 [ ]
cs 0x0 0
ss 0x37f 895
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
So, all the registers are messed up...
Any idea on how to fix this?
Thanks!
Edit: fixed the too long lines.
Edit2: Actually, after breaking with Ctrl+C I could change the arch, and the registers seem correct there... The RIP is as I expected, so the only issue with this solution seems to be the fact the breakpoint won't trigger (at least, not anything other than an error)... Any ideas?