* [RFC] Try to enhanced backtrace on i386 machines.
@ 2001-12-03 2:27 Pierre Muller
2001-12-03 12:35 ` Christopher Faylor
0 siblings, 1 reply; 3+ messages in thread
From: Pierre Muller @ 2001-12-03 2:27 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1118 bytes --]
GCC for i386 does several optimization
to allow correct pairing of instructions.
This leads in particular to mix loading of constants into registers
with usual prologue instructions.
The major effect is that the backtrace shows some
'pseudo' trace levels, which are due to a failure to get
the correct prologue.
One of the nastiest effect of this is that
if you use 'return' on that function, it sets a temporary
breakpoint on a wrong location and you program
continues without stopping when frame is left.
I started to implement some code that tries to deal with that issue.
Its far from perfect, but it gives already some result
(when debugging GDB with itself compiled with -O2,
it reduces the number of those false frame levels).
This code might probably be used at several other position.
All comments and suggestions welcome.
2001-12-02 Pierre Muller <muller@ics.u-strasbg.fr>
* i386-tdep.c (i386_skip_optimization_code): New function used to
skip over code inserted by optimizer.
(i386_get_frame_setup): Use i386_skip_optimization_code to
enhance prologue detection.
[-- Attachment #2: Type: text/plain, Size: 2882 bytes --]
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.47
diff -u -p -r1.47 i386-tdep.c
--- i386-tdep.c 2001/12/02 18:29:08 1.47
+++ i386-tdep.c 2001/12/03 10:23:00
@@ -314,6 +314,64 @@ i386_follow_jump (void)
codestream_seek (pos);
}
+/* Skip over movl $imm,%exx
+ or xorl %exx,%exx
+ as these instructions are inserted by GCC
+ to optimize code.
+ op must have been read using codestream_get. */
+
+unsigned char
+i386_skip_optimization_code (unsigned char op)
+{
+ CORE_ADDR pos;
+
+ while (1)
+ {
+ switch (op)
+ {
+ case 0xb8:
+ case 0xb9:
+ case 0xba:
+ case 0xbb:
+ case 0xbc:
+ case 0xbd:
+ case 0xbe:
+ case 0xbf:
+ /* 'movl $immediate_long,%exx'. */
+ pos = codestream_tell ();
+ pos += 4;
+ codestream_seek (pos);
+ op = codestream_get();
+ break;
+ case 0x31:
+ case 0x33:
+ /* xorl %exx,%exx. */
+ pos = codestream_tell ();
+ op = codestream_get ();
+ /* don't accept 'xorl %esp,%esp' nor 'xorl %ebp,%ebp'. */
+ if (op == 0xc0 /* xorl %eax,%eax */
+ || op == 0xc9 /* xorl %ebx,%ebx */
+ || op == 0xd2 /* xorl %ecx,%ecx */
+ || op == 0xdb /* xorl %edx,%edx */
+ || op == 0xf6 /* xorl %esi,%esi */
+ || op == 0xff /* xorl %edi,%edi */)
+ {
+ pos += 1;
+ codestream_seek (pos);
+ op = codestream_get();
+ }
+ else
+ {
+ codestream_seek (pos);
+ return op;
+ }
+ break;
+ default:
+ return op;
+ }
+ }
+}
+
/* Find & return the amount a local space allocated, and advance the
codestream to the first register push (if any).
@@ -396,8 +454,11 @@ i386_get_frame_setup (CORE_ADDR pc)
if (op == 0x55) /* pushl %ebp */
{
+ int pos = codestream_tell ();
+ op = codestream_get ();
+ op = i386_skip_optimization_code (op);
/* Check for "movl %esp, %ebp" -- can be written in two ways. */
- switch (codestream_get ())
+ switch (op)
{
case 0x8b:
if (codestream_get () != 0xec)
@@ -435,7 +496,6 @@ i386_get_frame_setup (CORE_ADDR pc)
{
char buf[4];
/* Maybe it is `subl' with a 32 bit immedediate. */
- codestream_get ();
if (codestream_get () != 0xec)
/* Some instruction starting with 0x81 other than `subl'. */
{
@@ -448,7 +508,8 @@ i386_get_frame_setup (CORE_ADDR pc)
}
else
{
- return 0;
+ codestream_seek (pos);
+ return 0;
}
}
else if (op == 0xc8)
[-- Attachment #3: Type: text/plain, Size: 176 bytes --]
Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC] Try to enhanced backtrace on i386 machines.
2001-12-03 2:27 [RFC] Try to enhanced backtrace on i386 machines Pierre Muller
@ 2001-12-03 12:35 ` Christopher Faylor
2001-12-04 7:34 ` Pierre Muller
0 siblings, 1 reply; 3+ messages in thread
From: Christopher Faylor @ 2001-12-03 12:35 UTC (permalink / raw)
To: gdb-patches
On Mon, Dec 03, 2001 at 11:28:07AM +0100, Pierre Muller wrote:
>GCC for i386 does several optimization to allow correct pairing of
>instructions.
>
>This leads in particular to mix loading of constants into registers
>with usual prologue instructions.
>
>The major effect is that the backtrace shows some 'pseudo' trace
>levels, which are due to a failure to get the correct prologue. One of
>the nastiest effect of this is that if you use 'return' on that
>function, it sets a temporary breakpoint on a wrong location and you
>program continues without stopping when frame is left.
>
>I started to implement some code that tries to deal with that issue.
>Its far from perfect, but it gives already some result (when debugging
>GDB with itself compiled with -O2, it reduces the number of those false
>frame levels).
>
>This code might probably be used at several other position.
>
>All comments and suggestions welcome.
It would be nice to improve backtraces on x86. What would really be
wonderful is to do this with frame pointerless functions.
Regarding your implementation, I wonder if it would be better to define
the opcodes as constants in the opcodes directory and use the defines in
both the opcodes and gdb directories? I realize that it is more work
but it seems like we've already got most of the information in this
directory.
cgf
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC] Try to enhanced backtrace on i386 machines.
2001-12-03 12:35 ` Christopher Faylor
@ 2001-12-04 7:34 ` Pierre Muller
0 siblings, 0 replies; 3+ messages in thread
From: Pierre Muller @ 2001-12-04 7:34 UTC (permalink / raw)
To: gdb-patches
At 21:35 03/12/2001 , Christopher Faylor a écrit:
>On Mon, Dec 03, 2001 at 11:28:07AM +0100, Pierre Muller wrote:
> >GCC for i386 does several optimization to allow correct pairing of
> >instructions.
> >
> >This leads in particular to mix loading of constants into registers
> >with usual prologue instructions.
> >
> >The major effect is that the backtrace shows some 'pseudo' trace
> >levels, which are due to a failure to get the correct prologue. One of
> >the nastiest effect of this is that if you use 'return' on that
> >function, it sets a temporary breakpoint on a wrong location and you
> >program continues without stopping when frame is left.
> >
> >I started to implement some code that tries to deal with that issue.
> >Its far from perfect, but it gives already some result (when debugging
> >GDB with itself compiled with -O2, it reduces the number of those false
> >frame levels).
> >
> >This code might probably be used at several other position.
> >
> >All comments and suggestions welcome.
>
>It would be nice to improve backtraces on x86. What would really be
>wonderful is to do this with frame pointerless functions.
This patch does nothing yet in that direction :(
>Regarding your implementation, I wonder if it would be better to define
>the opcodes as constants in the opcodes directory and use the defines in
>both the opcodes and gdb directories? I realize that it is more work
>but it seems like we've already got most of the information in this
>directory.
Sorry, but I don't really see what you mean here...
I looked at i386-dis.c code but its not clear to me
how we could use this...
Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-12-04 15:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-03 2:27 [RFC] Try to enhanced backtrace on i386 machines Pierre Muller
2001-12-03 12:35 ` Christopher Faylor
2001-12-04 7:34 ` Pierre Muller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox