diff --git a/gdb/testsuite/gdb.tui/tui-border-kind.exp b/gdb/testsuite/gdb.tui/tui-border-kind.exp
new file mode 100644
index 00000000000..cd6bf0899f0
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/tui-border-kind.exp
@@ -0,0 +1,83 @@
+# Copyright 2023 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/>.
+
+# Check that tui border-kind acs-or-ascii results in the right tui
+# border-kind.
+
+# We set variables in env on build that we need on host, so we require
+# host == build.
+require {!is_remote host}
+
+# Don't use tuiterm_env, it just supports tui border-kind ascii.
+# So we do a more basic test, and don't enter TUI.
+
+with_test_prefix TERM=screen {
+    save_vars { env(TERM) } {
+	setenv TERM screen
+	clean_restart
+
+	# Check that TERM=screen selects acs.
+	gdb_test "show tui border-kind" \
+	    {The kind of border for TUI windows is "acs-or-ascii" \(acs\).}
+
+    }
+}
+
+with_test_prefix TERM=linux {
+    save_vars { env(TERM) } {
+	setenv TERM linux
+	clean_restart
+
+	# Check that TERM=linux selects acs.	
+	gdb_test "show tui border-kind" \
+	    {The kind of border for TUI windows is "acs-or-ascii" \(acs\).}
+    }
+}
+
+
+with_test_prefix TERM=ansi {
+    save_vars { env(TERM) } {
+	setenv TERM ansi
+
+	with_test_prefix NCURSES_NO_UTF8_ACS=1 {
+	    setenv NCURSES_NO_UTF8_ACS 1
+	    clean_restart
+
+	    # Check that TERM=linux and NCURSES_NO_UTF8_ACS=1 selects acs.
+	    gdb_test "show tui border-kind" \
+		{The kind of border for TUI windows is "acs-or-ascii" \(acs\).}
+	}
+
+	with_test_prefix NCURSES_NO_UTF8_ACS=0 {
+	    setenv NCURSES_NO_UTF8_ACS 0
+	    clean_restart
+
+	    # Check that TERM=linux and NCURSES_NO_UTF8_ACS=0 selects acs.
+	    gdb_test "show tui border-kind" \
+		{The kind of border for TUI windows is "acs-or-ascii" \(acs\).}
+	}
+
+	with_test_prefix NCURSES_NO_UTF8_ACS=unset {
+	    unset -nocomplain env(NCURSES_NO_UTF8_ACS)
+	    clean_restart
+
+	    # Check that TERM=ansi with NCURSES_NO_UTF8_ACS unset selects ascii.
+	    gdb_test "show tui border-kind" \
+		[concat \
+		     {The kind of border for TUI windows is "acs-or-ascii"} \
+		     {\(ascii, NCURSES_NO_UTF8_ACS unset\).}]
+	}
+    }
+}
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 05edfe9a5b1..3d7a9df52de 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -804,7 +804,11 @@ namespace eval Term {
 	    return 0
 	}
 
+	# We could drop this, and the default tui border-kind acs-or-ascii
+	# would normally pick ascii.  But we'd run into if NCURSES_NO_UTF8_ACS
+	# would be set, which would pick acs instead.
 	gdb_test_no_output "set tui border-kind ascii"
+
 	gdb_test_no_output "maint set tui-resize-message on"
 	return 1
     }
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 3b17cb8dd29..1339fc0c8e2 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -93,6 +93,8 @@ static const char *const tui_border_kind_enums[] = {
   "space",
   "ascii",
   "acs",
+  "acs-or-space",
+  "acs-or-ascii",
   NULL
 };
 
@@ -207,15 +209,80 @@ The attribute mode to use for the TUI window borders is \"%s\".\n"),
 	      value);
 }
 
-static const char *tui_border_kind = "acs";
+/* Actual value of "tui border-kind" setting.  X-or-y values allowed.  */
+static const char *tui_border_kind_setting = "acs-or-ascii";
+
+/* Actual value of "tui border-kind".  X-or-y values not allowed.  */
+static const char *tui_border_kind_value = nullptr;
+
+/* Reason why y was used in a X-or-y value for "tui border-kind".  */
+static const char *tui_border_kind_value_reason = nullptr;
+
+static void
+determine_tui_border_kind_value (void)
+{
+  const char *fallback = nullptr;
+
+  tui_border_kind_value_reason = "";
+
+  if (strcmp (tui_border_kind_setting, "acs-or-ascii") == 0)
+    {
+      /* Tentatively set to acs, and define fallback.  */
+      tui_border_kind_value = "acs";
+      fallback = "ascii";
+    }
+  else if (strcmp (tui_border_kind_setting, "acs-or-space") == 0)
+    {
+      /* Tentatively set to acs, and define fallback.  */
+      tui_border_kind_value = "acs";
+      fallback = "space";
+    }
+  else
+    {
+      tui_border_kind_value = tui_border_kind_setting;
+      return;
+    }
+
+  char *env_term = getenv ("TERM");
+  if (strcmp (env_term, "linux") == 0 || strcmp (env_term, "screen") == 0)
+    {
+      /* Ncurses knows how to handle these TERM values.  */
+      return;
+    }
+
+  char *env_ncurses_no_utf8_acs = getenv ("NCURSES_NO_UTF8_ACS");
+  if (env_ncurses_no_utf8_acs != nullptr)
+    {
+      /* The user knowns if the workaround is required or not.  */
+      return;
+    }
+
+  /* There may be problems with acs, so apply the fall back.  */
+  tui_border_kind_value = fallback;
+  tui_border_kind_value_reason = ", NCURSES_NO_UTF8_ACS unset";
+}
+
+static const char *
+tui_border_kind (void)
+{
+  determine_tui_border_kind_value ();
+  return tui_border_kind_value;
+}
+
 static void
 show_tui_border_kind (struct ui_file *file, 
 		      int from_tty,
 		      struct cmd_list_element *c, 
 		      const char *value)
 {
-  gdb_printf (file, _("The kind of border for TUI windows is \"%s\".\n"),
-	      value);
+  if (strcmp (tui_border_kind (), value) != 0)
+    {
+      gdb_printf (file, _("The kind of border for TUI windows is \"%s\" (%s%s).\n"),
+		  value, tui_border_kind (), tui_border_kind_value_reason);
+    }
+  else
+    gdb_printf (file, _("The kind of border for TUI windows is \"%s\".\n"),
+		value);
 }
 
 /* Implementation of the "set/show style tui-current-position" commands.  */
@@ -298,25 +365,25 @@ tui_update_variables ()
   /* If one corner changes, all characters are changed.
      Only check the first one.  The ACS characters are determined at
      run time by curses terminal management.  */
-  entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
+  entry = translate (tui_border_kind (), tui_border_kind_translate_lrcorner);
   if (tui_border_lrcorner != (chtype) entry->value)
     {
       tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
       need_redraw = true;
     }
-  entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
+  entry = translate (tui_border_kind (), tui_border_kind_translate_llcorner);
   tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
+  entry = translate (tui_border_kind (), tui_border_kind_translate_ulcorner);
   tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
+  entry = translate (tui_border_kind (), tui_border_kind_translate_urcorner);
   tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_hline);
+  entry = translate (tui_border_kind (), tui_border_kind_translate_hline);
   tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_vline);
+  entry = translate (tui_border_kind (), tui_border_kind_translate_vline);
   tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
 
   return need_redraw;
@@ -1204,13 +1271,15 @@ defaults to 1, and WIN defaults to the currently focused window."));
 
   /* Define the tui control variables.  */
   add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
-			&tui_border_kind, _("\
+			&tui_border_kind_setting, _("\
 Set the kind of border for TUI windows."), _("\
 Show the kind of border for TUI windows."), _("\
 This variable controls the border of TUI windows:\n\
    space           use a white space\n\
    ascii           use ascii characters + - | for the border\n\
-   acs             use the Alternate Character Set"),
+   acs             use the Alternate Character Set\n\
+   acs-or-space    detect if acs is possible, otherwise use space\n\
+   acs-or-ascii    detect if acs is possible, otherwise use ascii"),
 			tui_set_var_cmd,
 			show_tui_border_kind,
 			&tui_setlist, &tui_showlist);
