From 9246b7bd6dfeb273f9be7648acffddfe19f966ff Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 17 Aug 2023 10:41:34 +0200 Subject: [PATCH] [gdb/build] Return const reference in target_read_auxv In target_read_auxv we return a copy of an object: ... gdb::optional target_read_auxv () { ... return info->data; } ... Return a const reference instead, saving a copy. This is exposed by using std::pmr::polymorphic_allocator instead of std::allocator in default_init_allocator. Tested on x86_64-linux. --- gdb/arm-fbsd-tdep.c | 2 +- gdb/auxv.c | 6 +++--- gdb/auxv.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c index acafc4a8bcd..b46fa91d0a0 100644 --- a/gdb/arm-fbsd-tdep.c +++ b/gdb/arm-fbsd-tdep.c @@ -244,7 +244,7 @@ arm_fbsd_read_description_auxv (const gdb::optional &auxv, const struct target_desc * arm_fbsd_read_description_auxv (bool tls) { - gdb::optional auxv = target_read_auxv (); + const gdb::optional &auxv = target_read_auxv (); return arm_fbsd_read_description_auxv (auxv, current_inferior ()->top_target (), current_inferior ()->gdbarch, diff --git a/gdb/auxv.c b/gdb/auxv.c index 812b2807554..3c27c1f1ffe 100644 --- a/gdb/auxv.c +++ b/gdb/auxv.c @@ -354,7 +354,7 @@ invalidate_auxv_cache (void) /* See auxv.h. */ -gdb::optional +const gdb::optional & target_read_auxv () { inferior *inf = current_inferior (); @@ -410,7 +410,7 @@ target_auxv_search (const gdb::byte_vector &auxv, target_ops *ops, int target_auxv_search (CORE_ADDR match, CORE_ADDR *valp) { - gdb::optional auxv = target_read_auxv (); + const gdb::optional &auxv = target_read_auxv (); if (!auxv.has_value ()) return -1; @@ -564,7 +564,7 @@ fprint_target_auxv (struct ui_file *file) struct gdbarch *gdbarch = target_gdbarch (); CORE_ADDR type, val; int ents = 0; - gdb::optional auxv = target_read_auxv (); + const gdb::optional &auxv = target_read_auxv (); if (!auxv.has_value ()) return -1; diff --git a/gdb/auxv.h b/gdb/auxv.h index 2441b6c02ab..a920f7a5da8 100644 --- a/gdb/auxv.h +++ b/gdb/auxv.h @@ -48,7 +48,7 @@ extern int svr4_auxv_parse (struct gdbarch *gdbarch, const gdb_byte **readptr, /* Read auxv data from the current inferior's target stack. */ -extern gdb::optional target_read_auxv (); +extern const gdb::optional &target_read_auxv (); /* Read auxv data from OPS. */ -- 2.30.2