This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC/RFA] continue stepping if landed in new range of same line


Hello,

This is a minor issue that I noticed while working on something else.
I noticed this on x86-linux, using a GNAT compiler based on GCC 4.1
and it can be reproduced using today's HEAD debugger (I used gdb
6.7.50.20071217-cvs).

I have pasted the sources I used to reproduce the problem at the end
of this email. To build them, just do:

    % gnatmake -g p

Break at line 22, and then try to step over it:

    (gdb) break pck.adb:22
    Breakpoint 1 at 0x804a32d: file pck.adb, line 22.
    (gdb) run
    [...]
    Breakpoint 1, pck.lock.update (<O>=(system.address) 0x8074b20, 
        <P>=(system.address) 0xbfcadcc8, <E>=1) at pck.adb:22
    22            end Update;
    (gdb) n
    22            end Update;

As you can see, the "next" command stops in the same line.

As it turns out, there are two block of instructions associated
to line 22.  The assembly code looks like this:

   - Line 22: A jump to the other line 22
              Some other code
   - Line 19: [...]
   - Line 22: The function epilogue

After the jump, the inferior stops and GDB finds that we stepped
inside the last line of our function, and decides that we should
stop:

  if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
    {
      /* If this is the last line of the function, don't keep stepping
         (it would probably step us out of the function).
         This is particularly necessary for a one-line function,
         in which after skipping the prologue we better stop even though
         we will be in mid-line.  */

This code predates the public CVS so I wasn't able to find much
besides the comment. After reading this comment, I am no longer
sure of what to do.

The behavior that I observed is a bit surprising, and I am not sure that
the comment above meant to include a case like mine. However, can we
still maintain support for one-line functions, and yet handle the case
above? After thinking about it for a while, I think it's possible, but
it requires a bit a processing.

Originally, I just added some code that would continue stepping if we
entered a new range with the same line number (within the same function
call), but I'm now realizing that this is just defeating exactly what
the code above was trying to achieve.

So I removed that code I added, and enhance the check above to
verify that we are inside what looks like a one-line function before
stopping.  This fixes my testcase, and introduces no regression.

2007-12-19  Joel Brobecker  <brobecker@adacore.com>

	* infrun.c (handle_inferior_event): Stop in the last line of
        a function only if it is a one-line function.

Tested on x86-linux.  The code inside the new if statement is completely
unchanged, just indented because of the extra if level.

Thoughts?  Note that the behavior dysfunction is minor enough in my eyes
that I would be content to let it go...

Thanks!
-- 
Joel

package Pck is

   protected Lock is
      function Get return Integer;
      procedure Set;
      procedure Set (X : Integer);
      entry Update (Val : Integer);
   private
      Dummy : Integer := 0;
   end Lock;

end Pck;
package body Pck is

   protected body Lock is
      function Get return Integer is
      begin
         return Dummy;
      end Get;

      procedure Set is
      begin
         Dummy := 1;
      end Set;

      procedure Set (X : Integer) is
      begin
         Dummy := X;
      end Set;

      entry Update (Val : Integer) when True is
      begin
         Dummy := Val;
      end Update;  --  <--  LINE 22
   end Lock;

end Pck;
with Pck; use Pck;

procedure P is
   Value : Integer;
begin
   Lock.Set;
   Lock.Set (1);
   Value := Lock.Get;
   Lock.Update (2);
end P;

Attachment: 02-infrun.c.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]