From: "Maciej W. Rozycki" <macro@mips.com>
To: gdb-patches@sourceware.org
Cc: Nigel Stephens <nigel@mips.com>,
"Maciej W. Rozycki" <macro@linux-mips.org>
Subject: Disassemble branch delay slot instructions automatically
Date: Tue, 15 May 2007 18:13:00 -0000 [thread overview]
Message-ID: <Pine.LNX.4.61.0705151913050.31736@perivale.mips.com> (raw)
Hello,
This is a change that implements automatic disassembly of instructions in
a branch delay slot if a branch is the last instruction to be output. It
is especially useful with the "display /i" command when single-stepping,
where you may want to see a single instruction normally not to get
distracted, but with a branch an intruction that follows would be executed
without having been printed.
Here is an example for MIPS machine code -- this is with our current
implementation:
(gdb) x /i 0x801018a4
0x801018a4 <pthread_create+52>: beqz v0,0x80101a10 <pthread_create+416>
and here -- the same command with the patch applied:
(gdb) x /i 0x801018a4
0x801018a4 <pthread_create+52>: beqz v0,0x80101a10 <pthread_create+416>
0x801018a8 <pthread_create+56>: li v1,11
This change has been tested natively for mips-unknown-linux-gnu and
remotely for mipsisa32-sde-elf, using mips-sim-sde32/-EB and
mips-sim-sde32/-EL as the targets, with no regressions.
2007-05-15 Nigel Stephens <nigel@mips.com>
Maciej W. Rozycki <macro@mips.com>
* disasm.c (gdb_set_disassemble_info): New public function to
set up a disassemble_info structure, ready for a call to
TARGET_PRINT_INSN.
* disasm.h (gdb_set_disassemble_info): Add prototype.
* printcmd.c (branch_delay_insns): New variable to record number
of delay slots after disassembling a branch.
(print_formatted): When disassembling don't call gdb_print_insn,
but call TARGET_PRINT_INSN directly. Then pick up the resulting
branch_delay_insns from the disassemble_info structure and store
in local variable of same name.
(do_examine): When disassembling, if the last instruction
disassembled has any branch delay slots, then bump the count so
that they get disassembled too.
OK to apply?
Maciej
12235.diff
Index: binutils-quilt/src/gdb/printcmd.c
===================================================================
--- binutils-quilt.orig/src/gdb/printcmd.c 2007-05-15 18:59:05.000000000 +0100
+++ binutils-quilt/src/gdb/printcmd.c 2007-05-15 18:59:46.000000000 +0100
@@ -43,6 +43,7 @@
#include "gdb_assert.h"
#include "block.h"
#include "disasm.h"
+#include "dis-asm.h"
#ifdef TUI
#include "tui/tui.h" /* For tui_active et.al. */
@@ -70,6 +71,10 @@
static CORE_ADDR next_address;
+/* Number of delay instructions following current disassembled insn. */
+
+static int branch_delay_insns;
+
/* Last address examined. */
static CORE_ADDR last_examine_address;
@@ -277,8 +282,17 @@
/* We often wrap here if there are long symbolic names. */
wrap_here (" ");
- next_address = VALUE_ADDRESS (val)
- + gdb_print_insn (VALUE_ADDRESS (val), stream);
+ {
+ static struct disassemble_info di;
+
+ gdb_set_disassemble_info (current_gdbarch, stream, &di);
+ next_address = (VALUE_ADDRESS (val)
+ + TARGET_PRINT_INSN (VALUE_ADDRESS (val), &di));
+ if (di.insn_info_valid)
+ branch_delay_insns = di.branch_delay_insns;
+ else
+ branch_delay_insns = 0;
+ }
break;
default:
@@ -800,6 +814,10 @@
release_value (last_examine_value);
print_formatted (last_examine_value, format, size, gdb_stdout);
+
+ /* Display any branch delay slots following the final insn. */
+ if (format == 'i' && count == 1)
+ count += branch_delay_insns;
}
printf_filtered ("\n");
gdb_flush (gdb_stdout);
Index: binutils-quilt/src/gdb/disasm.c
===================================================================
--- binutils-quilt.orig/src/gdb/disasm.c 2007-05-15 18:59:05.000000000 +0100
+++ binutils-quilt/src/gdb/disasm.c 2007-05-15 18:59:46.000000000 +0100
@@ -349,6 +349,15 @@
return di;
}
+/* Publicly callable version of gdb_disassemble_info which doesn't
+ return a structure, but stores the result via a pointer. */
+void
+gdb_set_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file,
+ struct disassemble_info *di)
+{
+ *di = gdb_disassemble_info (gdbarch, file);
+}
+
void
gdb_disassembly (struct ui_out *uiout,
char *file_string,
Index: binutils-quilt/src/gdb/disasm.h
===================================================================
--- binutils-quilt.orig/src/gdb/disasm.h 2007-05-15 18:59:05.000000000 +0100
+++ binutils-quilt/src/gdb/disasm.h 2007-05-15 18:59:46.000000000 +0100
@@ -35,4 +35,13 @@
extern int gdb_print_insn (CORE_ADDR memaddr, struct ui_file *stream);
+/* Fill in a disassemble_info structure, ready for a call to
+ TARGET_PRINT_INSN. */
+
+struct disassemble_info;
+
+extern void gdb_set_disassemble_info (struct gdbarch *,
+ struct ui_file *,
+ struct disassemble_info *);
+
#endif
next reply other threads:[~2007-05-15 18:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-15 18:13 Maciej W. Rozycki [this message]
2007-05-16 15:32 ` Daniel Jacobowitz
2007-05-18 15:47 ` Maciej W. Rozycki
2007-06-13 16:56 ` Daniel Jacobowitz
2007-06-20 13:56 ` Maciej W. Rozycki
2007-06-20 14:09 ` Daniel Jacobowitz
2007-06-20 15:25 ` Maciej W. Rozycki
2007-06-20 18:37 ` Eli Zaretskii
2007-06-21 15:19 ` Maciej W. Rozycki
2007-06-21 19:01 ` Eli Zaretskii
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=Pine.LNX.4.61.0705151913050.31736@perivale.mips.com \
--to=macro@mips.com \
--cc=gdb-patches@sourceware.org \
--cc=macro@linux-mips.org \
--cc=nigel@mips.com \
/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