public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 8/9] gdb/jit: apply minor cleanup and modernization
Date: Wed, 15 Jul 2020 10:16:36 +0200	[thread overview]
Message-ID: <a4ff79de117beaeba0e986dbf08dd14b648579df.1594799616.git.tankut.baris.aktemur@intel.com> (raw)
In-Reply-To: <cover.1594799616.git.tankut.baris.aktemur@intel.com>
In-Reply-To: <cover.1594799616.git.tankut.baris.aktemur@intel.com>

From: Simon Marchi <simon.marchi@polymtl.ca>

gdb/ChangeLog:
2020-07-14  Simon Marchi  <simon.marchi@polymtl.ca>
	    Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* jit.c (jit_read_descriptor): Define the descriptor address once,
	use twice.
	(jit_breakpoint_deleted): Move the declaration of the loop variable
	`iter` into the loop header.
	(jit_breakpoint_re_set_internal): Move the declaration of the local
	variable `objf_data` to the first point of definition.
	(jit_event_handler): Move the declaration of local variables
	`code_entry`, `entry_addr`, and `objf` to their first point of use.
	Rename `objf` to `jited`.
---
 gdb/jit.c | 53 +++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/gdb/jit.c b/gdb/jit.c
index e15b67107af..1850e5b143e 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -289,11 +289,12 @@ jit_read_descriptor (gdbarch *gdbarch,
   jiter_objfile_data *objf_data = jiter->jiter_data.get ();
   gdb_assert (objf_data != nullptr);
 
+  CORE_ADDR addr = MSYMBOL_VALUE_ADDRESS (jiter, objf_data->descriptor);
+
   if (jit_debug)
     fprintf_unfiltered (gdb_stdlog,
 			"jit_read_descriptor, descriptor_addr = %s\n",
-			paddress (gdbarch, MSYMBOL_VALUE_ADDRESS (jiter,
-								  objf_data->descriptor)));
+			paddress (gdbarch, addr));
 
   /* Figure out how big the descriptor is on the remote and how to read it.  */
   ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
@@ -302,9 +303,7 @@ jit_read_descriptor (gdbarch *gdbarch,
   desc_buf = (gdb_byte *) alloca (desc_size);
 
   /* Read the descriptor.  */
-  err = target_read_memory (MSYMBOL_VALUE_ADDRESS (jiter,
-						   objf_data->descriptor),
-			    desc_buf, desc_size);
+  err = target_read_memory (addr, desc_buf, desc_size);
   if (err)
     {
       printf_unfiltered (_("Unable to read JIT descriptor from "
@@ -865,12 +864,10 @@ jit_find_objf_with_entry_addr (CORE_ADDR entry_addr)
 static void
 jit_breakpoint_deleted (struct breakpoint *b)
 {
-  struct bp_location *iter;
-
   if (b->type != bp_jit_event)
     return;
 
-  for (iter = b->loc; iter != NULL; iter = iter->next)
+  for (bp_location *iter = b->loc; iter != nullptr; iter = iter->next)
     {
       for (objfile *objf : iter->pspace->objfiles ())
 	{
@@ -892,8 +889,6 @@ jit_breakpoint_deleted (struct breakpoint *b)
 static void
 jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, program_space *pspace)
 {
-  jiter_objfile_data *objf_data;
-
   for (objfile *the_objfile : pspace->objfiles ())
     {
       /* Lookup the registration symbol.  If it is missing, then we
@@ -910,7 +905,8 @@ jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, program_space *pspace)
 	  || BMSYMBOL_VALUE_ADDRESS (desc_symbol) == 0)
 	continue;
 
-      objf_data = get_jiter_objfile_data (reg_symbol.objfile);
+      jiter_objfile_data *objf_data
+	= get_jiter_objfile_data (reg_symbol.objfile);
       objf_data->register_code = reg_symbol.minsym;
       objf_data->descriptor = desc_symbol.minsym;
 
@@ -1261,9 +1257,6 @@ void
 jit_event_handler (gdbarch *gdbarch, objfile *jiter)
 {
   struct jit_descriptor descriptor;
-  struct jit_code_entry code_entry;
-  CORE_ADDR entry_addr;
-  struct objfile *objf;
 
   /* If we get a JIT breakpoint event for this objfile, it is necessarily a
      JITer.  */
@@ -1272,27 +1265,35 @@ jit_event_handler (gdbarch *gdbarch, objfile *jiter)
   /* Read the descriptor from remote memory.  */
   if (!jit_read_descriptor (gdbarch, &descriptor, jiter))
     return;
-  entry_addr = descriptor.relevant_entry;
+  CORE_ADDR entry_addr = descriptor.relevant_entry;
 
   /* Do the corresponding action.  */
   switch (descriptor.action_flag)
     {
     case JIT_NOACTION:
       break;
+
     case JIT_REGISTER:
-      jit_read_code_entry (gdbarch, entry_addr, &code_entry);
-      jit_register_code (gdbarch, entry_addr, &code_entry);
-      break;
+      {
+	jit_code_entry code_entry;
+	jit_read_code_entry (gdbarch, entry_addr, &code_entry);
+	jit_register_code (gdbarch, entry_addr, &code_entry);
+	break;
+      }
+
     case JIT_UNREGISTER:
-      objf = jit_find_objf_with_entry_addr (entry_addr);
-      if (objf == NULL)
-	printf_unfiltered (_("Unable to find JITed code "
-			     "entry at address: %s\n"),
-			   paddress (gdbarch, entry_addr));
-      else
-	objf->unlink ();
+      {
+	objfile *jited = jit_find_objf_with_entry_addr (entry_addr);
+	if (jited == nullptr)
+	  printf_unfiltered (_("Unable to find JITed code "
+			       "entry at address: %s\n"),
+			     paddress (gdbarch, entry_addr));
+	else
+	  jited->unlink ();
+
+	break;
+      }
 
-      break;
     default:
       error (_("Unknown action_flag value in JIT descriptor!"));
       break;
-- 
2.17.1


  parent reply	other threads:[~2020-07-15  8:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-15  8:16 [PATCH v3 0/9] Handling multiple JITers Tankut Baris Aktemur
2020-07-15  8:16 ` [PATCH v3 1/9] gdb/jit: pass the jiter objfile as an argument to jit_event_handler Tankut Baris Aktemur
2020-07-15 13:48   ` Simon Marchi
2020-07-21 16:24     ` Aktemur, Tankut Baris
2020-07-15  8:16 ` [PATCH v3 2/9] gdb/jit: link to jit_objfile_data directly from the objfile struct Tankut Baris Aktemur
2020-07-15 14:16   ` Simon Marchi
2020-07-21 16:25     ` Aktemur, Tankut Baris
2020-07-21 17:42       ` Simon Marchi
2020-07-15  8:16 ` [PATCH v3 3/9] gdb/jit: split jit_objfile_data in two Tankut Baris Aktemur
2020-07-15 14:19   ` Simon Marchi
2020-07-21 16:24     ` Aktemur, Tankut Baris
2020-07-15  8:16 ` [PATCH v3 4/9] gdb/jit: apply some simplifications and assertions Tankut Baris Aktemur
2020-07-15  8:16 ` [PATCH v3 5/9] gdb/jit: move cached_code_address and jit_breakpoint to jiter_objfile_data Tankut Baris Aktemur
2020-07-15  8:16 ` [PATCH v3 6/9] gdb/jit: enable tracking multiple JITer objfiles Tankut Baris Aktemur
2020-07-15  8:16 ` [PATCH v3 7/9] gdb/jit: remove jiter_objfile_data -> objfile back-link Tankut Baris Aktemur
2020-07-15  8:16 ` Tankut Baris Aktemur [this message]
2020-07-15  8:16 ` [PATCH v3 9/9] gdb/jit: skip jit symbol lookup if already detected the symbols don't exist Tankut Baris Aktemur
2020-07-19 15:44 ` [PATCH v3 0/9] Handling multiple JITers Simon Marchi

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=a4ff79de117beaeba0e986dbf08dd14b648579df.1594799616.git.tankut.baris.aktemur@intel.com \
    --to=tankut.baris.aktemur@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).