aboutsummaryrefslogtreecommitdiff
path: root/gdb/charset.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/charset.c
parent1da5d0e664e362857153af8682321a89ebafb7f6 (diff)
downloadgdb-dedb7102b3b35f789fd5c140fe01917eaeae2853.zip
gdb-dedb7102b3b35f789fd5c140fe01917eaeae2853.tar.gz
gdb-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/charset.c')
-rw-r--r--gdb/charset.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/gdb/charset.c b/gdb/charset.c
index 9b1de08..bf205ae 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -1029,6 +1029,9 @@ _initialize_charset ()
#endif
#endif
+ /* Recall that the first element is always "auto". */
+ host_charset_name = charset_enum[0];
+ gdb_assert (strcmp (host_charset_name, "auto") == 0);
add_setshow_enum_cmd ("charset", class_support,
charset_enum, &host_charset_name, _("\
Set the host and target character sets."), _("\
@@ -1057,6 +1060,9 @@ To see a list of the character sets GDB supports, type `set host-charset <TAB>'.
show_host_charset_name,
&setlist, &showlist);
+ /* Recall that the first element is always "auto". */
+ target_charset_name = charset_enum[0];
+ gdb_assert (strcmp (target_charset_name, "auto") == 0);
add_setshow_enum_cmd ("target-charset", class_support,
charset_enum, &target_charset_name, _("\
Set the target character set."), _("\
@@ -1069,6 +1075,9 @@ To see a list of the character sets GDB supports, type `set target-charset'<TAB>
show_target_charset_name,
&setlist, &showlist);
+ /* Recall that the first element is always "auto". */
+ target_wide_charset_name = charset_enum[0];
+ gdb_assert (strcmp (target_wide_charset_name, "auto") == 0);
add_setshow_enum_cmd ("target-wide-charset", class_support,
charset_enum, &target_wide_charset_name,
_("\