aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/ada/s-tasdeb-vms.adb
blob: 6c9ae75e332b50376a132f9f3ad8eec8cd3d7c1e (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
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
------------------------------------------------------------------------------
--                                                                          --
--                  GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                --
--                                                                          --
--                  S Y S T E M . T A S K I N G . D E B U G                 --
--                                                                          --
--                                  B o d y                                 --
--                                                                          --
--          Copyright (C) 2008-2013, Free Software Foundation, Inc.         --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
-- GNARL was developed by the GNARL team at Florida State University.       --
-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
--                                                                          --
------------------------------------------------------------------------------

--  OpenVMS Version

with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with System.Aux_DEC;
with System.CRTL;
with System.Task_Primitives.Operations;
package body System.Tasking.Debug is

   package OSI renames System.OS_Interface;
   package STPO renames System.Task_Primitives.Operations;

   use System.Aux_DEC;

   --  Condition value type

   subtype Cond_Value_Type is Unsigned_Longword;

   type Trace_Flag_Set is array (Character) of Boolean;

   Trace_On : Trace_Flag_Set := ('A' .. 'Z' => False, others => True);

   --  Print_Routine fuction codes

   type Print_Functions is
     (No_Print, Print_Newline, Print_Control,
      Print_String, Print_Symbol, Print_FAO);
   for Print_Functions use
     (No_Print => 0, Print_Newline => 1, Print_Control => 2,
      Print_String => 3, Print_Symbol => 4, Print_FAO => 5);

   --  Counted ascii type declarations

   subtype Count_Type is Natural range 0 .. 255;
   for Count_Type'Object_Size use 8;

   type ASCIC (Count : Count_Type) is record
      Text  : String (1 .. Count);
   end record;

   for ASCIC use record
      Count at 0 range 0 .. 7;
   end record;
   pragma Pack (ASCIC);

   type AASCIC is access ASCIC;
   for AASCIC'Size use 32;

   type AASCIC_Array is array (Positive range <>) of AASCIC;

   type ASCIC127 is record
      Count : Count_Type;
      Text  : String (1 .. 127);
   end record;

   for ASCIC127 use record
      Count at 0 range 0 .. 7;
      Text  at 1 range 0 .. 127 * 8 - 1;
   end record;

   --  DEBUG Event record types used to signal DEBUG about Ada events

   type Debug_Event_Record is record
      Code     : Unsigned_Word; --  Event code that uniquely identifies event
      Flags    : Bit_Array_8;   --  Flag bits
      --                            Bit 0: This event allows a parameter list
      --                            Bit 1: Parameters are address expressions
      Sentinal : Unsigned_Byte; --  Sentinal valuye: Always K_EVENT_SENT
      TS_Kind  : Unsigned_Byte; --  DST type specification: Always K_TS_TASK
      DType    : Unsigned_Byte; --  DTYPE of parameter if of atomic data type
      --                            Always K_DTYPE_TASK
      MBZ      : Unsigned_Byte; --  Unused (must be zero)
      Minchr   : Count_Type;    --  Minimum chars needed to identify event
      Name     : ASCIC (31);    --  Event name uppercase only
      Help     : AASCIC;        --  Event description
   end record;

   for Debug_Event_Record use record
      Code     at 0 range 0 .. 15;
      Flags    at 2 range 0 .. 7;
      Sentinal at 3 range 0 .. 7;
      TS_Kind  at 4 range 0 .. 7;
      Dtype    at 5 range 0 .. 7;
      MBZ      at 6 range 0 .. 7;
      Minchr   at 7 range 0 .. 7;
      Name     at 8 range 0 .. 32 * 8 - 1;
      Help     at 40 range 0 .. 31;
   end record;

   type Ada_Event_Control_Block_Type is record
      Code      : Unsigned_Word;     --  Reserved and defined by DEBUG
      Unused1   : Unsigned_Byte;     --  Reserved and defined by DEBUG
      Sentinal  : Unsigned_Byte;     --  Reserved and defined by DEBUG
      Facility  : Unsigned_Word;     --  Reserved and defined by DEBUG
      Flags     : Unsigned_Word;     --  Reserved and defined by DEBUG
      Value     : Unsigned_Longword; --  Reserved and defined by DEBUG
      Unused2   : Unsigned_Longword; --  Reserved and defined by DEBUG
      Sigargs   : Unsigned_Longword;
      P1        : Unsigned_Longword;
      Sub_Event : Unsigned_Longword;
   end record;

   for Ada_Event_Control_Block_Type use record
      Code      at 0 range 0 .. 15;
      Unused1   at 2 range 0 .. 7;
      Sentinal  at 3 range 0 .. 7;
      Facility  at 4 range 0 .. 15;
      Flags     at 6 range 0 .. 15;
      Value     at 8 range 0 .. 31;
      Unused2   at 12 range 0 .. 31;
      Sigargs   at 16 range 0 .. 31;
      P1        at 20 range 0 .. 31;
      Sub_Event at 24 range 0 .. 31;
   end record;

   type Ada_Event_Control_Block_Access is access Ada_Event_Control_Block_Type;
   for Ada_Event_Control_Block_Access'Size use 32;

   --  Print_Routine_Type with max optional parameters

   type Print_Routine_Type is access procedure
     (Print_Function    : Print_Functions;
      Print_Subfunction : Print_Functions;
      P1                : Unsigned_Longword := 0;
      P2                : Unsigned_Longword := 0;
      P3                : Unsigned_Longword := 0;
      P4                : Unsigned_Longword := 0;
      P5                : Unsigned_Longword := 0;
      P6                : Unsigned_Longword := 0);
   for Print_Routine_Type'Size use 32;

   ---------------
   -- Constants --
   ---------------

   --  These are used to obtain and convert task values
   K_CVT_VALUE_NUM  : constant := 1;
   K_CVT_NUM_VALUE  : constant := 2;
   K_NEXT_TASK      : constant := 3;

   --  These are used to ask ADA to display task information
   K_SHOW_TASK     : constant := 4;
   K_SHOW_STAT     : constant := 5;
   K_SHOW_DEADLOCK : constant := 6;

   --  These are used to get and set various attributes of one or more tasks
   --    Task state
   --  K_GET_STATE  : constant := 7;
   --  K_GET_ACTIVE : constant := 8;
   --  K_SET_ACTIVE : constant := 9;
   K_SET_ABORT  : constant := 10;
   --  K_SET_HOLD   : constant := 11;

   --    Task priority
   K_GET_PRIORITY      : constant := 12;
   K_SET_PRIORITY      : constant := 13;
   K_RESTORE_PRIORITY  : constant := 14;

   --    Task registers
   --  K_GET_REGISTERS     : constant := 15;
   --  K_SET_REGISTERS     : constant := 16;

   --  These are used to control definable events
   K_ENABLE_EVENT   : constant := 17;
   K_DISABLE_EVENT  : constant := 18;
   K_ANNOUNCE_EVENT : constant := 19;

   --  These are used to control time-slicing.
   --  K_SHOW_TIME_SLICE : constant := 20;
   --  K_SET_TIME_SLICE  : constant := 21;

   --  This is used to symbolize task stack addresses.
   --  K_SYMBOLIZE_ADDRESS : constant := 22;

   K_GET_CALLER : constant := 23;
   --  This is used to obtain the task value of the caller task

   --  Miscellaneous functions - see below for details

   K_CLEANUP_EVENT  : constant := 24;
   K_SHOW_EVENT_DEF : constant := 25;
   --  K_CHECK_TASK_STACK : constant := 26;  --  why commented out ???

   --  This is used to obtain the DBGEXT-interface revision level
   --  K_GET_DBGEXT_REV : constant := 27; -- why commented out ???

   K_GET_STATE_1 : constant := 28;
   --  This is used to obtain additional state info, primarily for PCA

   K_FIND_EVENT_BY_CODE : constant := 29;
   K_FIND_EVENT_BY_NAME : constant := 30;
   --  These are used to search for user-defined event entries

   --  This is used to stop task schedulding. Why commented out ???
   --  K_STOP_ALL_OTHER_TASKS : constant := 31;

   --  Debug event constants

   K_TASK_NOT_EXIST  : constant := 3;
   K_SUCCESS         : constant := 1;
   K_EVENT_SENT      : constant := 16#9A#;
   K_TS_TASK         : constant := 18;
   K_DTYPE_TASK      : constant := 44;

   --  Status signal constants

   SS_BADPARAM       : constant := 20;
   SS_NORMAL         : constant := 1;

   --  Miscellaneous mask constants

   V_EVNT_ALL        : constant := 0;
   V_Full_Display    : constant := 11;
   V_Suppress_Header : constant := 13;

   --  CMA constants (why are some commented out???)

   CMA_C_DEBGET_GUARDSIZE     : constant := 1;
   CMA_C_DEBGET_IS_HELD       : constant := 2;
--   CMA_C_DEBGET_IS_INITIAL    : constant := 3;
--   CMA_C_DEBGET_NUMBER        : constant := 4;
   CMA_C_DEBGET_STACKPTR      : constant := 5;
   CMA_C_DEBGET_STACK_BASE    : constant := 6;
   CMA_C_DEBGET_STACK_TOP     : constant := 7;
   CMA_C_DEBGET_SCHED_STATE   : constant := 8;
   CMA_C_DEBGET_YELLOWSIZE    : constant := 9;
--   CMA_C_DEBGET_BASE_PRIO     : constant := 10;
--   CMA_C_DEBGET_REGS          : constant := 11;
--   CMA_C_DEBGET_ALT_PENDING   : constant := 12;
--   CMA_C_DEBGET_ALT_A_ENABLE  : constant := 13;
--   CMA_C_DEBGET_ALT_G_ENABLE  : constant := 14;
--   CMA_C_DEBGET_SUBSTATE      : constant := 15;
--   CMA_C_DEBGET_OBJECT_ADDR   : constant := 16;
--   CMA_C_DEBGET_THKIND        : constant := 17;
--   CMA_C_DEBGET_DETACHED      : constant := 18;
   CMA_C_DEBGET_TCB_SIZE      : constant := 19;
--   CMA_C_DEBGET_START_PC      : constant := 20;
--   CMA_C_DEBGET_NEXT_PC       : constant := 22;
--   CMA_C_DEBGET_POLICY        : constant := 23;
--   CMA_C_DEBGET_STACK_YELLOW  : constant := 24;
--   CMA_C_DEBGET_STACK_DEFAULT : constant := 25;

   --  Miscellaneous counted ascii constants

   Star     : constant AASCIC := new ASCIC'(2, ("* "));
   NoStar   : constant AASCIC := new ASCIC'(2, ("  "));
   Hold     : constant AASCIC := new ASCIC'(4, ("HOLD"));
   NoHold   : constant AASCIC := new ASCIC'(4, ("    "));
   Header   : constant AASCIC := new ASCIC '
     (60, ("  task id     pri hold state   substate          task object"));
   Empty_Text : constant AASCIC := new ASCIC (0);

   --  DEBUG Ada tasking states equated to their GNAT tasking equivalents

   Ada_State_Invalid_State     : constant AASCIC :=
     new ASCIC'(17, "Invalid state    ");
--   Ada_State_Abnormal          : constant AASCIC :=
--     new ASCIC'(17, "Abnormal         ");
   Ada_State_Aborting          : constant AASCIC :=
     new ASCIC'(17, "Aborting         "); --  Aborting (new)
--   Ada_State_Completed_Abn     : constant AASCIC :=
--     new ASCIC'(17, "Completed  [abn] ");
--   Ada_State_Completed_Exc     : constant AASCIC :=
--     new ASCIC'(17, "Completed  [exc] ");
   Ada_State_Completed         : constant AASCIC :=
     new ASCIC'(17, "Completed        "); --  Master_Completion_Sleep
   Ada_State_Runnable          : constant AASCIC :=
     new ASCIC'(17, "Runnable         "); --  Runnable
   Ada_State_Activating        : constant AASCIC :=
     new ASCIC'(17, "Activating       ");
   Ada_State_Accept            : constant AASCIC :=
     new ASCIC'(17, "Accept           "); --  Acceptor_Sleep
   Ada_State_Select_or_Delay   : constant AASCIC :=
     new ASCIC'(17, "Select or delay  "); --  Acceptor_Delay_Sleep
   Ada_State_Select_or_Term    : constant AASCIC :=
     new ASCIC'(17, "Select or term.  "); -- Terminate_Alternative
   Ada_State_Select_or_Abort   : constant AASCIC :=
     new ASCIC'(17, "Select or abort  "); --  Async_Select_Sleep (new)
--   Ada_State_Select            : constant AASCIC :=
--     new ASCIC'(17, "Select           ");
   Ada_State_Activating_Tasks  : constant AASCIC :=
     new ASCIC'(17, "Activating tasks "); --  Activator_Sleep
   Ada_State_Delay             : constant AASCIC :=
     new ASCIC'(17, "Delay            "); --  AST_Pending
--   Ada_State_Dependents        : constant AASCIC :=
--     new ASCIC'(17, "Dependents       ");
   Ada_State_Entry_Call        : constant AASCIC :=
     new ASCIC'(17, "Entry call       "); --  Entry_Caller_Sleep
   Ada_State_Cond_Entry_Call   : constant AASCIC :=
     new ASCIC'(17, "Cond. entry call "); --  Call.Mode.Conditional_Call
   Ada_State_Timed_Entry_Call  : constant AASCIC :=
     new ASCIC'(17, "Timed entry call "); --  Call.Mode.Timed_Call
   Ada_State_Async_Entry_Call  : constant AASCIC :=
     new ASCIC'(17, "Async entry call "); --  Call.Mode.Asynchronous_Call (new)
--   Ada_State_Dependents_Exc    : constant AASCIC :=
--     new ASCIC'(17, "Dependents [exc] ");
   Ada_State_IO_or_AST         : constant AASCIC :=
     new ASCIC'(17, "I/O or AST       "); --  AST_Server_Sleep
--   Ada_State_Shared_Resource   : constant AASCIC :=
--     new ASCIC'(17, "Shared resource  ");
   Ada_State_Not_Yet_Activated : constant AASCIC :=
     new ASCIC'(17, "Not yet activated"); --  Unactivated
--   Ada_State_Terminated_Abn    : constant AASCIC :=
--     new ASCIC'(17, "Terminated [abn] ");
--   Ada_State_Terminated_Exc    : constant AASCIC :=
--     new ASCIC'(17, "Terminated [exc] ");
   Ada_State_Terminated        : constant AASCIC :=
     new ASCIC'(17, "Terminated       "); --  Terminated
   Ada_State_Server            : constant AASCIC :=
     new ASCIC'(17, "Server           "); --  Servers
   Ada_State_Async_Hold        : constant AASCIC :=
     new ASCIC'(17, "Async_Hold       "); --  Async_Hold

   --  Task state counted ascii constants

   Debug_State_Emp : constant AASCIC := new ASCIC'(5, "     ");
   Debug_State_Run : constant AASCIC := new ASCIC'(5, "RUN  ");
   Debug_State_Rea : constant AASCIC := new ASCIC'(5, "READY");
   Debug_State_Sus : constant AASCIC := new ASCIC'(5, "SUSP ");
   Debug_State_Ter : constant AASCIC := new ASCIC'(5, "TERM ");

   --  Priority order of event display

   Global_Event_Display_Order : constant array (Event_Kind_Type)
     of Event_Kind_Type := (
      Debug_Event_Abort_Terminated,
      Debug_Event_Activating,
      Debug_Event_Dependents_Exception,
      Debug_Event_Exception_Terminated,
      Debug_Event_Handled,
      Debug_Event_Handled_Others,
      Debug_Event_Preempted,
      Debug_Event_Rendezvous_Exception,
      Debug_Event_Run,
      Debug_Event_Suspended,
      Debug_Event_Terminated);

   --  Constant array defining all debug events

   Event_Directory : constant array (Event_Kind_Type)
     of Debug_Event_Record := (
      (Debug_Event_Activating,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       2,
       (31, "ACTIVATING                     "),
       new ASCIC'(41, "!_a task is about to begin its activation")),

      (Debug_Event_Run,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       2,
       (31, "RUN                            "),
       new ASCIC'(24, "!_a task is about to run")),

      (Debug_Event_Suspended,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       1,
       (31, "SUSPENDED                      "),
       new ASCIC'(33, "!_a task is about to be suspended")),

      (Debug_Event_Preempted,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       1,
       (31, "PREEMPTED                      "),
       new ASCIC'(33, "!_a task is about to be preempted")),

      (Debug_Event_Terminated,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       1,
       (31, "TERMINATED                     "),
       new ASCIC'(57,
        "!_a task is terminating (including by abort or exception)")),

      (Debug_Event_Abort_Terminated,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       2,
       (31, "ABORT_TERMINATED               "),
       new ASCIC'(40, "!_a task is terminating because of abort")),

      (Debug_Event_Exception_Terminated,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       1,
       (31, "EXCEPTION_TERMINATED           "),
       new ASCIC'(47, "!_a task is terminating because of an exception")),

      (Debug_Event_Rendezvous_Exception,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       3,
       (31, "RENDEZVOUS_EXCEPTION           "),
       new ASCIC'(49, "!_an exception is propagating out of a rendezvous")),

      (Debug_Event_Handled,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       1,
       (31, "HANDLED                        "),
       new ASCIC'(37, "!_an exception is about to be handled")),

      (Debug_Event_Dependents_Exception,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       1,
       (31, "DEPENDENTS_EXCEPTION           "),
       new ASCIC'(64,
        "!_an exception is about to cause a task to await dependent tasks")),

      (Debug_Event_Handled_Others,
       (False, False, False, False, False, False, False, True),
       K_EVENT_SENT,
       K_TS_TASK,
       K_DTYPE_TASK,
       0,
       1,
       (31, "HANDLED_OTHERS                 "),
       new ASCIC'(58,
        "!_an exception is about to be handled in an OTHERS handler")));

   --  Help on events displayed in DEBUG

   Event_Def_Help : constant AASCIC_Array := (
     new ASCIC'(0,  ""),
     new ASCIC'(65,
      "  The general forms of commands to set a breakpoint or tracepoint"),
     new ASCIC'(22, "  on an Ada event are:"),
     new ASCIC'(73, "    SET BREAK/EVENT=event [task[, ... ]] " &
                    "[WHEN(expr)] [DO(comnd[; ... ])]"),
     new ASCIC'(73, "    SET TRACE/EVENT=event [task[, ... ]] " &
                    "[WHEN(expr)] [DO(comnd[; ... ])]"),
     new ASCIC'(0,  ""),
     new ASCIC'(65,
      "  If tasks are specified, the breakpoint will trigger only if the"),
     new ASCIC'(40, "  event occurs for those specific tasks."),
     new ASCIC'(0,  ""),
     new ASCIC'(39, "  Ada event names and their definitions"),
     new ASCIC'(0,  ""));

   -----------------------
   -- Package Variables --
   -----------------------

   AC_Buffer : ASCIC127;

   Events_Enabled_Count : Integer := 0;

   Print_Routine_Bufsiz : constant := 132;
   Print_Routine_Bufcnt : Integer := 0;
   Print_Routine_Linbuf : String (1 .. Print_Routine_Bufsiz);

   Global_Task_Debug_Events : Debug_Event_Array :=
     (False, False, False, False, False, False, False, False,
      False, False, False, False, False, False, False, False);
   --  Global table of task debug events set by the debugger

   --------------------------
   -- Exported Subprograms --
   --------------------------

   procedure Default_Print_Routine
     (Print_Function    : Print_Functions;
      Print_Subfunction : Print_Functions;
      P1                : Unsigned_Longword := 0;
      P2                : Unsigned_Longword := 0;
      P3                : Unsigned_Longword := 0;
      P4                : Unsigned_Longword := 0;
      P5                : Unsigned_Longword := 0;
      P6                : Unsigned_Longword := 0);
   --  The default print routine if not overridden.
   --  Print_Function determines option argument formatting.
   --  Print_Subfunction buffers output if No_Print, calls Put_Output if
   --  Print_Newline

   pragma Export_Procedure
     (Default_Print_Routine,
      Mechanism => (Value, Value, Reference, Reference, Reference));

   --------------------------
   -- Imported Subprograms --
   --------------------------

   procedure Debug_Get
     (Thread_Id : OSI.Thread_Id;
      Item_Req  : Unsigned_Word;
      Out_Buff  : System.Address;
      Buff_Siz  : Unsigned_Word);

   procedure Debug_Get
     (Thread_Id : OSI.Thread_Id;
      Item_Req  : Unsigned_Word;
      Out_Buff  : Unsigned_Longword;
      Buff_Siz  : Unsigned_Word);
   pragma Import (External, Debug_Get);

   pragma Import_Procedure (Debug_Get, "CMA$DEBUG_GET",
     (OSI.Thread_Id, Unsigned_Word, System.Address, Unsigned_Word),
     (Reference, Value, Reference, Value));

   pragma Import_Procedure (Debug_Get, "CMA$DEBUG_GET",
     (OSI.Thread_Id, Unsigned_Word, Unsigned_Longword, Unsigned_Word),
     (Reference, Value, Reference, Value));

   procedure FAOL
     (Status : out Cond_Value_Type;
      Ctrstr : String;
      Outlen : out Unsigned_Word;
      Outbuf : out String;
      Prmlst : Unsigned_Longword_Array);
   pragma Import (External, FAOL);

   pragma Import_Valued_Procedure (FAOL, "SYS$FAOL",
     (Cond_Value_Type, String, Unsigned_Word, String, Unsigned_Longword_Array),
     (Value, Descriptor (S), Reference, Descriptor (S), Reference));

   procedure Put_Output (
     Status         : out Cond_Value_Type;
     Message_String : String);

   procedure Put_Output (Message_String : String);
   pragma Import (External, Put_Output);

   pragma Import_Valued_Procedure (Put_Output, "LIB$PUT_OUTPUT",
     (Cond_Value_Type, String),
     (Value, Short_Descriptor (S)));

   pragma Import_Procedure (Put_Output, "LIB$PUT_OUTPUT",
     (String),
     (Short_Descriptor (S)));

   procedure Signal
     (Condition_Value     : Cond_Value_Type;
      Number_Of_Arguments : Integer := Integer'Null_Parameter;
      FAO_Argument_1      : Unsigned_Longword :=
                              Unsigned_Longword'Null_Parameter);
   pragma Import (External, Signal);

   pragma Import_Procedure (Signal, "LIB$SIGNAL",
      (Cond_Value_Type, Integer, Unsigned_Longword),
      (Value, Value, Value),
       Number_Of_Arguments);

   ----------------------------
   -- Generic Instantiations --
   ----------------------------

   function Fetch is new Fetch_From_Address (Unsigned_Longword);
   pragma Unreferenced (Fetch);

   procedure Free is new Ada.Unchecked_Deallocation
     (Object => Ada_Event_Control_Block_Type,
      Name   => Ada_Event_Control_Block_Access);

   function To_AASCIC is new
     Ada.Unchecked_Conversion (Unsigned_Longword, AASCIC);

   function To_Addr is new
     Ada.Unchecked_Conversion (Task_Procedure_Access, Address);
   pragma Unreferenced (To_Addr);

   function To_EVCB is new
     Ada.Unchecked_Conversion
      (Unsigned_Longword, Ada_Event_Control_Block_Access);

   function To_Integer is new
     Ada.Unchecked_Conversion (Task_Id, System.Task_Primitives.Task_Address);

   function To_Print_Routine_Type is new
     Ada.Unchecked_Conversion (Short_Address, Print_Routine_Type);

   --  Optional argumements passed to Print_Routine have to be
   --  Unsigned_Longwords so define the required Unchecked_Conversions

   function To_UL is new
     Ada.Unchecked_Conversion (AASCIC, Unsigned_Longword);

   function To_UL is new
     Ada.Unchecked_Conversion (Integer, Unsigned_Longword);

   function To_UL is new
     Ada.Unchecked_Conversion (Task_Id, Unsigned_Longword);

   pragma Warnings (Off); --  Different sizes
   function To_UL is new
     Ada.Unchecked_Conversion (Task_Entry_Index, Unsigned_Longword);
   pragma Warnings (On);

   function To_UL is new
     Ada.Unchecked_Conversion (Short_Address, Unsigned_Longword);

   function To_UL is new
     Ada.Unchecked_Conversion
      (Ada_Event_Control_Block_Access, Unsigned_Longword);

   -----------------------
   -- Local Subprograms --
   -----------------------

   subtype Function_Codes is System.Aux_DEC.Unsigned_Word range 1 .. 31;
   --  The 31 function codes sent by the debugger needed to implement
   --  tasking support, enumerated below.

   type Register_Array is array (Natural range 0 .. 16) of
     System.Aux_DEC.Unsigned_Longword;
   --  The register array is a holdover from VAX and not used
   --  on Alpha or I64 but is kept as a filler below.

   type DBGEXT_Control_Block (Function_Code : Function_Codes) is record
      Facility_ID         : System.Aux_DEC.Unsigned_Word;
      --  For GNAT use the "Ada" facility ID
      Status              : System.Aux_DEC.Unsigned_Longword;
      --  Successful or otherwise returned status
      Flags               : System.Aux_DEC.Bit_Array_32;
      --   Used to flag event as global
      Print_Routine       : System.Aux_DEC.Short_Address;
      --  The print subprogram the caller wants to use for output
      Event_Code_or_EVCB  : System.Aux_DEC.Unsigned_Longword;
      --  Dual use Event Code or EVent Control Block
      Event_Value_or_Name : System.Aux_DEC.Unsigned_Longword;
      --  Dual use Event Value or Event Name string pointer
      Event_Entry         : System.Aux_DEC.Unsigned_Longword;
      Task_Value          : Task_Id;
      Task_Number         : Integer;
      Ada_Flags           : System.Aux_DEC.Bit_Array_32;
      Priority            : System.Aux_DEC.Bit_Array_32;
      Active_Registers    : System.Aux_DEC.Short_Address;

      case Function_Code is
         when K_GET_STATE_1 =>
            Base_Priority       : System.Aux_DEC.Bit_Array_32;
            Task_Type_Name      : System.Aux_DEC.Short_Address;
            Creation_PC         : System.Aux_DEC.Short_Address;
            Parent_Task_ID      : Task_Id;

         when others =>
            Ignored_Unused      : Register_Array;

      end case;
   end record;

   for DBGEXT_Control_Block use record
      Function_Code       at 0  range 0 .. 15;
      Facility_ID         at 2  range 0 .. 15;
      Status              at 4  range 0 .. 31;
      Flags               at 8  range 0 .. 31;
      Print_Routine       at 12 range 0 .. 31;
      Event_Code_or_EVCB  at 16 range 0 .. 31;
      Event_Value_or_Name at 20 range 0 .. 31;
      Event_Entry         at 24 range 0 .. 31;
      Task_Value          at 28 range 0 .. 31;
      Task_Number         at 32 range 0 .. 31;
      Ada_Flags           at 36 range 0 .. 31;
      Priority            at 40 range 0 .. 31;
      Active_Registers    at 44 range 0 .. 31;
      Ignored_Unused      at 48 range 0 .. 17 * 32 - 1;
      Base_Priority       at 48 range 0 .. 31;
      Task_Type_Name      at 52 range 0 .. 31;
      Creation_PC         at 56 range 0 .. 31;
      Parent_Task_ID      at 60 range 0 .. 31;
   end record;

   type DBGEXT_Control_Block_Access is access all DBGEXT_Control_Block;

   function DBGEXT (Control_Block : DBGEXT_Control_Block_Access)
     return System.Aux_DEC.Unsigned_Word;
   --  Exported to s-taprop.adb to avoid having a VMS specific s-tasdeb.ads
   pragma Convention (C, DBGEXT);
   pragma Export_Function (DBGEXT, "GNAT$DBGEXT");
   --  This routine is called by CMA when VMS DEBUG wants the Gnat RTL
   --  to give it some assistance (primarily when tasks are debugged).
   --
   --  The single parameter is an "external control block". On input to
   --  the Gnat RTL this control block determines the debugging function
   --  to be performed, and supplies parameters.  This routine cases on
   --  the function code, and calls the appropriate Gnat RTL routine,
   --  which returns values by modifying the external control block.

   procedure Announce_Event
      (Event_EVCB    : Unsigned_Longword;
       Print_Routine : Print_Routine_Type := Default_Print_Routine'Access);
   --  Announce the occurence of a DEBUG tasking event

   procedure Cleanup_Event (Event_EVCB : Unsigned_Longword);
   --  After DEBUG has processed an event that has signalled, the signaller
   --  must cleanup. Cleanup consists of freeing the event control block.

   procedure Disable_Event
      (Flags       : Bit_Array_32;
       Event_Value : Unsigned_Longword;
       Event_Code  : Unsigned_Longword;
       Status      : out Cond_Value_Type);
   --  Disable a DEBUG tasking event

   function DoAC (S : String) return Address;
   --  Convert a string to the address of an internal buffer containing
   --  the counted ASCII.

   procedure Enable_Event
      (Flags       : Bit_Array_32;
       Event_Value : Unsigned_Longword;
       Event_Code  : Unsigned_Longword;
       Status      : out Cond_Value_Type);
   --  Enable a requested DEBUG tasking event

   procedure Find_Event_By_Code
      (Event_Code  : Unsigned_Longword;
       Event_Entry : out Unsigned_Longword;
       Status      : out Cond_Value_Type);
   --  Convert an event code to the address of the event entry

   procedure Find_Event_By_Name
      (Event_Name  : Unsigned_Longword;
       Event_Entry : out Unsigned_Longword;
       Status      : out Cond_Value_Type);
   --  Find an event entry given the event name

   procedure List_Entry_Waiters
     (Task_Value      : Task_Id;
      Full_Display    : Boolean := False;
      Suppress_Header : Boolean := False;
      Print_Routine   : Print_Routine_Type := Default_Print_Routine'Access);
   --  List information about tasks waiting on an entry

   procedure Put (S : String);
   --  Display S on standard output

   procedure Put_Line (S : String := "");
   --  Display S on standard output with an additional line terminator

   procedure Show_Event
      (Print_Routine : Print_Routine_Type := Default_Print_Routine'Access);
   --  Show what events are available

   procedure Show_One_Task
     (Task_Value      : Task_Id;
      Full_Display    : Boolean := False;
      Suppress_Header : Boolean := False;
      Print_Routine   : Print_Routine_Type := Default_Print_Routine'Access);
   --  Display information about one task

   procedure Show_Rendezvous
     (Task_Value      : Task_Id;
      Ada_State       : AASCIC := Empty_Text;
      Full_Display    : Boolean := False;
      Suppress_Header : Boolean := False;
      Print_Routine   : Print_Routine_Type := Default_Print_Routine'Access);
   --  Display information about a task rendezvous

   procedure Trace_Output (Message_String : String);
   --  Call Put_Output if Trace_on ("VMS")

   procedure Write (Fd : Integer; S : String; Count : Integer);

   --------------------
   -- Announce_Event --
   --------------------

   procedure Announce_Event
      (Event_EVCB    : Unsigned_Longword;
       Print_Routine : Print_Routine_Type := Default_Print_Routine'Access)
   is
      EVCB : constant Ada_Event_Control_Block_Access := To_EVCB (Event_EVCB);

      Event_Kind : constant Event_Kind_Type :=
                     (if EVCB.Sub_Event /= 0
                      then Event_Kind_Type (EVCB.Sub_Event)
                      else Event_Kind_Type (EVCB.Code));

      TI : constant String := "   Task %TASK !UI is ";
      --  Announce prefix

   begin
      Trace_Output ("Announce called");

      case Event_Kind is
         when Debug_Event_Activating =>
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC (TI & "about to begin its activation")),
              EVCB.Value);
         when Debug_Event_Exception_Terminated =>
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC (TI & "terminating because of an exception")),
              EVCB.Value);
         when Debug_Event_Run =>
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC (TI & "about to run")),
              EVCB.Value);
         when Debug_Event_Abort_Terminated =>
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC (TI & "terminating because of abort")),
              EVCB.Value);
         when Debug_Event_Terminated =>
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC (TI & "terminating normally")),
              EVCB.Value);
         when others => null;
      end case;
   end Announce_Event;

   -------------------
   -- Cleanup_Event --
   -------------------

   procedure Cleanup_Event (Event_EVCB  : Unsigned_Longword) is
      EVCB : Ada_Event_Control_Block_Access := To_EVCB (Event_EVCB);
   begin
      Free (EVCB);
   end Cleanup_Event;

   ------------------------
   -- Continue_All_Tasks --
   ------------------------

   procedure Continue_All_Tasks is
   begin
      null; --  VxWorks
   end Continue_All_Tasks;

   ------------
   -- DBGEXT --
   ------------

   function DBGEXT
     (Control_Block : DBGEXT_Control_Block_Access)
      return System.Aux_DEC.Unsigned_Word
   is
      Print_Routine : Print_Routine_Type := Default_Print_Routine'Access;
   begin
      Trace_Output ("DBGEXT called");

      if Control_Block.Print_Routine /= Address_Zero then
         Print_Routine := To_Print_Routine_Type (Control_Block.Print_Routine);
      end if;

      case Control_Block.Function_Code is

         --  Convert a task value to a task number.
         --  The output results are stored in the CONTROL_BLOCK.

         when K_CVT_VALUE_NUM =>
            Trace_Output ("DBGEXT param 1 - CVT Value to NUM");
            Control_Block.Task_Number :=
              Control_Block.Task_Value.Known_Tasks_Index + 1;
            Control_Block.Status := K_SUCCESS;
            Trace_Output ("Task Number: ");
            Trace_Output (Integer'Image (Control_Block.Task_Number));
            return SS_NORMAL;

         --  Convert a task number to a task value.
         --  The output results are stored in the CONTROL_BLOCK.

         when K_CVT_NUM_VALUE =>
            Trace_Output ("DBGEXT param 2 - CVT NUM to Value");
            Trace_Output ("Task Number: ");
            Trace_Output (Integer'Image (Control_Block.Task_Number));
            Control_Block.Task_Value :=
              Known_Tasks (Control_Block.Task_Number - 1);
            Control_Block.Status := K_SUCCESS;
            Trace_Output ("Task Value: ");
            Trace_Output (Unsigned_Longword'Image
              (To_UL (Control_Block.Task_Value)));
            return SS_NORMAL;

         --  Obtain the "next" task after a specified task.
         --  ??? To do: If specified check the PRIORITY, STATE, and HOLD
         --  fields to restrict the selection of the next task.
         --  The output results are stored in the CONTROL_BLOCK.

         when K_NEXT_TASK =>
            Trace_Output ("DBGEXT param 3 - Next Task");
            Trace_Output ("Task Value: ");
            Trace_Output (Unsigned_Longword'Image
              (To_UL (Control_Block.Task_Value)));

            if Control_Block.Task_Value = null then
               Control_Block.Task_Value := Known_Tasks (Known_Tasks'First);
            else
               Control_Block.Task_Value :=
                 Known_Tasks (Control_Block.Task_Value.Known_Tasks_Index + 1);
            end if;

            if Control_Block.Task_Value = null then
               Control_Block.Task_Value := Known_Tasks (Known_Tasks'First);
            end if;

            Control_Block.Status := K_SUCCESS;
            return SS_NORMAL;

         --  Display the state of a task. The FULL bit is checked to decide if
         --  a full or brief task display is desired. The output results are
         --  stored in the CONTROL_BLOCK.

         when K_SHOW_TASK =>
            Trace_Output ("DBGEXT param 4 - Show Task");

            if Control_Block.Task_Value = null then
               Control_Block.Status := K_TASK_NOT_EXIST;
            else
               Show_One_Task
                 (Control_Block.Task_Value,
                  Control_Block.Ada_Flags (V_Full_Display),
                  Control_Block.Ada_Flags (V_Suppress_Header),
                  Print_Routine);

               Control_Block.Status := K_SUCCESS;
            end if;

            return SS_NORMAL;

         --  Enable a requested DEBUG tasking event

         when K_ENABLE_EVENT =>
            Trace_Output ("DBGEXT param 17 - Enable Event");
            Enable_Event
              (Control_Block.Flags,
               Control_Block.Event_Value_or_Name,
               Control_Block.Event_Code_or_EVCB,
               Control_Block.Status);

            return SS_NORMAL;

         --  Disable a DEBUG tasking event

         when K_DISABLE_EVENT =>
            Trace_Output ("DBGEXT param 18 - Disable Event");
            Disable_Event
              (Control_Block.Flags,
               Control_Block.Event_Value_or_Name,
               Control_Block.Event_Code_or_EVCB,
               Control_Block.Status);

            return SS_NORMAL;

         --  Announce the occurence of a DEBUG tasking event

         when K_ANNOUNCE_EVENT =>
            Trace_Output ("DBGEXT param 19 - Announce Event");
            Announce_Event
              (Control_Block.Event_Code_or_EVCB,
               Print_Routine);

            Control_Block.Status := K_SUCCESS;
            return SS_NORMAL;

         --  After DEBUG has processed an event that has signalled,
         --  the signaller must cleanup.
         --  Cleanup consists of freeing the event control block.

         when K_CLEANUP_EVENT =>
            Trace_Output ("DBGEXT param 24 - Cleanup Event");
            Cleanup_Event (Control_Block.Event_Code_or_EVCB);

            Control_Block.Status := K_SUCCESS;
            return SS_NORMAL;

         --  Show what events are available

         when K_SHOW_EVENT_DEF =>
            Trace_Output ("DBGEXT param 25 - Show Event Def");
            Show_Event (Print_Routine);

            Control_Block.Status := K_SUCCESS;
            return SS_NORMAL;

         --  Convert an event code to the address of the event entry

         when K_FIND_EVENT_BY_CODE =>
            Trace_Output ("DBGEXT param 29 - Find Event by Code");
            Find_Event_By_Code
              (Control_Block.Event_Code_or_EVCB,
               Control_Block.Event_Entry,
               Control_Block.Status);

            return SS_NORMAL;

         --  Find an event entry given the event name

         when K_FIND_EVENT_BY_NAME =>
            Trace_Output ("DBGEXT param 30 - Find Event by Name");
            Find_Event_By_Name
              (Control_Block.Event_Value_or_Name,
               Control_Block.Event_Entry,
               Control_Block.Status);
            return SS_NORMAL;

         --  ??? To do: Implement priority events
         --  Get, set or restore a task's priority

         when K_GET_PRIORITY or K_SET_PRIORITY or K_RESTORE_PRIORITY =>
            Trace_Output ("DBGEXT priority param - Not yet implemented");
            Trace_Output (Function_Codes'Image
             (Control_Block.Function_Code));
            return SS_BADPARAM;

         --  ??? To do: Implement show statistics event
         --  Display task statistics

         when K_SHOW_STAT =>
            Trace_Output ("DBGEXT show stat param - Not yet implemented");
            Trace_Output (Function_Codes'Image
             (Control_Block.Function_Code));
            return SS_BADPARAM;

         --  ??? To do: Implement get caller event
         --  Obtain the caller of a task in a rendezvous. If no rendezvous,
         --  null is returned

         when K_GET_CALLER =>
            Trace_Output ("DBGEXT get caller param - Not yet implemented");
            Trace_Output (Function_Codes'Image
             (Control_Block.Function_Code));
            return SS_BADPARAM;

         --  ??? To do: Implement set terminate event
         --  Terminate a task

         when K_SET_ABORT =>
            Trace_Output ("DBGEXT set terminate param - Not yet implemented");
            Trace_Output (Function_Codes'Image
             (Control_Block.Function_Code));
            return SS_BADPARAM;

         --  ??? To do: Implement show deadlock event
         --  Detect a deadlock

         when K_SHOW_DEADLOCK =>
            Trace_Output ("DBGEXT show deadlock param - Not yet implemented");
            Trace_Output (Function_Codes'Image
             (Control_Block.Function_Code));
            return SS_BADPARAM;

         when others =>
            Trace_Output ("DBGEXT bad param: ");
            Trace_Output (Function_Codes'Image
             (Control_Block.Function_Code));
            return SS_BADPARAM;

      end case;
   end DBGEXT;

   ---------------------------
   -- Default_Print_Routine --
   ---------------------------

   procedure Default_Print_Routine
     (Print_Function    : Print_Functions;
      Print_Subfunction : Print_Functions;
      P1                : Unsigned_Longword := 0;
      P2                : Unsigned_Longword := 0;
      P3                : Unsigned_Longword := 0;
      P4                : Unsigned_Longword := 0;
      P5                : Unsigned_Longword := 0;
      P6                : Unsigned_Longword := 0)
   is
      Status    : Cond_Value_Type;
      Linlen    : Unsigned_Word;
      Item_List : Unsigned_Longword_Array (1 .. 17) :=
        (1 .. 17 => 0);
   begin

      case Print_Function is
         when Print_Control | Print_String =>
            null;

         --  Formatted Ascii Output

         when Print_FAO =>
            Item_List (1) := P2;
            Item_List (2) := P3;
            Item_List (3) := P4;
            Item_List (4) := P5;
            Item_List (5) := P6;
            FAOL
              (Status,
               To_AASCIC (P1).Text,
               Linlen,
               Print_Routine_Linbuf
                 (1 + Print_Routine_Bufcnt .. Print_Routine_Bufsiz),
               Item_List);

            Print_Routine_Bufcnt := Print_Routine_Bufcnt + Integer (Linlen);

         --  Symbolic output

         when Print_Symbol =>
            Item_List (1) := P1;
            FAOL
              (Status,
               "!XI",
               Linlen,
               Print_Routine_Linbuf
                 (1 + Print_Routine_Bufcnt .. Print_Routine_Bufsiz),
               Item_List);

            Print_Routine_Bufcnt := Print_Routine_Bufcnt + Integer (Linlen);

         when others =>
            null;
      end case;

      case Print_Subfunction is

         --  Output buffer with a terminating newline

         when Print_Newline =>
            Put_Output (Status,
              Print_Routine_Linbuf (1 .. Print_Routine_Bufcnt));
            Print_Routine_Bufcnt := 0;

         --  Buffer the output

         when No_Print =>
            null;

         when others =>
            null;
      end case;

   end Default_Print_Routine;

   -------------------
   -- Disable_Event --
   -------------------

   procedure Disable_Event
      (Flags       : Bit_Array_32;
       Event_Value : Unsigned_Longword;
       Event_Code  : Unsigned_Longword;
       Status      : out Cond_Value_Type)
   is
      Task_Value : Task_Id;
      Task_Index : constant Integer := Integer (Event_Value) - 1;
   begin

      Events_Enabled_Count := Events_Enabled_Count - 1;

      if Flags (V_EVNT_ALL) then
         Global_Task_Debug_Events (Integer (Event_Code)) := False;
         Status := K_SUCCESS;
      else
         if Task_Index in Known_Tasks'Range then
            Task_Value := Known_Tasks (Task_Index);
            if Task_Value /= null then
               Task_Value.Common.Debug_Events (Integer (Event_Code)) := False;
               Status := K_SUCCESS;
            else
               Status := K_TASK_NOT_EXIST;
            end if;
         else
            Status := K_TASK_NOT_EXIST;
         end if;
      end if;

      --  Keep count of events for efficiency

      if Events_Enabled_Count <= 0 then
         Events_Enabled_Count := 0;
         Global_Task_Debug_Event_Set := False;
      end if;

   end Disable_Event;

   ----------
   -- DoAC --
   ----------

   function DoAC (S : String) return Address is
   begin
      AC_Buffer.Count := S'Length;
      AC_Buffer.Text (1 .. AC_Buffer.Count) := S;
      return AC_Buffer'Address;
   end DoAC;

   ------------------
   -- Enable_Event --
   ------------------

   procedure Enable_Event
      (Flags       : Bit_Array_32;
       Event_Value : Unsigned_Longword;
       Event_Code  : Unsigned_Longword;
       Status      : out Cond_Value_Type)
   is
      Task_Value : Task_Id;
      Task_Index : constant Integer := Integer (Event_Value) - 1;

   begin
      --  At least one event enabled, any and all events will cause a
      --  condition to be raised and checked. Major tasking slowdown.

      Global_Task_Debug_Event_Set := True;
      Events_Enabled_Count := Events_Enabled_Count + 1;

      if Flags (V_EVNT_ALL) then
         Global_Task_Debug_Events (Integer (Event_Code)) := True;
         Status := K_SUCCESS;
      else
         if Task_Index in Known_Tasks'Range then
            Task_Value := Known_Tasks (Task_Index);
            if Task_Value /= null then
               Task_Value.Common.Debug_Events (Integer (Event_Code)) := True;
               Status := K_SUCCESS;
            else
               Status := K_TASK_NOT_EXIST;
            end if;
         else
            Status := K_TASK_NOT_EXIST;
         end if;
      end if;

   end Enable_Event;

   ------------------------
   -- Find_Event_By_Code --
   ------------------------

   procedure Find_Event_By_Code
      (Event_Code  : Unsigned_Longword;
       Event_Entry : out Unsigned_Longword;
       Status      : out Cond_Value_Type)
   is
      K_SUCCESS       : constant := 1;
      K_NO_SUCH_EVENT : constant := 9;

   begin
      Trace_Output ("Looking for Event: ");
      Trace_Output (Unsigned_Longword'Image (Event_Code));

      for I in Event_Kind_Type'Range loop
         if Event_Code = Unsigned_Longword (Event_Directory (I).Code) then
            Event_Entry := To_UL (Event_Directory (I)'Address);
            Trace_Output ("Found Event # ");
            Trace_Output (Integer'Image (I));
            Status := K_SUCCESS;
            return;
         end if;
      end loop;

      Status := K_NO_SUCH_EVENT;
   end Find_Event_By_Code;

   ------------------------
   -- Find_Event_By_Name --
   ------------------------

   procedure Find_Event_By_Name
      (Event_Name  : Unsigned_Longword;
       Event_Entry : out Unsigned_Longword;
       Status      : out Cond_Value_Type)
   is
      K_SUCCESS       : constant := 1;
      K_NO_SUCH_EVENT : constant := 9;

      Event_Name_Cstr : constant ASCIC := To_AASCIC (Event_Name).all;
   begin
      Trace_Output ("Looking for Event: ");
      Trace_Output (Event_Name_Cstr.Text);

      for I in Event_Kind_Type'Range loop
         if Event_Name_Cstr.Count >= Event_Directory (I).Minchr
            and then Event_Name_Cstr.Count <= Event_Directory (I).Name.Count
            and then Event_Name_Cstr.Text (1 .. Event_Directory (I).Minchr) =
                Event_Directory (I).Name.Text (1 .. Event_Directory (I).Minchr)
         then
            Event_Entry := To_UL (Event_Directory (I)'Address);
            Trace_Output ("Found Event # ");
            Trace_Output (Integer'Image (I));
            Status := K_SUCCESS;
            return;
         end if;
      end loop;

      Status := K_NO_SUCH_EVENT;
   end Find_Event_By_Name;

   --------------------
   -- Get_User_State --
   --------------------

   function Get_User_State return Long_Integer is
   begin
      return STPO.Self.User_State;
   end Get_User_State;

   ------------------------
   -- List_Entry_Waiters --
   ------------------------

   procedure List_Entry_Waiters
     (Task_Value      : Task_Id;
      Full_Display    : Boolean := False;
      Suppress_Header : Boolean := False;
      Print_Routine   : Print_Routine_Type := Default_Print_Routine'Access)
   is
      pragma Unreferenced (Suppress_Header);

      Entry_Call : Entry_Call_Link;
      Have_Some  : Boolean := False;
   begin
      if not Full_Display then
         return;
      end if;

      if Task_Value.Entry_Queues'Length > 0 then
         Print_Routine (Print_FAO, Print_Newline,
           To_UL (DoAC ("        Waiting entry callers:")));
      end if;
      for I in Task_Value.Entry_Queues'Range loop
         Entry_Call := Task_Value.Entry_Queues (I).Head;
         if Entry_Call /= null then
            Have_Some := True;

            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC ("          Waiters for entry !UI:")),
              To_UL (I));

            loop
               declare
                  Task_Image : ASCIC :=
                   (Entry_Call.Self.Common.Task_Image_Len,
                    Entry_Call.Self.Common.Task_Image
                      (1 .. Entry_Call.Self.Common.Task_Image_Len));
               begin
                  Print_Routine (Print_FAO, Print_Newline,
                    To_UL (DoAC ("              %TASK !UI, type: !AC")),
                    To_UL (Entry_Call.Self.Known_Tasks_Index + 1),
                    To_UL (Task_Image'Address));
                  if Entry_Call = Task_Value.Entry_Queues (I).Tail then
                     exit;
                  end if;
                  Entry_Call := Entry_Call.Next;
               end;
            end loop;
         end if;
      end loop;
      if not Have_Some then
         Print_Routine (Print_FAO, Print_Newline,
           To_UL (DoAC ("          none.")));
      end if;
   end List_Entry_Waiters;

   ----------------
   -- List_Tasks --
   ----------------

   procedure List_Tasks is
      C : Task_Id;
   begin
      C := All_Tasks_List;

      while C /= null loop
         Print_Task_Info (C);
         C := C.Common.All_Tasks_Link;
      end loop;
   end List_Tasks;

   ------------------------
   -- Print_Current_Task --
   ------------------------

   procedure Print_Current_Task is
   begin
      Print_Task_Info (STPO.Self);
   end Print_Current_Task;

   ---------------------
   -- Print_Task_Info --
   ---------------------

   procedure Print_Task_Info (T : Task_Id) is
      Entry_Call : Entry_Call_Link;
      Parent     : Task_Id;

   begin
      if T = null then
         Put_Line ("null task");
         return;
      end if;

      Put (T.Common.Task_Image (1 .. T.Common.Task_Image_Len) & ": " &
           Task_States'Image (T.Common.State));

      Parent := T.Common.Parent;

      if Parent = null then
         Put (", parent: <none>");
      else
         Put (", parent: " &
              Parent.Common.Task_Image (1 .. Parent.Common.Task_Image_Len));
      end if;

      Put (", prio:" & T.Common.Current_Priority'Img);

      if not T.Callable then
         Put (", not callable");
      end if;

      if T.Aborting then
         Put (", aborting");
      end if;

      if T.Deferral_Level /= 0 then
         Put (", abort deferred");
      end if;

      if T.Common.Call /= null then
         Entry_Call := T.Common.Call;
         Put (", serving:");

         while Entry_Call /= null loop
            Put (To_Integer (Entry_Call.Self)'Img);
            Entry_Call := Entry_Call.Acceptor_Prev_Call;
         end loop;
      end if;

      if T.Open_Accepts /= null then
         Put (", accepting:");

         for J in T.Open_Accepts'Range loop
            Put (T.Open_Accepts (J).S'Img);
         end loop;

         if T.Terminate_Alternative then
            Put (" or terminate");
         end if;
      end if;

      if T.User_State /= 0 then
         Put (", state:" & T.User_State'Img);
      end if;

      Put_Line;
   end Print_Task_Info;

   ---------
   -- Put --
   ---------

   procedure Put (S : String) is
   begin
      Write (2, S, S'Length);
   end Put;

   --------------
   -- Put_Line --
   --------------

   procedure Put_Line (S : String := "") is
   begin
      Write (2, S & ASCII.LF, S'Length + 1);
   end Put_Line;

   ----------------------
   -- Resume_All_Tasks --
   ----------------------

   procedure Resume_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
      pragma Unreferenced (Thread_Self);
   begin
      null; --  VxWorks
   end Resume_All_Tasks;

   ---------------
   -- Set_Trace --
   ---------------

   procedure Set_Trace (Flag  : Character; Value : Boolean := True) is
   begin
      Trace_On (Flag) := Value;
   end Set_Trace;

   --------------------
   -- Set_User_State --
   --------------------

   procedure Set_User_State (Value : Long_Integer) is
   begin
      STPO.Self.User_State := Value;
   end Set_User_State;

   ----------------
   -- Show_Event --
   ----------------

   procedure Show_Event
      (Print_Routine : Print_Routine_Type := Default_Print_Routine'Access)
   is
   begin
      for I in Event_Def_Help'Range loop
         Print_Routine (Print_FAO, Print_Newline, To_UL (Event_Def_Help (I)));
      end loop;

      for I in Event_Kind_Type'Range loop
         Print_Routine (Print_FAO, Print_Newline,
           To_UL (Event_Directory
                   (Global_Event_Display_Order (I)).Name'Address));
         Print_Routine (Print_FAO, Print_Newline,
           To_UL (Event_Directory (Global_Event_Display_Order (I)).Help));
      end loop;
   end Show_Event;

   --------------------
   -- Show_One_Task --
   --------------------

   procedure Show_One_Task
     (Task_Value      : Task_Id;
      Full_Display    : Boolean := False;
      Suppress_Header : Boolean := False;
      Print_Routine   : Print_Routine_Type := Default_Print_Routine'Access)
   is
      Task_SP            : System.Address := Address_Zero;
      Stack_Base         : System.Address := Address_Zero;
      Stack_Top          : System.Address := Address_Zero;
      TCB_Size           : Unsigned_Longword := 0;
      CMA_TCB_Size       : Unsigned_Longword := 0;
      Stack_Guard_Size   : Unsigned_Longword := 0;
      Total_Task_Storage : Unsigned_Longword := 0;
      Stack_In_Use       : Unsigned_Longword := 0;
      Reserved_Size      : Unsigned_Longword := 0;
      Hold_Flag          : Unsigned_Longword := 0;
      Sched_State        : Unsigned_Longword := 0;
      User_Prio          : Unsigned_Longword := 0;
      Stack_Size         : Unsigned_Longword := 0;
      Run_State          : Boolean := False;
      Rea_State          : Boolean := False;
      Sus_State          : Boolean := False;
      Ter_State          : Boolean := False;

      Current_Flag : AASCIC := NoStar;
      Hold_String  : AASCIC := NoHold;
      Ada_State    : AASCIC := Ada_State_Invalid_State;
      Debug_State  : AASCIC := Debug_State_Emp;

      Ada_State_Len   : constant Unsigned_Longword := 17;
      Debug_State_Len : constant Unsigned_Longword := 5;

      Entry_Call : Entry_Call_Record;

   begin

      --  Initialize local task info variables

      Task_SP := Address_Zero;
      Stack_Base := Address_Zero;
      Stack_Top := Address_Zero;
      CMA_TCB_Size := 0;
      Stack_Guard_Size := 0;
      Reserved_Size := 0;
      Hold_Flag := 0;
      Sched_State := 0;
      TCB_Size := Unsigned_Longword (Task_Id'Size);

      if not Suppress_Header or else Full_Display then
         Print_Routine (Print_FAO, Print_Newline, To_UL (Empty_Text));
         Print_Routine (Print_FAO, Print_Newline, To_UL (Header));
      end if;

      Trace_Output ("Show_One_Task Task Value: ");
      Trace_Output (Unsigned_Longword'Image (To_UL (Task_Value)));

      --  Callback to DEBUG to get some task info

      if Task_Value.Common.State /= Terminated then
         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_STACKPTR,
            Task_SP,
            8);

         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_TCB_SIZE,
            CMA_TCB_Size,
            4);

         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_GUARDSIZE,
            Stack_Guard_Size,
            4);

         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_YELLOWSIZE,
            Reserved_Size,
            4);

         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_STACK_BASE,
            Stack_Base,
            8);

         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_STACK_TOP,
            Stack_Top,
            8);

         Stack_Size := Unsigned_Longword (Stack_Base - Stack_Top)
           - Reserved_Size - Stack_Guard_Size;
         Stack_In_Use := Unsigned_Longword (Stack_Base - Task_SP) + 4;
         Total_Task_Storage := TCB_Size + Stack_Size + Stack_Guard_Size
           + Reserved_Size + CMA_TCB_Size;

         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_IS_HELD,
            Hold_Flag,
            4);

         Hold_String := (if Hold_Flag /= 0 then Hold else NoHold);

         Debug_Get
           (STPO.Get_Thread_Id (Task_Value),
            CMA_C_DEBGET_SCHED_STATE,
            Sched_State,
            4);
      end if;

      Run_State := False;
      Rea_State := False;
      Sus_State := Task_Value.Common.State = Unactivated;
      Ter_State := Task_Value.Common.State = Terminated;

      if not Ter_State then
         Run_State := Sched_State = 0;
         Rea_State := Sched_State = 1;
         Sus_State := Sched_State /= 0 and Sched_State /= 1;
      end if;

      --  Set the debug state

      if Run_State then
         Debug_State := Debug_State_Run;
      elsif Rea_State then
         Debug_State := Debug_State_Rea;
      elsif Sus_State then
         Debug_State := Debug_State_Sus;
      elsif Ter_State then
         Debug_State := Debug_State_Ter;
      end if;

      Trace_Output ("Before case State: ");
      Trace_Output (Task_States'Image (Task_Value.Common.State));

      --  Set the Ada state

      case Task_Value.Common.State is
         when Unactivated =>
            Ada_State := Ada_State_Not_Yet_Activated;

         when Activating =>
            Ada_State := Ada_State_Activating;

         when Runnable =>
            Ada_State := Ada_State_Runnable;

         when Terminated =>
            Ada_State := Ada_State_Terminated;

         when Activator_Sleep =>
            Ada_State := Ada_State_Activating_Tasks;

         when Acceptor_Sleep =>
            Ada_State := Ada_State_Accept;

         when Acceptor_Delay_Sleep =>
            Ada_State := Ada_State_Select_or_Delay;

         when Entry_Caller_Sleep =>
            Entry_Call :=
              Task_Value.Entry_Calls (Task_Value.ATC_Nesting_Level);

            case Entry_Call.Mode is
               when Simple_Call =>
                  Ada_State := Ada_State_Entry_Call;
               when Conditional_Call =>
                  Ada_State := Ada_State_Cond_Entry_Call;
               when Timed_Call =>
                  Ada_State := Ada_State_Timed_Entry_Call;
               when Asynchronous_Call =>
                  Ada_State := Ada_State_Async_Entry_Call;
            end case;

         when Async_Select_Sleep =>
            Ada_State := Ada_State_Select_or_Abort;

         when Delay_Sleep =>
            Ada_State := Ada_State_Delay;

         when Master_Completion_Sleep =>
            Ada_State := Ada_State_Completed;

         when Master_Phase_2_Sleep =>
            Ada_State := Ada_State_Completed;

         when Interrupt_Server_Idle_Sleep |
              Interrupt_Server_Blocked_Interrupt_Sleep |
              Timer_Server_Sleep |
              Interrupt_Server_Blocked_On_Event_Flag =>
            Ada_State := Ada_State_Server;

         when AST_Server_Sleep =>
            Ada_State := Ada_State_IO_or_AST;

         when Asynchronous_Hold =>
            Ada_State := Ada_State_Async_Hold;

      end case;

      if Task_Value.Terminate_Alternative then
         Ada_State := Ada_State_Select_or_Term;
      end if;

      if Task_Value.Aborting then
         Ada_State := Ada_State_Aborting;
      end if;

      User_Prio := To_UL (Task_Value.Common.Current_Priority);
      Trace_Output ("After user_prio");

      --  Flag the current task

      Current_Flag := (if Task_Value = Self then Star else NoStar);

      --  Show task info

      Print_Routine (Print_FAO, No_Print, To_UL (DoAC ("!AC%TASK !5<!UI!>")),
        To_UL (Current_Flag), To_UL (Task_Value.Known_Tasks_Index + 1));

      Print_Routine (Print_FAO, No_Print, To_UL (DoAC ("!2UB")), User_Prio);

      Print_Routine (Print_FAO, No_Print, To_UL (DoAC (" !AC !5AD !17AD ")),
        To_UL (Hold_String), Debug_State_Len, To_UL (Debug_State),
        Ada_State_Len, To_UL (Ada_State));

--      Print_Routine (Print_Symbol, Print_Newline,
--         Fetch (To_Addr (Task_Value.Common.Task_Entry_Point)));

      Print_Routine (Print_FAO, Print_Newline, To_UL (Empty_Text));

      --  If /full qualfier passed, show detailed info

      if Full_Display then
         Show_Rendezvous (Task_Value, Ada_State, Full_Display,
           Suppress_Header, Print_Routine);

         List_Entry_Waiters (Task_Value, Full_Display,
           Suppress_Header, Print_Routine);

         Print_Routine (Print_FAO, Print_Newline, To_UL (Empty_Text));

         declare
            Task_Image : ASCIC := (Task_Value.Common.Task_Image_Len,
              Task_Value.Common.Task_Image
               (1 .. Task_Value.Common.Task_Image_Len));
         begin
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC ("        Task type:      !AC")),
              To_UL (Task_Image'Address));
         end;

         --  How to find Creation_PC ???
--         Print_Routine (Print_FAO, No_Print,
--           To_UL (DoAC ("        Created at PC:  ")),
--         Print_Routine (Print_FAO, Print_Newline, Creation_PC);

         if Task_Value.Common.Parent /= null then
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC ("        Parent task:    %TASK !UI")),
              To_UL (Task_Value.Common.Parent.Known_Tasks_Index + 1));
         else
            Print_Routine (Print_FAO, Print_Newline,
             To_UL (DoAC ("        Parent task:    none")));
         end if;

--         Print_Routine (Print_FAO, No_Print,
--           To_UL (DoAC ("        Start PC:       ")));
--         Print_Routine (Print_Symbol, Print_Newline,
--            Fetch (To_Addr (Task_Value.Common.Task_Entry_Point)));

         Print_Routine (Print_FAO, Print_Newline,
          To_UL (DoAC (
           "        Task control block:             Stack storage (bytes):")));

         Print_Routine (Print_FAO, Print_Newline,
          To_UL (DoAC (
           "          Task value:   !10<!UI!>        RESERVED_BYTES:  !10UI")),
          To_UL (Task_Value), Reserved_Size);

         Print_Routine (Print_FAO, Print_Newline,
          To_UL (DoAC (
           "          Entries:      !10<!UI!>        TOP_GUARD_SIZE:  !10UI")),
          To_UL (Task_Value.Entry_Num), Stack_Guard_Size);

         Print_Routine (Print_FAO, Print_Newline,
          To_UL (DoAC (
           "          Size:         !10<!UI!>        STORAGE_SIZE:    !10UI")),
          TCB_Size + CMA_TCB_Size, Stack_Size);

         Print_Routine (Print_FAO, Print_Newline,
          To_UL (DoAC (
           "        Stack addresses:                 Bytes in use:    !10UI")),
          Stack_In_Use);

         Print_Routine (Print_FAO, Print_Newline,
          To_UL (DoAC ("          Top address:  !10<!XI!>")),
          To_UL (Stack_Top));

         Print_Routine (Print_FAO, Print_Newline,
          To_UL (DoAC (
           "          Base address: !10<!XI!>      Total storage:     !10UI")),
          To_UL (Stack_Base), Total_Task_Storage);
      end if;

   end Show_One_Task;

   ---------------------
   -- Show_Rendezvous --
   ---------------------

   procedure Show_Rendezvous
     (Task_Value      : Task_Id;
      Ada_State       : AASCIC := Empty_Text;
      Full_Display    : Boolean := False;
      Suppress_Header : Boolean := False;
      Print_Routine   : Print_Routine_Type := Default_Print_Routine'Access)
   is
      pragma Unreferenced (Ada_State);
      pragma Unreferenced (Suppress_Header);

      Temp_Entry  : Entry_Index;
      Entry_Call  : Entry_Call_Record;
      Called_Task : Task_Id;
      AWR         : constant String := "        Awaiting rendezvous at: ";
      --  Common prefix

      procedure Print_Accepts;
      --  Display information about task rendezvous accepts

      procedure Print_Accepts is
      begin
         if Task_Value.Open_Accepts /= null then
            for I in Task_Value.Open_Accepts'Range loop
               Temp_Entry := Entry_Index (Task_Value.Open_Accepts (I).S);
               declare
                  Entry_Name_Image : ASCIC :=
                    (Task_Value.Entry_Names (Temp_Entry).all'Length,
                     Task_Value.Entry_Names (Temp_Entry).all);
               begin
                  Trace_Output ("Accept at: " & Entry_Name_Image.Text);
                  Print_Routine (Print_FAO, Print_Newline,
                    To_UL (DoAC ("             accept at: !AC")),
                    To_UL (Entry_Name_Image'Address));
               end;
            end loop;
         end if;
      end Print_Accepts;
   begin
      if not Full_Display then
         return;
      end if;

      Trace_Output ("Show_Rendezvous Task Value: ");
      Trace_Output (Unsigned_Longword'Image (To_UL (Task_Value)));

      if Task_Value.Common.State = Acceptor_Sleep and then
         not Task_Value.Terminate_Alternative
      then
         if Task_Value.Open_Accepts /= null then
            Temp_Entry := Entry_Index (Task_Value.Open_Accepts
              (Task_Value.Open_Accepts'First).S);
            declare
               Entry_Name_Image : ASCIC :=
                 (Task_Value.Entry_Names (Temp_Entry).all'Length,
                  Task_Value.Entry_Names (Temp_Entry).all);
            begin
               Trace_Output (AWR & "accept " & Entry_Name_Image.Text);
               Print_Routine (Print_FAO, Print_Newline,
                 To_UL (DoAC (AWR & "accept !AC")),
                 To_UL (Entry_Name_Image'Address));
            end;

         else
            Print_Routine (Print_FAO, Print_Newline,
              To_UL (DoAC ("        entry name unavailable")));
         end if;
      else
         case Task_Value.Common.State is
            when Acceptor_Sleep =>
               Print_Routine (Print_FAO, Print_Newline,
                 To_UL (DoAC (AWR & "select with terminate.")));
               Print_Accepts;

            when Async_Select_Sleep =>
               Print_Routine (Print_FAO, Print_Newline,
                 To_UL (DoAC (AWR & "select.")));
               Print_Accepts;

            when Acceptor_Delay_Sleep =>
               Print_Routine (Print_FAO, Print_Newline,
                 To_UL (DoAC (AWR & "select with delay.")));
               Print_Accepts;

            when Entry_Caller_Sleep =>
               Entry_Call :=
                 Task_Value.Entry_Calls (Task_Value.ATC_Nesting_Level);

               case Entry_Call.Mode is
                  when Simple_Call =>
                     Print_Routine (Print_FAO, Print_Newline,
                       To_UL (DoAC (AWR & "entry call")));
                  when Conditional_Call =>
                     Print_Routine (Print_FAO, Print_Newline,
                       To_UL (DoAC (AWR & "entry call with else")));
                  when Timed_Call =>
                     Print_Routine (Print_FAO, Print_Newline,
                       To_UL (DoAC (AWR & "entry call with delay")));
                  when Asynchronous_Call =>
                     Print_Routine (Print_FAO, Print_Newline,
                        To_UL (DoAC (AWR & "entry call with abort")));
               end case;
               Called_Task := Entry_Call.Called_Task;
               declare
                  Task_Image : ASCIC := (Called_Task.Common.Task_Image_Len,
                    Called_Task.Common.Task_Image
                     (1 .. Called_Task.Common.Task_Image_Len));
                  Entry_Name_Image : ASCIC :=
                    (Called_Task.Entry_Names (Entry_Call.E).all'Length,
                     Called_Task.Entry_Names (Entry_Call.E).all);
               begin
                  Print_Routine (Print_FAO, Print_Newline,
                    To_UL (DoAC
                     ("        for entry !AC in %TASK !UI type !AC")),
                    To_UL (Entry_Name_Image'Address),
                    To_UL (Called_Task.Known_Tasks_Index),
                    To_UL (Task_Image'Address));
               end;

            when others =>
               return;
         end case;
      end if;

   end Show_Rendezvous;

   ------------------------
   -- Signal_Debug_Event --
   ------------------------

   procedure Signal_Debug_Event
    (Event_Kind : Event_Kind_Type; Task_Value : Task_Id)
   is
      Do_Signal : Boolean;
      EVCB      : Ada_Event_Control_Block_Access;

      EVCB_Sent    : constant := 16#9B#;
      Ada_Facility : constant := 49;
      SS_DBGEVENT  : constant := 1729;
   begin
      Do_Signal := Global_Task_Debug_Events (Event_Kind);

      if not Do_Signal then
         if Task_Value /= null then
            Do_Signal := Do_Signal
              or else Task_Value.Common.Debug_Events (Event_Kind);
         end if;
      end if;

      if Do_Signal then
         --  Build an a tasking event control block and signal DEBUG

         EVCB := new Ada_Event_Control_Block_Type;
         EVCB.Code := Unsigned_Word (Event_Kind);
         EVCB.Sentinal := EVCB_Sent;
         EVCB.Facility := Ada_Facility;

         if Task_Value /= null then
            EVCB.Value := Unsigned_Longword (Task_Value.Known_Tasks_Index + 1);
         else
            EVCB.Value := 0;
         end if;

         EVCB.Sub_Event := 0;
         EVCB.P1 := 0;
         EVCB.Sigargs := 0;
         EVCB.Flags := 0;
         EVCB.Unused1 := 0;
         EVCB.Unused2 := 0;

         Signal (SS_DBGEVENT, 1, To_UL (EVCB));
      end if;
   end Signal_Debug_Event;

   --------------------
   -- Stop_All_Tasks --
   --------------------

   procedure Stop_All_Tasks is
   begin
      null; --  VxWorks
   end Stop_All_Tasks;

   ----------------------------
   -- Stop_All_Tasks_Handler --
   ----------------------------

   procedure Stop_All_Tasks_Handler is
   begin
      null; --  VxWorks
   end Stop_All_Tasks_Handler;

   -----------------------
   -- Suspend_All_Tasks --
   -----------------------

   procedure Suspend_All_Tasks (Thread_Self : OS_Interface.Thread_Id) is
      pragma Unreferenced (Thread_Self);
   begin
      null; --  VxWorks
   end Suspend_All_Tasks;

   ------------------------
   -- Task_Creation_Hook --
   ------------------------

   procedure Task_Creation_Hook (Thread : OS_Interface.Thread_Id) is
      pragma Unreferenced (Thread);
   begin
      null; --  VxWorks
   end Task_Creation_Hook;

   ---------------------------
   -- Task_Termination_Hook --
   ---------------------------

   procedure Task_Termination_Hook is
   begin
      null; --  VxWorks
   end Task_Termination_Hook;

   -----------
   -- Trace --
   -----------

   procedure Trace
     (Self_Id  : Task_Id;
      Msg      : String;
      Flag     : Character;
      Other_Id : Task_Id := null)
   is
   begin
      if Trace_On (Flag) then
         Put (To_Integer (Self_Id)'Img &
              ':' & Flag & ':' &
              Self_Id.Common.Task_Image (1 .. Self_Id.Common.Task_Image_Len) &
              ':');

         if Other_Id /= null then
            Put (To_Integer (Other_Id)'Img & ':');
         end if;

         Put_Line (Msg);
      end if;
   end Trace;

   ------------------
   -- Trace_Output --
   ------------------

   procedure Trace_Output (Message_String : String) is
   begin
      if Trace_On ('V') and Trace_On ('M') and Trace_On ('S') then
         Put_Output (Message_String);
      end if;
   end Trace_Output;

   -----------
   -- Write --
   -----------

   procedure Write (Fd : Integer; S : String; Count : Integer) is
      Discard : System.CRTL.ssize_t;
      pragma Unreferenced (Discard);
   begin
      Discard := System.CRTL.write (Fd, S (S'First)'Address,
                                    System.CRTL.size_t (Count));
      --  Is it really right to ignore write errors here ???
   end Write;

end System.Tasking.Debug;