[RFA/ia64] Limit prologue scanning to end of function

Joel Brobecker
2007-09-17T20:17:53Z

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

Hello,

This is a local fix that we made a couple of years ago, which we
forgot to submit for inclusion, somehow.

Basically, it's kind of hard to determine the end of a function
prologue on ia64 just by scanning the function code. So the examine_prologue
routine in ia64-tdep.c often ends up scanning a bit more code
than is necessary. As a consequence, this might cause us to go
too far when trying to skip the prologue.

To help in that task, we have a routine, called refine_prologue_limit,
whose job is to try using the line number information to find a better
limit for our function prologue. The problem is that this function needs
to handle optimizations where the compiler intermingles the different
lines:

/* Handle the case in which compiler's optimizer/scheduler
has moved instructions into the prologue. We scan ahead
in the function looking for address ranges whose corresponding
line number is less than or equal to the first one that we
found for the function. (It can be less than when the
scheduler puts a body instruction before the first prologue
instruction.) */
for (i = 2 * max_skip_non_prologue_insns;
i > 0 && (lim_pc == 0 || addr < lim_pc);
i--)

In some cases, the PC range given is larger than the function size.
As a result, we end up testing some line numbers that are actually
not part of the same routine, and sometimes selecting it (if the line
number is smaller).

The fix is simply to reduce the initial range to the function end
address.

2007-09-17 Joel Brobecker <brobecker@adacore.com>

* ia64-tdep.c (refine_prologue_limit): Make sure we don't scan
the linetable past the function end.

Tested on ia64-linux, no regression.
OK to commit? I also suggest this fix for gdb-6.7, since it looks
pretty safe. However, I think that the chances of a function whose
associated lines are smaller, and yet have a higher PC are relatively
small. So perhaps not worth the risk.

Thanks,
--
Joel

[-- Attachment #2: refine_limit.diff --]
[-- Type: text/plain, Size: 724 bytes --]

Index: ia64-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/ia64-tdep.c,v
retrieving revision 1.159
diff -u -p -r1.159 ia64-tdep.c
--- ia64-tdep.c 23 Aug 2007 18:08:35 -0000 1.159
+++ ia64-tdep.c 17 Sep 2007 19:15:51 -0000
@@ -967,6 +967,12 @@ refine_prologue_limit (CORE_ADDR pc, COR
{
struct symtab_and_line prologue_sal;
CORE_ADDR start_pc = pc;
+ CORE_ADDR end_pc;
+
+ /* The prologue can not possibly go past the function end itself,
+ so we can already adjust LIM_PC accordingly. */
+ if (find_pc_partial_function (pc, NULL, NULL, &end_pc) && end_pc < lim_pc)
+ lim_pc = end_pc;

/* Start off not trusting the limit. */
*trust_limit = 0;