[v2] gdb/riscv: fix creating breakpoints at invalid addresses

Message ID 20210325093954.3210-1-changbin.du@gmail.com
State New
Headers show
Series
  • [v2] gdb/riscv: fix creating breakpoints at invalid addresses
Related show

Commit Message

Simon Marchi via Gdb-patches March 25, 2021, 9:39 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): Remove call to read_code.
---
 gdb/ChangeLog    | 4 ++++
 gdb/riscv-tdep.c | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)

-- 
2.27.0

Comments

Andrew Burgess March 25, 2021, 11:10 a.m. | #1
* Changbin Du via Gdb-patches <gdb-patches@sourceware.org> [2021-03-25 09:39:54 +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): Remove call to read_code.


Thanks.

I pushed this fix to master.

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): Remove call to read_code.

> +

>  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

> 

>

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): Remove call to read_code.
+
 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)