[PATCH 1/3] gdb: constify auxv parse functions
Simon Marchi
simon.marchi@polymtl.ca
Thu Sep 29 20:43:52 GMT 2022
Constify the input parameters of the various auxv parse functions, they
don't need to modify the raw auxv data.
Change-Id: I13eacd5ab8e925ec2b5c1f7722cbab39c41516ec
---
gdb/auxv.c | 26 +++++++++++++-------------
gdb/auxv.h | 10 +++++-----
gdb/gdbarch-components.py | 4 ++--
gdb/gdbarch-gen.h | 4 ++--
gdb/gdbarch.c | 2 +-
gdb/ppc-linux-nat.c | 10 +++++-----
gdb/s390-linux-nat.c | 10 +++++-----
gdb/target-debug.h | 2 +-
gdb/target-delegates.c | 14 +++++++-------
gdb/target.h | 4 ++--
10 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/gdb/auxv.c b/gdb/auxv.c
index b248f997f1ca..63ee01c333c5 100644
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -250,14 +250,14 @@ memory_xfer_auxv (struct target_ops *ops,
the auxv type field as a parameter. */
static int
-generic_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp,
+generic_auxv_parse (struct gdbarch *gdbarch, const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp,
int sizeof_auxv_type)
{
struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
const int sizeof_auxv_val = ptr_type->length ();
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
- gdb_byte *ptr = *readptr;
+ const gdb_byte *ptr = *readptr;
if (endptr == ptr)
return 0;
@@ -281,8 +281,8 @@ generic_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
/* See auxv.h. */
int
-default_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+default_auxv_parse (struct target_ops *ops, const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
{
struct gdbarch *gdbarch = target_gdbarch ();
struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
@@ -295,8 +295,8 @@ default_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
/* See auxv.h. */
int
-svr4_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+svr4_auxv_parse (struct gdbarch *gdbarch, const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
{
struct type *int_type = builtin_type (gdbarch)->builtin_int;
const int sizeof_auxv_type = int_type->length ();
@@ -310,8 +310,8 @@ svr4_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
Return -1 if there is insufficient buffer for a whole entry.
Return 1 if an entry was read into *TYPEP and *VALP. */
int
-target_auxv_parse (gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+target_auxv_parse (const gdb_byte **readptr, const gdb_byte *endptr,
+ CORE_ADDR *typep, CORE_ADDR *valp)
{
struct gdbarch *gdbarch = target_gdbarch();
@@ -383,8 +383,8 @@ target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
if (!info->data)
return -1;
- gdb_byte *data = info->data->data ();
- gdb_byte *ptr = data;
+ const gdb_byte *data = info->data->data ();
+ const gdb_byte *ptr = data;
size_t len = info->data->size ();
while (1)
@@ -557,8 +557,8 @@ fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
if (!info->data)
return -1;
- gdb_byte *data = info->data->data ();
- gdb_byte *ptr = data;
+ const gdb_byte *data = info->data->data ();
+ const gdb_byte *ptr = data;
size_t len = info->data->size ();
while (target_auxv_parse (&ptr, data + len, &type, &val) > 0)
diff --git a/gdb/auxv.h b/gdb/auxv.h
index a4801c34d2f6..497318e87a04 100644
--- a/gdb/auxv.h
+++ b/gdb/auxv.h
@@ -31,8 +31,8 @@
Return 0 if *READPTR is already at the end of the buffer.
Return -1 if there is insufficient buffer for a whole entry.
Return 1 if an entry was read into *TYPEP and *VALP. */
-extern int default_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep,
+extern int default_auxv_parse (struct target_ops *ops, const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep,
CORE_ADDR *valp);
/* The SVR4 psABI implementation of to_auxv_parse, that uses an int to
@@ -42,15 +42,15 @@ extern int default_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
Return 0 if *READPTR is already at the end of the buffer.
Return -1 if there is insufficient buffer for a whole entry.
Return 1 if an entry was read into *TYPEP and *VALP. */
-extern int svr4_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep,
+extern int svr4_auxv_parse (struct gdbarch *gdbarch, const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep,
CORE_ADDR *valp);
/* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
Return 0 if *READPTR is already at the end of the buffer.
Return -1 if there is insufficient buffer for a whole entry.
Return 1 if an entry was read into *TYPEP and *VALP. */
-extern int target_auxv_parse (gdb_byte **readptr, gdb_byte *endptr,
+extern int target_auxv_parse (const gdb_byte **readptr, const gdb_byte *endptr,
CORE_ADDR *typep, CORE_ADDR *valp);
/* Extract the auxiliary vector entry with a_type matching MATCH.
diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py
index ad71bf754de9..6374240ae4b5 100644
--- a/gdb/gdbarch-components.py
+++ b/gdb/gdbarch-components.py
@@ -2492,8 +2492,8 @@ Return 1 if an entry was read into *TYPEP and *VALP.
type="int",
name="auxv_parse",
params=[
- ("gdb_byte **", "readptr"),
- ("gdb_byte *", "endptr"),
+ ("const gdb_byte **", "readptr"),
+ ("const gdb_byte *", "endptr"),
("CORE_ADDR *", "typep"),
("CORE_ADDR *", "valp"),
],
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index c7a24704c7cf..706dbb3befe1 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1539,8 +1539,8 @@ extern void set_gdbarch_program_breakpoint_here_p (struct gdbarch *gdbarch, gdba
extern bool gdbarch_auxv_parse_p (struct gdbarch *gdbarch);
-typedef int (gdbarch_auxv_parse_ftype) (struct gdbarch *gdbarch, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp);
-extern int gdbarch_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp);
+typedef int (gdbarch_auxv_parse_ftype) (struct gdbarch *gdbarch, const gdb_byte **readptr, const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp);
+extern int gdbarch_auxv_parse (struct gdbarch *gdbarch, const gdb_byte **readptr, const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp);
extern void set_gdbarch_auxv_parse (struct gdbarch *gdbarch, gdbarch_auxv_parse_ftype *auxv_parse);
/* Print the description of a single auxv entry described by TYPE and VAL
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 18d46a39d7a5..be73d399069e 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -5149,7 +5149,7 @@ gdbarch_auxv_parse_p (struct gdbarch *gdbarch)
}
int
-gdbarch_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+gdbarch_auxv_parse (struct gdbarch *gdbarch, const gdb_byte **readptr, const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->auxv_parse != NULL);
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index b089fcc8a5f5..dfa81e19a79f 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -530,8 +530,8 @@ struct ppc_linux_nat_target final : public linux_nat_target
const struct target_desc *read_description () override;
- int auxv_parse (gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+ int auxv_parse (const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
override;
/* Override linux_nat_target low methods. */
@@ -1915,8 +1915,8 @@ fill_fpregset (const struct regcache *regcache,
}
int
-ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep,
+ppc_linux_nat_target::auxv_parse (const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep,
CORE_ADDR *valp)
{
int tid = inferior_ptid.lwp ();
@@ -1926,7 +1926,7 @@ ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
int sizeof_auxv_field = ppc_linux_target_wordsize (tid);
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
- gdb_byte *ptr = *readptr;
+ const gdb_byte *ptr = *readptr;
if (endptr == ptr)
return 0;
diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c
index 73961c877691..2b21e0822362 100644
--- a/gdb/s390-linux-nat.c
+++ b/gdb/s390-linux-nat.c
@@ -132,8 +132,8 @@ class s390_linux_nat_target final : public linux_nat_target
/* Detect target architecture. */
const struct target_desc *read_description () override;
- int auxv_parse (gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+ int auxv_parse (const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
override;
/* Override linux_nat_target low methods. */
@@ -962,13 +962,13 @@ s390_target_wordsize (void)
}
int
-s390_linux_nat_target::auxv_parse (gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep,
+s390_linux_nat_target::auxv_parse (const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep,
CORE_ADDR *valp)
{
int sizeof_auxv_field = s390_target_wordsize ();
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
- gdb_byte *ptr = *readptr;
+ const gdb_byte *ptr = *readptr;
if (endptr == ptr)
return 0;
diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index ab89c0a51858..77033f00289b 100644
--- a/gdb/target-debug.h
+++ b/gdb/target-debug.h
@@ -76,7 +76,7 @@
target_debug_do_print (host_address_to_string (X))
#define target_debug_print_gdb_byte_p(X) \
target_debug_do_print (host_address_to_string (X))
-#define target_debug_print_gdb_byte_pp(X) \
+#define target_debug_print_const_gdb_byte_pp(X) \
target_debug_do_print (host_address_to_string (*(X)))
#define target_debug_print_enum_gdb_signal(X) \
target_debug_do_print (gdb_signal_to_name (X))
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index b6628c4d0be6..daf46821be07 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -119,7 +119,7 @@ struct dummy_target : public target_ops
void flash_done () override;
const struct target_desc *read_description () override;
ptid_t get_ada_task_ptid (long arg0, ULONGEST arg1) override;
- int auxv_parse (gdb_byte **arg0, gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3) override;
+ int auxv_parse (const gdb_byte **arg0, const gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3) override;
int search_memory (CORE_ADDR arg0, ULONGEST arg1, const gdb_byte *arg2, ULONGEST arg3, CORE_ADDR *arg4) override;
bool can_execute_reverse () override;
enum exec_direction_kind execution_direction () override;
@@ -293,7 +293,7 @@ struct debug_target : public target_ops
void flash_done () override;
const struct target_desc *read_description () override;
ptid_t get_ada_task_ptid (long arg0, ULONGEST arg1) override;
- int auxv_parse (gdb_byte **arg0, gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3) override;
+ int auxv_parse (const gdb_byte **arg0, const gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3) override;
int search_memory (CORE_ADDR arg0, ULONGEST arg1, const gdb_byte *arg2, ULONGEST arg3, CORE_ADDR *arg4) override;
bool can_execute_reverse () override;
enum exec_direction_kind execution_direction () override;
@@ -2623,27 +2623,27 @@ debug_target::get_ada_task_ptid (long arg0, ULONGEST arg1)
}
int
-target_ops::auxv_parse (gdb_byte **arg0, gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3)
+target_ops::auxv_parse (const gdb_byte **arg0, const gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3)
{
return this->beneath ()->auxv_parse (arg0, arg1, arg2, arg3);
}
int
-dummy_target::auxv_parse (gdb_byte **arg0, gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3)
+dummy_target::auxv_parse (const gdb_byte **arg0, const gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3)
{
return default_auxv_parse (this, arg0, arg1, arg2, arg3);
}
int
-debug_target::auxv_parse (gdb_byte **arg0, gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3)
+debug_target::auxv_parse (const gdb_byte **arg0, const gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3)
{
int result;
gdb_printf (gdb_stdlog, "-> %s->auxv_parse (...)\n", this->beneath ()->shortname ());
result = this->beneath ()->auxv_parse (arg0, arg1, arg2, arg3);
gdb_printf (gdb_stdlog, "<- %s->auxv_parse (", this->beneath ()->shortname ());
- target_debug_print_gdb_byte_pp (arg0);
+ target_debug_print_const_gdb_byte_pp (arg0);
gdb_puts (", ", gdb_stdlog);
- target_debug_print_gdb_byte_p (arg1);
+ target_debug_print_const_gdb_byte_p (arg1);
gdb_puts (", ", gdb_stdlog);
target_debug_print_CORE_ADDR_p (arg2);
gdb_puts (", ", gdb_stdlog);
diff --git a/gdb/target.h b/gdb/target.h
index 8e13ada07b6a..28aa92738930 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -862,8 +862,8 @@ struct target_ops
Return 0 if *READPTR is already at the end of the buffer.
Return -1 if there is insufficient buffer for a whole entry.
Return 1 if an entry was read into *TYPEP and *VALP. */
- virtual int auxv_parse (gdb_byte **readptr,
- gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+ virtual int auxv_parse (const gdb_byte **readptr,
+ const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
TARGET_DEFAULT_FUNC (default_auxv_parse);
/* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
--
2.37.3
More information about the Gdb-patches
mailing list