Make target_ops::has_execution take an 'inferior *' instead of a ptid_t
authorPedro Alves <palves@redhat.com>
Fri, 10 Jan 2020 20:05:44 +0000 (20:05 +0000)
committerPedro Alves <palves@redhat.com>
Fri, 10 Jan 2020 20:05:44 +0000 (20:05 +0000)
With the multi-target work, each inferior will have its own target
stack, so to call a target method, we'll need to make sure that the
inferior in question is the current one, otherwise target->beneath()
calls will find the target beneath in the wrong inferior.

In some places, it's much more convenient to be able to check whether
an inferior has execution without having to switch to it in order to
call target_has_execution on the right inferior/target stack, to avoid
side effects with switching inferior/thread/program space.

The current target_ops::has_execution method takes a ptid_t as
parameter, which, in a multi-target world, isn't sufficient to
identify the target.  This patch prepares to address that, by changing
the parameter to an inferior pointer instead.  From the inferior,
we'll be able to query its target stack to tell which target is
beneath.

Also adds a new inferior::has_execution() method to make callers a bit
more natural to read.

gdb/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

* corelow.c (core_target::has_execution): Change parameter type to
inferior pointer.
* inferior.c (number_of_live_inferiors): Use
inferior::has_execution instead of target_has_execution_1.
* inferior.h (inferior::has_execution): New.
* linux-thread-db.c (thread_db_target::update_thread_list): Use
inferior::has_execution instead of target_has_execution_1.
* process-stratum-target.c
(process_stratum_target::has_execution): Change parameter type to
inferior pointer.  Check the inferior's PID instead of
inferior_ptid.
* process-stratum-target.h
(process_stratum_target::has_execution): Change parameter type to
inferior pointer.
* record-full.c (record_full_core_target::has_execution): Change
parameter type to inferior pointer.
* target.c (target_has_execution_1): Change parameter type to
inferior pointer.
(target_has_execution_current): Adjust.
* target.h (target_ops::has_execution): Change parameter type to
inferior pointer.
(target_has_execution_1): Change parameter type to inferior
pointer.  Change return type to bool.
* tracefile.h (tracefile_target::has_execution): Change parameter
type to inferior pointer.

gdb/ChangeLog
gdb/corelow.c
gdb/inferior.c
gdb/inferior.h
gdb/linux-thread-db.c
gdb/process-stratum-target.c
gdb/process-stratum-target.h
gdb/record-full.c
gdb/target.c
gdb/target.h
gdb/tracefile.h

index 1100e421414d7719d9e0e7f6ce4588d245705914..6e97bd46a15877bf8a82796259e5e5cdc5c1e254 100644 (file)
@@ -1,3 +1,31 @@
+2020-01-10  Pedro Alves  <palves@redhat.com>
+
+       * corelow.c (core_target::has_execution): Change parameter type to
+       inferior pointer.
+       * inferior.c (number_of_live_inferiors): Use
+       inferior::has_execution instead of target_has_execution_1.
+       * inferior.h (inferior::has_execution): New.
+       * linux-thread-db.c (thread_db_target::update_thread_list): Use
+       inferior::has_execution instead of target_has_execution_1.
+       * process-stratum-target.c
+       (process_stratum_target::has_execution): Change parameter type to
+       inferior pointer.  Check the inferior's PID instead of
+       inferior_ptid.
+       * process-stratum-target.h
+       (process_stratum_target::has_execution): Change parameter type to
+       inferior pointer.
+       * record-full.c (record_full_core_target::has_execution): Change
+       parameter type to inferior pointer.
+       * target.c (target_has_execution_1): Change parameter type to
+       inferior pointer.
+       (target_has_execution_current): Adjust.
+       * target.h (target_ops::has_execution): Change parameter type to
+       inferior pointer.
+       (target_has_execution_1): Change parameter type to inferior
+       pointer.  Change return type to bool.
+       * tracefile.h (tracefile_target::has_execution): Change parameter
+       type to inferior pointer.
+
 2020-01-10  Pedro Alves  <palves@redhat.com>
 
        * exceptions.c (print_flush): Remove current_top_target() check.
index 0ec70c28b90d16b540a3eb08250af8ef74b968c1..74f660828df2b6b085f5f55b8ea433399303e4ef 100644 (file)
@@ -94,7 +94,7 @@ public:
   bool has_memory () override;
   bool has_stack () override;
   bool has_registers () override;
-  bool has_execution (ptid_t) override { return false; }
+  bool has_execution (inferior *inf) override { return false; }
 
   bool info_proc (const char *, enum info_proc_what) override;
 
index 98829252e5cf065cf6232f9b139b32de7ad0b607..3969ace13a848a411b6944ef45cf9cbfe0f7fcf8 100644 (file)
@@ -345,7 +345,7 @@ number_of_live_inferiors (void)
   int num_inf = 0;
 
   for (inferior *inf : all_non_exited_inferiors ())
-    if (target_has_execution_1 (ptid_t (inf->pid)))
+    if (inf->has_execution ())
       for (thread_info *tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
        {
          /* Found a live thread in this inferior, go to the next
index 3baac6efdabbbcb13ff90c40cb63fa87b4a4026d..fe94a01784df221c5d857ee97f2e2474ce4d2605 100644 (file)
@@ -339,6 +339,9 @@ public:
   /* Returns true if we can delete this inferior.  */
   bool deletable () const { return refcount () == 0; }
 
+  bool has_execution ()
+  { return target_has_execution_1 (this); }
+
   /* Pointer to next inferior in singly-linked list of inferiors.  */
   struct inferior *next = NULL;
 
index 54d96e9b19f2045c9716bf3d2385f322cfc3827f..62908896cc61b10c37ef5ff0cf6f3a73987d63a2 100644 (file)
@@ -1622,7 +1622,7 @@ thread_db_target::update_thread_list ()
         stop.  That uses thread_db entry points that do not walk
         libpthread's thread list, so should be safe, as well as more
         efficient.  */
-      if (target_has_execution_1 (thread->ptid))
+      if (thread->inf->has_execution ())
        continue;
 
       thread_db_find_new_threads_1 (thread);
index d6bc6abc4bb02724e02ec02ab4472ca775970333..658229f0d07ffd36cde9fa7b565108678cdcee0c 100644 (file)
@@ -77,9 +77,9 @@ process_stratum_target::has_registers ()
 }
 
 bool
-process_stratum_target::has_execution (ptid_t the_ptid)
+process_stratum_target::has_execution (inferior *inf)
 {
-  /* If there's no thread selected, then we can't make it run through
-     hoops.  */
-  return the_ptid != null_ptid;
+  /* If there's a process running already, we can't make it run
+     through hoops.  */
+  return inf->pid != 0;
 }
index 9cd2cf21f39871eaef40566e492e2d673d12274f..741e67bb6a6bea456ce36cf44093f9a3c99afe6e 100644 (file)
@@ -50,7 +50,7 @@ public:
   bool has_memory () override;
   bool has_stack () override;
   bool has_registers () override;
-  bool has_execution (ptid_t the_ptid) override;
+  bool has_execution (inferior *inf) override;
 };
 
 #endif /* !defined (PROCESS_STRATUM_TARGET_H) */
index c5ef59015b687a0188714fbcdf258262ab3234f3..1fd72d5c7c99cf3f969c8f65171c401c6797021e 100644 (file)
@@ -319,7 +319,7 @@ public:
                         struct bp_target_info *,
                         enum remove_bp_reason) override;
 
-  bool has_execution (ptid_t) override;
+  bool has_execution (inferior *inf) override;
 };
 
 static record_full_target record_full_ops;
@@ -2244,7 +2244,7 @@ record_full_core_target::remove_breakpoint (struct gdbarch *gdbarch,
 /* "has_execution" method for prec over corefile.  */
 
 bool
-record_full_core_target::has_execution (ptid_t the_ptid)
+record_full_core_target::has_execution (inferior *inf)
 {
   return true;
 }
index e3e30afd7a5450b65101ac2c90d8be7190bd65dd..7e7e875e68c4a357160e687d23a05c7ab06175c0 100644 (file)
@@ -223,20 +223,20 @@ target_has_registers_1 (void)
   return 0;
 }
 
-int
-target_has_execution_1 (ptid_t the_ptid)
+bool
+target_has_execution_1 (inferior *inf)
 {
   for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
-    if (t->has_execution (the_ptid))
-      return 1;
+    if (t->has_execution (inf))
+      return true;
 
-  return 0;
+  return false;
 }
 
 int
 target_has_execution_current (void)
 {
-  return target_has_execution_1 (inferior_ptid);
+  return target_has_execution_1 (current_inferior ());
 }
 
 /* This is used to implement the various target commands.  */
index 1ec7b900b133cdadb293e5ee63d985587b334163..b05a971e60093aa0674c5f66d80d1930958d7f39 100644 (file)
@@ -686,7 +686,7 @@ struct target_ops
     virtual bool has_memory () { return false; }
     virtual bool has_stack () { return false; }
     virtual bool has_registers () { return false; }
-    virtual bool has_execution (ptid_t) { return false; }
+    virtual bool has_execution (inferior *inf) { return false; }
 
     /* Control thread execution.  */
     virtual thread_control_capabilities get_thread_control_capabilities ()
@@ -1790,9 +1790,10 @@ extern int target_has_registers_1 (void);
    case this will become true after to_create_inferior or
    to_attach.  */
 
-extern int target_has_execution_1 (ptid_t);
+extern bool target_has_execution_1 (inferior *inf);
 
-/* Like target_has_execution_1, but always passes inferior_ptid.  */
+/* Like target_has_execution_1, but always passes
+   current_inferior().  */
 
 extern int target_has_execution_current (void);
 
index 8f9dc0e06d7de9210d51747908ecd8ce46b7a525..9c7fdea72970b386bdaaafb387aa411d58bd1c4b 100644 (file)
@@ -127,7 +127,7 @@ public:
   bool has_memory () override;
   bool has_stack () override;
   bool has_registers () override;
-  bool has_execution (ptid_t) override { return false; }
+  bool has_execution (inferior *inf) override { return false; }
   bool thread_alive (ptid_t ptid) override;
 };
 
This page took 0.031205 seconds and 4 git commands to generate.