public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Make "set osabi none" really work
@ 2018-03-22  4:11 Simon Marchi
  2018-03-22  4:11 ` [PATCH 2/2] Fix generation of x86-64 gdbarch with osabi none Simon Marchi
  2018-04-07 17:36 ` [PATCH 1/2] Make "set osabi none" really work Simon Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Simon Marchi @ 2018-03-22  4:11 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

I was looking for a way to reproduce easily PR 22979 by doing this:

  (gdb) set architecture i386:x86-64
  (gdb) set osabi none

However, I noticed that even though I did "set osabi none", the gdbarch
gdb created was for Linux:

  (gdb) set debug arch 1
  (gdb) set architecture i386:x86-64
  ...
  (gdb) set osabi none
  gdbarch_find_by_info: info.bfd_arch_info i386:x86-64
  gdbarch_find_by_info: info.byte_order 1 (little)
  gdbarch_find_by_info: info.osabi 4 (GNU/Linux)  <--- Wrong?
  gdbarch_find_by_info: info.abfd 0x0
  gdbarch_find_by_info: info.tdep_info 0x0
  gdbarch_find_by_info: Previous architecture 0x1e6fd30 (i386:x86-64)
  selected
  gdbarch_update_p: Architecture 0x1e6fd30 (i386:x86-64) unchanged

This is because the value GDB_OSABI_UNKNOWN has an unclear role,
sometimes meaning "no osabi" and sometimes "please selected
automatically".  Doing "set osabi none" sets the requested osabi to
GDB_OSABI_UNKNOWN, in which case gdbarch_info_fill overrides it with a
value from the target description, or the built-in default osabi.  This
means that it's impossible to force GDB not to use an osabi with "set
osabi".  Since my GDB's built-in default osabi is Linux, it always falls
back to GDB_OSABI_LINUX.

To fix it, I introduced GDB_OSABI_NONE, which really means "I don't want
any osabi".  GDB_OSABI_UNKNOWN can then be used only for "not set yet,
please auto-detect".  GDB_OSABI_UNINITIALIZED now seems unnecessary
since it overlaps with GDB_OSABI_UNKNOWN, so I think it can be removed
and gdbarch_info::osabi can be initialized to GDB_OSABI_UNKNOWN.

gdb/ChangeLog:

	* defs.h (enum gdb_osabi): Remove GDB_OSABI_UNINITIALIZED, add
	GDB_OSABI_NONE.
	* arch-utils.c (gdbarch_info_init): Don't set info->osabi.
	* osabi.c (gdb_osabi_names): Add "unknown" entry.

gdb/testsuite/ChangeLog:

	* gdb.base/osabi.exp: New file.
---
 gdb/arch-utils.c                 |  7 +++++--
 gdb/defs.h                       |  3 +--
 gdb/osabi.c                      | 12 +++++-------
 gdb/testsuite/gdb.base/osabi.exp | 26 ++++++++++++++++++++++++++
 4 files changed, 37 insertions(+), 11 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/osabi.exp

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 2ff0f4d..5986ed6 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -727,7 +727,6 @@ gdbarch_info_init (struct gdbarch_info *info)
   memset (info, 0, sizeof (struct gdbarch_info));
   info->byte_order = BFD_ENDIAN_UNKNOWN;
   info->byte_order_for_code = info->byte_order;
-  info->osabi = GDB_OSABI_UNINITIALIZED;
 }
 
 /* Similar to init, but this time fill in the blanks.  Information is
@@ -772,9 +771,10 @@ gdbarch_info_fill (struct gdbarch_info *info)
 
   /* "(gdb) set osabi ...".  Handled by gdbarch_lookup_osabi.  */
   /* From the manual override, or from file.  */
-  if (info->osabi == GDB_OSABI_UNINITIALIZED)
+  if (info->osabi == GDB_OSABI_UNKNOWN)
     info->osabi = gdbarch_lookup_osabi (info->abfd);
   /* From the target.  */
+
   if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
     info->osabi = tdesc_osabi (info->target_desc);
   /* From the configured default.  */
@@ -782,6 +782,9 @@ gdbarch_info_fill (struct gdbarch_info *info)
   if (info->osabi == GDB_OSABI_UNKNOWN)
     info->osabi = GDB_OSABI_DEFAULT;
 #endif
+  /* If we still don't know which osabi to pick, pick none.  */
+  if (info->osabi == GDB_OSABI_UNKNOWN)
+    info->osabi = GDB_OSABI_NONE;
 
   /* Must have at least filled in the architecture.  */
   gdb_assert (info->bfd_arch_info != NULL);
diff --git a/gdb/defs.h b/gdb/defs.h
index ff3599d..dc38a28 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -482,9 +482,8 @@ extern int longest_to_int (LONGEST);
    table in osabi.c.  */
 enum gdb_osabi
 {
-  GDB_OSABI_UNINITIALIZED = -1, /* For struct gdbarch_info.  */
-
   GDB_OSABI_UNKNOWN = 0,	/* keep this zero */
+  GDB_OSABI_NONE,
 
   GDB_OSABI_SVR4,
   GDB_OSABI_HURD,
diff --git a/gdb/osabi.c b/gdb/osabi.c
index fd44deb..ef1d993 100644
--- a/gdb/osabi.c
+++ b/gdb/osabi.c
@@ -58,6 +58,7 @@ struct osabi_names
    them in sync.  */
 static const struct osabi_names gdb_osabi_names[] =
 {
+  { "unknown", NULL },
   { "none", NULL },
 
   { "SVR4", NULL },
@@ -335,9 +336,11 @@ gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   struct gdb_osabi_handler *handler;
 
-  if (info.osabi == GDB_OSABI_UNKNOWN)
+  gdb_assert (info.osabi != GDB_OSABI_UNKNOWN);
+
+  if (info.osabi == GDB_OSABI_NONE)
     {
-      /* Don't complain about an unknown OSABI.  Assume the user knows
+      /* Don't complain about no OSABI.  Assume the user knows
 	 what they are doing.  */
       return;
     }
@@ -603,11 +606,6 @@ set_osabi (const char *args, int from_tty, struct cmd_list_element *c)
       user_selected_osabi = GDB_OSABI_DEFAULT;
       user_osabi_state = osabi_user;
     }
-  else if (strcmp (set_osabi_string, "none") == 0)
-    {
-      user_selected_osabi = GDB_OSABI_UNKNOWN;
-      user_osabi_state = osabi_user;
-    }
   else
     {
       int i;
diff --git a/gdb/testsuite/gdb.base/osabi.exp b/gdb/testsuite/gdb.base/osabi.exp
new file mode 100644
index 0000000..8d1ab5b
--- /dev/null
+++ b/gdb/testsuite/gdb.base/osabi.exp
@@ -0,0 +1,26 @@
+# Copyright (C) 2018 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite.
+
+# Test that choosing "set osabi none" really requests a gdbarch with no osabi.
+
+proc test_set_osabi_none { } {
+    clean_restart
+    gdb_test_no_output "set debug arch 1"
+    gdb_test "set osabi none" ".*gdbarch_find_by_info: info.osabi 1 \\(none\\).*"
+}
+
+test_set_osabi_none
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Fix generation of x86-64 gdbarch with osabi none
  2018-03-22  4:11 [PATCH 1/2] Make "set osabi none" really work Simon Marchi
@ 2018-03-22  4:11 ` Simon Marchi
  2018-04-07 17:36 ` [PATCH 1/2] Make "set osabi none" really work Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2018-03-22  4:11 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

When a 64-bits (x86-64) gdbarch is created, it is first born as a
32-bits gdbarch in i386_gdbarch_init.  The call gdbarch_init_osabi will
call the handler register for the selected (arch, osabi) pair, such as
amd64_linux_init_abi.  The various amd64 handlers call amd64_init_abi,
which turns the gdbarch into a 64-bits one.

When selecting the i386:x86-64 architecture with no osabi, no such
handler is ever called, so the gdbarch stays (wrongfully) a 32-bits one.

My first idea was to manually call amd64_init_abi & al in
i386_gdbarch_init when the osabi is GDB_OSABI_NONE.  However, this
doesn't work in a build of GDB where i386 is included as a target but
not amd64.  My next option (implemented in this patch), is to allow
registering handlers for GDB_OSABI_NONE.  I added two such handlers in
amd64-tdep.c, so now it works the same as for the "normal" osabis.  It
required re-ordering things in gdbarch_init_osabi to allow running
handlers for GDB_OSABI_NONE.

Without this patch applied (but with the previous one*) :

  (gdb) set osabi none
  (gdb) set architecture i386:x86-64
  The target architecture is assumed to be i386:x86-64
  (gdb) p sizeof(void*)
  $1 = 4

and now:

  (gdb) set osabi none
  (gdb) set architecture i386:x86-64
  The target architecture is assumed to be i386:x86-64
  (gdb) p sizeof(void*)
  $1 = 8

* Before the previous patch, which fixed "set osabi none", this bug was
  hidden because we didn't actually try to generate a gdbarch for no
  osabi, it would always fall back on Linux.  Generating the gdbarch for
  amd64/linux did work.

gdb/ChangeLog:

	PR gdb/22979
	* amd64-tdep.c (amd64_none_init_abi): New function.
	(amd64_x32_none_init_abi): New function.
	(_initialize_amd64_tdep): Register handlers for x86-64 and
	x64_32 with GDB_OSABI_NONE.
	* osabi.c (gdbarch_init_osabi): Allow running handlers for the
	GDB_OSABI_NONE osabi.

gdb/testsuite/ChangeLog:

	PR gdb/22979
	* gdb.arch/amd64-osabi.exp: New file.
---
 gdb/amd64-tdep.c                       | 24 ++++++++++++++++++-
 gdb/osabi.c                            | 14 +++++------
 gdb/testsuite/gdb.arch/amd64-osabi.exp | 43 ++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 8 deletions(-)
 create mode 100644 gdb/testsuite/gdb.arch/amd64-osabi.exp

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 07eef5e..bceb6e1 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -47,6 +47,7 @@
 #include "ax.h"
 #include "ax-gdb.h"
 #include "common/byte-vector.h"
+#include "osabi.h"
 
 /* Note that the AMD64 architecture was previously known as x86-64.
    The latter is (forever) engraved into the canonical system name as
@@ -3206,7 +3207,14 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
   set_gdbarch_insn_is_ret (gdbarch, amd64_insn_is_ret);
   set_gdbarch_insn_is_jump (gdbarch, amd64_insn_is_jump);
 }
-\f
+
+/* Initialize ARCH for x86-64, no osabi.  */
+
+static void
+amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
+{
+  amd64_init_abi (info, arch, amd64_target_description (X86_XSTATE_SSE_MASK));
+}
 
 static struct type *
 amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
@@ -3240,6 +3248,15 @@ amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
   set_gdbarch_ptr_bit (gdbarch, 32);
 }
 
+/* Initialize ARCH for x64-32, no osabi.  */
+
+static void
+amd64_x32_none_init_abi (gdbarch_info info, gdbarch *arch)
+{
+  amd64_x32_init_abi (info, arch,
+		      amd64_target_description (X86_XSTATE_SSE_MASK));
+}
+
 /* Return the target description for a specified XSAVE feature mask.  */
 
 const struct target_desc *
@@ -3263,6 +3280,11 @@ amd64_target_description (uint64_t xcr0)
 void
 _initialize_amd64_tdep (void)
 {
+  gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, GDB_OSABI_NONE,
+ 			  amd64_none_init_abi);
+  gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x64_32, GDB_OSABI_NONE,
+ 			  amd64_x32_none_init_abi);
+
 #if GDB_SELF_TEST
   struct
   {
diff --git a/gdb/osabi.c b/gdb/osabi.c
index ef1d993..7d0540b 100644
--- a/gdb/osabi.c
+++ b/gdb/osabi.c
@@ -338,13 +338,6 @@ gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   gdb_assert (info.osabi != GDB_OSABI_UNKNOWN);
 
-  if (info.osabi == GDB_OSABI_NONE)
-    {
-      /* Don't complain about no OSABI.  Assume the user knows
-	 what they are doing.  */
-      return;
-    }
-
   for (handler = gdb_osabi_handler_list; handler != NULL;
        handler = handler->next)
     {
@@ -378,6 +371,13 @@ gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 	}
     }
 
+  if (info.osabi == GDB_OSABI_NONE)
+    {
+      /* Don't complain about no OSABI.  Assume the user knows
+	 what they are doing.  */
+      return;
+    }
+
   warning
     ("A handler for the OS ABI \"%s\" is not built into this configuration\n"
      "of GDB.  Attempting to continue with the default %s settings.\n",
diff --git a/gdb/testsuite/gdb.arch/amd64-osabi.exp b/gdb/testsuite/gdb.arch/amd64-osabi.exp
new file mode 100644
index 0000000..9705797
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-osabi.exp
@@ -0,0 +1,43 @@
+# Copyright 2018 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Verify that gdbarches for i386 variants and osabi none are properly created.
+
+if { ![istarget x86_64-*-* ] } {
+    untested "skipping x86-64 specific test"
+    return
+}
+
+
+proc_with_prefix test_osabi_none { arch void_ptr_size long_double_size } {
+    clean_restart
+
+    gdb_test "set architecture i386:x86-64" "The target architecture is assumed to be i386:x86-64"
+    gdb_test_no_output "set osabi none" "set osabi none"
+    gdb_test "print sizeof (void*)" " = 8"
+    gdb_test "print sizeof (long double)" " = 16"
+}
+
+set infos { \
+    { "i386:x86-64" 8 16 } \
+    { "i386:x64-32" 4 16 } \
+    { "i386"        4 12 } }
+
+foreach info $infos {
+    lassign $info arch void_ptr_size long_double_size
+    with_test_prefix "arch=$arch" {
+	test_osabi_none $arch $void_ptr_size $long_double_size
+    }
+}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Make "set osabi none" really work
  2018-03-22  4:11 [PATCH 1/2] Make "set osabi none" really work Simon Marchi
  2018-03-22  4:11 ` [PATCH 2/2] Fix generation of x86-64 gdbarch with osabi none Simon Marchi
@ 2018-04-07 17:36 ` Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2018-04-07 17:36 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On 2018-03-22 00:11, Simon Marchi wrote:
> I was looking for a way to reproduce easily PR 22979 by doing this:
> 
>   (gdb) set architecture i386:x86-64
>   (gdb) set osabi none
> 
> However, I noticed that even though I did "set osabi none", the gdbarch
> gdb created was for Linux:
> 
>   (gdb) set debug arch 1
>   (gdb) set architecture i386:x86-64
>   ...
>   (gdb) set osabi none
>   gdbarch_find_by_info: info.bfd_arch_info i386:x86-64
>   gdbarch_find_by_info: info.byte_order 1 (little)
>   gdbarch_find_by_info: info.osabi 4 (GNU/Linux)  <--- Wrong?
>   gdbarch_find_by_info: info.abfd 0x0
>   gdbarch_find_by_info: info.tdep_info 0x0
>   gdbarch_find_by_info: Previous architecture 0x1e6fd30 (i386:x86-64)
>   selected
>   gdbarch_update_p: Architecture 0x1e6fd30 (i386:x86-64) unchanged
> 
> This is because the value GDB_OSABI_UNKNOWN has an unclear role,
> sometimes meaning "no osabi" and sometimes "please selected
> automatically".  Doing "set osabi none" sets the requested osabi to
> GDB_OSABI_UNKNOWN, in which case gdbarch_info_fill overrides it with a
> value from the target description, or the built-in default osabi.  This
> means that it's impossible to force GDB not to use an osabi with "set
> osabi".  Since my GDB's built-in default osabi is Linux, it always 
> falls
> back to GDB_OSABI_LINUX.
> 
> To fix it, I introduced GDB_OSABI_NONE, which really means "I don't 
> want
> any osabi".  GDB_OSABI_UNKNOWN can then be used only for "not set yet,
> please auto-detect".  GDB_OSABI_UNINITIALIZED now seems unnecessary
> since it overlaps with GDB_OSABI_UNKNOWN, so I think it can be removed
> and gdbarch_info::osabi can be initialized to GDB_OSABI_UNKNOWN.

I pushed these two patches in.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-07 17:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-22  4:11 [PATCH 1/2] Make "set osabi none" really work Simon Marchi
2018-03-22  4:11 ` [PATCH 2/2] Fix generation of x86-64 gdbarch with osabi none Simon Marchi
2018-04-07 17:36 ` [PATCH 1/2] Make "set osabi none" really work 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).