summaryrefslogtreecommitdiffstats
path: root/sim-scripts/rtems-gdb-macros-4.11
blob: f9a7cded4054f452954b79f4e550f9c13f072503 (plain) (blame)
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
###
# GDB macros for analyzing RTEMS threads
#
#  TODO:
#    + rtems_task_backtrack is CPU specific.  How to detect CPU in gdb?
#    + Generally need to detect when options like SMP, POSIX, etc. are
#      enabled/disabled and impact code generation for data structures.
#    + Add support for Classic API
#       - Periods
#       - Timers
#       - Partitions
#    + Add support for POSIX API
#       - Message Queues
#
# Commands implemented:
#    rtems_task_backtrack TCB
#    rtems_print_name name
#    rtems_internal_task index
#    rtems_internal_tasks
#    rtems_classic_tasks
#    rtems_classic_task index
#    rtems_classic_semaphore index
#    rtems_classic_semaphores
#    rtems_classic_message_queue index
#    rtems_classic_message_queues
#    rtems_classic_region index
#    rtems_classic_regions
#    rtems_posix_thread index
#    rtems_posix_threads
#    rtems_posix_semaphore index
#    rtems_posix_semaphores
#    rtems_posix_mutex index
#    rtems_posix_mutexes
#    rtems_tasks
#    rtems_task_stacks
#    rtems_internal_ticks_chain
#    rtems_internal_seconds_chain
#    rtems_malloc_walk
#    rtems_workspace_walk
#    rtems_tod
#    rtems_check_state
#

echo Loading GDB Macro Package for RTEMS 4.11...\n

#############################################################################
########                   Public Helper Macros                      ########
#############################################################################

####################
# rtems_task_backtrack
#
# ABSTRACT
#    Print backtrace of an RTEMS task
#
# ARGUMENTS:
#    arg0 = pointer to the Thread_Control_struct of the task.
#
define rtems_task_backtrack
  # Uncomment the following line for PowerPC support
  # set $stkp = $arg0->Registers.gpr1

  # Uncomment the following line for Coldfire support 
  # set $stkp = $arg0->Registers.a6

  # Uncomment the following line for i386 support 
  set $stkp = $arg0->Registers.ebp

  set $stkp = *(void**)$stkp
  while $stkp != 0
      info line **((void**)$stkp+1)
    set $stkp = *(void**)$stkp
  end
end
document rtems_task_backtrack
  Usage: rtems_task_backtrack TCB
  Displays a stack trace for the specific task
end

####################
# rtems_print_name
#
# ABSTRACT
#    Print backtrace of an RTEMS task
#
# ARGUMENTS:
#    arg0 = object name -- 32 bit format
#
define rtems_print_name
        set $name = $arg0
  set $n0 = (char) ($name >> 24)
  if $n0 < ' ' || $n0 > 'z'
      set $n0=' '
  end
  printf "%c",$n0
  set $n1 = (char) (0xff & ($name >> 16))
  if $n1 < ' ' || $n1 > 'z'
      set $n1=' '
  end
  printf "%c",$n1
  set $n2 = (char) (0xff & ($name >> 8))
  if $n2 < ' ' || $n2 > 'z'
      set $n2=' '
  end
  printf "%c",$n2
  set $n3 = (char) (0xff & $name)
  if $n3 < ' ' || $n3 > 'z'
      set $n3=' '
  end
  printf "%c | ",$n3
end
document rtems_print_name
  Usage: rtems_print_name name
  Attempt to print the Classic API style name in ASCII
end

#############################################################################
########         Helper Macros - Use Only From Other Macros          ########
#############################################################################

####################
# rtems_helper_task_dump
#
# ABSTRACT
#    Print information about an RTEMS task
#
# ARGUMENTS
#    arg0 = Task index in the corresponding _Information table.
#    arg1 = pointer to the Thread_Control_struct of the task.
#    arg2 = 1 for verbose output, 0 otherwise
#
define rtems_helper_task_dump
  set $d1t_num = $arg0
  set $pt = $arg1
  set $d1t_verbose = $arg2

  printf "%2d | ", $d1t_num
  set $id = $pt->Object.id
  set $name = (unsigned int)$pt->Object.name
  rtems_print_name $name

  printf "%08x | ",$id

  set $pri = $pt->current_priority
  printf "%3d | ",$pri

  set $cpu_time_used = $pt->cpu_time_used
  printf "%12d | ", $cpu_time_used

  set $stack_base = $pt->Start.Initial_stack.area
  set $stack_size = $pt->Start.Initial_stack.size
  printf "%p 0x%04x | ", $stack_base, $stack_size

  set $state = $pt->current_state
  if $state == 0
    printf "READY"
  end
  if $state & 1
    printf "DORM "
  end
  if $state & 2
    printf "SUSP "
  end
  if $state & 4
    printf "TRANS "
  end
  if $state & 8
    printf "DELAY "
  end
  if $state & 0x10
    printf "Wtime "
  end
  if $state & 0x20
    printf "Wbuf "
  end
  if $state & 0x40
    printf "Wseg "
  end
  if $state & 0x80
    printf "Wmsg "
  end
  if $state & 0x100
    printf "Wevnt "
  end
  if $state & 0x200
    printf "Wsem "
  end
  if $state & 0x400
    printf "Wmutex 0x%8x", $pt->Wait.id
  end
  if $state & 0x800
    printf "Wcvar "
  end
  if $state & 0x1000
    printf "Wjatx "
  end
  if $state & 0x2000
    printf "Wrpc "
  end
  if $state & 0x4000
    printf "Wrate "
  end
  if $state & 0x8000
    printf "Wsig "
  end
  if $state & 0x10000
    printf "Wisig "
  end

        printf "\n"
#    printf "\
#---+------+----------+-----+----------+------------------------------\n"
  if $d1t_verbose
     printf "\
BACKTRACE\n"
     rtems_task_backtrack $pt
  end
end
# Internal Helper Do Not Document

####################
# rtems_helper_task_header
#
# ABSTRACT
#    Print the header of the task list table
#
define rtems_helper_task_header
    printf "\
============================================================================\n"
  printf "\
 # | Name |    ID    | Pri |    Nsecs     | Stack Base/Size  | State\n"
    printf "\
---+------+----------+-----+--------------+------------------+--------------\n"
end
# Internal Helper Do Not Document

####################
# rtems_helper_show_task
#
# ABSTRACT
#    Support routine for verbose listing of a single task
#
# ARGUMENTS
#    arg0 = _Information table.
#    arg1 = index.
#
define rtems_helper_show_task
    rtems_helper_task_header
    set $pt = (struct Thread_Control_struct *)$arg0.local_table[$arg1]
    rtems_helper_task_dump $arg1 $pt 1
end
# Internal Helper Do Not Document

####################
# rtems_helper_show_tasks
#
# ABSTRACT
#    Support routine for verbose listing of all tasks of a given class
#
# ARGUMENTS
#    arg0 = _Information table for the class (internal, classic, POSIX etc.).
#
define rtems_helper_show_tasks
  rtems_helper_task_header
  set $index = 1
  while $index <= $arg0.maximum
    set $pt = (struct Thread_Control_struct *)$arg0.local_table[$index]
    if $pt != 0
    rtems_helper_task_dump $index $pt 0
    end
    set $index = $index + 1
  end
end
# Internal Helper Do Not Document

#############################################################################
########   Helper Macros For SuperCore - Use Only From Other Macros  ########
#############################################################################

####################
# rtems_helper_score_threadq
#
# ABSTRACT
#    Verbosely list a single SuperCore thread queue
#
# ARGUMENTS
#    arg0 = pointer to the thread queue
#
define rtems_helper_score_threadq
  set $tq = $arg0
  set $THREAD_QUEUE_DISCIPLINE_FIFO     = 0
  set $THREAD_QUEUE_DISCIPLINE_PRIORITY = 1

  if $tq->discipline == $THREAD_QUEUE_DISCIPLINE_FIFO
    printf "  FIFO - "
    set $limit = 1
  end

  if $tq->discipline == $THREAD_QUEUE_DISCIPLINE_PRIORITY
    printf "  PRIO - "
    set $limit = 3
  end


  # now walk them
  set $count = 0
  set $pri_index = 0
  set $queues = &$tq->Queues
  while $pri_index < $limit
    set $chain = &$queues.Priority[$pri_index]
    set $ptail = &$chain->Head.Node.previous
    set $next = $chain->Head.Node.next
    while $next != $ptail
      set $t = (struct Thread_Control_struct *)$next
      printf "0x%08x@%d ", $t->Object.id, $t->current_priority
      set $next = $next->next
      set $count = $count + 1
    end 
    set $pri_index = $pri_index + 1
  end
  if $count == 0
    printf "%s", "No waiting threads"
  end
end
# Internal Helper Do Not Document

####################
# rtems_helper_score_heap
#
# ABSTRACT
#    Verbosely list contents of a SuperCore Heap
#
# ARGUMENTS
#    arg0 = pointer to heap
#
define rtems_helper_score_heap
   set $heap = $arg0

   set $heapstart = $heap->start
   set $currentblock = $heapstart
   set $used = 0
   set $numused = 0
   set $free = 0
   set $numfree = 0
   while $currentblock->front_flag != 1
     if $currentblock->front_flag & 1
       if $arg0 != 0
 	printf "USED: %p %d\n", $currentblock, $currentblock->front_flag & ~1
       else
         printf "*"
       end
       set $used = $used + $currentblock->front_flag & ~1
       set $numused = $numused + 1
     else
       if $arg0 != 0
 	printf "FREE: %p %d\n", $currentblock, $currentblock->front_flag & ~1
       else
         printf "."
       end
       set $free = $free + $currentblock->front_flag & ~1
       set $numfree = $numfree + 1
     end
     set $currentblock = \
       (Heap_Block *)((char *)$currentblock + ($currentblock->front_flag&~1))
   end
   if $arg0 == 0
     printf "\n"
   end
   printf "TOTAL: %d (%d)\tUSED: %d (%d) \tFREE: %d (%d)\n", \
     $used + $free, $numused + $numfree, \
     $used, $numused, \
     $free, $numfree
end
# Internal Helper Do Not Document

####################
# rtems_helper_score_watchdog_chain
#
# ABSTRACT
#    Verbosely list a single SuperCore Watchdog chain
#
# ARGUMENTS
#    arg0 = pointer to Watchdog delta chain
#
define rtems_helper_score_watchdog_chain
  set $permt = &$arg0.Tail.Node
  set $node = $arg0.Head.Node.next

  if $node == $permt
    printf "Empty\n"
  end
  while $node != $permt
   set $wnode = (Watchdog_Control *)$node
   #print $wnode
   printf "======================\n0x%x, %d handler=", \
      $wnode, $wnode.delta_interval
   print $wnode.routine
   print/x *$wnode
   set $node = $node.next
  end
end
# Internal Helper Do Not Document

####################
# rtems_helper_score_mutex
#
# ABSTRACT
#    Verbosely list a single SuperCore mutex
#
# ARGUMENTS
#    arg0 = pointer to the mutex
#
define rtems_helper_score_mutex
  set $m = $arg0
  set $CORE_MUTEX_DISCIPLINES_FIFO               = 0
  set $CORE_MUTEX_DISCIPLINES_PRIORITY           = 1
  set $CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT   = 2
  set $CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING   = 3

  set $d = $m->Attributes.discipline
  if $d == $CORE_MUTEX_DISCIPLINES_FIFO
    printf "FIFO "
  end
  if $d == $CORE_MUTEX_DISCIPLINES_PRIORITY
    printf "PRIO "
  end
  if $d == $CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT
    printf "INHT "
  end
  if $d == $CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING
    printf "CEIL "
  end

  if $m->lock == 0 
    printf "LCK holder=0x%08x nest=%d\n", $m->holder_id, $m->nest_count
  else
    printf "UNL"
  end

  rtems_helper_score_threadq &$m->Wait_queue
end
# Internal Helper Do Not Document

####################
# rtems_helper_score_semaphore
#
# ABSTRACT
#    Verbosely list a single SuperCore semaphore
#
# ARGUMENTS
#    arg0 = pointer to the semaphore
#
define rtems_helper_score_semaphore
  set $s = $arg0

  if $s->count == 0 
    printf "Unavailable "
    rtems_helper_score_threadq &$s->Wait_queue
  else
    printf "Available Count=%d", $s->count
  end
end
# Internal Helper Do Not Document

####################
# rtems_helper_score_message_queue
#
# ABSTRACT
#    Verbosely list a single SuperCore Message Queue
#
# ARGUMENTS
#    arg0 = pointer to the message queue
#
define rtems_helper_score_message_queue
  set $mq = $arg0

  printf "%d/%d msgs ", \
    $mq->number_of_pending_messages, $mq->maximum_pending_messages
  if $mq->number_of_pending_messages == 0 
    rtems_helper_score_threadq &$mq->Wait_queue
  end
end
# Internal Helper Do Not Document

#############################################################################
########                     Internal Objects                        ########
#############################################################################

####################
# rtems_internal_task
#
# ABSTRACT
#    Verbosely list a single internal task
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_internal_task
  rtems_helper_show_task  _Thread_Internal_information $arg0
end
document rtems_internal_task
  Usage: rtems_internal_task index
  Displays detailed information about the specified internal RTEMS task
end

####################
# rtems_internal_tasks
#
# ABSTRACT
#    Dump all internal tasks
#
define rtems_internal_tasks
  rtems_helper_show_tasks  _Thread_Internal_information
end
document rtems_internal_tasks
  Usage: rtems_internal_tasks
  Displays a list of all internal RTEMS tasks
end

#############################################################################
########                        Classic API                          ########
#############################################################################

####################
# rtems_classic_tasks
#
# ABSTRACT
#    Dump all Classic tasks
#
define rtems_classic_tasks
  rtems_helper_show_tasks  _RTEMS_tasks_Information
end
document rtems_classic_tasks
  Usage: rtems_classic_tasks
  Displays a list of all Classic API RTEMS tasks
end

####################
# rtems_classic_task
#
# ABSTRACT
#    Verbosely list a single classic task
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_classic_task
  rtems_helper_show_task  _RTEMS_tasks_Information $arg0
end
document rtems_classic_task
  Usage: rtems_classic_task index
  Displays detailed information about the specified Classic API task
end

####################
# rtems_classic_semaphore
#
# ABSTRACT
#    Verbosely list a single Classic API semaphore
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_classic_semaphore

  set $d1t_num = $arg0
  set $inf = _Semaphore_Information
  set $sem = (Semaphore_Control *)$inf.local_table[$arg0]
  set $id = $sem->Object.id
  set $name = (unsigned int)$sem->Object.name

  printf "%2d | ", $d1t_num
        rtems_print_name $name
  printf "%08x | ",$id
  #  hack for is a mutex
  if $sem->attribute_set != 0
    printf "  Mutex "
    rtems_helper_score_mutex &$sem->Core_control.mutex 
  else
    printf "  Sem   " 
    rtems_helper_score_semaphore &$sem->Core_control.semaphore 
  end
  printf "\n"
  
end
document rtems_classic_semaphore
  Usage: rtems_classic_semaphore index
  Displays information about the specified Classic API Semaphore
end

####################
# rtems_classic_semaphores
#
# ABSTRACT
#    Verbosely list all Classic API semaphores
#
# ARGUMENTS: NONE
#
define rtems_classic_semaphores
  set $inf = _Semaphore_Information
  printf "\
=====================================================================\n"
  printf "\
 # | Name |    ID    | Information\n"
    printf "\
---+------+----------+-----------------------------------------------\n"
  set $index = 1
  while $index <= $inf.maximum
    set $pt = (Semaphore_Control *)$inf.local_table[$index]
    if $pt != 0
    rtems_classic_semaphore $index
    end
    set $index = $index + 1
  end
end
document rtems_classic_semaphores
  Usage: rtems_classic_semaphores
  Displays a list of all Classic API Semaphores
end


####################
# rtems_classic_message_queue
#
# ABSTRACT
#    Verbosely list a single Classic API Message Queue
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_classic_message_queue
  set $d1t_num = $arg0
  set $inf = _Message_queue_Information
  set $queue = (Message_queue_Control *)$inf.local_table[$arg0]
  set $id = $queue->Object.id
  set $name = (unsigned int)$queue->Object.name

  printf "%2d | ", $d1t_num
  rtems_print_name $name
  printf "%08x | ",$id
  rtems_helper_score_message_queue &$queue->message_queue 
  printf "\n"
end
document rtems_classic_message_queue
  Usage: rtems_classic_message_queue index
  Displays information about the specified Classic API Message Queue
end

####################
# rtems_classic_message_queues
#
# ABSTRACT
#    Verbosely list all Classic API Message Queues
#
# ARGUMENTS: NONE
#
define rtems_classic_message_queues
  set $inf = _Message_queue_Information
  printf "\
=====================================================================\n"
  printf "\
 # | Name |    ID    | Information\n"
    printf "\
---+------+----------+-----------------------------------------------\n"
  set $index = 1
  while $index <= $inf.maximum
    set $pt = (Message_queue_Control *)$inf.local_table[$index]
    if $pt != 0
    rtems_classic_message_queue $index
    end
    set $index = $index + 1
  end
end
document rtems_classic_message_queues
  Usage: rtems_classic_message_queues
  Displays a list of all Classic API Message Queues
end

####################
# rtems_classic_region
#
# ABSTRACT
#    Verbosely list a single Classic API Region
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_classic_region
  set $inf = _Region_Information
  set $d1t_num = $arg0
  set $r = (Region_Control *)$inf.local_table[$arg0]
  set $id = $r->Object.id
  set $name = (unsigned int)$r->Object.name

  printf "%2d | ", $d1t_num
  rtems_print_name $name
  printf "%08x | ",$id
  rtems_helper_score_heap &$r->Memory 
  printf "\n"
end
document rtems_classic_region
  Usage: rtems_classic_region index
  Displays information about the specified Classic API Region
end

####################
# rtems_classic_regions
#
# ABSTRACT
#    Verbosely list all Classic API Regions
#
# ARGUMENTS: NONE
#
define rtems_classic_regions
  set $inf = _Region_Information
  printf "\
=====================================================================\n"
  printf "\
 # | Name |    ID    | Information\n"
    printf "\
---+------+----------+-----------------------------------------------\n"
  set $index = 1
  while $index <= $inf.maximum
    set $pt = (Region_Control *)$inf.local_table[$index]
    if $pt != 0
    rtems_classic_region $index
    end
    set $index = $index + 1
  end
end
document rtems_classic_regions
  Usage: rtems_classic_regions
  Displays a list of all Classic API Regions
end

#############################################################################
########                          POSIX API                          ########
#############################################################################

####################
# rtems_posix_thread
#
# ABSTRACT
#    Verbosely list a single POSIX thread
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_posix_thread
  rtems_helper_show_task  _POSIX_Threads_Information $arg0
end
document rtems_posix_thread
  Usage: rtems_posix_thread index
  Displays detailed information about the specified POSIX API thread
end

####################
# rtems_posix_threads
#
# ABSTRACT
#    Dump all POSIX threads
#
# ARGUMENTS: NONE
#
define rtems_posix_threads
  rtems_helper_show_tasks  _POSIX_Threads_Information
end
document rtems_posix_threads
  Usage: rtems_posix_threads
  Displays a list of all POSIX API threads
end

####################
# rtems_posix_semaphore
#
# ABSTRACT
#    Verbosely list a single POSIX API semaphore
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_posix_semaphore

  set $d1t_num = $arg0
  set $inf = _POSIX_Semaphore_Information
  set $sem = (POSIX_Semaphore_Control *)$inf.local_table[$arg0]
  set $id = $sem->Object.id

  printf "%2d | ", $d1t_num
  if $sem->named
    printf "%s", (char *)$sem->Object.name
  end
  printf " %08x | ",$id
  rtems_helper_score_semaphore &$sem->Semaphore 
  printf "\n"
  
end
document rtems_posix_semaphore
  Usage: rtems_posix_semaphore index
  Displays information about the specified POSIX API Semaphore
end

####################
# rtems_posix_semaphores
#
# ABSTRACT
#    Verbosely list all POSIX API semaphores
#
# ARGUMENTS: NONE
#
define rtems_posix_semaphores
  set $inf = _POSIX_Semaphore_Information
  printf "\
=====================================================================\n"
  printf "\
 # |     ID    | Information\n"
    printf "\
---+-----------+-----------------------------------------------\n"
  set $index = 1
  while $index <= $inf.maximum
    set $pt = (POSIX_Semaphore_Control *)$inf.local_table[$index]
    if $pt != 0
    rtems_posix_semaphore $index
    end
    set $index = $index + 1
  end
end
document rtems_posix_semaphores
  Usage: rtems_posix_semaphores
  Displays a list of all POSIX API Semaphores
end

####################
# rtems_posix_mutex
#
# ABSTRACT
#    Verbosely list a single POSIX API mutex
#
# ARGUMENTS
#    arg0 = index in the _Information table
#
define rtems_posix_mutex

  set $d1t_num = $arg0
  set $inf = _POSIX_Mutex_Information
  set $mutex = (POSIX_Mutex_Control *)$inf.local_table[$arg0]
  set $id = $mutex->Object.id

  printf "%2d | ", $d1t_num
  printf "%08x | ",$id
  rtems_helper_score_mutex &$mutex->Mutex 
  printf "\n"
  
end
document rtems_posix_mutex
  Usage: rtems_posix_mutex index
  Displays information about the specified POSIX API Semaphore
end

####################
# rtems_posix_mutexes
#
# ABSTRACT
#    Verbosely list all POSIX API mutexes
#
# ARGUMENTS: NONE
#
define rtems_posix_mutexes
  set $inf = _POSIX_Mutex_Information
  printf "\
=====================================================================\n"
  printf "\
 # |    ID    | Information\n"
    printf "\
---+----------+-----------------------------------------------\n"
  set $index = 1
  while $index <= $inf.maximum
    set $pt = (POSIX_Mutex_Control *)$inf.local_table[$index]
    if $pt != 0
    rtems_posix_mutex $index
    end
    set $index = $index + 1
  end
end
document rtems_posix_mutexes
  Usage: rtems_posix_mutexes
  Displays a list of all POSIX API Mutexes
end

#############################################################################
########                    General and Cross API                    ########
#############################################################################

####################
# rtems_tasks
#
# ABSTRACT
#    Dump all tasks of all classes (internal, POSIX and Classic)
#
# ARGUMENTS: NONE
#
# TODO: NONE
define rtems_tasks
  printf "Executing: 0x%x, Heir: 0x%x\n", \
    _Per_CPU_Information.per_cpu.executing->Object.id, \
    _Per_CPU_Information.per_cpu.heir.Object.id

  printf "Internal Tasks\n"
  rtems_helper_show_tasks  _Thread_Internal_information
  printf "\
============================================================================\n"

  printf "Classic Tasks\n"
  rtems_helper_show_tasks  _RTEMS_tasks_Information
  printf "\
============================================================================\n"

  printf "POSIX Tasks\n"
  rtems_helper_show_tasks  _POSIX_Threads_Information
  printf "\
============================================================================\n"
end
document rtems_tasks
  Usage: rtems_tasks
  Displays a list of all internal and API defined tasks/threads
end

####################
# rtems_internal_ticks_chain
#
# ABSTRACT
#    Verbosely list contents of ticks chain tickled from clock tick
#
# ARGUMENTS: NONE
#
define rtems_internal_ticks_chain
  rtems_helper_score_watchdog_chain _Watchdog_Ticks_chain
end
document rtems_internal_ticks_chain
  Usage: rtems_internal_ticks_chain
  Lists the contains of the internal RTEMS delta chain used to manage
  all timing events that are tick based.  This chain will contain
  timeouts, delays, API defined timers, and the TOD update timer.
end

####################
# rtems_internal_seconds_chain
#
# ABSTRACT
#    Verbosely list contents of seconds chain tickled from clock tick
#
# ARGUMENTS: NONE
#
define rtems_internal_seconds_chain
  rtems_helper_score_watchdog_chain _Watchdog_Seconds_chain
end
document rtems_internal_seconds_chain
  Usage: rtems_internal_seconds_chain
  Lists the contains of the internal RTEMS delta chain used to manage
  all timing events that are TOD based.
end

####################
# rtems_malloc_walk
#
# ABSTRACT
#    Verbosely list the contents and state of the C Program Heap
#
# ARGUMENTS: None
#
define rtems_malloc_walk
  set $heap = &(((Region_Control *)\
    _Region_Information->local_table[RTEMS_Malloc_Heap&0xffff])->Memory)
   
  rtems_helper_score_heap $heap
end
document rtems_malloc_walk
  Usage: rtems_malloc_walk
  Display information about the C program heap
end

####################
# rtems_workspace_walk
#
# ABSTRACT
#    Verbosely list the contents and state of the C Program Heap
#
# ARGUMENTS: None
#
define rtems_workspace_walk
  set $heap = &_Workspace_Area

  rtems_helper_score_heap $heap
end
document rtems_workspace_walk
  Usage: rtems_workspace_walk
  Display information about the RTEMS Executive Workspace
end

####################
# rtems_tod
#
# ABSTRACT
#    Print out the current time of day
#
# ARGUMENTS: NONE
#
define rtems_tod
  #printf "Current Time -- %d seconds %d nanoseconds since 1970\n", \
  #  _TOD_Now.tv_sec, _TOD_Now.tv_nsec
  printf "Current Time -- current time is since 1970\n"
  print _TOD
end
document rtems_tod
  Usage: rtems_tod
  Display the current time of day according to RTEMS
  NOTE: If the TOD is not set, it will start at 1988.
end

####################
# rtems_check_state
#
# ABSTRACT
#    Check system state, dispatching critical section and ISR states
#
# ARGUMENTS: NONE
#
define rtems_check_state

  printf "RTEMS System State is: \n    "
  p _System_state_Current
  # Check Thread Dispatching Critical Sections
  set $tddl = _Thread_Dispatch_disable_level
  if $tddl == 0
    printf "NOT inside dispatching critical section\n"
  end
  if $tddl != 0
    printf "Inside dispatching critical section -- level = %d\n", $tddl
    if $tddl >= 100
      printf "HIGHLY PROBABLY DISPATCHING CRITICAL SECTION ERROR\n"
    end
  end

  # Check ISR Nesting and Dispatching Critical Sections
  set $isrnl = _Per_CPU_Information.isr_nest_level
  if $isrnl == 0
    printf "NOT inside an ISR\n"
  end
  if $isrnl != 0
    printf "Inside interrupt -- nest level = %d\n", $isrnl
    if $isrnl > $tddl
      printf "HIGHLY PROBABLY DISPATCHING CRITICAL SECTION ERROR\n"
      printf "ISR NEST LEVEL SHOULD ALWAYS BE >= DISPATCH DISABLE LEVEL\n"
    end
    if $isrnl < $tddl
      printf "It looks like you interrupted a dispatching critical section\n"
    end
  end
end
document rtems_check_state
  Usage: rtems_check_state
  This method displays information about the current state of RTEMS including
  dispatching disable critical sections and ISR nesting.  It performs some
  rudimentary consistency checks which might highlight problems.
end