This is the mail archive of the
gdb@sourceware.cygnus.com
mailing list for the GDB project.
GCC on Alpha/Digital UNIX putting ".stabn" in the middle of functionprologue
- To: gcc-patches at gcc dot gnu dot org, gdb at sourceware dot cygnus dot com
- Subject: GCC on Alpha/Digital UNIX putting ".stabn" in the middle of functionprologue
- From: Guy Harris <guy at netapp dot com>
- Date: Mon, 22 May 2000 18:19:26 -0700 (PDT)
This problem was originally reported to "gdb-bug@gnu.org" and
"egcs-bugs@cygnus.com" in
http://gcc.gnu.org/ml/gcc-bugs/1999-04/msg00898.html
which says that, on Alpha/Digital UNIX, the "next" command stepped into,
rather than over, a function call.
A similar problem is discussed in:
http://sourceware.cygnus.com/ml/bug-gdb/2000-03/msg00060.html
http://sourceware.cygnus.com/ml/bug-gdb/2000-04/msg00012.html
http://sourceware.cygnus.com/ml/bug-gdb/2000-04/msg00038.html
with GCC 2.95.2 on Digital UNIX 4.0D and 4.0E, with various versions of
GDB.
I see the same problem here, with GCC 2.95.1; it appears to be due to
GCC putting a ".stabn" in the middle of the function prologue - for
example, the following:
/* compile/link with debugging. */
/*when trying to step over the get_fname call, gdb will step into it instead.*/
void get_fname ()
{
const char* dir = "foo";
}
int main (int argc, char* argv[])
{
get_fname ();
}
compiles to:
...
.align 5
.globl get_fname
.ent get_fname
get_fname:
.frame $15,32,$26,0
.mask 0x4008000,-32
ldgp $29,0($27)
$get_fname..ng:
$LM1:
#.stabn 68,0,5,$LM1
lda $30,-32($30)
stq $26,0($30)
stq $15,8($30)
mov $30,$15
.prologue 1
$LM2:
#.stabn 68,0,6,$LM2
$LBB2:
lda $1,$LC0
stq $1,16($15)
...
with the "#.stabn" after "$LM1". The assembler and/or linker apparently
arrange to put a line number entry out for the start of the function, so
there end up being two line number entries, one for the beginning of the
function, and one for the code after the "ldgp".
This causes the GDB function "in_prologue()" to think that the "lda" at
"$LM1" is not part of the prologue, causing "next" to fail if the call
goes to "$get_fname..ng" (because the calling function and called
function can share a GP value).
(See the "gcc-bugs" message cited above for more details.)
A change to GCC that eliminates the "#.stabn" in the middle of the
prologue appears to fix this problem.
However:
1) I don't know whether, on *all* platforms for which GCC can
generate code for Alpha, the line number table entry for the
beginning of the function will be generated - if not, perhaps
a line number entry needs to be emitted by GCC (although I
think I have heard claims of problems with "next" on
Linux/Alpha; I may be misremembering, however, or those may
have been unrelated problems);
2) I don't know whether my change, which adds a
"NO_LINE_NUMBER_AFTER_PROLOGUE" #define that, if defined,
keeps "final_start_function()" from calling
"output_source_line()" to emit a line table entry, is the
right fix;
3) I don't know whether this might be needed for other targets,
e.g. MIPS.
Here's the patch I made to GCC:
Index: gcc/final.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/final.c,v
retrieving revision 1.131
diff -c -3 -p -r1.131 final.c
*** final.c 2000/05/22 17:05:15 1.131
--- final.c 2000/05/23 00:59:08
*************** final_start_function (first, file, optim
*** 1628,1635 ****
--- 1628,1637 ----
#endif
/* But only output line number for other debug info types if -g2
or better. */
+ #ifndef NO_LINE_NUMBER_AFTER_PROLOGUE
if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
output_source_line (file, first);
+ #endif
#ifdef LEAF_REG_REMAP
if (current_function_uses_only_leaf_regs)
Index: gcc/config/alpha/alpha.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/alpha/alpha.h,v
retrieving revision 1.97
diff -c -3 -p -r1.97 alpha.h
*** alpha.h 2000/03/31 04:48:39 1.97
--- alpha.h 2000/05/23 00:59:09
*************** struct machine_function
*** 1228,1233 ****
--- 1228,1242 ----
#define FUNCTION_END_PROLOGUE(FILE) output_end_prologue (FILE)
+ /* Don't put out a line number entry for the prologue of a function;
+ one appears to be generated automatically, at least on Digital
+ UNIX, and if we put one out in "output_source_line()" when called
+ from "final_start_function()", it gets put out after the
+ GP-loading portion of the prologue but before the rest of the
+ prologue, which confuses GDB and often causes the "next"
+ command to step into, rather than over, function calls. */
+ #define NO_LINE_NUMBER_AFTER_PROLOGUE 1
+
/* Output any profiling code before the prologue. */
#define PROFILE_BEFORE_PROLOGUE 1