summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.hp/quicksort.exp
blob: 719bfdfb0a97944e4a73f1f7cb4be79575447c10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# quicksort.exp -- Expect script to test gdb with quicksort.c
# Copyright (C) 1992 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# use this to debug:
#
#log_user 1

if $tracelevel then {
    strace $tracelevel
}

if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
    verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
    return 0
}

set testfile quicksort
set srcfile ${srcdir}/${subdir}/${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}

if [get_compiler_info ${binfile}] {
    return -1
}

# To build the executable we need to link against the thread library.
#
#     cc -Ae -g -o quicksort -lpthread quicksort.c
#
#compile "${srcfile} -Ae -g -lpthread -o ${binfile}"

if {$gcc_compiled == 0} {
    set additional_flags "additional_flags=-Ae"
} else {
    set additional_flags ""
}

if  { [gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}.o" object [list debug $additional_flags]] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}
remote_exec build "ld /usr/ccs/lib/crt0.o ${binfile}.o -lcl -lpthread  -lc /opt/langtools/lib/end.o -o ${binfile}"


# Thread stuff is _slow_; prepare for long waits.
#
set oldtimeout $timeout
set timeout [expr "$timeout + 300"]
set oldverbose $verbose
#set verbose 40

# Further, this test has some "null" lines designed
# to consume output from gdb that was too late to be
# matched (sequence is "gdb_test" sends; timeout and
# on to next send; result finally comes in; mismatch).
#
# The null command is 'gdb_test "p \$pc" ".*" ""'
#
# NOTE: to pass a literal "$", "/" or "*" (etc.) to gdb_test, 
#       remember that the pattern will be escaped once and 
#       $-evaluated twice:
#
#          "\\\*" matches "\*"
#          "\$"  matches "$"
#
proc fix_timeout {} {
    gdb_test "p \$pc" ".*" ""
}

#=========================
#
# Simple sanity test first.
#
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

gdb_test "tb 122" ".*Breakpoint.*" ""
gdb_test "r" ".*122.*" ""
gdb_test "thr 99" ".*Thread ID 99 not known.*" "Check too-big thread number"
gdb_test "tb 145 thr 3" ".*Breakpoint.*" "set thread-specific bp 145"
gdb_test "tb 146 thr 4" ".*Breakpoint.*" "set thread-specific bp 146"
gdb_test "c" ".*Switched to thread.*145.*" "auto switch"
gdb_test "c" ".*Switched to thread.*146.*" "auto switch 2"
gdb_test "c" ".*Program exited normally.*" ""

#=========================
#
# Test that you can't do a thread select after a program runs.
#
gdb_test "thread" ".*No stack.*" "No live thread after run"
gdb_test "thr 2"  ".*No stack.*" "Can't set thread after run"

#=========================
#
# Test thread command changes, look for frame level reset bug.
#
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
gdb_test "b 122" ".*" ""
gdb_test "r" ".*122.*" ""

# Prep for frame level test--go up/info thread/check frame
#
gdb_test "up" ".*quick_sort.*" ""
gdb_test "up" ".*main.*"       ""

send_gdb "i th\n"
gdb_expect {
  -re ".*7 thread.* in .* from .* in .* from .* 6 thread.*$gdb_prompt $" {
      fail "old thread command, says things twice"
  }
  -re ".*7 system thread.*6 system th.*5 sys.*4.*3.*2.*1.*work_init.*$gdb_prompt $" {
      pass "info threads"
  }
  -re ".*$gdb_prompt $"  { fail "no info thread command" }
  timeout { fail "timeout" }
}

# We should have been restored two frames up--check.
#
send_gdb "up\n"
gdb_expect {
    -re ".*Initial frame selected.*$gdb_prompt $" {
        pass "Frame correctly reset after 'info threads'"
    }
    -re ".*quick_sort.*$gdb_prompt $" {
        fail "Old gdb bug; should be fixed someday"
    }
    -re ".*$gdb_prompt $" {
        fail "real bug--FIX!"
    }
    timeout { fail "timeout" }
}

# Do it again, only just go to a middle frame, and use another thread.
#
gdb_test "thr 5" ".*" ""
gdb_test "bt" ".* ___ksleep.*_lwp_cond_timedwait.*pthread_cond_wait.*worker.*__pthread_create_system.*" ""
gdb_test "up" ".*1.*_lwp_cond_timedwait.*" ""
gdb_test "up" ".*2.*pthread_cond_wait.*"   ""
gdb_test "up" ".*3.*worker.*"              ""
gdb_test "i th" ".*7.*6.*work_init.*"      ""
gdb_test "f"  ".*3.*worker.*"              "Frame restored"
gdb_test "p wp->max_pile" ".*= 128.*"      "can see vars in frame"

# Thread command changes
#
gdb_test "thr"    ".*Current thread is 5.*"   "threads-no-num"
gdb_test "thr 6"  ".*Switching to thread 6.*" "new switch"
gdb_test "thr"    ".*Current thread is 6.*"   "check switch"
#gdb_test "thr 6"  ".*Current thread is already 6.*" "dup, no switch"
gdb_test "thr app all p x" ".*No symbol.*"    ""
gdb_test "thr"    ".*Current thread is 6.*"   "restore current thread"

#=========================
#
# Test new stepping
#

proc get_hit { } {
    global hit2
    global hit3
    global hit4
    global hit5
    global hit6
    global hit7
    global gdb_prompt

    send_gdb "cont\n"
    gdb_expect {
        -re ".*Breakpoint.*145.*$gdb_prompt $" {
            send_gdb "thr\n"
            gdb_expect {
                -re ".*is 7.*$gdb_prompt $" {
                    set hit7 [expr "$hit7 + 1"]
                }
                -re ".*is 6.*$gdb_prompt $" {
                    set hit6 [expr "$hit6 + 1"]
                }
                -re ".*is 5.*$gdb_prompt $" {
                    set hit5 [expr "$hit5 + 1"]
                }
                -re ".*is 4.*$gdb_prompt $" {
                    set hit4 [expr "$hit4 + 1"]
                }
                -re ".*is 3.*$gdb_prompt $" {
                    set hit3 [expr "$hit3 + 1"]
                }
                -re ".*is 2.*$gdb_prompt $" {
                    set hit2 [expr "$hit2 + 1"]
                }
                -re ".*$gdb_prompt $" {
                    fail "can't see which thread"
                }
                timeout { fail "timeout" }
            }
        }
        -re ".*$gdb_prompt $" {
            fail "thread command"
        }
        timeout { fail "timeout" }
    }
}

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
gdb_test "break 122" ".*" ""
gdb_test "run"      ".*122.*" ""

# Make sure we hit a bp on every thread.
#
# Try one, via thread-specific bps
#
gdb_test "break 145 thr 2" ".*" "set thread-specific bp thr 2"
gdb_test "break 145 thr 3" ".*" "set thread-specific bp thr 3"
gdb_test "break 145 thr 4" ".*" "set thread-specific bp thr 4"
gdb_test "break 145 thr 5" ".*" "set thread-specific bp thr 5"
gdb_test "break 145 thr 6" ".*" "set thread-specific bp thr 6"
gdb_test "break 145 thr 7" ".*" "set thread-specific bp thr 7"

set hit2 0
set hit3 0
set hit4 0
set hit5 0
set hit6 0
set hit7 0

get_hit
get_hit
get_hit
get_hit
get_hit
get_hit

if { [expr "$hit2 == 1"] 
  && [expr "$hit3 == 1"]
  && [expr "$hit4 == 1"]
  && [expr "$hit5 == 1"]
  && [expr "$hit6 == 1"]
  && [expr "$hit7 == 1"] } {
    pass "thread-specific bps 1"
} else {
    fail "thread-specific bps 1"
}

#====================
#
# Now use generic bps
#
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
gdb_test "b 122" ".*" ""
gdb_test "r" ".*122.*" ""

# Make sure we hit a bp on every thread.
#
# Try two, via non-thread-specific bp
#
gdb_test "b 145" ".*" "b 145"

set hit2 0
set hit3 0
set hit4 0
set hit5 0
set hit6 0
set hit7 0

get_hit
get_hit
get_hit
get_hit
get_hit
get_hit

if { [expr "$hit2 == 1"] 
  && [expr "$hit3 == 1"]
  && [expr "$hit4 == 1"]
  && [expr "$hit5 == 1"]
  && [expr "$hit6 == 1"]
  && [expr "$hit7 == 1"] } {
    pass "thread-specific bps 2"
} else {
    fail "thread-specific bps 2"
}

#====================
#
# Complicated (original) test next.
#
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

if ![runto_main] then {
   fail "Can't run to main"
   return 0
}

# OK, we're at "main", there should be one thread.
#
gdb_test "info thread" ".*\\\* 1 system thread .*main.*" "initial thread"
 
# Try to see the threads being created: set a breakpoint 
# after the creation and go around the loop a few times.
#
gdb_test "break 109" "Breakpoint.*109.*" "set bpt"

gdb_test "c" ".*New thread.*Breakpoint.*109.*" "first continue"
fix_timeout

# Make sure we don't wait (waiting is for attach test)
#
gdb_test "set wait_here = 0" ".*" ""

send_gdb "info thr\n"
gdb_expect {
    -re ".*2 system th.*1 sy.*109.*$gdb_prompt $" { pass "saw thread create" }
    -re ".*1 system thread.*87.*$gdb_prompt $"    { fail "didn't see thread create" }
    -re ".*$gdb_prompt $"                         { fail "no info thread command" }
    timeout { fail "timeout" }
}

gdb_test "c"      ".*New thread.*Breakpoint.*109.*" "continue"
fix_timeout

send_gdb "info thr\n"
gdb_expect {
    -re ".*3 system thread.*2 sys.*\\\* 1 system thread.*109.*$gdb_prompt $" { 
        pass "saw thread create" }
    -re ".*2 system thread.*1 sys.*109.*$gdb_prompt $" { 
        fail "didn't see thread create" 
    }
    -re ".*1 system thread.*109.*$gdb_prompt $" {
        fail "didn't see thread create" 
    }
    -re ".*$gdb_prompt $" {
        fail "no info thread command" 
    }
    timeout { fail "timeout" }
}

fix_timeout
gdb_test "clear" ".*Deleted breakpoint.*" ""

# Now go on to the end of thread creation.
#
gdb_test "b 122"  ".*"     "set bpt 122"
gdb_test "c"     ".*New thread.*New thread.*New thread.*122.*" ""
gdb_test "p \$pc" ".*" ""
gdb_test "clear" ".*Deleted breakpoint.*" ""

send_gdb "info thr\n"
gdb_expect {
    -re ".*7 system thread.*6 sys.*5.*1 system thread.*122.*$gdb_prompt $" 
        { pass "saw thread creates" }
    -re ".*$gdb_prompt $"                           
        { fail "no info thread command" }
    timeout { fail "timeout" }
}

# Try a thread-specific breakpoint; we expect the other threads to
# be waiting at this point.
#
gdb_test "thr 3"  ".*Switching to thread.*ksleep.*" "thread switch"
gdb_test "i th"   ".*\\\* 3 system thread.*"        "show new current thread"

gdb_test "up"     ".*lwp_cond_timedwait.*" ""
gdb_test "up"     ".*pthread_cond_wait.*"  ""
gdb_test "up"     ".*worker.*144.*"        ""

gdb_test "b 145 th 3" ".*Breakpoint.*145.*" "set thread-specific bp"
gdb_test "i b"    ".*breakpoint.*breakpoint.*145 thread 3.*" "show thread-specific bp"

gdb_test "c"      ".*Breakpoint.*145.*145.*" "hit thread-specific bp"
gdb_test "p \$pc" ".*" ""

# Test thread apply command on thread specific data.
#
gdb_test "thre app all p \$pc" ".*Thread 7.*Thread 6.*Thread 5.*Thread 4.*Thread 3.*Thread 2.*Thread 1.*" "thread apply all"
gdb_test "thr ap 1 3 5 p \$pc" ".*Thread 1.*Thread 3.*Thread 5.*" "thr app 1 3 5"

# Switch again, and test that others continue on a "next"
# This test _could_ fail due to timing issues, but that's
# unlikely.
#
gdb_test "thr 7" ".*Switching to thread.*" ""

# Make sure that "up" stops at __pthread_exit, or
# __pthread_create, the pseudo-roots, and that we 
# only see that pseudo-root once.
#
send_gdb "bt\n"
gdb_expect {
    -re ".*Error accessing memory address.*" { fail "bt" }
    -re ".*pthread_create.*pthread_create.*" { fail "bt" }
    -re ".*worker.*pthread_create.*"         { pass "bt" }
    -re ".*pthread_exit.*"                   { pass "bt" }
    timeout { fail "timeout on bt" }
}

gdb_test "up" ".*"           ""
gdb_test "up" ".*"           ""
gdb_test "up" ".*144.*"      "Up 3"
gdb_test "up" ".*pthread_.*" "Up 4"
gdb_test "up" ".*Initial frame selected; you cannot go up.*" "catch end of thread stack"

#=====================
#
# Things get iffy here; when we step, sometimes the step
# completes, sometimes it doesn't.  When it doesn't, we
# hit a bp somewhere else and the step never completes
# (wait_for_inferior just evaporates it). 
#
# I think the right answer is that any failures here
# should stick around to trigger later fixing.
#
#  Here's the plan: 
#
#  Bps at 148 (5) and 154 (6) on thread 7 (two bps so we 
#     see the difference between going around the loop and
#     reporting the same bp hit twice).
#
#  Bp at 144 on thread 3.
#
#  Step out of a library routine.
#
# Either the step will finish or a bp will hit.  Try to
# handle all the cases.
#
gdb_test "b 148 thr 7" ".*Breakpoint.*148.*" ""
gdb_test "b 154 thr 7" ".*Breakpoint.*154.*" "set bpt 2"

set hit_154_bp 0
set hit_148_bp 0
set hit_145_bp 0
set step_completed 0

# Expect zero hits
#
gdb_test "i b" ".*" ""

send_gdb "n\n"
gdb_expect {
    -re ".*Single stepping.*_lwp_cond_timedwait.*$gdb_prompt $" {
        send_gdb "thr\n"
        gdb_expect {
            -re ".*is 7.*$gdb_prompt $" {
                set step_completed 1
                pass "completed step in library code"
            }
            -re ".*$gdb_prompt $" {
                fail "completed step in library code, but in wrong thread"
            }
            timeout { fail "timeout" }
        }
    }
    -re ".*Single stepping.*Switched to thread 3.*Breakpoint.*$gdb_prompt $" {
        pass "step cancelled; hit bp due to thread parallelism"
        set hit_145_bp 1
    }
    -re ".*Single stepping.*Switched to thread 7.*Breakpoint.*148.*$gdb_prompt $" {
        pass "step cancelled; hit bp due to thread parallelism"
        set hit_148_bp 1
    }
    -re ".*Single stepping.*Switched to thread 7.*Breakpoint.*154.*$gdb_prompt $" {
        pass "step cancelled; hit bp due to thread parallelism"
        set hit_154_bp 1
    }
    -re ".*$gdb_prompt $" {
        send_gdb "thr\n"
        gdb_expect {
            -re ".*is 7.*$gdb_prompt $" {
                fail "No event?"
            }
            -re ".*$gdb_prompt $" {
                fail "No event"
            }
            timeout { fail "timeout" }
        }
    }
    timeout { fail "timeout" }
}

# Sometimes used to get SIGTRAP here; that should be fixed
#

# Expect appropriate hits of bpt; too much work to parse
# result and check...
#
gdb_test "i b" ".*" ""

send_gdb "c\n"
gdb_expect {
    -re ".*SIGTRAP.*$gdb_prompt $" {
        fail "got SIGTRAP"
    }
    -re ".*Switched to thread 7.*Breakpoint.*154.*$gdb_prompt $" {
        if { $hit_154_bp == 1 } {
            fail "re-hit old bp"
        } else {
            pass "continue; hit parallel event after continue"
        }
        set hit_154_bp 1
    }
    -re ".*Switched to thread 7.*Breakpoint.*148.*$gdb_prompt $" {
        if { $hit_148_bp == 1 } {
            fail "re-hit old bp"
        } else {
            pass "continue; hit parallel event after continue"
        }
        set hit_148_bp 1
    }
    -re ".*Breakpoint.*154.*$gdb_prompt $" {
        if { $hit_154_bp == 1 } {
            fail "re-hit old bp"
        } else {
            send_gdb "thr\n"
            gdb_expect {
                -re ".*is 7.*$gdb_prompt $" {
                    pass "continue; hit parallel event after continue"
                }
                -re ".*$gdb_prompt $" {
                    fail "hit bp in wrong thread"
                }
                timeout { fail "timeout" }
            }
        }
        set hit_154_bp 1
    }
    -re ".*Breakpoint.*148.*$gdb_prompt $" {
        if { $hit_148_bp == 1 } {
            fail "re-hit old bp"
        } else {
            send_gdb "thr\n"
            gdb_expect {
                -re ".*is 7.*$gdb_prompt $" {
                    pass "continue; hit parallel event after continue"
                }
                -re ".*$gdb_prompt $" {
                    fail "hit bp in wrong thread"
                }
                timeout { fail "timeout" }
            }
        }
        set hit_148_bp 1
    }
    -re ".*Breakpoint.*145.*$gdb_prompt $" {
        if { $hit_145_bp == 1 } {
            fail "re-hit old bp"
        } else {
            send_gdb "thr\n"
            gdb_expect {
                -re ".*is 3.*$gdb_prompt $" {
                    pass "continue; hit parallel event after continue"
                }
                -re ".*$gdb_prompt $" {
                    fail "hit bp in wrong thread"
                }
                timeout { fail "timeout" }
            }
        }
        set hit_145_bp 1
    }
    -re ".*_lwp_cond_timedwait.*$gdb_prompt $" {
        pass "continue; hit step completion after continue"
    }
    -re ".*Program exited normally.*" {
        fail "Program ended? HOW?"
    }
    -re ".*$gdb_prompt $" {
        fail "Unexpected event"
    }
    timeout { fail "timeout" }
}

# There are a number of places we _could_ be now;
# this is the price of really running in parallel.
#
send_gdb "n\n"
gdb_expect {
    -re ".*Switched to thread 7.*pthread_cond_wait.*$gdb_prompt $" {
        if { $step_completed } {
            fail "step already completed"
        } else {
            pass "finish step"
        }
    }
    -re ".*pthread_cond_wait.*$gdb_prompt $" {
        #
        # Unlikely, but we might finish the range step from inside
        # ksleep, before anything else.
        #
        if { $step_completed } {
            fail "step already completed"
        } else {
            send_gdb "thr\n"
            gdb_expect {
                -re ".*is 7.*$gdb_prompt $" {
                    pass "finish step"
                }
                -re ".*$gdb_prompt $" {
                    fail "step in wrong thread"
                }
                timeout { fail "timeout" }
            }
        }
    }
    -re ".*Switched to thread.*Breakpoint.*145.*$gdb_prompt $" {
        pass "auto-switch thread" 
    }
    -re ".*Breakpoint.*145.*$gdb_prompt $" {
        pass "auto-switch not needed, ok" 
    }
    -re ".*140.*while.*n_pile.*$gdb_prompt $" {
        #
        # This is just going around the loop from the 154 bp.
        #
        send_gdb "thr\n"
        gdb_expect {
            -re ".*is 7.*$gdb_prompt $" {
                pass "finish step"
            }
            -re ".*$gdb_prompt $" {
                fail "step in wrong thread"
            }
            timeout { fail "timeout" }
        }
    }
    -re ".*149.*ptr = wp.*pile.*$gdb_prompt $" {
        #
        # This is just going around the loop from the 148 bp.
        #
        if { $hit_154_bp } {
            send_gdb "thr\n"
            gdb_expect {
                -re ".*is 7.*$gdb_prompt $" {
                    pass "finish step"
                }
                -re ".*$gdb_prompt $" {
                    fail "step in wrong thread"
                } 
                timeout { fail "timeout" }
            }
        } else {
            pass "step from 149 but didn't hit it first"
        }
    }
    -re ".*Breakpoint 5.*154.*$gdb_prompt $" {
        gdb_test "i b" ".*" ""
        if { $hit_154_bp } {
            fail "hit bp again?"
        } else {
            pass "hit bp"
        }
    }
    -re ".*Breakpoint 5.*148.*$gdb_prompt $" {
        gdb_test "i b" ".*" ""
        if { $hit_148_bp } {
            fail "hit bp again?"
        } else {
            pass "hit bp"
        }
    }
    -re ".*$gdb_prompt $" {
        fail "no step finished"
    }
    timeout { fail "timeout on 'next'" }
}

# Let's get into some kind of known state again.
#
gdb_test "thr 7" ".*" ""
gdb_test "info thread" ".*" ""
#gdb_test "i b" ".*" ""

# Leave breakpoint "154 thr 7" as only live bp.
# 
gdb_test "d 1"   ".*" "del main bp"
gdb_test "d 4"   ".*" "thread-specific bpt delete"
gdb_test "d 5"   ".*" "other bp delete"
send_gdb "i b\n"
gdb_expect {
    -re ".*breakpoint.*breakpoint.*$gdb_prompt $" {
        fail "more than one bp left"
    }
    -re ".*breakpoint.*154.*thread.*7.*$gdb_prompt $" {
        pass "Only one bp left"
    }
    -re ".*$gdb_prompt $" {
        fail "Wrong or no bp left"
    }
    timeout { fail "timeout on info b" }
}

send_gdb "c\n" 
gdb_expect {
    -re ".*SIGTRAP.*Switched to thread.*$gdb_prompt $" {
        fail "SIGTRAP error; lost thread-specific bpt"
    }
    -re ".*SIGTRAP.*Switched to thread.*154.*$gdb_prompt $" {
        fail "SIGTRAP, but hit right thread-specific bpt"
    }
    -re ".*Switched to thread.*Breakpoint.*154.*$gdb_prompt $" {
        pass "auto-switch back"
    }
    -re ".*Breakpoint.*154.*$gdb_prompt $" {
        pass "step to bp"
    }
    -re ".*$gdb_prompt $" {
        fail "auto-switch back" 
    }
    -re ".*Program exited normally.*$gdb_prompt $" {
        fail "step lost"
    }
    timeout {
        fail "timeout"
    }
}
fix_timeout

gdb_test "cle"   ".*Deleted breakpoint.*" "delete last breakpoint"

# Sometimes get SIGTRAP here.  Continue sometimes gets another...
#
send_gdb "c\n"
gdb_expect {
    -re ".*SIGTRAP.*154.*154.*$gdb_prompt $" {
        fail "SIGTRAP on deleted bp 154 "
        send_gdb "c\n" 
        gdb_expect {
            -re ".*$gdb_prompt $" { pass "fixup"}
            timeout { fail "fixup" }
        }
   }
    -re ".*SIGTRAP.*144.*145.*$gdb_prompt $" {
        fail "SIGTRAP on deleted bp 145 "
        send_gdb "c\n"
        gdb_expect {
            -re ".*$gdb_prompt $" { pass "fixup"}
            timeout { fail "fixup" }
        }
    }
    -re ".*SIGTRAP.*148.*148.*$gdb_prompt $" {
        fail "SIGTRAP on deleted bp 148 "
        send_gdb "c\n"
        gdb_expect {
            -re ".*$gdb_prompt $" { pass "fixup"}
            timeout { fail "fixup" }
        }
    }
    -re ".*SIGTRAP.*$gdb_prompt $" {
        fail "unknown SIGTRAP"
        send_gdb "c\n"
        gdb_expect {
            -re ".*$gdb_prompt $" { pass "fixup"}
            timeout { fail "fixup" }
        }
    }
    -re ".*Program exited.*$gdb_prompt $" {
        pass "run to end"
    }
    -re ".*$gdb_prompt $" {
        fail "run to end"
        send_gdb "c\n"
        gdb_expect {
            -re ".*$gdb_prompt $" { pass "fixup"}
            timeout { fail "fixup" }
        }
    }
    timeout { fail "timeout" }
}

gdb_test "p \$pc" ".*No registers.*" "program done"

# Done!
#
gdb_exit

set timeout $oldtimeout
set verbose $oldverbose

# execute_anywhere "rm -f ${binfile}"
#
return 0