--- /dev/null
+# 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/>.
+
+# This test is for creating thread-specific breakpoint using the MI,
+# and checking the results from GDB.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+if {[mi_clean_restart]} {
+    return
+}
+
+standard_testfile
+
+if [build_executable ${testfile}.exp ${binfile} ${srcfile}] {
+    return -1
+}
+
+if {[mi_clean_restart $binfile]} {
+    return -1
+}
+
+mi_create_breakpoint "-p 1 bar" "thread-specific b/p on bar" \
+    -thread "1"
+
+proc make_loc {num} {
+    return [mi_make_breakpoint_loc -thread "1" -number "$::decimal\\.$num"]
+}
+
+set loc1 [make_loc 1]
+set loc2 [make_loc 2]
+set loc3 [make_loc 3]
+
+mi_create_breakpoint_multi "-p 1 foo" "thread-specific b/p on foo" \
+    -thread "1" \
+    -locations "\\\[$loc1,$loc2,$loc3\\\]"
 
 # locations.
 #
 # All arguments for the breakpoint location may be specified using the
-# options number, enabled, addr, func, file, fullname, line and
-# thread-groups.
+# options: number, enabled, addr, func, file, fullname, line,
+# thread-groups, and thread.
+#
+# For the option -thread the corresponding output field is only added
+# if the option is present and not set to the empty string.
 #
 # Example: mi_make_breakpoint_loc -number 2.1 -file ".*/myfile.c" -line 3
 # will return the breakpoint location:
 proc mi_make_breakpoint_loc {args} {
     parse_args {{number .*} {enabled .*} {addr .*}
        {func .*} {file .*} {fullname .*} {line .*}
-       {thread-groups \\\[.*\\\]}}
+       {thread-groups \\\[.*\\\]} {thread ""}}
 
     set attr_list {}
     foreach attr [list number enabled addr func file \
        lappend attr_list $attr [set $attr]
     }
 
-    return "{[mi_build_kv_pairs $attr_list]}"
+    set result [mi_build_kv_pairs $attr_list]
+
+    if {[string length $thread] > 0} {
+       append result ","
+       append result [mi_build_kv_pairs [list "thread" $thread]]
+    }
+
+    return "{$result}"
 }
 
 # Bits shared between mi_make_breakpoint and mi_make_breakpoint_multi.
 
-proc mi_make_breakpoint_1 {attr_list cond evaluated-by times \
+proc mi_make_breakpoint_1 {attr_list thread cond evaluated-by times \
                           ignore script original-location} {
     set result "bkpt=\\\{[mi_build_kv_pairs $attr_list]"
 
     # There are always exceptions.
 
-    # If COND is not preset, do not output it.
+    # If THREAD is not present, do not output it.
+    if {[string length $thread] > 0} {
+       append result ","
+       append result [mi_build_kv_pairs [list "thread" $thread]]
+    }
+
+    # If COND is not present, do not output it.
     if {[string length $cond] > 0} {
        append result ","
        append result [mi_build_kv_pairs [list "cond" $cond]]
 # -dprintf-insert, or -break-info with breakpoints with multiple
 # locations.
 #
-# All arguments for the breakpoint may be specified using the options
-# number, type, disp, enabled, func, cond, evaluated-by, times,
-# ignore, script and locations.
+# All arguments for the breakpoint may be specified using the options:
+# number, type, disp, enabled, times, ignore, script,
+# original-location, cond, evaluated-by, locations, and thread.
 #
 # Only if -script and -ignore are given will they appear in the output.
 # Otherwise, this procedure will skip them using ".*".
 #
+# For the options -thread and -cond the corresponding output fields
+# are only added if the options are present and not set to the empty
+# string.
+#
 # Example: mi_make_breakpoint_multi -number 2 -locations "$loc"
 # will return the breakpoint:
 # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr="<MULTIPLE>",
     parse_args {{number .*} {type .*} {disp .*} {enabled .*}
        {times .*} {ignore 0}
        {script ""} {original-location .*} {cond ""} {evaluated-by ""}
-       {locations .*}}
+       {locations .*} {thread ""}}
 
     set attr_list {}
     foreach attr [list number type disp enabled] {
     lappend attr_list "addr" "<MULTIPLE>"
 
     set result [mi_make_breakpoint_1 \
-                   $attr_list $cond ${evaluated-by} $times \
+                   $attr_list $thread $cond ${evaluated-by} $times \
                    $ignore $script ${original-location}]
 
     append result ","
 # be used to test the output of -break-insert, -dprintf-insert, or
 # -break-info for pending breakpoints.
 #
-# Arguments for the breakpoint may be specified using the options
-# number, type, disp, enabled, pending.
+# Arguments for the breakpoint may be specified using the options:
+# number, type, disp, enabled, pending, original-location, and thread.
+#
+# For the option -thread the corresponding output field is only
+# included if the option is present and not the empty string.
 #
 # Example: mi_make_breakpoint_pending -number 2 -pending func
 # will return the breakpoint:
 
 proc mi_make_breakpoint_pending {args} {
     parse_args {{number .*} {type .*} {disp .*} {enabled .*}
-       {pending .*} {original-location .*}}
+       {pending .*} {original-location .*} {thread ""}}
 
     set attr_list {}
     foreach attr [list number type disp enabled] {
     set evaluated-by ""
 
     set result [mi_make_breakpoint_1 \
-                   $attr_list $cond ${evaluated-by} $times \
+                   $attr_list $thread $cond ${evaluated-by} $times \
                    $ignore $script ${original-location}]
 
     append result "\\\}"
     parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*}
        {func .*} {file .*} {fullname .*} {line .*}
        {thread-groups \\\[.*\\\]} {times .*} {ignore 0}
-       {script ""} {original-location .*} {cond ""} {evaluated-by ""}}
+       {script ""} {original-location .*} {cond ""} {evaluated-by ""}
+       {thread ""}}
 
     set attr_list {}
     foreach attr [list number type disp enabled addr func file \
     }
 
     set result [mi_make_breakpoint_1 \
-                   $attr_list $cond ${evaluated-by} $times \
+                   $attr_list $thread $cond ${evaluated-by} $times \
                    $ignore $script ${original-location}]
 
     append result "\\\}"