public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/28371] New: gdb: watchpoint for local variable doesn't work on RISC-V
@ 2021-09-22  7:00 shivam98.tkg at gmail dot com
  2021-09-23  4:03 ` [Bug gdb/28371] " shivam98.tkg at gmail dot com
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: shivam98.tkg at gmail dot com @ 2021-09-22  7:00 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28371

            Bug ID: 28371
           Summary: gdb: watchpoint for local variable doesn't work on
                    RISC-V
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: shivam98.tkg at gmail dot com
  Target Milestone: ---

Created attachment 13674
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13674&action=edit
test program

Please consider the following program :-

  1 /* This testcase is part of GDB, the GNU debugger.
  2 
  3    Copyright 2010-2021 Free Software Foundation, Inc.
  4 
  5    This program is free software; you can redistribute it and/or modify
  6    it under the terms of the GNU General Public License as published by
  7    the Free Software Foundation; either version 3 of the License, or
  8    (at your option) any later version.
  9 
 10    This program is distributed in the hope that it will be useful,
 11    but WITHOUT ANY WARRANTY; without even the implied warranty of
 12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13    GNU General Public License for more details.
 14 
 15    You should have received a copy of the GNU General Public License
 16    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
*/
 17 
 18 int global = 0;
 19 int global2 = 0;
 20 
 21 int func(int *foo)
 22 {
 23   (*foo)++;
 24   global++;
 25   global2++;
 26   return 0;
 27 }
 28 
 29 void func2(int *foo)
 30 {
 31   global2++;
 32 }
 33 
 34 int main()
 35 {
 36   int q = 0;
 37 
 38   func2 (&q);
 39   global2++;
 40 
 41   while (1)
 42     {
 43       func(&q);
 44     }
 45 
 46   return 0;
 47 }

Steps to produce the issue :- 

clang -g -static watch-cond.c -o watch

(clang is cross compile by following these instruction :-
https://github.com/sifive/riscv-llvm#how-can-i-build-llvmclang-and-use-it-to-cross-compile-for-a-riscv-target)

qemu-riscv64 -g 1234 watch-cond
(start the server)

riscv64-unknown-elf-gdb watch-cond
(start client)

(gdb) target remote :1234
Remote debugging using :1234
0x00000000000100f8 in _start ()
(gdb) set can-use-hw-watchpoints 0
(gdb) b 36
Breakpoint 1 at 0x101e0: file watch-cond.c, line 36.
(gdb) n
Single stepping until exit from function _start,
which has no line number information.

Breakpoint 1, main () at watch-cond.c:36
36        int q = 0;
(gdb) watch q
Watchpoint 2: q
(gdb) c
Continuing.

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
0x00000000000101cc in func2 (foo=0x0) at watch-cond.c:32
32      }
(gdb) disass main
Dump of assembler code for function main:
   0x00000000000101a0 <+0>:     addi    sp,sp,-32
   0x00000000000101a2 <+2>:     sd      ra,24(sp)
   0x00000000000101a4 <+4>:     sd      s0,16(sp)
   0x00000000000101a6 <+6>:     addi    s0,sp,32
   0x00000000000101a8 <+8>:     li      a0,0
   0x00000000000101aa <+10>:    sw      a0,-20(s0)
   0x00000000000101ae <+14>:    sw      a0,-24(s0)
   0x00000000000101b2 <+18>:    j       0x101b6 <main+22>
   0x00000000000101b6 <+22>:    lw      a1,-24(s0)
   0x00000000000101ba <+26>:    li      a0,4
   0x00000000000101bc <+28>:    blt     a0,a1,0x101d0 <main+48>
   0x00000000000101c0 <+32>:    j       0x101c4 <main+36>
   0x00000000000101c4 <+36>:    addi    a0,s0,-24
   0x00000000000101c8 <+40>:    jal     ra,0x10180 <func>
   0x00000000000101cc <+44>:    j       0x101b6 <main+22>
   0x00000000000101d0 <+48>:    li      a0,0
   0x00000000000101d2 <+50>:    ld      s0,16(sp)
   0x00000000000101d4 <+52>:    ld      ra,24(sp)
   0x00000000000101d6 <+54>:    addi    sp,sp,32
   0x00000000000101d8 <+56>:    ret
End of assembler dump.


(gdb)  p &q
$1 = (int *) 0x40008001d8

(gdb) info frame
Stack level 0, frame at 0x40008001f0:
 pc = 0x101e0 in main (watch-cond.c:36); saved pc = 0x10134
 source language c.
 Arglist at 0x40008001f0, args: 
 Locals at 0x40008001f0, Previous frame's sp is 0x40008001f0
 Saved registers:
  ra at 0x40008001e8, fp at 0x40008001e0, pc at 0x40008001e8Could not fetch
register "ustatus"; remote failure reply 'E14'


objdump --disassemble watch-cond

00000000000101d2 <main>:
   101d2: 01 11         addi    sp, sp, -32
   101d4: 06 ec         sd      ra, 24(sp)
   101d6: 22 e8         sd      s0, 16(sp)
   101d8: 00 10         addi    s0, sp, 32
   101da: 01 45         mv      a0, zero
   101dc: 23 26 a4 fe   sw      a0, -20(s0)
   101e0: 23 24 a4 fe   sw      a0, -24(s0)
   101e4: 13 05 84 fe   addi    a0, s0, -24
   101e8: ef f0 df fc   jal     0x101b4 <func2>
   101ec: 03 a5 41 f6   lw      a0, -156(gp)
   101f0: 05 25         addiw   a0, a0, 1
   101f2: 23 a2 a1 f6   sw      a0, -156(gp)
   101f6: 6f 00 40 00   j       0x101fa <main+0x28>
   101fa: 13 05 84 fe   addi    a0, s0, -24
   101fe: ef f0 3f f8   jal     0x10180 <func>
   10202: 6f f0 9f ff   j       0x101fa <main+0x28>


I tested same the program debugging, compiled with gcc compiler, working fine.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2021-10-26 10:18 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22  7:00 [Bug gdb/28371] New: gdb: watchpoint for local variable doesn't work on RISC-V shivam98.tkg at gmail dot com
2021-09-23  4:03 ` [Bug gdb/28371] " shivam98.tkg at gmail dot com
2021-09-24 22:51 ` wilson at gcc dot gnu.org
2021-09-26 18:17 ` shivam98.tkg at gmail dot com
2021-09-26 18:39 ` shivam98.tkg at gmail dot com
2021-09-28  2:07 ` evandro.menezes at sifive dot com
2021-09-29 21:28 ` wilson at gcc dot gnu.org
2021-09-29 21:42 ` jrtc27 at jrtc27 dot com
2021-09-29 21:42 ` jrtc27 at jrtc27 dot com
2021-09-30  9:56 ` shivam98.tkg at gmail dot com
2021-09-30  9:57 ` shivam98.tkg at gmail dot com
2021-09-30  9:59 ` shivam98.tkg at gmail dot com
2021-09-30 10:02 ` shivam98.tkg at gmail dot com
2021-09-30 10:35 ` schwab@linux-m68k.org
2021-10-01 19:48 ` wilson at gcc dot gnu.org
2021-10-11 10:11 ` shivam98.tkg at gmail dot com
2021-10-26  6:03 ` shivam98.tkg at gmail dot com
2021-10-26 10:18 ` shivam98.tkg at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).