dtrace.vim 6.3 KB

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