]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/makekdebugevents.py
xnu-6153.11.26.tar.gz
[apple/xnu.git] / bsd / kern / makekdebugevents.py
CommitLineData
04b8595b
A
1#!/usr/bin/python
2#
3# This script scans the trace.codes file, containing a mapping of event id to
4# event name for all events, and writes to stdout a C declaration for a table
5# named kd_events[] or these mappings.
6# Required to generate a header file used by DEVELOPMENT and DEBUG kernels.
7#
8
9import sys
10import re
11
12# we expect one arg specifying the path to the trace.codes file
13if (len(sys.argv) < 2):
14 exit(1)
15trace_code_file = sys.argv[1]
16
17# regular expression pattern to match <hex_id> <string>
18id_name_pattern = re.compile('0x([0-9a-fA-F]+)\s+([^\s]*)')
19code_table = []
20
21# scan file to generate internal table
22with open(trace_code_file, 'rt') as codes:
23 for line in codes:
24 m = id_name_pattern.match(line)
25 if m:
26 code_table += [(int(m.group(1),base=16), m.group(2))]
27
28# emit typedef:
29print "typedef struct {"
30print " uint32_t id;"
31print " const char *name;"
32print "} kd_event_t;"
33# emit structure declaration and sorted initialization:
34print "kd_event_t kd_events[] = {"
35for mapping in sorted(code_table, key=lambda x: x[0]):
36 print " {0x%x, \"%s\"}," % mapping
37print "};"
38