aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/NEWS3
-rw-r--r--gdb/cli/cli-cmds.c157
-rw-r--r--gdb/doc/ChangeLog4
-rw-r--r--gdb/doc/gdb.texinfo30
5 files changed, 150 insertions, 53 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 46041a4..7120c0a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2008-05-05 Doug Evans <dje@google.com>
+
+ * NEWS: Mention new /m modifier for disassemble command.
+ * cli/cli-cmds.c (print_disassembly): New function.
+ (disassemble_current_function): New function
+ (disassemble_command): Recognize /m modifier, print mixed
+ source+assembly.
+ (init_cli_cmds): Update disassemble help text.
+
2008-05-05 Maxim Grigoriev <maxim2405@gmail.com>
* xtensa-tdep.c: Update for unwinder changes.
diff --git a/gdb/NEWS b/gdb/NEWS
index ecee868..550f96b 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
*** Changes since GDB 6.8
+* The "disassemble" command now supports an optional /m modifier to print mixed
+source+assembly.
+
* GDB now supports multiple function calling conventions according to the
DWARF-2 DW_AT_calling_convention function attribute.
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index ce7378e..3cde3fc 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -892,12 +892,75 @@ list_command (char *arg, int from_tty)
0);
}
-/* Dump a specified section of assembly code. With no command line
- arguments, this command will dump the assembly code for the
- function surrounding the pc value in the selected frame. With one
- argument, it will dump the assembly code surrounding that pc value.
- Two arguments are interpeted as bounds within which to dump
- assembly. */
+/* Subroutine of disassemble_command to simplify it.
+ Perform the disassembly.
+ NAME is the name of the function if known, or NULL.
+ [LOW,HIGH) are the range of addresses to disassemble.
+ MIXED is non-zero to print source with the assembler. */
+
+static void
+print_disassembly (const char *name, CORE_ADDR low, CORE_ADDR high, int mixed)
+{
+#if defined(TUI)
+ if (!tui_is_window_visible (DISASSEM_WIN))
+#endif
+ {
+ printf_filtered ("Dump of assembler code ");
+ if (name != NULL)
+ printf_filtered ("for function %s:\n", name);
+ else
+ printf_filtered ("from %s to %s:\n", paddress (low), paddress (high));
+
+ /* Dump the specified range. */
+ gdb_disassembly (uiout, 0, 0, mixed, -1, low, high);
+
+ printf_filtered ("End of assembler dump.\n");
+ gdb_flush (gdb_stdout);
+ }
+#if defined(TUI)
+ else
+ {
+ tui_show_assembly (low);
+ }
+#endif
+}
+
+/* Subroutine of disassemble_command to simplify it.
+ Print a disassembly of the current function.
+ MIXED is non-zero to print source with the assembler. */
+
+static void
+disassemble_current_function (int mixed)
+{
+ CORE_ADDR low, high, pc;
+ char *name;
+
+ pc = get_frame_pc (get_selected_frame (_("No frame selected.")));
+ if (find_pc_partial_function (pc, &name, &low, &high) == 0)
+ error (_("No function contains program counter for selected frame."));
+#if defined(TUI)
+ /* NOTE: cagney/2003-02-13 The `tui_active' was previously
+ `tui_version'. */
+ if (tui_active)
+ /* FIXME: cagney/2004-02-07: This should be an observer. */
+ low = tui_get_low_disassembly_address (low, pc);
+#endif
+ low += gdbarch_deprecated_function_start_offset (current_gdbarch);
+
+ print_disassembly (name, low, high, mixed);
+}
+
+/* Dump a specified section of assembly code.
+
+ Usage:
+ disassemble [/m]
+ - dump the assembly code for the function of the current pc
+ disassemble [/m] addr
+ - dump the assembly code for the function at ADDR
+ disassemble [/m] low high
+ - dump the assembly code in the range [LOW,HIGH)
+
+ A /m modifier will include source code with the assembly. */
static void
disassemble_command (char *arg, int from_tty)
@@ -906,26 +969,44 @@ disassemble_command (char *arg, int from_tty)
char *name;
CORE_ADDR pc, pc_masked;
char *space_index;
-#if 0
- asection *section;
-#endif
+ int mixed_source_and_assembly;
name = NULL;
- if (!arg)
+ mixed_source_and_assembly = 0;
+
+ if (arg && *arg == '/')
{
- pc = get_frame_pc (get_selected_frame (_("No frame selected.")));
- if (find_pc_partial_function (pc, &name, &low, &high) == 0)
- error (_("No function contains program counter for selected frame."));
-#if defined(TUI)
- /* NOTE: cagney/2003-02-13 The `tui_active' was previously
- `tui_version'. */
- if (tui_active)
- /* FIXME: cagney/2004-02-07: This should be an observer. */
- low = tui_get_low_disassembly_address (low, pc);
-#endif
- low += gdbarch_deprecated_function_start_offset (current_gdbarch);
+ ++arg;
+
+ if (*arg == '\0')
+ error (_("Missing modifier."));
+
+ while (*arg && ! isspace (*arg))
+ {
+ switch (*arg++)
+ {
+ case 'm':
+ mixed_source_and_assembly = 1;
+ break;
+ default:
+ error (_("Invalid disassembly modifier."));
+ }
+ }
+
+ while (isspace (*arg))
+ ++arg;
+ }
+
+ if (! arg || ! *arg)
+ {
+ disassemble_current_function (mixed_source_and_assembly);
+ return;
}
- else if (!(space_index = (char *) strchr (arg, ' ')))
+
+ /* FIXME: 'twould be nice to allow spaces in the expression for the first
+ arg. Allow comma separater too? */
+
+ if (!(space_index = (char *) strchr (arg, ' ')))
{
/* One argument. */
pc = parse_and_eval_address (arg);
@@ -948,36 +1029,7 @@ disassemble_command (char *arg, int from_tty)
high = parse_and_eval_address (space_index + 1);
}
-#if defined(TUI)
- if (!tui_is_window_visible (DISASSEM_WIN))
-#endif
- {
- printf_filtered ("Dump of assembler code ");
- if (name != NULL)
- {
- printf_filtered ("for function %s:\n", name);
- }
- else
- {
- printf_filtered ("from ");
- deprecated_print_address_numeric (low, 1, gdb_stdout);
- printf_filtered (" to ");
- deprecated_print_address_numeric (high, 1, gdb_stdout);
- printf_filtered (":\n");
- }
-
- /* Dump the specified range. */
- gdb_disassembly (uiout, 0, 0, 0, -1, low, high);
-
- printf_filtered ("End of assembler dump.\n");
- gdb_flush (gdb_stdout);
- }
-#if defined(TUI)
- else
- {
- tui_show_assembly (low);
- }
-#endif
+ print_disassembly (name, low, high, mixed_source_and_assembly);
}
static void
@@ -1387,6 +1439,7 @@ With two args if one is empty it stands for ten lines away from the other arg.")
c = add_com ("disassemble", class_vars, disassemble_command, _("\
Disassemble a specified section of memory.\n\
Default is the function surrounding the pc of the selected frame.\n\
+With a /m modifier, source lines are included (if available).\n\
With a single argument, the function surrounding that address is dumped.\n\
Two arguments are taken as a range of memory to dump."));
set_cmd_completer (c, location_completer);
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index f371b21..dd5ee73 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-05-05 Doug Evans <dje@google.com>
+
+ * gdb.texinfo (disassemble): Document /m modifier.
+
2008-05-05 Vladimir Prus <vladimir@codesourcery.com>
* gdb.texinfo (Maintenance Commands): Clarify that "maint time"
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f4b9417..16b9b66 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -5446,8 +5446,11 @@ Variables}).
@cindex machine instructions
@cindex listing machine instructions
@item disassemble
+@itemx disassemble /m
This specialized command dumps a range of memory as machine
-instructions. The default memory range is the function surrounding the
+instructions. It can also print mixed source+disassembly by specifying
+the @code{/m} modifier.
+The default memory range is the function surrounding the
program counter of the selected frame. A single argument to this
command is a program counter value; @value{GDBN} dumps the function
surrounding this value. Two arguments specify a range of addresses
@@ -5471,6 +5474,31 @@ Dump of assembler code from 0x32c4 to 0x32e4:
End of assembler dump.
@end smallexample
+Here is an example showing mixed source+assembly for Intel x86:
+
+@smallexample
+(@value{GDBP}) disas /m main
+Dump of assembler code for function main:
+5 @{
+0x08048330 <main+0>: push %ebp
+0x08048331 <main+1>: mov %esp,%ebp
+0x08048333 <main+3>: sub $0x8,%esp
+0x08048336 <main+6>: and $0xfffffff0,%esp
+0x08048339 <main+9>: sub $0x10,%esp
+
+6 printf ("Hello.\n");
+0x0804833c <main+12>: movl $0x8048440,(%esp)
+0x08048343 <main+19>: call 0x8048284 <puts@@plt>
+
+7 return 0;
+8 @}
+0x08048348 <main+24>: mov $0x0,%eax
+0x0804834d <main+29>: leave
+0x0804834e <main+30>: ret
+
+End of assembler dump.
+@end smallexample
+
Some architectures have more than one commonly-used set of instruction
mnemonics or other syntax.