diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 9d3e8eb..2579b7d 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -597,7 +597,7 @@
 
   *size = kind;
 
-  if (strcmp (target_shortname, "sim") == 0)
+  if (strcmp (target_shortname (), "sim") == 0)
     return bfin_sim_breakpoint;
   else
     return bfin_breakpoint;
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 5ca9933..17fb04f 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2505,7 +2505,7 @@
 	 so, print the state we are left in.  */
       if (target_has_stack)
 	{
-	  printf_filtered (_("In %s,\n"), target_longname);
+	  printf_filtered (_("In %s,\n"), target_longname ());
 	  print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 	}
     }
diff --git a/gdb/infrun.c b/gdb/infrun.c
index d8a6eed..2bc4f64 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2074,7 +2074,8 @@
   if (!target_can_lock_scheduler)
     {
       scheduler_mode = schedlock_off;
-      error (_("Target '%s' cannot support this command."), target_shortname);
+      error (_("Target '%s' cannot support this command."),
+	     target_shortname ());
     }
 }
 
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 0e99fa3..eeb8cae 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -322,7 +322,7 @@
     error (_("Already in reverse mode."));
 
   if (!target_can_execute_reverse)
-    error (_("Target %s does not support this command."), target_shortname);
+    error (_("Target %s does not support this command."), target_shortname ());
 
   scoped_restore save_exec_dir = make_scoped_restore (&execution_direction,
 						      EXEC_REVERSE);
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 67b4690..9f8d965 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -834,7 +834,7 @@
 
   unpush_target (this);		/* calls gdbsim_close to do the real work */
   if (from_tty)
-    printf_filtered ("Ending simulator %s debugging\n", target_shortname);
+    printf_filtered ("Ending simulator %s debugging\n", target_shortname ());
 }
 
 /* Resume execution of the target process.  STEP says whether to single-step
@@ -1142,7 +1142,7 @@
   if (exec_bfd)
     {
       fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
-			  target_shortname, file);
+			  target_shortname (), file);
       sim_info (sim_data->gdbsim_desc, 0);
     }
 }
diff --git a/gdb/reverse.c b/gdb/reverse.c
index f2d2bf0..284ac66 100644
--- a/gdb/reverse.c
+++ b/gdb/reverse.c
@@ -45,7 +45,7 @@
 	   cmd);
 
   if (!target_can_execute_reverse)
-    error (_("Target %s does not support this command."), target_shortname);
+    error (_("Target %s does not support this command."), target_shortname ());
 
   std::string reverse_command = string_printf ("%s %s", cmd, args ? args : "");
   scoped_restore restore_exec_dir
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 48a388b..cbd2972 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -432,7 +432,7 @@
   *size = kind;
 
   /* For remote stub targets, trapa #20 is used.  */
-  if (strcmp (target_shortname, "remote") == 0)
+  if (strcmp (target_shortname (), "remote") == 0)
     {
       static unsigned char big_remote_breakpoint[] = { 0xc3, 0x20 };
       static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
diff --git a/gdb/target.h b/gdb/target.h
index 1bb7276..5a85bdc 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1314,8 +1314,21 @@
 
 /* Define easy words for doing these operations on our current target.  */
 
-#define	target_shortname	(current_top_target ()->shortname ())
-#define	target_longname		(current_top_target ()->longname ())
+static inline const char *
+target_shortname ()
+{
+  target_ops *c = current_top_target ();
+
+  return c != nullptr ? c->shortname () : "";
+}
+
+static inline const char *
+target_longname ()
+{
+  target_ops *c = current_top_target ();
+
+  return c != nullptr ? c->longname () : "";
+}
 
 /* Does whatever cleanup is required for a target that we are no
    longer going to be calling.  This routine is automatically always
diff --git a/gdb/testsuite/gdb.tui/segfault-corefile-run.exp b/gdb/testsuite/gdb.tui/segfault-corefile-run.exp
new file mode 100644
index 0000000..532c982
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/segfault-corefile-run.exp
@@ -0,0 +1,60 @@
+# Copyright 2019 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/>.
+
+# Test whether we can load a corefile, enable TUI and then invoke
+# "run" without having a segfault.
+#
+# Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1765117
+
+load_lib "tuiterm.exp"
+
+standard_testfile tui-layout.c
+
+set core "${testfile}.core"
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
+    return -1
+}
+
+# Only run on native boards.
+if { [use_gdb_stub] || [target_info gdb_protocol] == "extended-remote" } {
+    untested "not supported"
+    return
+}
+
+if { ![runto_main] } {
+    untested "could not run to main"
+    return -1
+}
+
+if { ![gdb_gcore_cmd "$core" "save a corefile"] } {
+    untested "could not generate a corefile"
+    return -1
+}
+
+Term::clean_restart 24 80 $testfile
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+}
+
+set text [Term::get_all_lines]
+gdb_assert {![string match "No Source Available" $text]} \
+    "initial source listing"
+
+Term::command "core-file $core"
+Term::check_contents "load corefile" "21 *return 0"
+
+Term::command "run"
+Term::check_contents "run until the end" "\\\[Inferior $decimal \\\(process $decimal\\\) exited normally\\]"
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 078f819..77be8d9 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -83,7 +83,7 @@
       pid_name = pid_name_holder.c_str ();
     }
 
-  target_width = strlen (target_shortname);
+  target_width = strlen (target_shortname ());
   if (target_width > MAX_TARGET_WIDTH)
     target_width = MAX_TARGET_WIDTH;
 
@@ -152,7 +152,7 @@
   string_file string;
 
   if (target_width > 0)
-    string.printf ("%*.*s ", -target_width, target_width, target_shortname);
+    string.printf ("%*.*s ", -target_width, target_width, target_shortname ());
   if (pid_width > 0)
     string.printf ("%*.*s ", -pid_width, pid_width, pid_name);
 
