aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2020-07-22 15:56:06 +0200
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2020-07-22 15:56:06 +0200
commit238b5c9f0881b2e27d2eb111ad9c7fe874859acf (patch)
tree4a6c48835685490c23f61d568798cf575ed39acc /gdb
parentfe053b9e85378b4df1397684266b2cddcce8123b (diff)
downloadgdb-238b5c9f0881b2e27d2eb111ad9c7fe874859acf.zip
gdb-238b5c9f0881b2e27d2eb111ad9c7fe874859acf.tar.gz
gdb-238b5c9f0881b2e27d2eb111ad9c7fe874859acf.tar.bz2
gdb/jit: link to jit_objfile_data directly from the objfile struct
Remove the use of objfile_data to associate a jit_objfile_data with an objfile. Instead, directly link to a jit_objfile_data from an objfile struct. The goal is to eliminate unnecessary abstraction. The free_objfile_data function naturally becomes the destructor of jit_objfile_data. However, free_objfile_data accesses the objfile to which the data is attached, which the destructor of jit_objfile_data doesn't have access to. To work around this, add a backlink to the owning objfile in jit_objfile_data. This is however temporary, it goes away in a subsequent patch. gdb/ChangeLog: 2020-07-22 Simon Marchi <simon.marchi@polymtl.ca> * jit.h: Forward-declare `struct minimal_symbol`. (struct jit_objfile_data): Migrate to here from jit.c; also add a constructor, destructor, and an objfile* field. * jit.c (jit_objfile_data): Remove. (struct jit_objfile_data): Migrate from here to jit.h. (jit_objfile_data::~jit_objfile_data): New destructor implementation with code moved from free_objfile_data. (free_objfile_data): Delete. (get_jit_objfile_data): Update to use the jit_data field of objfile. (jit_find_objf_with_entry_addr): Ditto. (jit_inferior_exit_hook): Ditto. (_initialize_jit): Remove the call to register_objfile_data_with_cleanup. * objfiles.h (struct objfile) <jit_data>: New field.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog17
-rw-r--r--gdb/jit.c83
-rw-r--r--gdb/jit.h29
-rw-r--r--gdb/objfiles.h4
4 files changed, 72 insertions, 61 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7d52e22..ed90071 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,20 @@
+2020-07-22 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * jit.h: Forward-declare `struct minimal_symbol`.
+ (struct jit_objfile_data): Migrate to here from jit.c; also add a
+ constructor, destructor, and an objfile* field.
+ * jit.c (jit_objfile_data): Remove.
+ (struct jit_objfile_data): Migrate from here to jit.h.
+ (jit_objfile_data::~jit_objfile_data): New destructor
+ implementation with code moved from free_objfile_data.
+ (free_objfile_data): Delete.
+ (get_jit_objfile_data): Update to use the jit_data field of objfile.
+ (jit_find_objf_with_entry_addr): Ditto.
+ (jit_inferior_exit_hook): Ditto.
+ (_initialize_jit): Remove the call to
+ register_objfile_data_with_cleanup.
+ * objfiles.h (struct objfile) <jit_data>: New field.
+
2020-07-22 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* jit.h: Forward-declare `struct objfile`.
diff --git a/gdb/jit.c b/gdb/jit.c
index 41ed81a..39e3641 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -45,8 +45,6 @@
static std::string jit_reader_dir;
-static const struct objfile_data *jit_objfile_data;
-
static const char *const jit_break_name = "__jit_debug_register_code";
static const char *const jit_descriptor_name = "__jit_debug_descriptor";
@@ -265,24 +263,25 @@ struct jit_program_space_data
static program_space_key<jit_program_space_data> jit_program_space_key;
-/* Per-objfile structure recording the addresses in the program space.
- This object serves two purposes: for ordinary objfiles, it may
- cache some symbols related to the JIT interface; and for
- JIT-created objfiles, it holds some information about the
- jit_code_entry. */
+/* Destructor for jit_objfile_data. */
-struct jit_objfile_data
+jit_objfile_data::~jit_objfile_data ()
{
- /* Symbol for __jit_debug_register_code. */
- struct minimal_symbol *register_code;
-
- /* Symbol for __jit_debug_descriptor. */
- struct minimal_symbol *descriptor;
+ /* Free the data allocated in the jit_program_space_data slot. */
+ if (this->register_code != NULL)
+ {
+ struct jit_program_space_data *ps_data;
- /* Address of struct jit_code_entry in this objfile. This is only
- non-zero for objfiles that represent code created by the JIT. */
- CORE_ADDR addr;
-};
+ ps_data = jit_program_space_key.get (this->objfile->pspace);
+ if (ps_data != NULL && ps_data->objfile == this->objfile)
+ {
+ ps_data->objfile = NULL;
+ if (ps_data->jit_breakpoint != NULL)
+ delete_breakpoint (ps_data->jit_breakpoint);
+ ps_data->cached_code_address = 0;
+ }
+ }
+}
/* Fetch the jit_objfile_data associated with OBJF. If no data exists
yet, make a new structure and attach it. */
@@ -290,16 +289,10 @@ struct jit_objfile_data
static struct jit_objfile_data *
get_jit_objfile_data (struct objfile *objf)
{
- struct jit_objfile_data *objf_data;
+ if (objf->jit_data == nullptr)
+ objf->jit_data.reset (new jit_objfile_data (objf));
- objf_data = (struct jit_objfile_data *) objfile_data (objf, jit_objfile_data);
- if (objf_data == NULL)
- {
- objf_data = XCNEW (struct jit_objfile_data);
- set_objfile_data (objf, jit_objfile_data, objf_data);
- }
-
- return objf_data;
+ return objf->jit_data.get ();
}
/* Remember OBJFILE has been created for struct jit_code_entry located
@@ -915,13 +908,10 @@ jit_find_objf_with_entry_addr (CORE_ADDR entry_addr)
{
for (objfile *objf : current_program_space->objfiles ())
{
- struct jit_objfile_data *objf_data;
-
- objf_data
- = (struct jit_objfile_data *) objfile_data (objf, jit_objfile_data);
- if (objf_data != NULL && objf_data->addr == entry_addr)
+ if (objf->jit_data != nullptr && objf->jit_data->addr == entry_addr)
return objf;
}
+
return NULL;
}
@@ -1325,10 +1315,7 @@ jit_inferior_exit_hook (struct inferior *inf)
{
for (objfile *objf : current_program_space->objfiles_safe ())
{
- struct jit_objfile_data *objf_data
- = (struct jit_objfile_data *) objfile_data (objf, jit_objfile_data);
-
- if (objf_data != NULL && objf_data->addr != 0)
+ if (objf->jit_data != nullptr && objf->jit_data->addr != 0)
objf->unlink ();
}
}
@@ -1371,30 +1358,6 @@ jit_event_handler (gdbarch *gdbarch, objfile *jiter)
}
}
-/* Called to free the data allocated to the jit_program_space_data slot. */
-
-static void
-free_objfile_data (struct objfile *objfile, void *data)
-{
- struct jit_objfile_data *objf_data = (struct jit_objfile_data *) data;
-
- if (objf_data->register_code != NULL)
- {
- struct jit_program_space_data *ps_data;
-
- ps_data = jit_program_space_key.get (objfile->pspace);
- if (ps_data != NULL && ps_data->objfile == objfile)
- {
- ps_data->objfile = NULL;
- if (ps_data->jit_breakpoint != NULL)
- delete_breakpoint (ps_data->jit_breakpoint);
- ps_data->cached_code_address = 0;
- }
- }
-
- xfree (data);
-}
-
/* Initialize the jit_gdbarch_data slot with an instance of struct
jit_gdbarch_data_type */
@@ -1427,8 +1390,6 @@ _initialize_jit ()
gdb::observers::inferior_exit.attach (jit_inferior_exit_hook);
gdb::observers::breakpoint_deleted.attach (jit_breakpoint_deleted);
- jit_objfile_data =
- register_objfile_data_with_cleanup (NULL, free_objfile_data);
jit_gdbarch_data = gdbarch_data_register_pre_init (jit_gdbarch_data_init);
if (is_dl_available ())
{
diff --git a/gdb/jit.h b/gdb/jit.h
index 71e78a5..6109216 100644
--- a/gdb/jit.h
+++ b/gdb/jit.h
@@ -21,6 +21,7 @@
#define JIT_H
struct objfile;
+struct minimal_symbol;
/* When the JIT breakpoint fires, the inferior wants us to take one of
these actions. These values are used by the inferior, so the
@@ -66,6 +67,34 @@ struct jit_descriptor
CORE_ADDR first_entry;
};
+/* Per-objfile structure recording the addresses in the program space.
+ This object serves two purposes: for ordinary objfiles, it may
+ cache some symbols related to the JIT interface; and for
+ JIT-created objfiles, it holds some information about the
+ jit_code_entry. */
+
+struct jit_objfile_data
+{
+ jit_objfile_data (struct objfile *objfile)
+ : objfile (objfile)
+ {}
+
+ ~jit_objfile_data ();
+
+ /* Back-link to the objfile. */
+ struct objfile *objfile;
+
+ /* Symbol for __jit_debug_register_code. */
+ minimal_symbol *register_code = nullptr;
+
+ /* Symbol for __jit_debug_descriptor. */
+ minimal_symbol *descriptor = nullptr;
+
+ /* Address of struct jit_code_entry in this objfile. This is only
+ non-zero for objfiles that represent code created by the JIT. */
+ CORE_ADDR addr = 0;
+};
+
/* Looks for the descriptor and registration symbols and breakpoints
the registration function. If it finds both, it registers all the
already JITed code. If it has already found the symbols, then it
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 56ff521..b21b426 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -36,6 +36,7 @@
#include "bcache.h"
#include "gdbarch.h"
#include "gdbsupport/refcounted-object.h"
+#include "jit.h"
struct htab;
struct objfile_data;
@@ -697,6 +698,9 @@ public:
store these here rather than in struct block. Static links must be
allocated on the objfile's obstack. */
htab_up static_links;
+
+ /* JIT-related data for this objfile. */
+ std::unique_ptr<jit_objfile_data> jit_data = nullptr;
};
/* A deleter for objfile. */