xref: /vim-8.2.3635/runtime/syntax/dtrace.vim (revision 89bcfda6)
1446cb837SBram Moolenaar" DTrace D script syntax file. To avoid confusion with the D programming
2446cb837SBram Moolenaar" language, I call this script dtrace.vim instead of d.vim.
3446cb837SBram Moolenaar" Language: D script as described in "Solaris Dynamic Tracing Guide",
4446cb837SBram Moolenaar"           http://docs.sun.com/app/docs/doc/817-6223
5446cb837SBram Moolenaar" Version: 1.5
6446cb837SBram Moolenaar" Last Change: 2008/04/05
7446cb837SBram Moolenaar" Maintainer: Nicolas Weber <[email protected]>
8446cb837SBram Moolenaar
9446cb837SBram Moolenaar" dtrace lexer and parser are at
10446cb837SBram Moolenaar" http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libdtrace/common/dt_lex.l
11446cb837SBram Moolenaar" http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libdtrace/common/dt_grammar.y
12446cb837SBram Moolenaar
13*89bcfda6SBram Moolenaar" quit when a syntax file was already loaded
14*89bcfda6SBram Moolenaarif exists("b:current_syntax")
15446cb837SBram Moolenaar  finish
16446cb837SBram Moolenaarendif
17446cb837SBram Moolenaar
18446cb837SBram Moolenaar" Read the C syntax to start with
19446cb837SBram Moolenaarruntime! syntax/c.vim
20446cb837SBram Moolenaarunlet b:current_syntax
21446cb837SBram Moolenaar
22446cb837SBram Moolenaarsyn clear cCommentL  " dtrace doesn't support // style comments
23446cb837SBram Moolenaar
24446cb837SBram Moolenaar" First line may start with #!, also make sure a '-s' flag is somewhere in
25446cb837SBram Moolenaar" that line.
26446cb837SBram Moolenaarsyn match dtraceComment "\%^#!.*-s.*"
27446cb837SBram Moolenaar
28446cb837SBram Moolenaar" Probe descriptors need explicit matches, so that keywords in probe
29446cb837SBram Moolenaar" descriptors don't show up as errors. Note that this regex detects probes
30446cb837SBram Moolenaar" as "something with three ':' in it". This works in practice, but it's not
31446cb837SBram Moolenaar" really correct. Also add special case code for BEGIN, END and ERROR, since
32446cb837SBram Moolenaar" they are common.
33446cb837SBram Moolenaar" Be careful not to detect '/*some:::node*/\n/**/' as probe, as it's
34446cb837SBram Moolenaar" commented out.
35446cb837SBram Moolenaar" XXX: This allows a probe description to end with ',', even if it's not
36446cb837SBram Moolenaar" followed by another probe.
37446cb837SBram Moolenaar" XXX: This doesn't work if followed by a comment.
38446cb837SBram Moolenaarlet s:oneProbe = '\%(BEGIN\|END\|ERROR\|\S\{-}:\S\{-}:\S\{-}:\S\{-}\)\_s*'
39446cb837SBram Moolenaarexec 'syn match dtraceProbe "'.s:oneProbe.'\%(,\_s*'.s:oneProbe.'\)*\ze\_s\%({\|\/[^*]\|\%$\)"'
40446cb837SBram Moolenaar
41446cb837SBram Moolenaar" Note: We have to be careful to not make this match /* */ comments.
42446cb837SBram Moolenaar" Also be careful not to eat `c = a / b; b = a / 2;`. We use the same
43446cb837SBram Moolenaar" technique as the dtrace lexer: a predicate has to be followed by {, ;, or
44446cb837SBram Moolenaar" EOF. Also note that dtrace doesn't allow an empty predicate // (we do).
45446cb837SBram Moolenaar" This regex doesn't allow a divison operator in the predicate.
46446cb837SBram Moolenaar" Make sure that this matches the empty predicate as well.
47446cb837SBram Moolenaar" XXX: This doesn't work if followed by a comment.
48446cb837SBram Moolenaarsyn match dtracePredicate "/\*\@!\_[^/]*/\ze\_s*\%({\|;\|\%$\)"
49446cb837SBram Moolenaar  "contains=ALLBUT,dtraceOption  " this lets the region contain too much stuff
50446cb837SBram Moolenaar
51446cb837SBram Moolenaar" Pragmas.
52446cb837SBram Moolenaar" dtrace seems not to support whitespace before or after the '='.  dtrace
53446cb837SBram Moolenaar" supports only one option per #pragma, and no continuations of #pragma over
54446cb837SBram Moolenaar" several lines with '\'.
55446cb837SBram Moolenaar" Note that dtrace treats units (Hz etc) as case-insenstive, we allow only
56446cb837SBram Moolenaar" sane unit capitalization in this script (ie 'ns', 'us', 'ms', 's' have to be
57446cb837SBram Moolenaar" small, Hertz can be 'Hz' or 'hz')
58446cb837SBram Moolenaar" XXX: "cpu" is always highlighted as builtin var, not as option
59446cb837SBram Moolenaar
60446cb837SBram Moolenaar"   auto or manual: bufresize
61446cb837SBram Moolenaarsyn match dtraceOption contained "bufresize=\%(auto\|manual\)\s*$"
62446cb837SBram Moolenaar
63446cb837SBram Moolenaar"   scalar: cpu jstackframes jstackstrsize nspec stackframes stackindent ustackframes
64446cb837SBram Moolenaarsyn match dtraceOption contained "\%(cpu\|jstackframes\|jstackstrsize\|nspec\|stackframes\|stackindent\|ustackframes\)=\d\+\s*$"
65446cb837SBram Moolenaar
66446cb837SBram Moolenaar"   size: aggsize bufsize dynvarsize specsize strsize
67446cb837SBram Moolenaar"   size defaults to something if no unit is given (ie., having no unit is ok)
68446cb837SBram Moolenaarsyn match dtraceOption contained "\%(aggsize\|bufsize\|dynvarsize\|specsize\|strsize\)=\d\+\%(k\|m\|g\|t\|K\|M\|G\|T\)\=\s*$"
69446cb837SBram Moolenaar
70446cb837SBram Moolenaar"   time: aggrate cleanrate statusrate switchrate
71446cb837SBram Moolenaar"   time defaults to hz if no unit is given
72446cb837SBram Moolenaarsyn match dtraceOption contained "\%(aggrate\|cleanrate\|statusrate\|switchrate\)=\d\+\%(hz\|Hz\|ns\|us\|ms\|s\)\=\s*$"
73446cb837SBram Moolenaar
74446cb837SBram Moolenaar"   No type: defaultargs destructive flowindent grabanon quiet rawbytes
75446cb837SBram Moolenaarsyn match dtraceOption contained "\%(defaultargs\|destructive\|flowindent\|grabanon\|quiet\|rawbytes\)\s*$"
76446cb837SBram Moolenaar
77446cb837SBram Moolenaar
78446cb837SBram Moolenaar" Turn reserved but unspecified keywords into errors
79446cb837SBram Moolenaarsyn keyword dtraceReservedKeyword auto break case continue counter default do
80446cb837SBram Moolenaarsyn keyword dtraceReservedKeyword else for goto if import probe provider
81446cb837SBram Moolenaarsyn keyword dtraceReservedKeyword register restrict return static switch while
82446cb837SBram Moolenaar
83446cb837SBram Moolenaar" Add dtrace-specific stuff
84446cb837SBram Moolenaarsyn keyword dtraceOperator   sizeof offsetof stringof xlate
85446cb837SBram Moolenaarsyn keyword dtraceStatement  self inline xlate this translator
86446cb837SBram Moolenaar
87446cb837SBram Moolenaar" Builtin variables
88446cb837SBram Moolenaarsyn keyword dtraceIdentifier arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9
89446cb837SBram Moolenaarsyn keyword dtraceIdentifier args caller chip cpu curcpu curlwpsinfo curpsinfo
90446cb837SBram Moolenaarsyn keyword dtraceIdentifier curthread cwd epid errno execname gid id ipl lgrp
91446cb837SBram Moolenaarsyn keyword dtraceIdentifier pid ppid probefunc probemod probename probeprov
92446cb837SBram Moolenaarsyn keyword dtraceIdentifier pset root stackdepth tid timestamp uid uregs
93446cb837SBram Moolenaarsyn keyword dtraceIdentifier vtimestamp walltimestamp
94446cb837SBram Moolenaarsyn keyword dtraceIdentifier ustackdepth
95446cb837SBram Moolenaar
96446cb837SBram Moolenaar" Macro Variables
97446cb837SBram Moolenaarsyn match dtraceConstant     "$[0-9]\+"
98446cb837SBram Moolenaarsyn match dtraceConstant     "$\(egid\|euid\|gid\|pgid\|ppid\)"
99446cb837SBram Moolenaarsyn match dtraceConstant     "$\(projid\|sid\|target\|taskid\|uid\)"
100446cb837SBram Moolenaar
101446cb837SBram Moolenaar" Data Recording Actions
102446cb837SBram Moolenaarsyn keyword dtraceFunction   trace tracemem printf printa stack ustack jstack
103446cb837SBram Moolenaar
104446cb837SBram Moolenaar" Process Destructive Actions
105446cb837SBram Moolenaarsyn keyword dtraceFunction   stop raise copyout copyoutstr system
106446cb837SBram Moolenaar
107446cb837SBram Moolenaar" Kernel Destructive Actions
108446cb837SBram Moolenaarsyn keyword dtraceFunction   breakpoint panic chill
109446cb837SBram Moolenaar
110446cb837SBram Moolenaar" Special Actions
111446cb837SBram Moolenaarsyn keyword dtraceFunction   speculate commit discard exit
112446cb837SBram Moolenaar
113446cb837SBram Moolenaar" Subroutines
114446cb837SBram Moolenaarsyn keyword dtraceFunction   alloca basename bcopy cleanpath copyin copyinstr
115446cb837SBram Moolenaarsyn keyword dtraceFunction   copyinto dirname msgdsize msgsize mutex_owned
116446cb837SBram Moolenaarsyn keyword dtraceFunction   mutex_owner mutex_type_adaptive progenyof
117446cb837SBram Moolenaarsyn keyword dtraceFunction   rand rw_iswriter rw_write_held speculation
118446cb837SBram Moolenaarsyn keyword dtraceFunction   strjoin strlen
119446cb837SBram Moolenaar
120446cb837SBram Moolenaar" Aggregating Functions
121446cb837SBram Moolenaarsyn keyword dtraceAggregatingFunction count sum avg min max lquantize quantize
122446cb837SBram Moolenaar
123446cb837SBram Moolenaarsyn keyword dtraceType int8_t int16_t int32_t int64_t intptr_t
124446cb837SBram Moolenaarsyn keyword dtraceType uint8_t uint16_t uint32_t uint64_t uintptr_t
125446cb837SBram Moolenaarsyn keyword dtraceType string
126446cb837SBram Moolenaarsyn keyword dtraceType pid_t id_t
127446cb837SBram Moolenaar
128446cb837SBram Moolenaar
129446cb837SBram Moolenaar" Define the default highlighting.
130446cb837SBram Moolenaar" We use `hi def link` directly, this requires 5.8.
131446cb837SBram Moolenaarhi def link dtraceReservedKeyword Error
132446cb837SBram Moolenaarhi def link dtracePredicate String
133446cb837SBram Moolenaarhi def link dtraceProbe dtraceStatement
134446cb837SBram Moolenaarhi def link dtraceStatement Statement
135446cb837SBram Moolenaarhi def link dtraceConstant Constant
136446cb837SBram Moolenaarhi def link dtraceIdentifier Identifier
137446cb837SBram Moolenaarhi def link dtraceAggregatingFunction dtraceFunction
138446cb837SBram Moolenaarhi def link dtraceFunction Function
139446cb837SBram Moolenaarhi def link dtraceType Type
140446cb837SBram Moolenaarhi def link dtraceOperator Operator
141446cb837SBram Moolenaarhi def link dtraceComment Comment
142446cb837SBram Moolenaarhi def link dtraceNumber Number
143446cb837SBram Moolenaarhi def link dtraceOption Identifier
144446cb837SBram Moolenaar
145446cb837SBram Moolenaarlet b:current_syntax = "dtrace"
146