public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Coercing GDB to disassemble Intel 16-bit code
@ 2022-11-13 23:01 Maxim Blinov
  0 siblings, 0 replies; only message in thread
From: Maxim Blinov @ 2022-11-13 23:01 UTC (permalink / raw)
  To: gdb

Hi all, I was hacking some MBR bootloader code today, but I've hit an
annoyance: GDB isn't over-keen on disassembling the code as 16-bit
intel code. The target is qemu-system-i386, launched to wait on a GDB
connection over tcp:9000. Below is my GDB session to illustrate:

(gdb) tar rem :9000
Remote debugging using :9000
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0000fff0 in ?? ()
(gdb) b *0x7c00
Breakpoint 1 at 0x7c00
(gdb) c
Continuing.

Thread 1 hit Breakpoint 1, 0x00007c00 in ?? ()
(gdb) set architecture i8086
The target architecture is set to "i8086".
(gdb) disas /r 0x7c00,+20
Dump of assembler code from 0x7c00 to 0x7c14:
=> 0x00007c00:  e8 00 00 eb 3b          call   0x3beb7c05
   0x00007c05:  00 00                   add    %al,(%eax)
   0x00007c07:  00 10                   add    %dl,(%eax)
   0x00007c09:  00 00                   add    %al,(%eax)
   0x00007c0b:  00 c7                   add    %al,%bh
   0x00007c0d:  02 00                   add    (%eax),%al
   0x00007c0f:  00 ac 71 00 00 d2 7b    add    %ch,0x7bd20000(%ecx,%esi,2)
End of assembler dump.
(gdb)

Infact most of that is bogus anyway (the `add`'s are just trying to
disassembly zeroes): but the very first `call` should be to 0x7c05,
not 0x3beb7c05! Infact GDB has merged two instructions into one.
Objdump gives the correct disassembly, as below:

$ objdump -m i8086 -b binary --adjust-vma=0x7c00 -D bootsect.img  | head -n 100
...
00007c00 <.data>:
    7c00:    e8 00 00                 call   0x7c03
    7c03:    eb 3b                    jmp    0x7c40
    7c05:    00 00                    add    %al,(%bx,%si)
    7c07:    00 10                    add    %dl,(%bx,%si)
    7c09:    00 00                    add    %al,(%bx,%si)
...

Any ideas?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-13 23:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-13 23:01 Coercing GDB to disassemble Intel 16-bit code Maxim Blinov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).