[RFC][PATCH 4/7] Add address argument to compile_to_object
paul-naert
paul_naert@hotmail.fr
Thu May 14 14:08:46 GMT 2020
This enables the caller to have the compiler look at locals from a different frame than the current one.
This function is also set as non static to make it available for the patch command.
---
gdb/compile/compile-internal.h | 11 +++++++++++
gdb/compile/compile.c | 24 ++++++++++++++++--------
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
index 9c0e989..648b2ea 100644
--- a/gdb/compile/compile-internal.h
+++ b/gdb/compile/compile-internal.h
@@ -207,4 +207,15 @@ private:
std::string m_object_file;
};
+/* Process the compilation request. On success it returns the object
+ and source file names. On an error condition, error () is
+ called.
+ if addr is set to 0, the program is compiled in the scope of the
+ current frame. Otherwise it uses the frame containing the
+ instruction at address addr. */
+compile_file_names compile_to_object(struct command_line *cmd,
+ const char *cmd_string,
+ enum compile_i_scope_types scope,
+ CORE_ADDR addr);
+
#endif /* COMPILE_COMPILE_INTERNAL_H */
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 94942db..ce01a08 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -667,13 +667,12 @@ print_callback (void *ignore, const char *message)
fputs_filtered (message, gdb_stderr);
}
-/* Process the compilation request. On success it returns the object
- and source file names. On an error condition, error () is
- called. */
-static compile_file_names
+/* See compile-internal.h. */
+
+compile_file_names
compile_to_object (struct command_line *cmd, const char *cmd_string,
- enum compile_i_scope_types scope)
+ enum compile_i_scope_types scope, CORE_ADDR address)
{
const struct block *expr_block;
CORE_ADDR trash_pc, expr_pc;
@@ -687,8 +686,17 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
error (_("The program must be running for the compile command to "\
"work."));
- expr_block = get_expr_block_and_pc (&trash_pc);
- expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
+ if(address == 0)
+ {
+ /* Use current address. */
+ expr_block = get_expr_block_and_pc (&trash_pc);
+ expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
+ }
+ else
+ {
+ expr_block = block_for_pc(address);
+ expr_pc = address;
+ }
/* Set up instance and context for the compiler. */
if (current_language->la_get_compile_instance == NULL)
@@ -824,7 +832,7 @@ eval_compile_command (struct command_line *cmd, const char *cmd_string,
{
struct compile_module *compile_module;
- compile_file_names fnames = compile_to_object (cmd, cmd_string, scope);
+ compile_file_names fnames = compile_to_object (cmd, cmd_string, scope, 0);
gdb::unlinker object_remover (fnames.object_file ());
gdb::unlinker source_remover (fnames.source_file ());
--
2.7.4
More information about the Gdb-patches
mailing list