From: Maxim Blinov <maxim.a.blinov@gmail.com>
To: gdb@sourceware.org
Subject: Coercing GDB to disassemble Intel 16-bit code
Date: Sun, 13 Nov 2022 23:01:50 +0000 [thread overview]
Message-ID: <CAHXVFWmpGM7BaVuDS4G7fjwXXCWvrdRv+HWsuX1M7OcxM0o8wg@mail.gmail.com> (raw)
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?
reply other threads:[~2022-11-13 23:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHXVFWmpGM7BaVuDS4G7fjwXXCWvrdRv+HWsuX1M7OcxM0o8wg@mail.gmail.com \
--to=maxim.a.blinov@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).