I wanted to set up a breakpoint in gdb, and since it can't handle the symbols correctly, I decided to use the "jmp $" and "set $pc+=2" trick to step through. My code is as follows:
Code: Select all
/*** endless loop ***/
dbg_printf("dispatch loop\n");
ee: goto ee;
while(1) {
/* get work */
msg = mq_recv();
Code: Select all
(gdb) symbol-file bin/initrd/lib/libc.so
Reading symbols from bin/initrd/lib/libc.so...done.
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x0000000000209b02 in ?? ()
(gdb) x /16i $pc
=> 0x209b02: jmp 0x209b02
0x209b04: leaveq
0x209b05: retq
0x209b06: push %rbp
0x209b07: mov %rsp,%rbp
It shouldn't been a leaveq+retq there! So I've investigated a bit. I'm compiling with "-g -O0" flags, that should disable all optimizations. When I comment out the "ee: goto ee;", I got:
Code: Select all
objdump -d libc.so
...
1b0e: e8 dd 34 00 00 callq 4ff0 <dbg_printf@plt>
1b13: b8 00 00 00 00 mov $0x0,%eax
1b18: e8 63 34 00 00 callq 4f80 <mq_recv@plt>
...
Code: Select all
objdump -d libc.so
...
1b0b: e8 00 33 00 00 callq 4e10 <dbg_printf@plt>
1b10: eb fe jmp 1b10 <mq_dispatch+0x1bc>
1b12: c9 leaveq
1b13: c3 retq
0000000000001b14 <atexit>:
Solution, ughly it is, but works (at least on x86_64):
Code: Select all
/*** endless loop ***/
dbg_printf("dispatch loop\n");
__asm__ __volatile__ ("1:jmp 1b");
while(1) {
/* get work */
msg = mq_recv();
Code: Select all
objdump -d libc.so
...
1b0e: e8 ed 34 00 00 callq 5000 <dbg_printf@plt>
1b13: eb fe jmp 1b13 <mq_dispatch+0x1bf>
1b15: b8 00 00 00 00 mov $0x0,%eax
1b1a: e8 71 34 00 00 callq 4f90 <mq_recv@plt>
...