blob: 2f2d6e2cc7779b524c916cd9cd81730f534dd0f5 [file] [log] [blame]
Bram Moolenaar446cb832008-06-24 21:56:24 +00001" DTrace D script syntax file. To avoid confusion with the D programming
2" language, I call this script dtrace.vim instead of d.vim.
3" Language: D script as described in "Solaris Dynamic Tracing Guide",
4" http://docs.sun.com/app/docs/doc/817-6223
5" Version: 1.5
6" Last Change: 2008/04/05
7" Maintainer: Nicolas Weber <nicolasweber@gmx.de>
8
9" dtrace lexer and parser are at
10" http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libdtrace/common/dt_lex.l
11" http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libdtrace/common/dt_grammar.y
12
13if version < 600
14 syntax clear
15elseif exists("b:current_syntax")
16 finish
17endif
18
19" Read the C syntax to start with
20if version < 600
21 so <sfile>:p:h/c.vim
22else
23 runtime! syntax/c.vim
24 unlet b:current_syntax
25endif
26
27syn clear cCommentL " dtrace doesn't support // style comments
28
29" First line may start with #!, also make sure a '-s' flag is somewhere in
30" that line.
31syn match dtraceComment "\%^#!.*-s.*"
32
33" Probe descriptors need explicit matches, so that keywords in probe
34" descriptors don't show up as errors. Note that this regex detects probes
35" as "something with three ':' in it". This works in practice, but it's not
36" really correct. Also add special case code for BEGIN, END and ERROR, since
37" they are common.
38" Be careful not to detect '/*some:::node*/\n/**/' as probe, as it's
39" commented out.
40" XXX: This allows a probe description to end with ',', even if it's not
41" followed by another probe.
42" XXX: This doesn't work if followed by a comment.
43let s:oneProbe = '\%(BEGIN\|END\|ERROR\|\S\{-}:\S\{-}:\S\{-}:\S\{-}\)\_s*'
44exec 'syn match dtraceProbe "'.s:oneProbe.'\%(,\_s*'.s:oneProbe.'\)*\ze\_s\%({\|\/[^*]\|\%$\)"'
45
46" Note: We have to be careful to not make this match /* */ comments.
47" Also be careful not to eat `c = a / b; b = a / 2;`. We use the same
48" technique as the dtrace lexer: a predicate has to be followed by {, ;, or
49" EOF. Also note that dtrace doesn't allow an empty predicate // (we do).
50" This regex doesn't allow a divison operator in the predicate.
51" Make sure that this matches the empty predicate as well.
52" XXX: This doesn't work if followed by a comment.
53syn match dtracePredicate "/\*\@!\_[^/]*/\ze\_s*\%({\|;\|\%$\)"
54 "contains=ALLBUT,dtraceOption " this lets the region contain too much stuff
55
56" Pragmas.
57" dtrace seems not to support whitespace before or after the '='. dtrace
58" supports only one option per #pragma, and no continuations of #pragma over
59" several lines with '\'.
60" Note that dtrace treats units (Hz etc) as case-insenstive, we allow only
61" sane unit capitalization in this script (ie 'ns', 'us', 'ms', 's' have to be
62" small, Hertz can be 'Hz' or 'hz')
63" XXX: "cpu" is always highlighted as builtin var, not as option
64
65" auto or manual: bufresize
66syn match dtraceOption contained "bufresize=\%(auto\|manual\)\s*$"
67
68" scalar: cpu jstackframes jstackstrsize nspec stackframes stackindent ustackframes
69syn match dtraceOption contained "\%(cpu\|jstackframes\|jstackstrsize\|nspec\|stackframes\|stackindent\|ustackframes\)=\d\+\s*$"
70
71" size: aggsize bufsize dynvarsize specsize strsize
72" size defaults to something if no unit is given (ie., having no unit is ok)
73syn match dtraceOption contained "\%(aggsize\|bufsize\|dynvarsize\|specsize\|strsize\)=\d\+\%(k\|m\|g\|t\|K\|M\|G\|T\)\=\s*$"
74
75" time: aggrate cleanrate statusrate switchrate
76" time defaults to hz if no unit is given
77syn match dtraceOption contained "\%(aggrate\|cleanrate\|statusrate\|switchrate\)=\d\+\%(hz\|Hz\|ns\|us\|ms\|s\)\=\s*$"
78
79" No type: defaultargs destructive flowindent grabanon quiet rawbytes
80syn match dtraceOption contained "\%(defaultargs\|destructive\|flowindent\|grabanon\|quiet\|rawbytes\)\s*$"
81
82
83" Turn reserved but unspecified keywords into errors
84syn keyword dtraceReservedKeyword auto break case continue counter default do
85syn keyword dtraceReservedKeyword else for goto if import probe provider
86syn keyword dtraceReservedKeyword register restrict return static switch while
87
88" Add dtrace-specific stuff
89syn keyword dtraceOperator sizeof offsetof stringof xlate
90syn keyword dtraceStatement self inline xlate this translator
91
92" Builtin variables
93syn keyword dtraceIdentifier arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9
94syn keyword dtraceIdentifier args caller chip cpu curcpu curlwpsinfo curpsinfo
95syn keyword dtraceIdentifier curthread cwd epid errno execname gid id ipl lgrp
96syn keyword dtraceIdentifier pid ppid probefunc probemod probename probeprov
97syn keyword dtraceIdentifier pset root stackdepth tid timestamp uid uregs
98syn keyword dtraceIdentifier vtimestamp walltimestamp
99syn keyword dtraceIdentifier ustackdepth
100
101" Macro Variables
102syn match dtraceConstant "$[0-9]\+"
103syn match dtraceConstant "$\(egid\|euid\|gid\|pgid\|ppid\)"
104syn match dtraceConstant "$\(projid\|sid\|target\|taskid\|uid\)"
105
106" Data Recording Actions
107syn keyword dtraceFunction trace tracemem printf printa stack ustack jstack
108
109" Process Destructive Actions
110syn keyword dtraceFunction stop raise copyout copyoutstr system
111
112" Kernel Destructive Actions
113syn keyword dtraceFunction breakpoint panic chill
114
115" Special Actions
116syn keyword dtraceFunction speculate commit discard exit
117
118" Subroutines
119syn keyword dtraceFunction alloca basename bcopy cleanpath copyin copyinstr
120syn keyword dtraceFunction copyinto dirname msgdsize msgsize mutex_owned
121syn keyword dtraceFunction mutex_owner mutex_type_adaptive progenyof
122syn keyword dtraceFunction rand rw_iswriter rw_write_held speculation
123syn keyword dtraceFunction strjoin strlen
124
125" Aggregating Functions
126syn keyword dtraceAggregatingFunction count sum avg min max lquantize quantize
127
128syn keyword dtraceType int8_t int16_t int32_t int64_t intptr_t
129syn keyword dtraceType uint8_t uint16_t uint32_t uint64_t uintptr_t
130syn keyword dtraceType string
131syn keyword dtraceType pid_t id_t
132
133
134" Define the default highlighting.
135" We use `hi def link` directly, this requires 5.8.
136hi def link dtraceReservedKeyword Error
137hi def link dtracePredicate String
138hi def link dtraceProbe dtraceStatement
139hi def link dtraceStatement Statement
140hi def link dtraceConstant Constant
141hi def link dtraceIdentifier Identifier
142hi def link dtraceAggregatingFunction dtraceFunction
143hi def link dtraceFunction Function
144hi def link dtraceType Type
145hi def link dtraceOperator Operator
146hi def link dtraceComment Comment
147hi def link dtraceNumber Number
148hi def link dtraceOption Identifier
149
150let b:current_syntax = "dtrace"