Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] skip_prologue_sal and sal expansion
@ 2009-06-02 16:21 Jerome Guitton
  2009-06-02 16:51 ` Doug Evans
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jerome Guitton @ 2009-06-02 16:21 UTC (permalink / raw)
  To: gdb-patches

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


A couple of cleanups in breakpoint.c. Let me give some background
first; consider the following program:

int counter = 42;

inline void
callee ()
{
  counter = 0; /* set breakpoint in an inlined function.  */
}

void
caller ()
{
  callee ();
}

int
main ()
{
  caller ();
  callee ();
  return counter;
}



When callee is inlined, we have three occurence for the line
"counter = 0;": inlined in caller, inlined in main, and not inlined.
When a breakpoint is set on this line, GDB sets a breakpoint on 3
locations.

(gdb) l p.c:6
1       int counter = 42;
2
3       inline void
4       callee ()
5       {
6         counter = 0;
7       }
8
9       void
10      caller ()
(gdb) b 6
Breakpoint 1 at 0x1800074: file p.c, line 6. (3 locations)


I have recently hit a bug in an assembler which was optimizing out the
prologue line info; it was making GDB think that the line
"counter = 0;" was a part of callee's prologue. And this pointed me to
something strange in GDB.

After having used this bogus assembler to generate my program, if I try
to set a breakpoint at line "counter = 0;", I end up with only one
occurence instead of three:

(gdb) b 6  
Breakpoint 1 at 0x1800074: file p.c, line 6.

The problem was in skip_prologue_sal defined in breakpoint.c. When it
actually skips a prologue, it does not assure that the other sal's
fields (explicit_pc and explicit_line) are left unchanged. In my case,
it was accidently changing explicit_line from 1 to 0. This change
disabled the line sal expansion, and in consequence we ended up with
the breakpoint set in only one location. I think that it's a bug in
skip_prologue_sal, this function should not change mess with these
fields.

Now, if I change skip_prologue_sal to copy explicit_line and
explicit_pc, the line expansion is done; but we should make sure that
prologue is skipped similarly, otherwise we get an assertion failure
when the address returned by resolve_sal_pc cannot be found after
line sal expansion:

(gdb) break p.c:6
../../src/gdb/breakpoint.c:5113: internal-error: expand_line_sal_maybe:
Assertion `found' failed.


Patch attached, tested on x86-linux. OK to apply?


2009-06-02  Jerome Guitton  <guitton@adacore.com>

	* breakpoint.c (expand_line_sal_maybe): When explicit_line,
	skip prologue on each sals.
	(skip_prologue_sal): Return explicit_line and explicit_pc
	unmodified.

[-- Attachment #2: inline.diff --]
[-- Type: text/x-diff, Size: 1568 bytes --]

Index: breakpoint.c
===================================================================
--- breakpoint.c	(revision 148760)
+++ breakpoint.c	(working copy)
@@ -207,6 +207,9 @@ static void disable_trace_command (char 
 
 static void trace_pass_command (char *, int);
 
+static void skip_prologue_sal (struct symtab_and_line *sal);
+
+
 /* Flag indicating that a command has proceeded the inferior past the
    current breakpoint.  */
 
@@ -5412,6 +5415,15 @@ expand_line_sal_maybe (struct symtab_and
 	    }
 	}
     }
+  else
+    {
+      for (i = 0; i < expanded.nelts; ++i)
+	{
+	  /* If this SAL corresponds to a breakpoint inserted using a
+	     line number, then skip the function prologue if necessary.  */
+	  skip_prologue_sal (&expanded.sals[i]);
+	}
+    }
 
   
   if (expanded.nelts <= 1)
@@ -5896,7 +5908,8 @@ set_breakpoint (char *address, char *con
 
 /* Adjust SAL to the first instruction past the function prologue.
    The end of the prologue is determined using the line table from
-   the debugging information.
+   the debugging information.  explicit_pc and explicit_line are
+   not modified.
 
    If SAL is already past the prologue, then do nothing.  */
 
@@ -5911,7 +5924,11 @@ skip_prologue_sal (struct symtab_and_lin
 
   start_sal = find_function_start_sal (sym, 1);
   if (sal->pc < start_sal.pc)
-    *sal = start_sal;
+    {
+      start_sal.explicit_line = sal->explicit_line;
+      start_sal.explicit_pc = sal->explicit_pc;
+      *sal = start_sal;
+    }
 }
 
 /* Helper function for break_command_1 and disassemble_command.  */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFA] skip_prologue_sal and sal expansion
  2009-06-02 16:21 [RFA] skip_prologue_sal and sal expansion Jerome Guitton
@ 2009-06-02 16:51 ` Doug Evans
  2009-06-15 10:49 ` Jerome Guitton
  2009-06-17 19:34 ` Joel Brobecker
  2 siblings, 0 replies; 5+ messages in thread
From: Doug Evans @ 2009-06-02 16:51 UTC (permalink / raw)
  To: Jerome Guitton; +Cc: gdb-patches

On Tue, Jun 2, 2009 at 9:21 AM, Jerome Guitton <guitton@adacore.com> wrote:
>
> A couple of cleanups in breakpoint.c. Let me give some background
> first; consider the following program:
>
> int counter = 42;
>
> inline void
> callee ()
> {
>  counter = 0; /* set breakpoint in an inlined function.  */
> }
>
> void
> caller ()
> {
>  callee ();
> }
>
> int
> main ()
> {
>  caller ();
>  callee ();
>  return counter;
> }
>
>
>
> When callee is inlined, we have three occurence for the line
> "counter = 0;": inlined in caller, inlined in main, and not inlined.
> When a breakpoint is set on this line, GDB sets a breakpoint on 3
> locations.
>
> (gdb) l p.c:6
> 1       int counter = 42;
> 2
> 3       inline void
> 4       callee ()
> 5       {
> 6         counter = 0;
> 7       }
> 8
> 9       void
> 10      caller ()
> (gdb) b 6
> Breakpoint 1 at 0x1800074: file p.c, line 6. (3 locations)
>
>
> I have recently hit a bug in an assembler which was optimizing out the
> prologue line info; it was making GDB think that the line
> "counter = 0;" was a part of callee's prologue. And this pointed me to
> something strange in GDB.
>
> After having used this bogus assembler to generate my program, if I try
> to set a breakpoint at line "counter = 0;", I end up with only one
> occurence instead of three:
>
> (gdb) b 6
> Breakpoint 1 at 0x1800074: file p.c, line 6.
>
> The problem was in skip_prologue_sal defined in breakpoint.c. When it
> actually skips a prologue, it does not assure that the other sal's
> fields (explicit_pc and explicit_line) are left unchanged. In my case,
> it was accidently changing explicit_line from 1 to 0. This change
> disabled the line sal expansion, and in consequence we ended up with
> the breakpoint set in only one location. I think that it's a bug in
> skip_prologue_sal, this function should not change mess with these
> fields.
>
> Now, if I change skip_prologue_sal to copy explicit_line and
> explicit_pc, the line expansion is done; but we should make sure that
> prologue is skipped similarly, otherwise we get an assertion failure
> when the address returned by resolve_sal_pc cannot be found after
> line sal expansion:
>
> (gdb) break p.c:6
> ../../src/gdb/breakpoint.c:5113: internal-error: expand_line_sal_maybe:
> Assertion `found' failed.
>
>
> Patch attached, tested on x86-linux. OK to apply?
>
>
> 2009-06-02  Jerome Guitton  <guitton@adacore.com>
>
>        * breakpoint.c (expand_line_sal_maybe): When explicit_line,
>        skip prologue on each sals.
>        (skip_prologue_sal): Return explicit_line and explicit_pc
>        unmodified.
>

Sounds reasonable to me (fwiw).  Still need to wait for an official
maintainer's comments.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFA] skip_prologue_sal and sal expansion
  2009-06-02 16:21 [RFA] skip_prologue_sal and sal expansion Jerome Guitton
  2009-06-02 16:51 ` Doug Evans
@ 2009-06-15 10:49 ` Jerome Guitton
  2009-06-17 19:34 ` Joel Brobecker
  2 siblings, 0 replies; 5+ messages in thread
From: Jerome Guitton @ 2009-06-15 10:49 UTC (permalink / raw)
  To: gdb-patches


Ping


Jerome Guitton (guitton@adacore.com):

> 
> A couple of cleanups in breakpoint.c. Let me give some background
> first; consider the following program:
> 
> int counter = 42;
> 
> inline void
> callee ()
> {
>   counter = 0; /* set breakpoint in an inlined function.  */
> }
> 
> void
> caller ()
> {
>   callee ();
> }
> 
> int
> main ()
> {
>   caller ();
>   callee ();
>   return counter;
> }
> 
> 
> 
> When callee is inlined, we have three occurence for the line
> "counter = 0;": inlined in caller, inlined in main, and not inlined.
> When a breakpoint is set on this line, GDB sets a breakpoint on 3
> locations.
> 
> (gdb) l p.c:6
> 1       int counter = 42;
> 2
> 3       inline void
> 4       callee ()
> 5       {
> 6         counter = 0;
> 7       }
> 8
> 9       void
> 10      caller ()
> (gdb) b 6
> Breakpoint 1 at 0x1800074: file p.c, line 6. (3 locations)
> 
> 
> I have recently hit a bug in an assembler which was optimizing out the
> prologue line info; it was making GDB think that the line
> "counter = 0;" was a part of callee's prologue. And this pointed me to
> something strange in GDB.
> 
> After having used this bogus assembler to generate my program, if I try
> to set a breakpoint at line "counter = 0;", I end up with only one
> occurence instead of three:
> 
> (gdb) b 6  
> Breakpoint 1 at 0x1800074: file p.c, line 6.
> 
> The problem was in skip_prologue_sal defined in breakpoint.c. When it
> actually skips a prologue, it does not assure that the other sal's
> fields (explicit_pc and explicit_line) are left unchanged. In my case,
> it was accidently changing explicit_line from 1 to 0. This change
> disabled the line sal expansion, and in consequence we ended up with
> the breakpoint set in only one location. I think that it's a bug in
> skip_prologue_sal, this function should not change mess with these
> fields.
> 
> Now, if I change skip_prologue_sal to copy explicit_line and
> explicit_pc, the line expansion is done; but we should make sure that
> prologue is skipped similarly, otherwise we get an assertion failure
> when the address returned by resolve_sal_pc cannot be found after
> line sal expansion:
> 
> (gdb) break p.c:6
> ../../src/gdb/breakpoint.c:5113: internal-error: expand_line_sal_maybe:
> Assertion `found' failed.
> 
> 
> Patch attached, tested on x86-linux. OK to apply?
> 
> 
> 2009-06-02  Jerome Guitton  <guitton@adacore.com>
> 
> 	* breakpoint.c (expand_line_sal_maybe): When explicit_line,
> 	skip prologue on each sals.
> 	(skip_prologue_sal): Return explicit_line and explicit_pc
> 	unmodified.

> Index: breakpoint.c
> ===================================================================
> --- breakpoint.c	(revision 148760)
> +++ breakpoint.c	(working copy)
> @@ -207,6 +207,9 @@ static void disable_trace_command (char 
>  
>  static void trace_pass_command (char *, int);
>  
> +static void skip_prologue_sal (struct symtab_and_line *sal);
> +
> +
>  /* Flag indicating that a command has proceeded the inferior past the
>     current breakpoint.  */
>  
> @@ -5412,6 +5415,15 @@ expand_line_sal_maybe (struct symtab_and
>  	    }
>  	}
>      }
> +  else
> +    {
> +      for (i = 0; i < expanded.nelts; ++i)
> +	{
> +	  /* If this SAL corresponds to a breakpoint inserted using a
> +	     line number, then skip the function prologue if necessary.  */
> +	  skip_prologue_sal (&expanded.sals[i]);
> +	}
> +    }
>  
>    
>    if (expanded.nelts <= 1)
> @@ -5896,7 +5908,8 @@ set_breakpoint (char *address, char *con
>  
>  /* Adjust SAL to the first instruction past the function prologue.
>     The end of the prologue is determined using the line table from
> -   the debugging information.
> +   the debugging information.  explicit_pc and explicit_line are
> +   not modified.
>  
>     If SAL is already past the prologue, then do nothing.  */
>  
> @@ -5911,7 +5924,11 @@ skip_prologue_sal (struct symtab_and_lin
>  
>    start_sal = find_function_start_sal (sym, 1);
>    if (sal->pc < start_sal.pc)
> -    *sal = start_sal;
> +    {
> +      start_sal.explicit_line = sal->explicit_line;
> +      start_sal.explicit_pc = sal->explicit_pc;
> +      *sal = start_sal;
> +    }
>  }
>  
>  /* Helper function for break_command_1 and disassemble_command.  */


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFA] skip_prologue_sal and sal expansion
  2009-06-02 16:21 [RFA] skip_prologue_sal and sal expansion Jerome Guitton
  2009-06-02 16:51 ` Doug Evans
  2009-06-15 10:49 ` Jerome Guitton
@ 2009-06-17 19:34 ` Joel Brobecker
  2009-06-19 15:17   ` Jerome Guitton
  2 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2009-06-17 19:34 UTC (permalink / raw)
  To: Jerome Guitton; +Cc: gdb-patches

> 2009-06-02  Jerome Guitton  <guitton@adacore.com>
> 
> 	* breakpoint.c (expand_line_sal_maybe): When explicit_line,
> 	skip prologue on each sals.
> 	(skip_prologue_sal): Return explicit_line and explicit_pc
> 	unmodified.

This makes sense to me. Please go ahead and check it in.

-- 
Joel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFA] skip_prologue_sal and sal expansion
  2009-06-17 19:34 ` Joel Brobecker
@ 2009-06-19 15:17   ` Jerome Guitton
  0 siblings, 0 replies; 5+ messages in thread
From: Jerome Guitton @ 2009-06-19 15:17 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Joel Brobecker (brobecker@adacore.com):

> > 2009-06-02  Jerome Guitton  <guitton@adacore.com>
> > 
> > 	* breakpoint.c (expand_line_sal_maybe): When explicit_line,
> > 	skip prologue on each sals.
> > 	(skip_prologue_sal): Return explicit_line and explicit_pc
> > 	unmodified.
> 
> This makes sense to me. Please go ahead and check it in.

Thank you. It has been checked in.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-06-19 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-02 16:21 [RFA] skip_prologue_sal and sal expansion Jerome Guitton
2009-06-02 16:51 ` Doug Evans
2009-06-15 10:49 ` Jerome Guitton
2009-06-17 19:34 ` Joel Brobecker
2009-06-19 15:17   ` Jerome Guitton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox