Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix alignment of disassemble /r
@ 2014-04-11 22:24 Daniel Gutson
  2014-04-16 12:20 ` Daniel Gutson
  2014-04-17  1:09 ` Yao Qi
  0 siblings, 2 replies; 11+ messages in thread
From: Daniel Gutson @ 2014-04-11 22:24 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 993 bytes --]

Hi,

   when disassembling in raw mode (/r) in a variable-length insn
architecture (i.e. x86),
the output can be completely messed since no alignment takes place.

I am aware of the uiout->table stuff, but it seems an overkill since I
should change
the current_uiout when disassembling in this mode (and I didn't find
any actual use of this
machinery at least for x86).
Therefore, I added a hack in the dump_insns when the /r flag is specified.
This clearly isn't the cutiest thing in the world, and I specified a
hardcoded maximum number
of opcode bytes to align (currently 8) though it is easily changeable.

Please let me know if this approach is OK or I should do something
else. Maybe consider whether
current arch is insn-len variable?

If this happens to be OK, please commit it for me since I don't have
write access.

Thanks,

   Daniel.


2014-04-11  Daniel Gutson  <daniel.gutson@tallertechnologies.com>

        * disasm.c (dump_insns): Added right alignment when showing opcodes.

[-- Attachment #2: disasm.patch --]
[-- Type: text/x-patch, Size: 1478 bytes --]

diff --git a/gdb/disasm.c b/gdb/disasm.c
index d94225b..0fd5aa1 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -107,6 +107,13 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
   int offset;
   int line;
   struct cleanup *ui_out_chain;
+  /* This array holds enough space for 8 bytes of opcodes;
+     since the format is 02x plus the space, the length
+     the array is (2chars + 1space) * 8 bytes + 1zero = 25 chars.  */
+  char right_align[8 * 3 + 1];
+
+  memset(right_align, ' ', sizeof(right_align) - 2);
+  right_align[sizeof(right_align) - 1] = 0;
 
   for (pc = low; pc < high;)
     {
@@ -154,6 +161,7 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
           bfd_byte data;
           int status;
           const char *spacer = "";
+          unsigned int alignment_pos = 0;
 
           /* Build the opcodes using a temporary stream so we can
              write them out in a single go for the MI.  */
@@ -170,8 +178,11 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
               fprintf_filtered (opcode_stream, "%s%02x",
                                 spacer, (unsigned) data);
               spacer = " ";
+              alignment_pos += 3;
             }
           ui_out_field_stream (uiout, "opcodes", opcode_stream);
+          if (alignment_pos < sizeof(right_align))
+            ui_out_text (uiout, &right_align[alignment_pos]);
           ui_out_text (uiout, "\t");
 
           do_cleanups (cleanups);

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-03-04 20:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-11 22:24 [PATCH] Fix alignment of disassemble /r Daniel Gutson
2014-04-16 12:20 ` Daniel Gutson
2014-04-17  1:09 ` Yao Qi
2014-04-17 14:37   ` Daniel Gutson
2014-04-17 16:27     ` Doug Evans
2014-04-17 17:27       ` Daniel Gutson
2014-04-17 18:19         ` Doug Evans
2014-04-21  0:56         ` Yao Qi
2014-04-21 16:00           ` Daniel Gutson
2014-04-22 12:14             ` Daniel Gutson
2016-03-04 20:41               ` Daniel Gutson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox