-
Notifications
You must be signed in to change notification settings - Fork 146
/
kgmacros
13670 lines (12500 loc) · 386 KB
/
kgmacros
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
# Kernel gdb macros
#
# These gdb macros should be useful during kernel development in
# determining what's going on in the kernel.
#
# All the convenience variables used by these macros begin with $kgm_
set print asm-demangle on
set cp-abi gnu-v2
# This option tells gdb to relax its stack tracing heuristics
# Useful for debugging across stack switches
# (to the interrupt stack, for instance). Requires gdb-675 or greater.
set backtrace sanity-checks off
echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
define kgm
printf ""
echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
end
document kgm
| These are the kernel gdb macros. These gdb macros are intended to be
| used when debugging a remote kernel via the kdp protocol. Typically, you
| would connect to your remote target like so:
| (gdb) target remote-kdp
| (gdb) attach <name-of-remote-host>
|
| The following macros are available in this package:
| showversion Displays a string describing the remote kernel version
|
| showalltasks Display a summary listing of all tasks
| showallthreads Display info about all threads in the system
| showallstacks Display the stack for each thread in the system
| showcurrentthreads Display info about the thread running on each cpu
| showcurrentstacks Display the stack for the thread running on each cpu
| showallvm Display a summary listing of all the vm maps
| showallvme Display a summary listing of all the vm map entries
| showallipc Display a summary listing of all the ipc spaces
| showipcsummary Display a summary listing of the ipc spaces of all tasks
| showallrights Display a summary listing of all the ipc rights
| showallkexts Display a summary listing of all loaded kexts (alias: showallkmods)
| showallknownkexts Display a summary listing of all kexts, loaded or not
| showallbusyports Display a listing of all ports with unread messages
| showallprocessors Display a listing of all psets and processors
|
| showallclasses Display info about all OSObject subclasses in the system
| showobject Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
| showregistry Show info about all registry entries in the current plane
| showregistryprops Show info about all registry entries in the current plane, and their properties
| showregistryentry Show info about a registry entry; its properties and descendants in the current plane
| setregistryplane Set the plane to be used for the iokit registry macros (pass zero for list)
|
| setfindregistrystr Set the encoded string for matching with
| findregistryentry or findregistryprop (created from
| strcmp_arg_pack64)
| findregistryentry Find a registry entry that matches the encoded string
| findregistryentries Find all the registry entries that match the encoded string
| findregistryprop Search the registry entry for a property that matches
| the encoded string
|
| showtask Display info about the specified task
| showtaskthreads Display info about the threads in the task
| showtaskstacks Display the stack for each thread in the task
| showtaskvm Display info about the specified task's vm_map
| showtaskvme Display info about the task's vm_map entries
| showtaskipc Display info about the specified task's ipc space
| showtaskrights Display info about the task's ipc space entries
| showtaskrightsbt Display info about the task's ipc space entries with back traces
| showtaskbusyports Display all of the task's ports with unread messages
|
| showact Display info about a thread specified by activation
| showactstack Display the stack for a thread specified by activation
|
| showmap Display info about the specified vm_map
| showmapvme Display a summary list of the specified vm_map's entries
|
| showipc Display info about the specified ipc space
| showrights Display a summary list of all the rights in an ipc space
|
| showpid Display info about the process identified by pid
| showproc Display info about the process identified by proc struct
| showprocinfo Display detailed info about the process identified by proc struct
| showprocfiles Given a proc_t pointer, display the list of open file descriptors
| showproclocks Given a proc_t pointer, display the list of advisory file locks
| zombproc Print out all procs in the zombie list
| showproctree Show all the processes in a hierarchical tree form
| allproc Print out all process in the system not in the zombie list
| zombstacks Print out all stacks of tasks that are exiting
|
| showinitchild Print out all processes in the system which are children of init process
|
| showkext Display info about a kext (alias: showkmod)
| showkextaddr Given an address, display the kext and offset (alias: showkmodaddr)
|
| dumpcallqueue Dump out all the entries given a queue head
|
| showallmtx Display info about mutexes usage
| showallrwlck Display info about reader/writer locks usage
|
| zprint Display info about the memory zones
| showioalloc Display info about iokit allocations
| paniclog Display the panic log info
|
| switchtoact Switch to different context specified by activation
| switchtoctx Switch to different context
| showuserstack Display numeric backtrace of the user stack for an
| activation
| showtaskuserstacks Display user stacks for a specified task
| showuserregisters Display user registers for the specified thread
| showtaskuserregisters Display user registers for the specified task
|
| switchtouserthread Switch to the user context of the specified thread
| resetstacks Return to the original kernel context
|
| resetctx Reset context
| resume_on Resume when detaching from gdb
| resume_off Don't resume when detaching from gdb
|
| sendcore Configure kernel to send a coredump to the specified IP
| sendsyslog Configure kernel to send a system log to the specified IP
| sendpaniclog Configure kernel to send a panic log to the specified IP
| disablecore Configure the kernel to disable coredump transmission
| getdumpinfo Retrieve the current remote dump parameters
| setdumpinfo Configure the remote dump parameters
|
| switchtocorethread Corefile version of "switchtoact"
| resetcorectx Corefile version of "resetctx"
|
| readphys8 Reads the specified untranslated address (8-bit read)
| readphys16 Reads the specified untranslated address (16-bit read)
| readphys32 Reads the specified untranslated address (32-bit read)
| readphys64 Reads the specified untranslated address (64-bit read)
| writephys8 Writes to the specified untranslated address (8-bit write)
| writephys16 Writes to the specified untranslated address (16-bit write)
| writephys32 Writes to the specified untranslated address (32-bit write)
| writephys64 Writes to the specified untranslated address (64-bit write)
|
| readioport8 Read 8-bits from the specified I/O Port
| readioport16 Read 16-bits from the specified I/O Port
| readioport32 Read 32-bits from the specified I/O Port
| writeioport8 Write 8-bits into the specified I/O Port
| writeioport16 Write 16-bits into the specified I/O Port
| writeioport32 Write 32-bits into the specified I/O Port
|
| readmsr64 Read 64-bits from the specified MSR
| writemsr64 Write 64-bits into the specified MSR
|
| rtentry_showdbg Print the debug information of a route entry
| rtentry_trash Walk the list of trash route entries
|
| inifa_showdbg Print the debug information of an IPv4 interface address
| in6ifa_showdbg Print the debug information of an IPv6 interface address
| inm_showdbg Print the debug information of an IPv4 multicast address
| ifma_showdbg Print the debug information of a link multicast address
| ifpref_showdbg Print the debug information of an interface ref count
|
| ndpr_showdbg Print the debug information of a nd_prefix structure
| nddr_showdbg Print the debug information of a nd_defrouter structure
|
| imo_showdbg Print the debug information of a ip_moptions structure
| im6o_showdbg Print the debug information of a ip6_moptions structure
|
| inifa_trash Walk the list of trash in_ifaddr entries
| in6ifa_trash Walk the list of trash in6_ifaddr entries
| inm_trash Walk the list of trash in_multi entries
| in6m_trash Walk the list of trash in6_multi entries
| ifma_trash Walk the list of trash ifmultiaddr entries
|
| mbuf_walkpkt Walk the mbuf packet chain (m_nextpkt)
| mbuf_walk Walk the mbuf chain (m_next)
| mbuf_buf2slab Find the slab structure of the corresponding buffer
| mbuf_buf2mca Find the mcache audit structure of the corresponding mbuf
| mbuf_showmca Print the contents of an mbuf mcache audit structure
| mbuf_showactive Print all active/in-use mbuf objects
| mbuf_showinactive Print all freed/in-cache mbuf objects
| mbuf_showall Print all mbuf objects
| mbuf_slabs Print all slabs in the group
| mbuf_slabstbl Print slabs table
| mbuf_stat Print extended mbuf allocator statistics
| mbuf_countchain Count the length of an mbuf chain
| mbuf_topleak Print the top suspected mbuf leakers
| mbuf_traceleak Print the leak information for a given leak address
|
| mcache_walkobj Walk the mcache object chain (obj_next)
| mcache_stat Print all mcaches in the system
| mcache_showcache Display the number of objects in the cache
|
| showbootargs Display boot arguments passed to the target kernel
| showbootermemorymap Dump phys memory map from EFI
|
| systemlog Display the kernel's printf ring buffer
|
| hexdump Show the contents of memory as a hex/ASCII dump
|
| showvnodepath Print the path for a vnode
| showvnodelocks Display list of advisory locks held/blocked on a vnode
| showvnodedev Display information about a device vnode
| showtty Display information about a struct tty
| showallvols Display a summary of mounted volumes
| showvnode Display info about one vnode
| showvolvnodes Display info about all vnodes of a given volume
| showvolbusyvnodes Display info about busy (iocount!=0) vnodes of a given volume
| showallbusyvnodes Display info about all busy (iocount!=0) vnodes
| showallvnodes Display info about all vnodes
| print_vnode Print out the fields of a vnode struct
| showprocvnodes Print out all the open fds which are vnodes in a process
| showallprocvnodes Print out all the open fds which are vnodes in any process
| showmountvnodes Print the vnode list
| showmountallvnodes Print the vnode inactive list
| showworkqvnodes Print the vnode worker list
| shownewvnodes Print the new vnode list
|
| ifconfig display ifconfig-like output
| showifnets show the list of attached and detached interfaces
| showifaddrs show the list of addresses for the given ifp
| showifmultiaddrs show the list of multicast addresses for the given ifp
| showinmultiaddrs show the list of IPv4 multicast addresses records
| showin6multiaddrs show the list of IPv6 multicast addresses records
|
| showsocket Display information about a socket
| showprocsockets Given a proc_t pointer, display information about its sockets
| showallprocsockets Display information about the sockets of all the processes
|
| show_tcp_pcbinfo Display the list of the TCP protocol control blocks
| show_tcp_timewaitslots Display the list of the TCP protocol control blocks in TIMEWAIT
| show_udp_pcbinfo Display the list of UDP protocol control blocks
|
| show_rt_inet Display the IPv4 routing table
| show_rt_inet6 Display the IPv6 routing table
|
| showpmworkqueue Display the IOPMWorkQueue object
| showregistrypmstate Display power management state for all IOPower registry entries
| showioservicepm Display the IOServicePM object
| showstacksaftertask showallstacks starting after a given task
| showstacksafterthread showallstacks starting after a given thread
|
| showMCAstate Print machine-check register state after MC exception.
|
| showallgdbstacks Cause GDB to trace all thread stacks
| showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
| kdp-reenter Schedule reentry into the debugger and continue.
| kdp-reboot Restart remote target
| kdp-version Get KDP version number
|
| zstack Print zalloc caller stack (zone leak debugging)
| findoldest Find oldest zone leak debugging record
| countpcs Print how often a pc occurs in the zone leak log
|
| showtopztrace Print the ztrace with the most outstanding allocated memory
| showztrace Print a backtrace record given its index
| showzalloc Print an allocation record + stacktrace at index
| showztraceaddr Print a backtrace record given its address
| showztracesabove Print all the backtrace records with a size bigger than X
| showzstacktrace Symbolicate and print a stored OSBacktrace
|
| showztraces Finds all in-use traces in the ztraces table
| showzallocs Finds all in-use allocations in the zallocs table
| showzstats Shows the statistics gathered about the hash tables
|
| showzallocsfortrace Print all the allocations that refer to a trace
| showztracehistogram Prints a histogram of the ztraces table
| showzallochistogram Prints a histogram of the zallocs table
|
| pmap_walk Perform a page-table walk
| pmap_vtop Translate a virtual address to physical address
|
| showuserdyldinfo Show dyld information and error messages
| in the target task
| showuserlibraries Show binary images known by dyld in the
| target task
| showallvmstats Prints a summary of vm statistics in a table format
| memstats Displays memory statistics in a table format
|
| showthreadfortid Displays the address of the thread structure
| for a given thread_id value.
|
| strcmp_nomalloc A version of strcmp that avoids the use of malloc
| through the use of encoded strings created via
| strcmp_arg_pack64.
| strcmp_arg_pack64 Pack a string into a 64-bit quantity for use by
| strcmp_nomalloc
|
| pci_cfg_read8 Read 8-bits from a PCI config space register
| pci_cfg_read16 Read 16-bits from a PCI config space register
| pci_cfg_read32 Read 32-bits from a PCI config space register
| pci_cfg_write8 Write 8-bits into a PCI config space register
| pci_cfg_write16 Write 16-bits into a PCI config space register
| pci_cfg_write32 Write 32-bits into a PCI config space register
| pci_cfg_dump Dump entire config space for a PCI device
| pci_cfg_scan Perform a scan for PCI devices
| pci_cfg_dump_all Dump config spaces for all detected PCI devices
|
| lapic_read32 Read APIC entry
| lapic_write32 Write APIC entry
| lapic_dump Dump APIC entries
|
| ioapic_read32 Read IOAPIC entry
| ioapic_write32 Write IOAPIC entry
| ioapic_dump Dump IOAPIC entries
|
| showallproviders Display summary listing of all dtrace_providers
| showallmodctls Display summary listing of all dtrace modctls
| showmodctl Display info about a dtrace modctl
| showfbtprobe Display info about an fbt probe given an id (traverses fbt_probetab)
| processortimers Display all processor timers, noting any inconsistencies
|
| maplocalcache Enable local caching in GDB for improved debug speeds
| flushlocalcahe Disable local caching in GDB (deletes all memory regions)
|
| Type "help <macro>" for more specific help on a particular macro.
| Type "show user <macro>" to see what the macro is really doing.
end
# This macro should appear before any symbol references, to facilitate
# a gdb "source" without a loaded symbol file.
define showversion
kdp-kernelversion
end
document showversion
Syntax: showversion
| Read the kernel version string from a fixed address in low
| memory. Useful if you don't know which kernel is on the other end,
| and need to find the appropriate symbols. Beware that if you've
| loaded a symbol file, but aren't connected to a remote target,
| the version string from the symbol file will be displayed instead.
| This macro expects to be connected to the remote kernel to function
| correctly.
end
set $kgm_mtype_ppc = 0x00000012
set $kgm_mtype_arm = 0x0000000C
set $kgm_mtype_i386 = 0x00000007
set $kgm_mtype_x86_64 = 0x01000007
set $kgm_mtype_x86_any = $kgm_mtype_i386
set $kgm_mtype_x86_mask = 0xFEFFFFFF
set $kgm_mtype = ((unsigned int *)&_mh_execute_header)[1]
set $kgm_lp64 = $kgm_mtype & 0x01000000
set $kgm_manual_pkt_ppc = 0x549C
set $kgm_manual_pkt_i386 = 0x249C
set $kgm_manual_pkt_x86_64 = 0xFFFFFF8000002930
set $kgm_manual_pkt_arm = 0xFFFF04A0
set $kgm_kdp_pkt_data_len = 128
# part of data packet
set $kgm_kdp_pkt_hdr_req_off = 0
set $kgm_kdp_pkt_hdr_seq_off = 1
set $kgm_kdp_pkt_hdr_len_off = 2
set $kgm_kdp_pkt_hdr_key_off = 4
# after data packet
set $kgm_kdp_pkt_len_off = $kgm_kdp_pkt_data_len
set $kgm_kdp_pkt_input_off = $kgm_kdp_pkt_data_len + 4
set $kgm_kdp_pkt_hostreboot = 0x13
set $kgm_kdp_pkt_hdr_size = 8
set $kgm_readphys_force_kdp = 0
set $kgm_readphys_force_physmap = 0
set $kgm_lcpu_self = 0xFFFE
set $kgm_reg_depth = 0
set $kgm_reg_depth_max = 0xFFFF
set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
set $kgm_namekey = (OSSymbol *) 0
set $kgm_childkey = (OSSymbol *) 0
set $kgm_show_object_addrs = 0
set $kgm_show_object_retain = 0
set $kgm_show_props = 0
set $kgm_show_data_alwaysbytes = 0
set $kgm_show_kmod_syms = 0
# send a manual packet header that doesn't require knowing the location
# of everything.
define manualhdrint
set $req = $arg0
set $hdrp = (uint32_t *) $kgm_manual_pkt_i386
if ($kgm_mtype == $kgm_mtype_ppc)
set $hdrp = (uint32_t *) $kgm_manual_pkt_ppc
set $req = $req << 1 # shift to deal with endiannness
end
if ($kgm_mtype == $kgm_mtype_x86_64)
set $hdrp = (uint64_t *) $kgm_manual_pkt_x86_64
end
if ($kgm_mtype == $kgm_mtype_arm)
set $hdrp = (uint32_t *) $kgm_manual_pkt_arm
end
set $pkt_hdr = *$hdrp
set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 0
set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_len_off)) = $kgm_kdp_pkt_hdr_size
set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_req_off)) = $req
set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_seq_off)) = 0
set *((uint16_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_len_off)) = $kgm_kdp_pkt_hdr_size
set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_key_off)) = 0
set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 1
# dummy to make sure manual packet is executed
set $kgm_dummy = &_mh_execute_header
end
# Print a pointer
define showptr
if $kgm_lp64
printf "0x%016llx", $arg0
else
printf "0x%08x", $arg0
end
end
# for headers, leave 8 chars for LP64 pointers
define showptrhdrpad
if $kgm_lp64
printf " "
end
end
# Print a userspace pointer, using $kgm_tasp
define showuserptr
set $kgm_userptr_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
if $kgm_userptr_task_64
printf "0x%016llx", $arg0
else
printf "0x%08x", $arg0
end
end
define showkmodheader
printf "kmod_info "
showptrhdrpad
printf " address "
showptrhdrpad
printf " size "
showptrhdrpad
printf " id refs version name\n"
end
define showkmodint
set $kgm_kmodp = (struct kmod_info *)$arg0
showptr $kgm_kmodp
printf " "
showptr $kgm_kmodp->address
printf " "
showptr $kgm_kmodp->size
printf " "
printf "%3d ", $kgm_kmodp->id
printf "%5d ", $kgm_kmodp->reference_count
printf "%10s ", $kgm_kmodp->version
printf "%s\n", $kgm_kmodp->name
end
# cached info of the last kext found, to speed up subsequent lookups
set $kgm_pkmod = 0
set $kgm_pkmodst = 0
set $kgm_pkmoden = 0
define showkmodaddrint
showptr $arg0
if ((unsigned long)$arg0 >= (unsigned long)$kgm_pkmodst) && ((unsigned long)$arg0 < (unsigned long)$kgm_pkmoden)
set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_pkmodst)
printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
else
set $kgm_kmodp = (struct kmod_info *)kmod
if ($kgm_mtype == $kgm_mtype_x86_64) && ($arg0 >= (unsigned long)&_mh_execute_header)
# kexts are loaded below the kernel for x86_64
set $kgm_kmodp = 0
end
while $kgm_kmodp
set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_kmodp->address)
if ($kgm_kmodp->address <= $arg0) && ($kgm_off < $kgm_kmodp->size)
printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
set $kgm_pkmod = $kgm_kmodp
set $kgm_pkmodst = $kgm_kmodp->address
set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmodp->size
set $kgm_kmodp = 0
else
set $kgm_kmodp = $kgm_kmodp->next
end
end
end
end
define showkmodaddr
showkmodaddrint $arg0
end
document showkmodaddr
Syntax: (gdb) showkmodaddr <addr>
| Given an address, print the offset and name for the kmod containing it
end
define showkmod
showkmodheader
showkmodint $arg0
end
document showkmod
Syntax: (gdb) showkmod <kmod>
| Routine to print info about a kext
end
define showkext
showkmod $arg0
end
document showkext
Syntax: (gdb) showkext <kmod_info_address>
| Routine to print info about a kext
end
define showallkmods
showkmodheader
set $kgm_kmodp = (struct kmod_info *)kmod
while $kgm_kmodp
showkmodint $kgm_kmodp
set $kgm_kmodp = $kgm_kmodp->next
end
end
document showallkmods
Syntax: (gdb) showallkmods
| Routine to print a summary listing of all loaded kexts
end
define showallkexts
showallkmods
end
document showallkexts
Syntax: (gdb) showallkexts
| Routine to print a summary listing of all loaded kexts
end
# See OSKextVersion.c for the C code this is based on
#
set $KGM_OSKEXT_VERS_MAJ_MULT = 100000000
set $KGM_OSKEXT_VERS_MIN_MULT = 1000000
set $KGM_OSKEXT_VERS_REV_MULT = 10000
set $KGM_OSKEXT_VERS_STAGE_MULT = 1000
define printoskextversion
set $vers_scratch = $arg0
if ($vers_scratch == -1)
printf "(invalid)"
else
set $vers_major = $vers_scratch / $KGM_OSKEXT_VERS_MAJ_MULT
set $vers_scratch = $vers_scratch - ($vers_major * $KGM_OSKEXT_VERS_MAJ_MULT)
set $vers_minor = $vers_scratch / $KGM_OSKEXT_VERS_MIN_MULT
set $vers_scratch = $vers_scratch - ( $vers_minor * $KGM_OSKEXT_VERS_MIN_MULT)
set $vers_revision = $vers_scratch / $KGM_OSKEXT_VERS_REV_MULT
set $vers_scratch = $vers_scratch - ( $vers_revision * $KGM_OSKEXT_VERS_REV_MULT)
set $vers_stage = $vers_scratch / $KGM_OSKEXT_VERS_STAGE_MULT
set $vers_scratch = $vers_scratch - ( $vers_stage * $KGM_OSKEXT_VERS_STAGE_MULT)
set $vers_stagelevel = $vers_scratch
printf "%d.%d", $vers_major, $vers_minor
if ($vers_revision > 0)
printf ".%d", $vers_revision
end
if ($vers_stage == 1)
printf "d"
end
if ($vers_stage == 3)
printf "a"
end
if ($vers_stage == 5)
printf "b"
end
if ($vers_stage == 7)
printf "fc"
end
if ($vers_stage == 1 || $vers_stage == 3 || $vers_stage == 5 || $vers_stage == 7)
printf "%d", $vers_stagelevel
end
end
end
define showallknownkexts
set $kext_count = sKextsByID->count
set $kext_index = 0
printf "%d kexts in sKextsByID:\n", $kext_count
printf "OSKext * "
showptrhdrpad
printf "load_addr "
showptrhdrpad
printf " id name (version)\n"
while $kext_index < $kext_count
set $kext_id = sKextsByID->dictionary[$kext_index].key->string
set $oskext = (OSKext *)sKextsByID->dictionary[$kext_index].value
showptr $oskext
printf " "
if ($oskext->flags.loaded)
showptr $oskext->kmod_info
printf " "
printf "%3d", $oskext->loadTag
else
showptrhdrpad
printf " -------- "
printf " "
printf " --"
end
printf " "
printf "%.64s (", $kext_id
printoskextversion (uint64_t)$oskext->version
printf ")\n"
set $kext_index = $kext_index + 1
end
end
document showallknownkexts
Syntax: (gdb) showallknownkexts
| Routine to print a summary listing of all kexts, loaded or not
end
define showactheader
printf " "
showptrhdrpad
printf " thread "
showptrhdrpad
printf " thread_id "
showptrhdrpad
printf " processor "
showptrhdrpad
printf " pri io_policy state wait_queue"
showptrhdrpad
printf " wait_event\n"
end
define showactint
printf " "
showptrhdrpad
set $kgm_thread = *(struct thread *)$arg0
showptr $arg0
if ($kgm_thread.static_param)
printf "[WQ]"
else
printf " "
end
printf " 0x%llx ", $kgm_thread.thread_id
showptr $kgm_thread.last_processor
printf " %3d ", $kgm_thread.sched_pri
if ($kgm_thread.uthread != 0)
set $kgm_printed = 0
set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
if ($kgm_uthread->uu_flag & 0x400)
printf "RAGE "
else
printf " "
end
set $diskpolicy = 0
if ($kgm_thread->ext_appliedstate.hw_disk != 0)
set $diskpolicy = $kgm_thread->ext_appliedstate.hw_disk
else
if ($kgm_thread->appliedstate.hw_disk != 0)
set $diskpolicy = $kgm_thread->appliedstate.hw_disk
end
end
if ($kgm_thread->ext_appliedstate.hw_bg != 0)
set $diskpolicy = 5
end
if ($kgm_thread->appliedstate.hw_bg != 0)
set $diskpolicy = 4
end
if ($diskpolicy == 2)
printf "PASS "
set $kgm_printed = 1
end
if ($diskpolicy == 3)
printf "THROT "
set $kgm_printed = 1
end
if ($diskpolicy == 4)
printf "BG_THRT "
set $kgm_printed = 1
end
if ($diskpolicy == 5)
printf "EBG_THRT"
set $kgm_printed = 1
end
if ($kgm_printed == 0)
printf " "
end
end
set $kgm_state = $kgm_thread.state
if $kgm_state & 0x80
printf "I"
end
if $kgm_state & 0x40
printf "P"
end
if $kgm_state & 0x20
printf "A"
end
if $kgm_state & 0x10
printf "H"
end
if $kgm_state & 0x08
printf "U"
end
if $kgm_state & 0x04
printf "R"
end
if $kgm_state & 0x02
printf "S"
end
if $kgm_state & 0x01
printf "W"
printf "\t "
showptr $kgm_thread.wait_queue
printf " "
if (((unsigned long)$kgm_thread.wait_event > (unsigned long)&last_kernel_symbol) \
&& ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
showkmodaddr $kgm_thread.wait_event
else
output /a $kgm_thread.wait_event
end
if ($kgm_thread.uthread != 0)
set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
if ($kgm_uthread->uu_wmesg != 0)
printf "\t \"%s\"", $kgm_uthread->uu_wmesg
end
end
end
if ($kgm_thread.uthread != 0)
set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
if ($kgm_uthread->pth_name && $kgm_uthread->pth_name[0])
printf "\n\t\tThread Name: %s", $kgm_uthread->pth_name
end
end
if $arg1 != 0
if ($kgm_thread.kernel_stack != 0)
if ($kgm_thread.uthread != 0)
printf "\n "
set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
if ($kgm_uthread->uu_kwe.kwe_kwqqueue != 0)
set $kwq = (ksyn_wait_queue_t)$kgm_uthread->uu_kwe.kwe_kwqqueue
printf " kwq_lockcount:0x%x; kwq_retval:0x%x", $kgm_uthread->uu_kwe.kwe_lockseq, $kgm_uthread->uu_kwe.kwe_psynchretval
printf "\n "
show_kwq $kwq
printf " "
end
end
if ($kgm_thread.reserved_stack != 0)
printf "\n "
showptrhdrpad
printf " reserved_stack="
showptr $kgm_thread.reserved_stack
end
printf "\n "
showptrhdrpad
printf " kernel_stack="
showptr $kgm_thread.kernel_stack
if ($kgm_mtype == $kgm_mtype_ppc)
set $mysp = $kgm_thread.machine.pcb->save_r1
end
if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
set $kgm_statep = (struct x86_kernel_state *) \
($kgm_thread->kernel_stack + kernel_stack_size \
- sizeof(struct x86_kernel_state))
if ($kgm_mtype == $kgm_mtype_i386)
set $mysp = $kgm_statep->k_ebp
else
set $mysp = $kgm_statep->k_rbp
end
end
if ($kgm_mtype == $kgm_mtype_arm)
if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
&& ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
set $mysp = $r7
else
set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
set $mysp = $kgm_statep->r[7]
end
end
set $prevsp = $mysp - 16
printf "\n "
showptrhdrpad
printf " stacktop="
showptr $mysp
if ($kgm_mtype == $kgm_mtype_ppc)
set $stkmask = 0xf
else
set $stkmask = 0x3
end
set $kgm_return = 0
set $kgm_actint_framecount = 0
while ($mysp != 0) && (($mysp & $stkmask) == 0) \
&& ($mysp != $prevsp) \
&& ((((unsigned long) $mysp ^ (unsigned long) $prevsp) < 0x2000) \
|| (((unsigned long)$mysp < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
&& ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack)))) \
&& ($kgm_actint_framecount < 128)
printf "\n "
set $kgm_actint_framecount = $kgm_actint_framecount + 1
showptrhdrpad
printf " "
showptr $mysp
printf " "
if ($kgm_mtype == $kgm_mtype_ppc)
set $kgm_return = *($mysp + 8)
end
if ($kgm_mtype == $kgm_mtype_i386)
set $kgm_return = *($mysp + 4)
end
if ($kgm_mtype == $kgm_mtype_x86_64)
set $kgm_return = *(unsigned long *)($mysp + 8)
end
if ($kgm_mtype == $kgm_mtype_arm)
set $kgm_return = *($mysp + 4)
end
if (((unsigned long) $kgm_return < (unsigned long) &_mh_execute_header || \
(unsigned long) $kgm_return >= (unsigned long) &last_kernel_symbol ) \
&& ($kgm_show_kmod_syms == 0))
showkmodaddr $kgm_return
else
output /a $kgm_return
end
set $prevsp = $mysp
set $mysp = *(unsigned long *)$mysp
end
set $kgm_return = 0
printf "\n "
showptrhdrpad
printf " stackbottom="
showptr $prevsp
else
printf "\n "
showptrhdrpad
printf " continuation="
output /a $kgm_thread.continuation
end
printf "\n"
else
printf "\n"
end
end
define showact
showactheader
showactint $arg0 0
end
document showact
Syntax: (gdb) showact <activation>
| Routine to print out the state of a specific thread.
end
define showactstack
showactheader
showactint $arg0 1
end
document showactstack
Syntax: (gdb) showactstack <activation>
| Routine to print out the stack of a specific thread.
end
define showallthreads
set $kgm_head_taskp = &tasks
set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
while $kgm_taskp != $kgm_head_taskp
showtaskheader
showtaskint $kgm_taskp
showactheader
set $kgm_head_actp = &($kgm_taskp->threads)
set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
while $kgm_actp != $kgm_head_actp
showactint $kgm_actp 0
set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
end
printf "\n"
set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
end
end
document showallthreads
Syntax: (gdb) showallthreads
| Routine to print out info about all threads in the system.
end
define showprocessorint
set $kgm_processor_int = (struct processor *)$arg0
printf "Processor "
showptr $kgm_processor_int
printf " State %d (cpu_id 0x%x)\n", ($kgm_processor_int)->state, ($kgm_processor_int)->cpu_id
end
define showcurrentthreads
set $kgm_prp = (struct processor *)processor_list
while $kgm_prp != 0
showprocessorint $kgm_prp
if ($kgm_prp)->active_thread != 0
set $kgm_actp = ($kgm_prp)->active_thread
showtaskheader
showtaskint ($kgm_actp)->task
showactheader
showactint $kgm_actp 0
printf "\n"
end
set $kgm_prp = ($kgm_prp)->processor_list
end
end
document showcurrentthreads
Syntax: (gdb) showcurrentthreads
| Routine to print out info about the thread running on each cpu.
end
define _showrunqint
set $kgm_runq = (struct run_queue *)$arg0
printf " Priority Run Queue Info: Count %d\n", $kgm_runq->count
set $kgm_runq_queue_i = 0
set $kgm_runq_queue_count = sizeof($kgm_runq->queues)/sizeof($kgm_runq->queues[0])
while $kgm_runq->count && $kgm_runq_queue_i < $kgm_runq_queue_count
set $kgm_runq_queue_head = &$kgm_runq->queues[$kgm_runq_queue_i]
set $kgm_runq_queue_p = $kgm_runq_queue_head->next
if $kgm_runq_queue_p != $kgm_runq_queue_head
set $kgm_runq_queue_this_count = 0
while $kgm_runq_queue_p != $kgm_runq_queue_head
set $kgm_runq_queue_this_count = $kgm_runq_queue_this_count + 1
showtask ((thread_t)$kgm_runq_queue_p)->task
showactstack $kgm_runq_queue_p
set $kgm_runq_queue_p = $kgm_runq_queue_p->next
end
printf " Queue Priority %3d [", $kgm_runq_queue_i
showptr $kgm_runq_queue_head
printf "] Count %d\n", $kgm_runq_queue_this_count
end
set $kgm_runq_queue_i = $kgm_runq_queue_i + 1
end
end
define _showgrrrint
set $kgm_grrr_runq = $arg0
printf " GRRR Info: Count %d Weight %d Current Group ", $kgm_grrr_runq->count, $kgm_grrr_runq->weight
showptr $kgm_grrr_runq->current_group
printf "\n"
set $kgm_grrr_group_i = 0
set $kgm_grrr_group_count = sizeof($kgm_grrr_runq->groups)/sizeof($kgm_grrr_runq->groups[0])
while $kgm_grrr_runq->count && $kgm_grrr_group_i < $kgm_grrr_group_count
set $kgm_grrr_group = &$kgm_grrr_runq->groups[$kgm_grrr_group_i]
if $kgm_grrr_group->count > 0
printf " Group %3d [", $kgm_grrr_group->index
showptr $kgm_grrr_group
printf "] Count %d Weight %d\n", $kgm_grrr_group->count, $kgm_grrr_group->weight
set $kgm_grrr_group_client_head = &$kgm_grrr_group->clients
set $kgm_grrr_group_client = $kgm_grrr_group_client_head->next
while $kgm_grrr_group_client != $kgm_grrr_group_client_head
# showtask ((thread_t)$kgm_grrr_group_client)->task
# showactstack $kgm_grrr_group_client
set $kgm_grrr_group_client = $kgm_grrr_group_client->next
end
end
set $kgm_grrr_group_i = $kgm_grrr_group_i + 1
end
end
define showallprocessors
set $kgm_pset = &pset0
set $kgm_show_grrr = 0
set $kgm_show_priority_runq = 0
set $kgm_show_priority_pset_runq = 0
set $kgm_show_fairshare_grrr = 0
set $kgm_show_fairshare_list = 0
if _sched_enum == 1
set $kgm_show_priority_runq = 1
set $kgm_show_fairshare_list = 1
end
if _sched_enum == 2
set $kgm_show_priority_pset_runq = 1
set $kgm_show_fairshare_list = 1
end
if _sched_enum == 4
set $kgm_show_grrr = 1
set $kgm_show_fairshare_grrr = 1