This is the mail archive of the gdb-prs@sources.redhat.com 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]

breakpoints/1558: Hits breakpoint at main after function called from main


>Number:         1558
>Category:       breakpoints
>Synopsis:       Hits breakpoint at main after function called from main
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          patch
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 19 19:48:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Fred Fish
>Release:        unknown-1.0
>Organization:
>Environment:
sh-elf
>Description:
The prologue scanning code in sh-elf-gdb has problems for
the case where the compiler schedules a call to another 
function into the prologue of the caller.  Gdb sets the
breakpoint on the caller after the call to the callee,
which is very confusing.

Note this only applies when no debug info is present and
the code is compiled with optimization.
>How-To-Repeat:
For the following test case:
 
  sub1 ()
  {
    printf ("In sub1\n");
  }
   
  sub2 ()
  {
    printf ("In sub2\n");
  }
   
  main ()
  {
    sub1 ();
    sub2 ();
  }
 
sh-elf-gcc with -O2 will schedule the code to call sub1 into the
prologue of main.  If the code is compiled WITHOUT debug info, the
prologue scanner in gdb will not stop when it sees the jsr and will
eventually return a pc somewhere after the jsr.  For example:
 
  (gdb) br main
  Breakpoint 1 at 0x1162
  (gdb) x/8i main
  0x1158 <main>:        mov.l   r14,@-r15
  0x115a <main+2>:      mov.l   0x116c <main+20>,r0     ! 0x1120
  0x115c <main+4>:      sts.l   pr,@-r15
  0x115e <main+6>:      jsr     @r0
  0x1160 <main+8>:      mov     r15,r14
* 0x1162 <main+10>:     mov.l   0x1170 <main+24>,r1     ! 0x113c
  0x1164 <main+12>:     mov     r14,r15
  0x1166 <main+14>:     lds.l   @r15+,pr
 
Note that the breakpoint on main() gets set well after the jsr.  When
you set breakpoints at sub1 and sub2 and run the program, you get:
 
  (gdb) run
  Starting program: /links1/build/sourceware/gdb/T-sh-elf/gdb/g
  Breakpoint 2, 0x00001128 in sub1 ()
  (gdb) c
  Continuing.
  In sub1
  Breakpoint 1, 0x00001162 in main ()
  (gdb) c
  Continuing.
  Breakpoint 3, 0x00001144 in sub2 ()
  (gdb) c
  Continuing.
  In sub2
  Program exited with code 012.
 
which is very confusing because it appears that sub1 is called before main!

With the attached patch, the prologue scanner returns the pc of the
jsr instruction, allowing the breakpoint at main to be hit before the
breakpoint at sub1:
                                                                                                                                                                                                     
  (gdb) br main
  Breakpoint 1 at 0x115e
  (gdb) x/8i main
  0x1158 <main>:        mov.l   r14,@-r15
  0x115a <main+2>:      mov.l   0x116c <main+20>,r0     ! 0x1120
  0x115c <main+4>:      sts.l   pr,@-r15
* 0x115e <main+6>:      jsr     @r0
  0x1160 <main+8>:      mov     r15,r14
  0x1162 <main+10>:     mov.l   0x1170 <main+24>,r1     ! 0x113c
  0x1164 <main+12>:     mov     r14,r15
  0x1166 <main+14>:     lds.l   @r15+,pr
  (gdb) br sub1
  Breakpoint 2 at 0x1128
  (gdb) br sub2
  Breakpoint 3 at 0x1144
  (gdb) run
  Starting program: /links1/build/sourceware/gdb/T-sh-elf/gdb/g
  Breakpoint 1, 0x0000115e in main ()
  (gdb) c
  Continuing.
  Breakpoint 2, 0x00001128 in sub1 ()
  (gdb) c
  Continuing.
  In sub1
  Breakpoint 3, 0x00001144 in sub2 ()
  (gdb) c
  Continuing.
  In sub2
  Program exited with code 012.
 
It's also useful to note where the breakpoint gets set if you recompile to generate
debugging information:
 
  (gdb) br main
  Breakpoint 1 at 0x115a: file g.c, line 13.
  (gdb) x/8i main
  0x1158 <main>:          mov.l   r14,@-r15
  0x115a <main+2>:        mov.l   0x116c <main+20>,r0     ! 0x1120
  0x115c <main+4>:        sts.l   pr,@-r15
  0x115e <main+6>:        jsr     @r0
  0x1160 <main+8>:        mov     r15,r14
  0x1162 <main+10>:       mov.l   0x1170 <main+24>,r1     ! 0x113c
  0x1164 <main+12>:       mov     r14,r15
  0x1166 <main+14>:       lds.l   @r15+,pr
 
This patch causes no regressions in the gdb testsuite.

>Fix:
Attached patch causes the prologue scanner to stop at the
call to another function.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="gdb.patch"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="gdb.patch"

MjAwNC0wMi0xMiAgRnJlZCBGaXNoICA8Zm5mQHJlZGhhdC5jb20+CgoJKiBzaC10ZGVwLmMgKElT
X0pTUik6IE5ldyBtYWNyby4KCShzaF9hbmFseXplX3Byb2xvZ3VlKTogVXNlIElTX0pTUiB0byB0
ZXJtaW5hdGUgcHJvbG9ndWUgc2Nhbi4KCkluZGV4OiBzaC10ZGVwLmMKPT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1Mg
ZmlsZTogL2N2cy9zcmMvc3JjL2dkYi9zaC10ZGVwLmMsdgpyZXRyaWV2aW5nIHJldmlzaW9uIDEu
MTU4CmRpZmYgLWMgLXAgLXIxLjE1OCBzaC10ZGVwLmMKKioqIHNoLXRkZXAuYwkxMSBGZWIgMjAw
NCAxNTo0MDoyOCAtMDAwMAkxLjE1OAotLS0gc2gtdGRlcC5jCTEyIEZlYiAyMDA0IDIxOjE2OjM5
IC0wMDAwCioqKioqKioqKioqKioqKiBzaF9icmVha3BvaW50X2Zyb21fcGMgKENPUkVfQUREUiAq
cGNwdHIsCioqKiAzMzMsMzM4ICoqKioKLS0tIDMzMywzNDEgLS0tLQogICNkZWZpbmUgR0VUX1NP
VVJDRV9SRUcoeCkgIAkoKCh4KSA+PiA0KSAmIDB4ZikKICAjZGVmaW5lIEdFVF9UQVJHRVRfUkVH
KHgpICAJKCgoeCkgPj4gOCkgJiAweGYpCiAgCisgLyogSlNSIEBSbSAgICAgICAgIDAxMDBtbW1t
MDAwMDEwMTEgKi8KKyAjZGVmaW5lIElTX0pTUih4KQkJKCgoeCkgJiAweGYwZmYpID09IDB4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gMiwgMik7CisgCSAgaWYgKElTX01PVl9TUF9GUCAoaW5zdCkpCisgCSAgICBjYWNoZS0+
dXNlc19mcCA9IDE7CiAgCSAgYnJlYWs7CiAgCX0KICAjaWYgMAkJCQkvKiBUaGlzIHVzZWQgdG8g
anVzdCBzdG9wIHdoZW4gaXQgZm91bmQgYW4gaW5zdHJ1Y3Rpb24gdGhhdAo=


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