aboutsummaryrefslogtreecommitdiff
path: root/gdb/osabi.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-01-04 08:52:40 -0700
committerTom Tromey <tromey@adacore.com>2022-01-26 06:49:51 -0700
commitdedb7102b3b35f789fd5c140fe01917eaeae2853 (patch)
tree9331b631ef404e8704a7a4f5b939fdb1192ef4ee /gdb/osabi.c
parent1da5d0e664e362857153af8682321a89ebafb7f6 (diff)
downloadbinutils-dedb7102b3b35f789fd5c140fe01917eaeae2853.zip
binutils-dedb7102b3b35f789fd5c140fe01917eaeae2853.tar.gz
binutils-dedb7102b3b35f789fd5c140fe01917eaeae2853.tar.bz2
Fix another crash with gdb parameters in Python
While looking into the language-capturing issue, I found another way to crash gdb using parameters from Python: (gdb) python print(gdb.parameter('endian')) (This is related to PR python/12188, though this patch isn't going to fix what that bug is really about.) The problem here is that the global variable that underlies the "endian" parameter is initialized to NULL. However, that's not a valid value for an "enum" set/show parameter. My understanding is that, in gdb, an "enum" parameter's underlying variable must have a value that is "==" (not just strcmp-equal) to one of the values coming from the enum array. This invariant is relied on in various places. I started this patch by fixing the problem with "endian". Then I added some assertions to add_setshow_enum_cmd to try to catch other problems of the same type. This patch fixes all the problems that I found. I also looked at all the calls to add_setshow_enum_cmd to ensure that they were all included in the gdb I tested. I think they are: there are no calls in nat-* files, or in remote-sim.c; and I was trying a build with all targets, Python, and Guile enabled. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12188
Diffstat (limited to 'gdb/osabi.c')
-rw-r--r--gdb/osabi.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/gdb/osabi.c b/gdb/osabi.c
index 40c86e7..d4a9806 100644
--- a/gdb/osabi.c
+++ b/gdb/osabi.c
@@ -666,11 +666,13 @@ _initialize_gdb_osabi ()
generic_elf_osabi_sniffer);
/* Register the "set osabi" command. */
+ user_osabi_state = osabi_auto;
+ set_osabi_string = gdb_osabi_available_names[0];
+ gdb_assert (strcmp (set_osabi_string, "auto") == 0);
add_setshow_enum_cmd ("osabi", class_support, gdb_osabi_available_names,
&set_osabi_string,
_("Set OS ABI of target."),
_("Show OS ABI of target."),
NULL, set_osabi, show_osabi,
&setlist, &showlist);
- user_osabi_state = osabi_auto;
}