gdb/riscv: fix creating breakpoints at invalid addresses

Message ID 20210325084757.32077-1-changbin.du@gmail.com
State Superseded
Headers show
Series
  • gdb/riscv: fix creating breakpoints at invalid addresses
Related show

Commit Message

Lancelot SIX via Gdb-patches March 25, 2021, 8:47 a.m.
To allow breakpoints to be created at invalid addresses,
target_read_code() is used instead of read_code(). The
original read_code() should be removed, otherwise the
breakpoint command will fail.

(gdb) hbreak setup_arch
Cannot access memory at address 0xffffffe000c036ac

gdb/ChangeLog:
2021-03-24  Changbin Du <changbin.du@gmail.com>

        * riscv-tdep.c (riscv_breakpoint_kind_from_pc): Update.
---
 gdb/ChangeLog    | 4 ++++
 gdb/riscv-tdep.c | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)

-- 
2.27.0

Comments

Andrew Burgess March 25, 2021, 9:17 a.m. | #1
* Changbin Du via Gdb-patches <gdb-patches@sourceware.org> [2021-03-25 08:47:57 +0000]:

> To allow breakpoints to be created at invalid addresses,

> target_read_code() is used instead of read_code(). The

> original read_code() should be removed, otherwise the

> breakpoint command will fail.

> 

> (gdb) hbreak setup_arch

> Cannot access memory at address 0xffffffe000c036ac

> 

> gdb/ChangeLog:

> 2021-03-24  Changbin Du <changbin.du@gmail.com>

> 

>         * riscv-tdep.c (riscv_breakpoint_kind_from_pc): Update.


Can you change this to 'Remove call to read_code.' or similar.  Just
saying 'Update.' isn't very helpful.

Approved with that change.

Thanks,
Andrew



> ---

>  gdb/ChangeLog    | 4 ++++

>  gdb/riscv-tdep.c | 1 -

>  2 files changed, 4 insertions(+), 1 deletion(-)

> 

> diff --git a/gdb/ChangeLog b/gdb/ChangeLog

> index a548c58e8f72..a84299a2cc38 100644

> --- a/gdb/ChangeLog

> +++ b/gdb/ChangeLog

> @@ -1,3 +1,7 @@

> +2021-03-25  Changbin Du <changbin.du@gmail.com>

> +

> +	* riscv-tdep.c (riscv_breakpoint_kind_from_pc): Update.

> +

>  2021-03-24  Simon Marchi  <simon.marchi@polymtl.ca>

>  

>  	* target.h (current_top_target): Remove, make callers use the

> diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c

> index ca3efaf71cf8..c17839968465 100644

> --- a/gdb/riscv-tdep.c

> +++ b/gdb/riscv-tdep.c

> @@ -706,7 +706,6 @@ riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)

>  	     user.  */

>  	  if (target_read_code (*pcptr, buf, 1) == -1)

>  	    buf[0] = 0;

> -	  read_code (*pcptr, buf, 1);

>  	}

>  

>        if (riscv_debug_breakpoints)

> -- 

> 2.27.0

> 

>
Lancelot SIX via Gdb-patches March 25, 2021, 9:39 a.m. | #2
On Thu, Mar 25, 2021 at 09:17:52AM +0000, Andrew Burgess wrote:
> * Changbin Du via Gdb-patches <gdb-patches@sourceware.org> [2021-03-25 08:47:57 +0000]:

> 

> > To allow breakpoints to be created at invalid addresses,

> > target_read_code() is used instead of read_code(). The

> > original read_code() should be removed, otherwise the

> > breakpoint command will fail.

> > 

> > (gdb) hbreak setup_arch

> > Cannot access memory at address 0xffffffe000c036ac

> > 

> > gdb/ChangeLog:

> > 2021-03-24  Changbin Du <changbin.du@gmail.com>

> > 

> >         * riscv-tdep.c (riscv_breakpoint_kind_from_pc): Update.

> 

> Can you change this to 'Remove call to read_code.' or similar.  Just

> saying 'Update.' isn't very helpful.

>

Sure, please checkout in v2. Thanks.
 
> Approved with that change.

> 

> Thanks,

> Andrew

> 

> 

> 

> > ---

> >  gdb/ChangeLog    | 4 ++++

> >  gdb/riscv-tdep.c | 1 -

> >  2 files changed, 4 insertions(+), 1 deletion(-)

> > 

> > diff --git a/gdb/ChangeLog b/gdb/ChangeLog

> > index a548c58e8f72..a84299a2cc38 100644

> > --- a/gdb/ChangeLog

> > +++ b/gdb/ChangeLog

> > @@ -1,3 +1,7 @@

> > +2021-03-25  Changbin Du <changbin.du@gmail.com>

> > +

> > +	* riscv-tdep.c (riscv_breakpoint_kind_from_pc): Update.

> > +

> >  2021-03-24  Simon Marchi  <simon.marchi@polymtl.ca>

> >  

> >  	* target.h (current_top_target): Remove, make callers use the

> > diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c

> > index ca3efaf71cf8..c17839968465 100644

> > --- a/gdb/riscv-tdep.c

> > +++ b/gdb/riscv-tdep.c

> > @@ -706,7 +706,6 @@ riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)

> >  	     user.  */

> >  	  if (target_read_code (*pcptr, buf, 1) == -1)

> >  	    buf[0] = 0;

> > -	  read_code (*pcptr, buf, 1);

> >  	}

> >  

> >        if (riscv_debug_breakpoints)

> > -- 

> > 2.27.0

> > 

> > 


-- 
Cheers,
Changbin Du

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a548c58e8f72..a84299a2cc38 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@ 
+2021-03-25  Changbin Du <changbin.du@gmail.com>
+
+	* riscv-tdep.c (riscv_breakpoint_kind_from_pc): Update.
+
 2021-03-24  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* target.h (current_top_target): Remove, make callers use the
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index ca3efaf71cf8..c17839968465 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -706,7 +706,6 @@  riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 	     user.  */
 	  if (target_read_code (*pcptr, buf, 1) == -1)
 	    buf[0] = 0;
-	  read_code (*pcptr, buf, 1);
 	}
 
       if (riscv_debug_breakpoints)