]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2009-07-11 Hui Zhu <teawater@gmail.com>
authorHui Zhu <teawater@gmail.com>
Sat, 11 Jul 2009 14:04:23 +0000 (14:04 +0000)
committerHui Zhu <teawater@gmail.com>
Sat, 11 Jul 2009 14:04:23 +0000 (14:04 +0000)
* cli/cli-cmds.c (disassemble_command): Add a new modifier /r
to "disassemble" command to print the raw instructions in hex as
well as in symbolic form.
(init_cli_cmds): Ditto.
(print_disassembly): Change "mixed" to "flags" to translate
the behavior of disassemble.
(disassemble_current_function): Ditto.
* mi/mi-cmd-disas.c (mi_cmd_disassemble): Ditto.
* stack.c (gdb_disassembly_stub): Ditto.
* disasm.c (do_mixed_source_and_assembly): Ditto.
(do_mixed_source_and_assembly): Ditto.
(do_assembly_only): Ditto.
(gdb_disassembly): Ditto.
(dump_insns): print the raw instructions in hex as well as in
symbolic form if DISASSEMBLY_RAW_INSN and flags is true.
* disasm.h (DISASSEMBLY_SOURCE): Include source code with the
assembly if it and flags is true.
(DISASSEMBLY_RAW_INSN): Include the raw instructions in hex with
the assembly if it and flags is true.
(gdb_disassembly): Update extern.
* NEWS: Document disassemble/r support.

gdb/ChangeLog
gdb/NEWS
gdb/cli/cli-cmds.c
gdb/disasm.c
gdb/disasm.h
gdb/mi/mi-cmd-disas.c
gdb/stack.c

index dd0518a8500e8ee48af3d9f3242e7b4e66075db1..30896bf644b783932e9f6f4ef7f71b2cc2a15512 100644 (file)
@@ -1,3 +1,27 @@
+2009-07-11  Hui Zhu  <teawater@gmail.com>
+
+       * cli/cli-cmds.c (disassemble_command): Add a new modifier /r
+       to "disassemble" command to print the raw instructions in hex as
+       well as in symbolic form.
+       (init_cli_cmds): Ditto.
+       (print_disassembly): Change "mixed" to "flags" to translate
+       the behavior of disassemble.
+       (disassemble_current_function): Ditto.
+       * mi/mi-cmd-disas.c (mi_cmd_disassemble): Ditto.
+       * stack.c (gdb_disassembly_stub): Ditto.
+       * disasm.c (do_mixed_source_and_assembly): Ditto.
+       (do_mixed_source_and_assembly): Ditto.
+       (do_assembly_only): Ditto.
+       (gdb_disassembly): Ditto.
+       (dump_insns): print the raw instructions in hex as well as in
+       symbolic form if DISASSEMBLY_RAW_INSN and flags is true.
+       * disasm.h (DISASSEMBLY_SOURCE): Include source code with the
+       assembly if it and flags is true.
+       (DISASSEMBLY_RAW_INSN): Include the raw instructions in hex with
+       the assembly if it and flags is true.
+       (gdb_disassembly): Update extern.
+       * NEWS: Document disassemble/r support.
+
 2009-07-10  Tom Tromey  <tromey@redhat.com>
 
        * dwarf2-frame.c: Include dwarf2.h, not elf/dwarf2.h.
index 68776a58ff59afd5ba6a0645614bce7352fbe64e..b444f7402b2accd1452a6047d82397ad40b0f494 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 6.8
 
+* "disassemble" command with a /r modifier, print the raw instructions
+in hex as well as in symbolic form."
+
 * Process record and replay
 
   In a architecture environment that supports ``process record and
index 9c112043d138c2a11eaa19d0bf770ad320c79a56..ce7c2a63066ddfdb79ff402766fd4409443a649c 100644 (file)
@@ -908,7 +908,7 @@ list_command (char *arg, int from_tty)
 
 static void
 print_disassembly (struct gdbarch *gdbarch, const char *name,
-                  CORE_ADDR low, CORE_ADDR high, int mixed)
+                  CORE_ADDR low, CORE_ADDR high, int flags)
 {
 #if defined(TUI)
   if (!tui_is_window_visible (DISASSEM_WIN))
@@ -922,7 +922,7 @@ print_disassembly (struct gdbarch *gdbarch, const char *name,
                         paddress (gdbarch, low), paddress (gdbarch, high));
 
       /* Dump the specified range.  */
-      gdb_disassembly (gdbarch, uiout, 0, mixed, -1, low, high);
+      gdb_disassembly (gdbarch, uiout, 0, flags, -1, low, high);
 
       printf_filtered ("End of assembler dump.\n");
       gdb_flush (gdb_stdout);
@@ -940,7 +940,7 @@ print_disassembly (struct gdbarch *gdbarch, const char *name,
    MIXED is non-zero to print source with the assembler.  */
 
 static void
-disassemble_current_function (int mixed)
+disassemble_current_function (int flags)
 {
   struct frame_info *frame;
   struct gdbarch *gdbarch;
@@ -961,20 +961,21 @@ disassemble_current_function (int mixed)
 #endif
   low += gdbarch_deprecated_function_start_offset (gdbarch);
 
-  print_disassembly (gdbarch, name, low, high, mixed);
+  print_disassembly (gdbarch, name, low, high, flags);
 }
 
 /* Dump a specified section of assembly code.
 
    Usage:
-     disassemble [/m]
+     disassemble [/mr]
        - dump the assembly code for the function of the current pc
-     disassemble [/m] addr
+     disassemble [/mr] addr
        - dump the assembly code for the function at ADDR
-     disassemble [/m] low high
+     disassemble [/mr] low high
        - dump the assembly code in the range [LOW,HIGH)
 
-   A /m modifier will include source code with the assembly.  */
+   A /m modifier will include source code with the assembly.
+   A /r modifier will include raw instructions in hex with the assembly.  */
 
 static void
 disassemble_command (char *arg, int from_tty)
@@ -984,10 +985,10 @@ disassemble_command (char *arg, int from_tty)
   char *name;
   CORE_ADDR pc, pc_masked;
   char *space_index;
-  int mixed_source_and_assembly;
+  int flags;
 
   name = NULL;
-  mixed_source_and_assembly = 0;
+  flags = 0;
 
   if (arg && *arg == '/')
     {
@@ -1001,7 +1002,10 @@ disassemble_command (char *arg, int from_tty)
          switch (*arg++)
            {
            case 'm':
-             mixed_source_and_assembly = 1;
+             flags |= DISASSEMBLY_SOURCE;
+             break;
+           case 'r':
+             flags |= DISASSEMBLY_RAW_INSN;
              break;
            default:
              error (_("Invalid disassembly modifier."));
@@ -1014,7 +1018,7 @@ disassemble_command (char *arg, int from_tty)
 
   if (! arg || ! *arg)
     {
-      disassemble_current_function (mixed_source_and_assembly);
+      disassemble_current_function (flags);
       return;
     }
 
@@ -1044,7 +1048,7 @@ disassemble_command (char *arg, int from_tty)
       high = parse_and_eval_address (space_index + 1);
     }
 
-  print_disassembly (gdbarch, name, low, high, mixed_source_and_assembly);
+  print_disassembly (gdbarch, name, low, high, flags);
 }
 
 static void
@@ -1454,6 +1458,7 @@ With two args if one is empty it stands for ten lines away from the other arg.")
 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 /r modifier, raw instructions in hex are included.\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);
index dcb06334dbdaa82081427a7b5f323a657bc05b17..6a1a31663c8e0352a9d0a84d2a5bc255da26601a 100644 (file)
@@ -88,7 +88,7 @@ static int
 dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
            struct disassemble_info * di,
            CORE_ADDR low, CORE_ADDR high,
-           int how_many, struct ui_stream *stb)
+           int how_many, int flags, struct ui_stream *stb)
 {
   int num_displayed = 0;
   CORE_ADDR pc;
@@ -135,7 +135,23 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
        xfree (name);
 
       ui_file_rewind (stb->stream);
-      pc += gdbarch_print_insn (gdbarch, pc, di);
+      if (flags & DISASSEMBLY_RAW_INSN)
+        {
+          CORE_ADDR old_pc = pc;
+          bfd_byte data;
+          int status;
+          pc += gdbarch_print_insn (gdbarch, pc, di);
+          for (;old_pc < pc; old_pc++)
+            {
+              status = (*di->read_memory_func) (old_pc, &data, 1, di);
+              if (status != 0)
+                (*di->memory_error_func) (status, old_pc, di);
+              ui_out_message (uiout, 0, " %02x", (unsigned)data);
+            }
+          ui_out_text (uiout, "\t");
+        }
+      else
+        pc += gdbarch_print_insn (gdbarch, pc, di);
       ui_out_field_stream (uiout, "inst", stb);
       ui_file_rewind (stb->stream);
       do_cleanups (ui_out_chain);
@@ -154,7 +170,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
                              struct linetable_entry *le,
                              CORE_ADDR low, CORE_ADDR high,
                              struct symtab *symtab,
-                             int how_many, struct ui_stream *stb)
+                             int how_many, int flags, struct ui_stream *stb)
 {
   int newlines = 0;
   struct dis_line_entry *mle;
@@ -278,7 +294,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
 
       num_displayed += dump_insns (gdbarch, uiout, di,
                                   mle[i].start_pc, mle[i].end_pc,
-                                  how_many, stb);
+                                  how_many, flags, stb);
 
       /* When we've reached the end of the mle array, or we've seen the last
          assembly range for this source line, close out the list/tuple.  */
@@ -301,14 +317,15 @@ static void
 do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
                  struct disassemble_info * di,
                  CORE_ADDR low, CORE_ADDR high,
-                 int how_many, struct ui_stream *stb)
+                 int how_many, int flags, struct ui_stream *stb)
 {
   int num_displayed = 0;
   struct cleanup *ui_out_chain;
 
   ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
 
-  num_displayed = dump_insns (gdbarch, uiout, di, low, high, how_many, stb);
+  num_displayed = dump_insns (gdbarch, uiout, di, low, high, how_many,
+                              flags, stb);
 
   do_cleanups (ui_out_chain);
 }
@@ -356,7 +373,7 @@ gdb_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file)
 void
 gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
                char *file_string,
-               int mixed_source_and_assembly,
+               int flags,
                int how_many, CORE_ADDR low, CORE_ADDR high)
 {
   struct ui_stream *stb = ui_out_stream_new (uiout);
@@ -377,13 +394,13 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
       nlines = symtab->linetable->nitems;
     }
 
-  if (!mixed_source_and_assembly || nlines <= 0
+  if (!(flags & DISASSEMBLY_SOURCE) || nlines <= 0
       || symtab == NULL || symtab->linetable == NULL)
-    do_assembly_only (gdbarch, uiout, &di, low, high, how_many, stb);
+    do_assembly_only (gdbarch, uiout, &di, low, high, how_many, flags, stb);
 
-  else if (mixed_source_and_assembly)
+  else if (flags & DISASSEMBLY_SOURCE)
     do_mixed_source_and_assembly (gdbarch, uiout, &di, nlines, le, low,
-                                 high, symtab, how_many, stb);
+                                 high, symtab, how_many, flags, stb);
 
   do_cleanups (cleanups);
   gdb_flush (gdb_stdout);
index a11280d5b1521e6db9445da50e1efe97adced465..a6f6d396d28768116774a454da6a59dda57b6c23 100644 (file)
@@ -19,6 +19,9 @@
 #ifndef DISASM_H
 #define DISASM_H
 
+#define DISASSEMBLY_SOURCE     (0x1 << 0)
+#define DISASSEMBLY_RAW_INSN   (0x1 << 1)
+
 struct ui_out;
 struct ui_file;
 
index d63f1ad0ebb6cb4067502ec64f6d88dfad87281b..e17f38abb8b02de4a81578cdb9ef65ddb4e84569 100644 (file)
@@ -156,6 +156,6 @@ mi_cmd_disassemble (char *command, char **argv, int argc)
 
   gdb_disassembly (gdbarch, uiout,
                   file_string,
-                  mixed_source_and_assembly, how_many, low, high);
+                  DISASSEMBLY_SOURCE, how_many, low, high);
 
 }
index 3eea0a1b181100b4f4e767e79d2623c8d8d856cb..82ac0d48fe0260d476554c04217271dc53de5b8a 100644 (file)
@@ -481,7 +481,9 @@ static void
 gdb_disassembly_stub (void *args)
 {
   struct gdb_disassembly_stub_args *p = args;
-  gdb_disassembly (p->gdbarch, uiout, 0, 0, p->how_many, p->low, p->high);
+  gdb_disassembly (p->gdbarch, uiout, 0,
+                   DISASSEMBLY_SOURCE | DISASSEMBLY_RAW_INSN, p->how_many,
+                   p->low, p->high);
 }
 
 /* Use TRY_CATCH to catch the exception from the gdb_disassembly