From: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] gdb, gdbarch, infcall: Add reserve_stack_space method to gdbarch
Date: Wed, 22 Mar 2023 18:13:52 +0100 [thread overview]
Message-ID: <20230322171352.9087-3-mohamed.bouhaouel@intel.com> (raw)
In-Reply-To: <20230322171352.9087-1-mohamed.bouhaouel@intel.com>
Change the 'reserve_stack_space' function from a static common method to a
target-dependent method.
Signed-off-by: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com>
---
gdb/gdbarch-gen.h | 6 ++++++
gdb/gdbarch.c | 22 ++++++++++++++++++++++
gdb/gdbarch_components.py | 10 ++++++++++
gdb/infcall.c | 16 ++++++----------
gdb/infcall.h | 9 +++++++++
5 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index a9b0fe26837..ca3e074de8f 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1687,3 +1687,9 @@ extern void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_g
typedef void (gdbarch_read_core_file_mappings_ftype) (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb);
extern void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb);
extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings);
+
+/* Reserve space on the stack for a value of the given type. */
+
+typedef CORE_ADDR (gdbarch_reserve_stack_space_ftype) (struct gdbarch *gdbarch, const type *valtype, CORE_ADDR &sp);
+extern CORE_ADDR gdbarch_reserve_stack_space (struct gdbarch *gdbarch, const type *valtype, CORE_ADDR &sp);
+extern void set_gdbarch_reserve_stack_space (struct gdbarch *gdbarch, gdbarch_reserve_stack_space_ftype *reserve_stack_space);
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index a411e5bbac7..25fdfc6b4c2 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -254,6 +254,7 @@ struct gdbarch
gdbarch_type_align_ftype *type_align = default_type_align;
gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = default_get_pc_address_flags;
gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = default_read_core_file_mappings;
+ gdbarch_reserve_stack_space_ftype *reserve_stack_space = default_reserve_stack_space;
};
/* Create a new ``struct gdbarch'' based on information provided by
@@ -518,6 +519,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of type_align, invalid_p == 0 */
/* Skip verify of get_pc_address_flags, invalid_p == 0 */
/* Skip verify of read_core_file_mappings, invalid_p == 0 */
+ /* Skip verify of reserve_stack_space, invalid_p == 0 */
if (!log.empty ())
internal_error (_("verify_gdbarch: the following are invalid ...%s"),
log.c_str ());
@@ -1362,6 +1364,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
gdb_printf (file,
"gdbarch_dump: read_core_file_mappings = <%s>\n",
host_address_to_string (gdbarch->read_core_file_mappings));
+ gdb_printf (file,
+ "gdbarch_dump: reserve_stack_space = <%s>\n",
+ host_address_to_string (gdbarch->reserve_stack_space));
if (gdbarch->dump_tdep != NULL)
gdbarch->dump_tdep (gdbarch, file);
}
@@ -5365,3 +5370,20 @@ set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch,
{
gdbarch->read_core_file_mappings = read_core_file_mappings;
}
+
+CORE_ADDR
+gdbarch_reserve_stack_space (struct gdbarch *gdbarch, const type *valtype, CORE_ADDR &sp)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->reserve_stack_space != NULL);
+ if (gdbarch_debug >= 2)
+ gdb_printf (gdb_stdlog, "gdbarch_reserve_stack_space called\n");
+ return gdbarch->reserve_stack_space (gdbarch, valtype, sp);
+}
+
+void
+set_gdbarch_reserve_stack_space (struct gdbarch *gdbarch,
+ gdbarch_reserve_stack_space_ftype reserve_stack_space)
+{
+ gdbarch->reserve_stack_space = reserve_stack_space;
+}
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 10e8c2d52c8..800054a34b4 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -2683,3 +2683,13 @@ Read core file mappings
predefault="default_read_core_file_mappings",
invalid=False,
)
+
+Method(
+ comment="Reserve space on the stack for a value of the given type.",
+ type="CORE_ADDR",
+ name="reserve_stack_space",
+ params=[("const type *", "valtype"), ("CORE_ADDR &", "sp")],
+ predefault="default_reserve_stack_space",
+ predicate=False,
+ invalid=False,
+)
diff --git a/gdb/infcall.c b/gdb/infcall.c
index b945adebc93..8ef05bec3e0 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -702,16 +702,12 @@ run_inferior_call (std::unique_ptr<call_thread_fsm> sm,
return caught_error;
}
-/* Reserve space on the stack for a value of the given type.
- Return the address of the allocated space.
- Make certain that the value is correctly aligned.
- The SP argument is modified. */
+/* See infcall.h. */
-static CORE_ADDR
-reserve_stack_space (const type *values_type, CORE_ADDR &sp)
+CORE_ADDR
+default_reserve_stack_space (gdbarch *gdbarch, const type *values_type,
+ CORE_ADDR &sp)
{
- frame_info_ptr frame = get_current_frame ();
- struct gdbarch *gdbarch = get_frame_arch (frame);
CORE_ADDR addr = 0;
if (gdbarch_inner_than (gdbarch, 1, 2))
@@ -1116,7 +1112,7 @@ call_function_by_hand_dummy (struct value *function,
/* Make a copy of the argument on the stack. If the argument is
trivially copy ctor'able, copy bit by bit. Otherwise, call
the copy ctor to initialize the clone. */
- CORE_ADDR addr = reserve_stack_space (param_type, sp);
+ CORE_ADDR addr = gdbarch_reserve_stack_space (gdbarch, param_type, sp);
value *clone
= value_from_contents_and_address (param_type, nullptr, addr);
push_thread_stack_temporary (call_thread.get (), clone);
@@ -1201,7 +1197,7 @@ call_function_by_hand_dummy (struct value *function,
if (return_method != return_method_normal
|| (stack_temporaries && class_or_union_p (values_type)))
- struct_addr = reserve_stack_space (values_type, sp);
+ struct_addr = gdbarch_reserve_stack_space (gdbarch, values_type, sp);
std::vector<struct value *> new_args;
if (return_method == return_method_hidden_param)
diff --git a/gdb/infcall.h b/gdb/infcall.h
index af3dd49220a..807d86d3989 100644
--- a/gdb/infcall.h
+++ b/gdb/infcall.h
@@ -79,4 +79,13 @@ extern void error_call_unknown_return_type (const char *func_name);
extern value *default_value_arg_coerce (gdbarch *gdbarch, value *arg,
type *param_type, int is_prototyped);
+
+/* Reserve space on the stack for a value of the given type.
+ Return the address of the allocated space.
+ Make certain that the value is correctly aligned.
+ The SP argument is modified. */
+
+extern CORE_ADDR default_reserve_stack_space (gdbarch *gdbarch,
+ const type *values_type,
+ CORE_ADDR &sp);
#endif
--
2.25.1
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2023-03-22 17:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-22 17:13 [PATCH 0/2] Add more flexibility to inferior call Mohamed Bouhaouel
2023-03-22 17:13 ` [PATCH 1/2] gdb, gdbarch, infcall: Add value_arg_coerce method to gdbarch Mohamed Bouhaouel
2023-03-22 19:18 ` Simon Marchi
2023-03-22 17:13 ` Mohamed Bouhaouel [this message]
2023-03-22 19:16 ` [PATCH 0/2] Add more flexibility to inferior call Simon Marchi
2023-03-23 11:34 ` Bouhaouel, Mohamed
2023-03-24 13:38 ` Simon Marchi
2023-03-24 14:10 ` Bouhaouel, Mohamed
2023-03-24 14:12 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230322171352.9087-3-mohamed.bouhaouel@intel.com \
--to=mohamed.bouhaouel@intel.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).