* [PATCH 0/4] Add inferior parameter to inferior_created and use it
@ 2020-10-18 23:15 Simon Marchi
2020-10-18 23:15 ` [PATCH 1/4] gdb: add inferior parameter to inferior_created observable Simon Marchi
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Simon Marchi @ 2020-10-18 23:15 UTC (permalink / raw)
To: gdb-patches
I made this in the context of some other work, and I think it makes
sense on its own, so I am posting it on its own.
Simon Marchi (4):
gdb: add inferior parameter to inferior_created observable
gdb: pass inferior to check_pid_namespace_match
gdb: make jit.c use the inferior_created inferior parameter
gdb: use inferior parameter in add_vsyscall_page
gdb/aix-thread.c | 2 +-
gdb/bsd-uthread.c | 2 +-
gdb/dummy-frame.c | 2 +-
gdb/infcmd.c | 2 +-
gdb/infrun.c | 2 +-
gdb/jit.c | 27 ++++++++++-----------------
gdb/jit.h | 3 ++-
gdb/linux-thread-db.c | 8 ++++----
gdb/m68k-linux-tdep.c | 2 +-
gdb/observable.h | 2 +-
gdb/ravenscar-thread.c | 2 +-
gdb/symfile-mem.c | 5 +++--
12 files changed, 27 insertions(+), 32 deletions(-)
--
2.28.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] gdb: add inferior parameter to inferior_created observable
2020-10-18 23:15 [PATCH 0/4] Add inferior parameter to inferior_created and use it Simon Marchi
@ 2020-10-18 23:15 ` Simon Marchi
2020-10-18 23:15 ` [PATCH 2/4] gdb: pass inferior to check_pid_namespace_match Simon Marchi
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2020-10-18 23:15 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
From: Simon Marchi <simon.marchi@efficios.com>
I think it would make sense for the inferior_created observable to say
which inferior is being dealt with, rather than relying on it being the
current inferior.
This patch adds an inferior parameter to inferior_created, but does not
change the callbacks to use it.
gdb/ChangeLog:
* aix-thread.c (aix_thread_inferior_created): Add inferior
parameter.
* bsd-uthread.c (bsd_uthread_inferior_created): Likewise.
* dummy-frame.c (cleanup_dummy_frames): Likewise.
* jit.c (jit_inferior_created): Likewise.
* linux-thread-db.c (thread_db_inferior_created): Likewise.
* m68k-linux-tdep.c (m68k_linux_inferior_created): Likewise.
* observable.h (inferior_created): Likewise.
* ravenscar-thread.c (ravenscar_inferior_created): Likewise.
* symfile-mem.c (add_vsyscall_page): Likewise.
* infcmd.c (post_create_inferior): Pass inferior argument.
Change-Id: I2543d19ff055a9df6b269929faea10b27d2adc5e
---
gdb/aix-thread.c | 2 +-
gdb/bsd-uthread.c | 2 +-
gdb/dummy-frame.c | 2 +-
gdb/infcmd.c | 2 +-
gdb/jit.c | 2 +-
gdb/linux-thread-db.c | 2 +-
gdb/m68k-linux-tdep.c | 2 +-
gdb/observable.h | 2 +-
gdb/ravenscar-thread.c | 2 +-
gdb/symfile-mem.c | 2 +-
10 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index b4100a55ae95..bedd97d439a7 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1015,7 +1015,7 @@ new_objfile (struct objfile *objfile)
/* Attach to process specified by ARGS. */
static void
-aix_thread_inferior_created ()
+aix_thread_inferior_created (inferior *inf)
{
pd_enable ();
}
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index e83707fd7c50..ffbee4a15f92 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -263,7 +263,7 @@ bsd_uthread_deactivate (void)
}
static void
-bsd_uthread_inferior_created ()
+bsd_uthread_inferior_created (inferior *inf)
{
bsd_uthread_activate (NULL);
}
diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c
index 1952d2eb6f30..0b99e5c1c6a7 100644
--- a/gdb/dummy-frame.c
+++ b/gdb/dummy-frame.c
@@ -273,7 +273,7 @@ find_dummy_frame_dtor (dummy_frame_dtor_ftype *dtor, void *dtor_data)
them up at least once whenever we start a new inferior. */
static void
-cleanup_dummy_frames ()
+cleanup_dummy_frames (inferior *inf)
{
while (dummy_frame_stack != NULL)
remove_dummy_frame (&dummy_frame_stack);
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 498089fdb529..068de96941a6 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -347,7 +347,7 @@ post_create_inferior (int from_tty)
if the now pushed target supports hardware watchpoints. */
breakpoint_re_set ();
- gdb::observers::inferior_created.notify ();
+ gdb::observers::inferior_created.notify (current_inferior ());
}
/* Kill the inferior if already running. This function is designed
diff --git a/gdb/jit.c b/gdb/jit.c
index 9298ac0f4877..6f1f7e69d5e5 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -1232,7 +1232,7 @@ jit_inferior_init (struct gdbarch *gdbarch)
/* inferior_created observer. */
static void
-jit_inferior_created ()
+jit_inferior_created (inferior *inf)
{
jit_inferior_created_hook ();
}
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index c625cefead2f..e759ecc95135 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1310,7 +1310,7 @@ check_pid_namespace_match (void)
This handles the case of debugging statically linked executables. */
static void
-thread_db_inferior_created ()
+thread_db_inferior_created (inferior *inf)
{
check_pid_namespace_match ();
check_for_thread_db ();
diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
index e4fc2faecb20..752260e86164 100644
--- a/gdb/m68k-linux-tdep.c
+++ b/gdb/m68k-linux-tdep.c
@@ -211,7 +211,7 @@ struct m68k_linux_sigtramp_info
static int target_is_uclinux;
static void
-m68k_linux_inferior_created ()
+m68k_linux_inferior_created (inferior *inf)
{
/* Record that we will need to re-evaluate whether we are running on a
uClinux or normal GNU/Linux target (see m68k_linux_get_sigtramp_info). */
diff --git a/gdb/observable.h b/gdb/observable.h
index d9d0f149f6f5..9114b28d04f0 100644
--- a/gdb/observable.h
+++ b/gdb/observable.h
@@ -87,7 +87,7 @@ extern observable<> executable_changed;
instruction. For 'attach' and 'core', gdb calls this observer
immediately after connecting to the inferior, and before any
information on the inferior has been printed. */
-extern observable<> inferior_created;
+extern observable<inferior */* inferior */> inferior_created;
/* The status of process record for inferior inferior in gdb has
changed. The process record is started if STARTED is true, and
diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index a7c59ad325a3..29f8ae1ae5f7 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -657,7 +657,7 @@ ravenscar_thread_target::xfer_partial (enum target_object object,
/* Observer on inferior_created: push ravenscar thread stratum if needed. */
static void
-ravenscar_inferior_created ()
+ravenscar_inferior_created (inferior *inf)
{
const char *err_msg;
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 5f212e10323f..18ab9357dbb0 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -157,7 +157,7 @@ add_symbol_file_from_memory_command (const char *args, int from_tty)
This function is called via the inferior_created observer. */
static void
-add_vsyscall_page ()
+add_vsyscall_page (inferior *inf)
{
struct mem_range vsyscall_range;
--
2.28.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/4] gdb: pass inferior to check_pid_namespace_match
2020-10-18 23:15 [PATCH 0/4] Add inferior parameter to inferior_created and use it Simon Marchi
2020-10-18 23:15 ` [PATCH 1/4] gdb: add inferior parameter to inferior_created observable Simon Marchi
@ 2020-10-18 23:15 ` Simon Marchi
2020-10-18 23:15 ` [PATCH 3/4] gdb: make jit.c use the inferior_created inferior parameter Simon Marchi
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2020-10-18 23:15 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
From: Simon Marchi <simon.marchi@efficios.com>
Pass the inferior argument available in thread_db_inferior_created, and
use it to do most things requiring the inferior.
check_pid_namespace_match is not completely decoupled from the current
inferior yet, there are hidden references behind target_can_run, for
example. But I think this is still a good step forward.
gdb/ChangeLog:
* linux-thread-db.c (check_pid_namespace_match): Add inferior
parameter and use it.
(thread_db_inferior_created): Pass inferior argument.
Change-Id: Ib768b14fc61dcf115fe13f776691f2c2f36e0679
---
gdb/linux-thread-db.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index e759ecc95135..7cbdfa5080d9 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1286,7 +1286,7 @@ thread_db_new_objfile (struct objfile *objfile)
}
static void
-check_pid_namespace_match (void)
+check_pid_namespace_match (inferior *inf)
{
/* Check is only relevant for local targets targets. */
if (target_can_run ())
@@ -1296,7 +1296,7 @@ check_pid_namespace_match (void)
child's thread list, we'll mistakenly think it has no threads
since the thread PID fields won't match the PID we give to
libthread_db. */
- if (!linux_ns_same (inferior_ptid.pid (), LINUX_NS_PID))
+ if (!linux_ns_same (inf->pid, LINUX_NS_PID))
{
warning (_ ("Target and debugger are in different PID "
"namespaces; thread lists and other data are "
@@ -1312,7 +1312,7 @@ check_pid_namespace_match (void)
static void
thread_db_inferior_created (inferior *inf)
{
- check_pid_namespace_match ();
+ check_pid_namespace_match (inf);
check_for_thread_db ();
}
--
2.28.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/4] gdb: make jit.c use the inferior_created inferior parameter
2020-10-18 23:15 [PATCH 0/4] Add inferior parameter to inferior_created and use it Simon Marchi
2020-10-18 23:15 ` [PATCH 1/4] gdb: add inferior parameter to inferior_created observable Simon Marchi
2020-10-18 23:15 ` [PATCH 2/4] gdb: pass inferior to check_pid_namespace_match Simon Marchi
@ 2020-10-18 23:15 ` Simon Marchi
2020-10-18 23:15 ` [PATCH 4/4] gdb: use inferior parameter in add_vsyscall_page Simon Marchi
2020-10-24 4:02 ` [PATCH 0/4] Add inferior parameter to inferior_created and use it Joel Brobecker
4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2020-10-18 23:15 UTC (permalink / raw)
To: gdb-patches
Use the inferior parameter now available in jit_inferior_created_hook.
It is passed down to jit_inferior_init, which uses it as much as
possible instead of the current inferior or current program space.
gdb/ChangeLog:
* jit.c (jit_reader_load_command): Pass current inferior.
(jit_inferior_init): Change parameter type to inferior, use it.
(jit_inferior_created): Remove.
(jit_inferior_created_hook): Pass inferior parameter down.
(_initialize_jit): Use jit_inferior_created_hook instead of
jit_inferior_created.
* jit.h (jit_inferior_created_hook): Add inferior parameter.
* infrun.c (follow_exec): Pass inferior to
jit_inferior_created_hook.
Change-Id: If3a2114a933370dd313d5abd623136d273cdb8fa
---
gdb/infrun.c | 2 +-
gdb/jit.c | 27 ++++++++++-----------------
gdb/jit.h | 3 ++-
3 files changed, 13 insertions(+), 19 deletions(-)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 8ae39a2877b3..e3194b61441e 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1236,7 +1236,7 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
solib_create_inferior_hook (0);
- jit_inferior_created_hook ();
+ jit_inferior_created_hook (inf);
breakpoint_re_set ();
diff --git a/gdb/jit.c b/gdb/jit.c
index 6f1f7e69d5e5..fd24d5391596 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -49,7 +49,6 @@ static const char jit_break_name[] = "__jit_debug_register_code";
static const char jit_descriptor_name[] = "__jit_debug_descriptor";
-static void jit_inferior_init (struct gdbarch *gdbarch);
static void jit_inferior_exit_hook (struct inferior *inf);
/* An unwinder is registered for every gdbarch. This key is used to
@@ -221,7 +220,7 @@ jit_reader_load_command (const char *args, int from_tty)
loaded_jit_reader = jit_reader_load (file.get ());
reinit_frame_cache ();
- jit_inferior_created_hook ();
+ jit_inferior_created_hook (current_inferior ());
}
/* Provides the jit-reader-unload command. */
@@ -1178,20 +1177,22 @@ jit_prepend_unwinder (struct gdbarch *gdbarch)
/* Register any already created translations. */
static void
-jit_inferior_init (struct gdbarch *gdbarch)
+jit_inferior_init (inferior *inf)
{
struct jit_descriptor descriptor;
struct jit_code_entry cur_entry;
CORE_ADDR cur_entry_addr;
+ struct gdbarch *gdbarch = inf->gdbarch;
+ program_space *pspace = inf->pspace;
if (jit_debug)
fprintf_unfiltered (gdb_stdlog, "jit_inferior_init\n");
jit_prepend_unwinder (gdbarch);
- jit_breakpoint_re_set_internal (gdbarch, current_program_space);
+ jit_breakpoint_re_set_internal (gdbarch, pspace);
- for (objfile *jiter : current_program_space->objfiles ())
+ for (objfile *jiter : pspace->objfiles ())
{
if (jiter->jiter_data == nullptr)
continue;
@@ -1229,20 +1230,12 @@ jit_inferior_init (struct gdbarch *gdbarch)
}
}
-/* inferior_created observer. */
-
-static void
-jit_inferior_created (inferior *inf)
-{
- jit_inferior_created_hook ();
-}
-
-/* Exported routine to call when an inferior has been created. */
+/* See jit.h. */
void
-jit_inferior_created_hook (void)
+jit_inferior_created_hook (inferior *inf)
{
- jit_inferior_init (target_gdbarch ());
+ jit_inferior_init (inf);
}
/* Exported routine to call to re-set the jit breakpoints,
@@ -1343,7 +1336,7 @@ _initialize_jit ()
show_jit_debug,
&setdebuglist, &showdebuglist);
- gdb::observers::inferior_created.attach (jit_inferior_created);
+ gdb::observers::inferior_created.attach (jit_inferior_created_hook);
gdb::observers::inferior_exit.attach (jit_inferior_exit_hook);
gdb::observers::breakpoint_deleted.attach (jit_breakpoint_deleted);
diff --git a/gdb/jit.h b/gdb/jit.h
index 739a8f30e2c6..6f972a6e077a 100644
--- a/gdb/jit.h
+++ b/gdb/jit.h
@@ -20,6 +20,7 @@
#ifndef JIT_H
#define JIT_H
+struct inferior;
struct objfile;
struct minimal_symbol;
@@ -107,7 +108,7 @@ struct jited_objfile_data
already JITed code. If it has already found the symbols, then it
doesn't try again. */
-extern void jit_inferior_created_hook (void);
+extern void jit_inferior_created_hook (inferior *inf);
/* Re-establish the jit breakpoint(s). */
--
2.28.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/4] gdb: use inferior parameter in add_vsyscall_page
2020-10-18 23:15 [PATCH 0/4] Add inferior parameter to inferior_created and use it Simon Marchi
` (2 preceding siblings ...)
2020-10-18 23:15 ` [PATCH 3/4] gdb: make jit.c use the inferior_created inferior parameter Simon Marchi
@ 2020-10-18 23:15 ` Simon Marchi
2020-10-24 4:02 ` [PATCH 0/4] Add inferior parameter to inferior_created and use it Joel Brobecker
4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2020-10-18 23:15 UTC (permalink / raw)
To: gdb-patches
Use the new inferior parameter instead of target_gdbarch. There are
still hidden references to the current context behind core_bfd and
exec_bfd, but this seemed better than nothing.
gdb/ChangeLog:
* symfile-mem.c (add_vsyscall_page): Use inferior parameter
instead of target_gdbarch.
Change-Id: Iaf5ace555ee8e46cbef5190aca1f6fe639f06677
---
gdb/symfile-mem.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 18ab9357dbb0..62c5664879fd 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -53,6 +53,7 @@
#include "auxv.h"
#include "elf/common.h"
#include "gdb_bfd.h"
+#include "inferior.h"
/* Verify parameters of target_read_memory_bfd and target_read_memory are
compatible. */
@@ -161,7 +162,7 @@ add_vsyscall_page (inferior *inf)
{
struct mem_range vsyscall_range;
- if (gdbarch_vsyscall_range (target_gdbarch (), &vsyscall_range))
+ if (gdbarch_vsyscall_range (inf->gdbarch, &vsyscall_range))
{
struct bfd *bfd;
--
2.28.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] Add inferior parameter to inferior_created and use it
2020-10-18 23:15 [PATCH 0/4] Add inferior parameter to inferior_created and use it Simon Marchi
` (3 preceding siblings ...)
2020-10-18 23:15 ` [PATCH 4/4] gdb: use inferior parameter in add_vsyscall_page Simon Marchi
@ 2020-10-24 4:02 ` Joel Brobecker
2020-10-25 13:06 ` Simon Marchi
4 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2020-10-24 4:02 UTC (permalink / raw)
To: Simon Marchi via Gdb-patches
Hi Simon,
On Sun, Oct 18, 2020 at 07:15:22PM -0400, Simon Marchi via Gdb-patches wrote:
> I made this in the context of some other work, and I think it makes
> sense on its own, so I am posting it on its own.
>
> Simon Marchi (4):
> gdb: add inferior parameter to inferior_created observable
> gdb: pass inferior to check_pid_namespace_match
> gdb: make jit.c use the inferior_created inferior parameter
> gdb: use inferior parameter in add_vsyscall_page
I went through the patches, and they look good to me :-).
I understand that there are still some hidden references to the
"current" context, but it's a nice step forward towards reducing
those, so thank you!
--
Joel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] Add inferior parameter to inferior_created and use it
2020-10-24 4:02 ` [PATCH 0/4] Add inferior parameter to inferior_created and use it Joel Brobecker
@ 2020-10-25 13:06 ` Simon Marchi
0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2020-10-25 13:06 UTC (permalink / raw)
To: Joel Brobecker, Simon Marchi via Gdb-patches
On 2020-10-24 12:02 a.m., Joel Brobecker wrote:
> Hi Simon,
>
> On Sun, Oct 18, 2020 at 07:15:22PM -0400, Simon Marchi via Gdb-patches wrote:
>> I made this in the context of some other work, and I think it makes
>> sense on its own, so I am posting it on its own.
>>
>> Simon Marchi (4):
>> gdb: add inferior parameter to inferior_created observable
>> gdb: pass inferior to check_pid_namespace_match
>> gdb: make jit.c use the inferior_created inferior parameter
>> gdb: use inferior parameter in add_vsyscall_page
>
> I went through the patches, and they look good to me :-).
> I understand that there are still some hidden references to the
> "current" context, but it's a nice step forward towards reducing
> those, so thank you!
Thanks, I pushed the series.
Simon
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-10-25 13:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-18 23:15 [PATCH 0/4] Add inferior parameter to inferior_created and use it Simon Marchi
2020-10-18 23:15 ` [PATCH 1/4] gdb: add inferior parameter to inferior_created observable Simon Marchi
2020-10-18 23:15 ` [PATCH 2/4] gdb: pass inferior to check_pid_namespace_match Simon Marchi
2020-10-18 23:15 ` [PATCH 3/4] gdb: make jit.c use the inferior_created inferior parameter Simon Marchi
2020-10-18 23:15 ` [PATCH 4/4] gdb: use inferior parameter in add_vsyscall_page Simon Marchi
2020-10-24 4:02 ` [PATCH 0/4] Add inferior parameter to inferior_created and use it Joel Brobecker
2020-10-25 13:06 ` Simon Marchi
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).