* BUG & sugg. PATCH in GDB 5.3 (and prob. earlier) with text alignment
[not found] <200303280527.h2S5RihC064049@router.uvt.ro>
@ 2003-03-28 18:37 ` Cornel Izbasa
2003-03-28 20:09 ` Andrew Cagney
0 siblings, 1 reply; 2+ messages in thread
From: Cornel Izbasa @ 2003-03-28 18:37 UTC (permalink / raw)
To: gdb-patches
[-- 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);
^ permalink raw reply [flat|nested] 2+ messages in thread