[gdb, hurd] Work around conflict between Mach's 'thread_info' function, and GDB's...
authorThomas Schwinge <thomas@codesourcery.com>
Wed, 13 Feb 2019 11:02:20 +0000 (12:02 +0100)
committerThomas Schwinge <thomas@codesourcery.com>
Thu, 14 Feb 2019 15:02:33 +0000 (16:02 +0100)
    In file included from ./nm.h:25:0,
                     from [...]/gdb/defs.h:423,
                     from [...]/gdb/gdb.c:19:
    [...]/gdb/regcache.h:35:46: warning: 'get_thread_regcache' initialized and declared 'extern'
     extern struct regcache *get_thread_regcache (thread_info *thread);
                                                  ^~~~~~~~~~~
    [...]/gdb/regcache.h:35:46: error: 'regcache* get_thread_regcache' redeclared as different kind of symbol
    [...]
    [...]/gdb/gdbarch.h:1203:69: error: 'thread_info' is not a type
     extern LONGEST gdbarch_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread);
                                                                         ^~~~~~~~~~~

Fixed with a different (self-contained, more maintainable?) approach compared
to what has been done in commit 7aabaf9d4ad52a1df1f551908fbd8cafc5e7597a
"Create private_thread_info hierarchy", and commit
75cbc781e371279f4403045be93b07fd8fe7fde5 "gdb: For macOS, s/thread_info/struct
thread_info/".  We don't want to change all the GDB code to everywhere use
'class thread_info' or 'struct thread_info' instead of plain 'thread_info'.

gdb/
* config/i386/nm-i386gnu.h: Don't "#include" any files.
* gnu-nat.h (mach_thread_info): New function.
* gnu-nat.c (thread_takeover_sc_cmd): Use it.

gdb/ChangeLog
gdb/config/i386/nm-i386gnu.h
gdb/gnu-nat.c
gdb/gnu-nat.h
gdb/i386-gnu-nat.c

index e6d86e25520b9a98c157caa574d67046c6757c41..c88216b94b730a934f9ef9d90053f4d00622c0bc 100644 (file)
@@ -1,5 +1,9 @@
 2019-02-14  Thomas Schwinge  <thomas@codesourcery.com>
 
+       * config/i386/nm-i386gnu.h: Don't "#include" any files.
+       * gnu-nat.h (mach_thread_info): New function.
+       * gnu-nat.c (thread_takeover_sc_cmd): Use it.
+
        * config/i386/nm-i386gnu.h (gnu_target_pid_to_str): Remove.
 
 2019-02-14  Frederic Konrad  <konrad@adacore.com>
index 8f36102da499b1a739b54d2969541c7f8da0b61b..e859b23f2b23b6b2aa2e9c7db086d819957414a6 100644 (file)
 #ifndef CONFIG_I386_NM_I386GNU_H
 #define CONFIG_I386_NM_I386GNU_H
 
-#include <unistd.h>
-#include <mach.h>
-#include <mach/exception.h>
-#include "regcache.h"
-
 /* Thread flavors used in re-setting the T bit.  */
 #define THREAD_STATE_FLAVOR            i386_REGS_SEGS_STATE
 #define THREAD_STATE_SIZE              i386_THREAD_STATE_COUNT
index cb8331daaf4c128fca61b31ec6c8610744a3a51d..bd8fcb6e59bfdac162cfd5cf17facb77fda9a404 100644 (file)
@@ -20,6 +20,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* Include this first, to pick up the <mach.h> 'thread_info' diversion.  */
+#include "gnu-nat.h"
+
 /* Mach/Hurd headers are not yet ready for C++ compilation.  */
 extern "C"
 {
@@ -67,7 +70,6 @@ extern "C"
 #include "gdb_obstack.h"
 #include "tid-parse.h"
 
-#include "gnu-nat.h"
 #include "inf-child.h"
 
 /* MIG stubs are not yet ready for C++ compilation.  */
@@ -3429,8 +3431,9 @@ thread_takeover_sc_cmd (const char *args, int from_tty)
   thread_basic_info_data_t _info;
   thread_basic_info_t info = &_info;
   mach_msg_type_number_t info_len = THREAD_BASIC_INFO_COUNT;
-  kern_return_t err =
-  thread_info (thread->port, THREAD_BASIC_INFO, (int *) &info, &info_len);
+  kern_return_t err
+    = mach_thread_info (thread->port, THREAD_BASIC_INFO,
+                       (int *) &info, &info_len);
   if (err)
     error (("%s."), safe_strerror (err));
   thread->sc = info->suspend_count;
index 9df479c8506a72ff7f6ebefa2b8f9e71d790a833..dbad0cac93f78577627f1fa77ba1f3fdf1944664 100644 (file)
 #ifndef GNU_NAT_H
 #define GNU_NAT_H
 
-#include <unistd.h>
+#include "defs.h"
+
+/* Work around conflict between Mach's 'thread_info' function, and GDB's
+   'thread_info' class.  Make the former available as 'mach_thread_info'.  */
+#define thread_info mach_thread_info
+/* Mach headers are not yet ready for C++ compilation.  */
+extern "C"
+{
 #include <mach.h>
+}
+#undef thread_info
+/* Divert 'mach_thread_info' to the original Mach 'thread_info' function.  */
+extern __typeof__ (mach_thread_info) mach_thread_info asm ("thread_info");
+
+#include <unistd.h>
 
 struct inf;
 
index ffba941eef935940b39b46f70634bf8d002fd3ca..c23c4bc79cfc18fd3b0003dd9bd1ac2e718514f1 100644 (file)
@@ -17,6 +17,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* Include this first, to pick up the <mach.h> 'thread_info' diversion.  */
+#include "gnu-nat.h"
+
 /* Mach/Hurd headers are not yet ready for C++ compilation.  */
 extern "C"
 {
@@ -34,7 +37,6 @@ extern "C"
 
 #include "i386-tdep.h"
 
-#include "gnu-nat.h"
 #include "inf-child.h"
 #include "i387-tdep.h"