From dedb7102b3b35f789fd5c140fe01917eaeae2853 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 4 Jan 2022 08:52:40 -0700 Subject: 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 --- gdb/osabi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gdb/osabi.c') 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; } -- cgit v1.1