diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2018-04-07 13:23:28 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2018-04-07 13:23:28 -0400 |
commit | 26540402495f35d5f19762ceba66605bca8fa63b (patch) | |
tree | bfe4bbb93b8541a490cfe9545e2d3830c3cd5631 | |
parent | 9018be22e022e6db2ba07c4e407c7244022bc69a (diff) | |
download | gdb-26540402495f35d5f19762ceba66605bca8fa63b.zip gdb-26540402495f35d5f19762ceba66605bca8fa63b.tar.gz gdb-26540402495f35d5f19762ceba66605bca8fa63b.tar.bz2 |
Make "set osabi none" really work (PR 22980)
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:
PR gdb/22980
* 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:
PR gdb/22980
* gdb.base/osabi.exp: New file.
-rw-r--r-- | gdb/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/arch-utils.c | 7 | ||||
-rw-r--r-- | gdb/defs.h | 3 | ||||
-rw-r--r-- | gdb/osabi.c | 12 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/osabi.exp | 26 |
6 files changed, 50 insertions, 11 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index aad71e4..a5773e8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2018-04-07 Simon Marchi <simon.marchi@ericsson.com> + PR gdb/22980 + * 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. + +2018-04-07 Simon Marchi <simon.marchi@ericsson.com> + * common/byte-vector.h (char_vector): New type. * target.h (target_read_alloc): Return gdb::optional<byte_vector>. 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); @@ -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/ChangeLog b/gdb/testsuite/ChangeLog index 5536e5b..5a885bf 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-04-07 Simon Marchi <simon.marchi@ericsson.com> + + PR gdb/22980 + * gdb.base/osabi.exp: New file. + 2018-04-02 Weimin Pan <weimin.pan@oracle.com> * gdb.cp/static-typedef-print.exp: New file. 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 |