]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add setting to control frame language mismatch warning
authorTom Tromey <tromey@adacore.com>
Fri, 1 Nov 2024 16:08:34 +0000 (10:08 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 11 Nov 2024 14:42:01 +0000 (07:42 -0700)
A customer noted that there is no way to prevent the "current language
does not match this frame" warning.  This patch adds a new setting to
allow this warning to be suppressed.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/NEWS
gdb/doc/gdb.texinfo
gdb/language.c
gdb/language.h
gdb/testsuite/gdb.base/langs.exp
gdb/testsuite/gdb.base/with.exp
gdb/top.c

index 74ba5b4ee59801a541283fcab244a2b605f8ce21..38efc3b543afc51127af4a548287436e2082aa87 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -85,6 +85,11 @@ set style line-number background COLOR
 set style line-number intensity VALUE
   Control the styling of line numbers printed by GDB.
 
+set warn-language-frame-mismatch [on|off]
+show warn-language-frame-mismatch
+  Control the warning that is emitted when specifying a language that
+  does not match the current frame's language.
+
 maintenance info inline-frames [ADDRESS]
   New command which displays GDB's inline-frame information for the
   current address, or for ADDRESS if specified.  The output identifies
index 844e66046c63e9ff6e890b6fcec95d9798841386..53f41e674449981d781b7e4b04f74e5764754d8e 100644 (file)
@@ -16795,6 +16795,19 @@ written in one source language can be used by a main program written in
 a different source language.  Using @samp{set language auto} in this
 case frees you from having to set the working language manually.
 
+The warning is enabled by default, but it can be controlled via a
+setting:
+
+@table @code
+@item set warn-language-frame-mismatch [on|off]
+@kindex warn-language-frame-mismatch
+Enable or disable the warning that is issued when the current language
+is set to a value that does not match the current frame.
+
+@item show warn-language-frame-mismatch
+Show whether the frame-mismatch warning will be issued.
+@end table
+
 @node Show
 @section Displaying the Language
 
index d697331040d9fe53578e423ea4495cbdce6c77e0..a8548a2e82fdc9d8508b65e1a8e489ef5d0beb8b 100644 (file)
@@ -82,6 +82,9 @@ static const struct language_defn *global_current_language;
 static lazily_set_language_ftype *lazy_language_setter;
 enum language_mode language_mode = language_mode_auto;
 
+/* Whether to warn on language changes.  */
+bool warn_frame_lang_mismatch = true;
+
 /* See language.h.  */
 
 const struct language_defn *
@@ -168,7 +171,7 @@ show_language_command (struct ui_file *file, int from_tty,
                _("The current source language is \"%s\".\n"),
                current_language->name ());
 
-  if (has_stack_frames ())
+  if (warn_frame_lang_mismatch && has_stack_frames ())
     {
       frame_info_ptr frame;
 
@@ -1144,5 +1147,15 @@ For Fortran the default is off; for other languages the default is on."),
                        show_case_command,
                        &setlist, &showlist);
 
+  add_setshow_boolean_cmd ("warn-language-frame-mismatch", class_obscure,
+                          &warn_frame_lang_mismatch, _("\
+Enable or disable the frame language-mismatch warning."),
+                          _("\
+Show the current setting of the frame language-mismatch warning."),
+                          _("\
+The frame-language-mismatch warning is issued when the current language\n\
+does not match the selected frame's language."), nullptr, nullptr,
+                          &setlist, &showlist);
+
   add_set_language_command ();
 }
index 985e6227c670c2a670986e9524f094797115c1a6..26d7fb2a532f2fba70197465e4924d189b012533 100644 (file)
@@ -731,6 +731,10 @@ extern const struct language_defn *expected_language;
 
 extern const char lang_frame_mismatch_warn[];
 
+/* Controls whether to warn on a frame language mismatch.  */
+
+extern bool warn_frame_lang_mismatch;
+
 /* language_mode == 
    language_mode_auto:   current_language automatically set upon selection
    of scope (e.g. stack frame)
index 0acc1d683e1b9fe5d5a089e39fcd8b23d568f4a0..862741b1cefa263e8a17b3f44aa4f4f5746c68d0 100644 (file)
@@ -98,9 +98,9 @@ clean_restart $binfile
 # Try exercising the "minimal" language a bit...
 
 if {[runto csub]} {
-    gdb_test "set lang minimal" \
-             "Warning: the current language does not match this frame." \
-             "set lang to minimal"
+    # Also test warn-language-frame-mismatch.
+    gdb_test_no_output "set warn-language-frame-mismatch off"
+    gdb_test_no_output "set lang minimal" "set lang to minimal"
     
     gdb_test "print x" " = 5000" "print parameter value"
 
index a6460810efc741f577bce9308ee8761b5fdb4d6f..2e54825427472ec66f5cb711a73262bee42fc86e 100644 (file)
@@ -238,7 +238,7 @@ with_test_prefix "errors" {
 
     # Try ambiguous settings.
     gdb_test "with w" \
-       "Ambiguous set command \"w\": watchdog, width, write\\."
+       "Ambiguous set command \"w\": warn-language-frame-mismatch, watchdog, width, write\\."
     gdb_test "with print m" \
        "Ambiguous set print command \"m\": max-depth, max-symbolic-offset, memory-tag-violations\\."
 
index d34e733eb0ff224fd6e3781d4517dc0fa2624a16..45261c8f2a561c6abda0f707bfdba296ded0e1d1 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -388,7 +388,7 @@ check_frame_language_change (void)
   /* FIXME: This should be cacheing the frame and only running when
      the frame changes.  */
 
-  if (has_stack_frames ())
+  if (warn_frame_lang_mismatch && has_stack_frames ())
     {
       enum language flang;