public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: paul-naert <paul_naert@hotmail.fr>
To: gdb-patches@sourceware.org
Cc: paul-naert <paul_naert@hotmail.fr>
Subject: [RFC][PATCH 4/7] Add address argument to compile_to_object
Date: Thu, 14 May 2020 10:08:46 -0400	[thread overview]
Message-ID: <20200514140849.31845-5-paul_naert@hotmail.fr> (raw)
In-Reply-To: <20200514140849.31845-1-paul_naert@hotmail.fr>

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


  parent reply	other threads:[~2020-05-14 14:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 14:08 [RFC][PATCH 0/7] Patching new code in a binary paul-naert
2020-05-14 14:08 ` [RFC][PATCH 1/7] Add addr argument to infcall_mmap paul-naert
2020-05-14 14:08 ` [RFC][PATCH 2/7] Change memory protection for compile arguments to RW paul-naert
2020-05-22 19:18   ` Tom Tromey
2020-05-14 14:08 ` [RFC][PATCH 3/7] Make create_sals_from_location_default non static paul-naert
2020-05-14 14:08 ` paul-naert [this message]
2020-05-14 14:08 ` [RFC][PATCH 5/7] Add the option to defer register storage for compiled object loading paul-naert
2020-05-22 19:39   ` Tom Tromey
2020-05-14 14:08 ` [RFC][PATCH 6/7] Convert short jumps to long ones in amd64_relocate_instruction paul-naert
2020-05-22 19:41   ` Tom Tromey
2020-05-14 14:08 ` [RFC][PATCH 7/7] Add the patch command to dynamically inject code in the inferior paul-naert
2020-05-22 19:50   ` Tom Tromey
2020-05-22 19:57 ` [RFC][PATCH 0/7] Patching new code in a binary 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=20200514140849.31845-5-paul_naert@hotmail.fr \
    --to=paul_naert@hotmail.fr \
    --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).