Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Cornel Izbasa <cornel@myri1.info.uvt.ro>
To: gdb-patches@sources.redhat.com
Subject: BUG & sugg. PATCH in GDB 5.3 (and prob. earlier) with text alignment
Date: Fri, 28 Mar 2003 18:37:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.44.0303282023030.16994-200000@myri1.info.uvt.ro> (raw)
In-Reply-To: <200303280527.h2S5RihC064049@router.uvt.ro>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1472 bytes --]

There's an incorrect text alignment in GDB 5.3 and 5.0 (probably others) 
that causes the instruction in first line of the disassembly text to be 
incorrectly aligned with the others, if the function name is less than 
3 characters long (and in some other cases). 

...
int fa(int a)
{
         return 0;       
}
...
 
(gdb) disas fa
Dump of assembler code for function fa:
0x8048448 <fa>: push   %ebp
0x8048449 <fa+1>:       mov    %esp,%ebp
0x804844b <fa+3>:       mov    $0x0,%eax
0x8048450 <fa+8>:       pop    %ebp
0x8048451 <fa+9>:       ret    
0x8048452 <fa+10>:      mov    %esi,%esi
End of assembler dump.
 
So, I've changed disassemble_command, print_address and 
print_symbolic_address in the gdb/printcmd.c and their 
prototypes in gdb/defs.h to get correct text alignment.
 
After patching with text-align.patch (attached)
the disassembly looks like this:
 
(gdb) disas fa 
Dump of assembler code for function fa:
0x8048448 <fa>:         push   %ebp
0x8048449 <fa+1>:       mov    %esp,%ebp
0x804844b <fa+3>:       mov    $0x0,%eax
0x8048450 <fa+8>:       pop    %ebp
0x8048451 <fa+9>:       ret    
0x8048452 <fa+10>:      mov    %esi,%esi
End of assembler dump.
 
I've tested it for many functions and it seems to work OK.
I should do the same for the case when we also print file 
names and line numbers, but I thought I'd better get a more 
informed opinion first.
 
Hope this helps in some way,
Please let me know if I need to change anything,

Cornel

[-- Attachment #2: Fix incorrect text-alignment --]
[-- Type: TEXT/PLAIN, Size: 4552 bytes --]

diff -urN oldgdb/gdb/defs.h newgdb/gdb/defs.h
--- oldgdb/gdb/defs.h	Thu Aug  1 20:18:32 2002
+++ newgdb/gdb/defs.h	Fri Mar 28 05:02:00 2003
@@ -549,7 +549,7 @@
 
 extern void set_next_address (CORE_ADDR);
 
-extern void print_address_symbolic (CORE_ADDR, struct ui_file *, int,
+extern unsigned int print_address_symbolic (CORE_ADDR, struct ui_file *, int,
 				    char *);
 
 extern int build_address_symbolic (CORE_ADDR addr,
@@ -562,7 +562,7 @@
 
 extern void print_address_numeric (CORE_ADDR, int, struct ui_file *);
 
-extern void print_address (CORE_ADDR, struct ui_file *);
+extern unsigned int print_address (CORE_ADDR, struct ui_file *);
 
 /* From source.c */
 
diff -urN oldgdb/gdb/printcmd.c newgdb/gdb/printcmd.c
--- oldgdb/gdb/printcmd.c	Thu Jul 11 23:46:19 2002
+++ newgdb/gdb/printcmd.c	Fri Mar 28 05:50:41 2003
@@ -543,7 +543,8 @@
    form.  However note that DO_DEMANGLE can be overridden by the specific
    settings of the demangle and asm_demangle variables.  */
 
-void
+/* Return the number of characters took-up by the offset. */
+unsigned int
 print_address_symbolic (CORE_ADDR addr, struct ui_file *stream, int do_demangle,
 			char *leadin)
 {
@@ -552,7 +553,9 @@
   int unmapped = 0;
   int offset = 0;
   int line = 0;
-
+  unsigned int aux; /* auxiliary var used to compute the value to store in chars */
+  unsigned int chars = 0; /* number of chars used for the offset */
+  
   /* throw away both name and filename */
   struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
   make_cleanup (free_current_contents, &filename);
@@ -560,7 +563,7 @@
   if (build_address_symbolic (addr, do_demangle, &name, &offset, &filename, &line, &unmapped))
     {
       do_cleanups (cleanup_chain);
-      return;
+      return 0;
     }
 
   fputs_filtered (leadin, stream);
@@ -569,9 +572,22 @@
   else
     fputs_filtered ("<", stream);
   fputs_filtered (name, stream);
-  if (offset != 0)
-    fprintf_filtered (stream, "+%u", (unsigned int) offset);
-
+  if (offset != 0) 
+    {
+      /* This is for the '+' in "+%u" */
+      chars++; 
+      fprintf_filtered (stream, "+%u", (unsigned int) offset);
+      /* Compute the number of characters took-up by offset. */
+      aux = offset;    
+      while(aux /= 10)
+        chars++;
+      chars++;
+    } 
+  else
+    /* offset took-up 0 characters, because we don't print anything in this case. */ 
+    chars = 0;
+  
+    
   /* Append source filename and line number if desired.  Give specific
      line # of this addr, if we have it; else line # of the nearest symbol.  */
   if (print_symbol_filename && filename != NULL)
@@ -587,6 +603,7 @@
     fputs_filtered (">", stream);
 
   do_cleanups (cleanup_chain);
+  return chars;
 }
 
 /* Given an address ADDR return all the elements needed to print the
@@ -747,11 +764,14 @@
    First print it as a number.  Then perhaps print
    <SYMBOL + OFFSET> after the number.  */
 
-void
+/* Return the number of characters took-up by the offset in print_address_symbolic. 
+   We use this in disassemble_command for correct text alignment. */
+unsigned int
 print_address (CORE_ADDR addr, struct ui_file *stream)
 {
   print_address_numeric (addr, 1, stream);
-  print_address_symbolic (addr, stream, asm_demangle, " ");
+  /* Return the number of characters took-up by the offset. */
+  return print_address_symbolic (addr, stream, asm_demangle, " ");
 }
 
 /* Print address ADDR symbolically on STREAM.  Parameter DEMANGLE
@@ -2276,6 +2296,7 @@
   char *name;
   CORE_ADDR pc, pc_masked;
   char *space_index;
+  unsigned int more_spaces; /* the number of extra characters for printing the offset in print_address_symbolic */
 #if 0
   asection *section;
 #endif
@@ -2345,8 +2366,16 @@
       while (pc_masked < high)
 	{
 	  QUIT;
-	  print_address (pc_masked, gdb_stdout);
-	  printf_filtered (":\t");
+	  /* Get the number of extra characters used by the offset on this line. */
+	  more_spaces = print_address (pc_masked, gdb_stdout);
+	  /* We allow for maximum 8 extra characters - adjust this how you see fit. */
+	  more_spaces = 8 - more_spaces;
+	  
+	  printf_filtered(": ");
+	  /* We print the extra spaces needed for this line so that we get a correct alignment. */
+	  while(more_spaces--)
+	    printf_filtered(" ");
+	  
 	  /* We often wrap here if there are long symbolic names.  */
 	  wrap_here ("    ");
 	  pc += print_insn (pc, gdb_stdout);

       reply	other threads:[~2003-03-28 18:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200303280527.h2S5RihC064049@router.uvt.ro>
2003-03-28 18:37 ` Cornel Izbasa [this message]
2003-03-28 20:09   ` Andrew Cagney

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.44.0303282023030.16994-200000@myri1.info.uvt.ro \
    --to=cornel@myri1.info.uvt.ro \
    --cc=gdb-patches@sources.redhat.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