Skip to content

Commit 74fc45a

Browse files
committed
SystemTap: run CPreProcessor parser as a guest on %{...%} areas
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent ae17644 commit 74fc45a

File tree

6 files changed

+161
-14
lines changed

6 files changed

+161
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
--sort=no
22
--fields=+ner
33
--extras=+r
4+
--extras=+g

Units/parser-systemtap.r/probes.d/expected.tags

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,34 @@ tcp.ipv6.setsockopt.return input.stp /^probe tcp.ipv6.setsockopt.return = kernel
3939
tcp.receive input.stp /^probe tcp.receive = tcp.ipv4.receive, tcp.ipv6.receive$/;" p line:667 roles:def end:669
4040
tcp.ipv4.receive input.stp /^probe tcp.ipv4.receive = kernel.function("tcp_v4_rcv")$/;" p line:671 roles:def end:694
4141
tcp.ipv6.receive input.stp /^probe tcp.ipv6.receive = kernel.function("tcp_v6_rcv")!,$/;" p line:696 roles:def end:730
42+
linux/version.h input.stp /^#include <linux\/version.h>/;" h line:22 roles:system
43+
net/sock.h input.stp /^#include <net\/sock.h>/;" h line:23 roles:system
44+
net/tcp.h input.stp /^#include <net\/tcp.h>/;" h line:24 roles:system
45+
net/ip.h input.stp /^#include <net\/ip.h>/;" h line:25 roles:system
46+
linux/skbuff.h input.stp /^#include <linux\/skbuff.h>/;" h line:26 roles:system
47+
TCP_CONGESTION input.stp /^#define TCP_CONGESTION /;" d line:229 file: roles:def end:229
48+
TCP_MD5SIG input.stp /^#define TCP_MD5SIG /;" d line:232 file: roles:def end:232
49+
TCP_COOKIE_TRANSACTIONS input.stp /^#define TCP_COOKIE_TRANSACTIONS /;" d line:235 file: roles:def end:235
50+
TCP_THIN_LINEAR_TIMEOUTS input.stp /^#define TCP_THIN_LINEAR_TIMEOUTS /;" d line:238 file: roles:def end:238
51+
TCP_THIN_DUPACK input.stp /^#define TCP_THIN_DUPACK /;" d line:241 file: roles:def end:241
52+
TCP_USER_TIMEOUT input.stp /^#define TCP_USER_TIMEOUT /;" d line:244 file: roles:def end:244
53+
linux/in6.h input.stp /^#include <linux\/in6.h>/;" h line:289 roles:system
54+
IPV6_2292PKTINFO input.stp /^#define IPV6_2292PKTINFO /;" d line:291 file: roles:def end:291
55+
IPV6_2292HOPOPTS input.stp /^#define IPV6_2292HOPOPTS /;" d line:294 file: roles:def end:294
56+
IPV6_2292DSTOPTS input.stp /^#define IPV6_2292DSTOPTS /;" d line:297 file: roles:def end:297
57+
IPV6_2292RTHDR input.stp /^#define IPV6_2292RTHDR /;" d line:300 file: roles:def end:300
58+
IPV6_2292PKTOPTIONS input.stp /^#define IPV6_2292PKTOPTIONS /;" d line:303 file: roles:def end:303
59+
IPV6_2292HOPLIMIT input.stp /^#define IPV6_2292HOPLIMIT /;" d line:306 file: roles:def end:306
60+
IPV6_RECVPKTINFO input.stp /^#define IPV6_RECVPKTINFO /;" d line:309 file: roles:def end:309
61+
IPV6_RECVHOPLIMIT input.stp /^#define IPV6_RECVHOPLIMIT /;" d line:312 file: roles:def end:312
62+
IPV6_RECVHOPOPTS input.stp /^#define IPV6_RECVHOPOPTS /;" d line:315 file: roles:def end:315
63+
IPV6_RTHDRDSTOPTS input.stp /^#define IPV6_RTHDRDSTOPTS /;" d line:318 file: roles:def end:318
64+
IPV6_RECVRTHDR input.stp /^#define IPV6_RECVRTHDR /;" d line:321 file: roles:def end:321
65+
IPV6_RECVDSTOPTS input.stp /^#define IPV6_RECVDSTOPTS /;" d line:324 file: roles:def end:324
66+
IPV6_RECVPATHMTU input.stp /^#define IPV6_RECVPATHMTU /;" d line:327 file: roles:def end:327
67+
IPV6_PATHMTU input.stp /^#define IPV6_PATHMTU /;" d line:330 file: roles:def end:330
68+
IPV6_DONTFRAG input.stp /^#define IPV6_DONTFRAG /;" d line:333 file: roles:def end:333
69+
IPV6_ADDR_PREFERENCES input.stp /^#define IPV6_ADDR_PREFERENCES /;" d line:336 file: roles:def end:336
70+
IPV6_MINHOPCOUNT input.stp /^#define IPV6_MINHOPCOUNT /;" d line:339 file: roles:def end:339
71+
IPV6_RECVORIGDSTADDR input.stp /^#define IPV6_RECVORIGDSTADDR /;" d line:342 file: roles:def end:342
72+
IPV6_TRANSPARENT input.stp /^#define IPV6_TRANSPARENT /;" d line:345 file: roles:def end:345

docs/man/ctags-lang-systemtap.7.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ DESCRIPTION
2020
-----------
2121
This man page gathers random notes about tagging SystemTap scripts.
2222

23+
Guests
24+
~~~~~~~~~~~
25+
The SystemTap parser runs CPreProcessor as a guest parser on the areas
26+
surrounded by `%{` and `%}`.
27+
28+
"input.stp"
29+
30+
.. code-block:: SystemTap
31+
32+
%{
33+
#define X 1
34+
%}
35+
36+
"output.tags"
37+
with "--options=NONE -o - --sort=no --extras=+{guest} input.stp"
38+
39+
.. code-block:: tags
40+
41+
X input.stp /^#define X /;" d file:
42+
2343
VERSIONS
2444
--------
2545

man/ctags-lang-systemtap.7.rst.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ DESCRIPTION
2020
-----------
2121
This man page gathers random notes about tagging SystemTap scripts.
2222

23+
Guests
24+
~~~~~~~~~~~
25+
The SystemTap parser runs CPreProcessor as a guest parser on the areas
26+
surrounded by `%{` and `%}`.
27+
28+
"input.stp"
29+
30+
.. code-block:: SystemTap
31+
32+
%{
33+
#define X 1
34+
%}
35+
36+
"output.tags"
37+
with "--options=NONE -o - --sort=no --extras=+{guest} input.stp"
38+
39+
.. code-block:: tags
40+
41+
X input.stp /^#define X /;" d file:
42+
2343
VERSIONS
2444
--------
2545

optlib/systemtap.c

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,17 @@ static void initializeSystemTapParser (const langType language)
6161
"^global[[:space:]]+",
6262
"", "", "{tenter=vars}", NULL);
6363
addLanguageTagMultiTableRegex (language, "main",
64-
"^%[\\{(]",
65-
"", "", "{tenter=cfuncStmt}", NULL);
64+
"^(%\\{)",
65+
"", "", "{tenter=cfuncStmt}"
66+
"{{\n"
67+
" 1@ true\n"
68+
"}}", NULL);
69+
addLanguageTagMultiTableRegex (language, "main",
70+
"^%\\(",
71+
"", "", "{tenter=cfuncStmt}"
72+
"{{\n"
73+
" false\n"
74+
"}}", NULL);
6675
addLanguageTagMultiTableRegex (language, "main",
6776
"^.",
6877
"", "", "", NULL);
@@ -199,8 +208,17 @@ static void initializeSystemTapParser (const langType language)
199208
"^\\{",
200209
"", "", "{tenter=funcStmt,stmtend}", NULL);
201210
addLanguageTagMultiTableRegex (language, "funcBody",
202-
"^%[\\{(]",
203-
"", "", "{tenter=cfuncStmt,stmtend}", NULL);
211+
"^(%\\{)",
212+
"", "", "{tenter=cfuncStmt,stmtend}"
213+
"{{\n"
214+
" 1@ true\n"
215+
"}}", NULL);
216+
addLanguageTagMultiTableRegex (language, "funcBody",
217+
"^%\\(",
218+
"", "", "{tenter=cfuncStmt,stmtend}"
219+
"{{\n"
220+
" false\n"
221+
"}}", NULL);
204222
addLanguageTagMultiTableRegex (language, "funcBody",
205223
"^\\#",
206224
"", "", "{tenter=comment_oneline}", NULL);
@@ -235,8 +253,17 @@ static void initializeSystemTapParser (const langType language)
235253
"^//",
236254
"", "", "{tenter=comment_oneline}", NULL);
237255
addLanguageTagMultiTableRegex (language, "funcStmt",
238-
"^%[\\{(]",
239-
"", "", "{tenter=cfuncStmt}", NULL);
256+
"^(%\\{)",
257+
"", "", "{tenter=cfuncStmt}"
258+
"{{\n"
259+
" 1@ true\n"
260+
"}}", NULL);
261+
addLanguageTagMultiTableRegex (language, "funcStmt",
262+
"^%\\(",
263+
"", "", "{tenter=cfuncStmt}"
264+
"{{\n"
265+
" false\n"
266+
"}}", NULL);
240267
addLanguageTagMultiTableRegex (language, "funcStmt",
241268
"^\\{",
242269
"", "", "{tenter=funcStmt}", NULL);
@@ -262,11 +289,31 @@ static void initializeSystemTapParser (const langType language)
262289
"^'",
263290
"", "", "{tenter=ssliteral}", NULL);
264291
addLanguageTagMultiTableRegex (language, "cfuncStmt",
265-
"^%[\\})]",
292+
"^%\\)",
266293
"", "", "{tleave}", NULL);
267294
addLanguageTagMultiTableRegex (language, "cfuncStmt",
268-
"^%[\\{(]",
269-
"", "", "{tenter=cfuncStmt}", NULL);
295+
"^(%\\})",
296+
"", "", "{tleave}"
297+
"{{\n"
298+
" {\n"
299+
" % TODO: If the function name of SystemTap side can be passed to\n"
300+
" % the C code area, running C parser is meaningfully.\n"
301+
" % However, we have not implemented such a feature yet.\n"
302+
" (CPreProcessor) exch @1 _makepromise { pop } if\n"
303+
" } if\n"
304+
"}}", NULL);
305+
addLanguageTagMultiTableRegex (language, "cfuncStmt",
306+
"^(%\\{)",
307+
"", "", "{tenter=cfuncStmt}"
308+
"{{\n"
309+
" 1@ true\n"
310+
"}}", NULL);
311+
addLanguageTagMultiTableRegex (language, "cfuncStmt",
312+
"^%\\(",
313+
"", "", "{tenter=cfuncStmt}"
314+
"{{\n"
315+
" false\n"
316+
"}}", NULL);
270317
addLanguageTagMultiTableRegex (language, "cfuncStmt",
271318
"^.",
272319
"", "", "", NULL);

optlib/systemtap.ctags

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@
108108
--_mtable-regex-SystemTap=main/@define[[:space:]]+//{tenter=macro}
109109
--_mtable-regex-SystemTap=main/function[[:space:]]+//{tenter=func}
110110
--_mtable-regex-SystemTap=main/global[[:space:]]+//{tenter=vars}
111-
--_mtable-regex-SystemTap=main/%[\{(]//{tenter=cfuncStmt}
111+
--_mtable-regex-SystemTap=main/(%\{)//{tenter=cfuncStmt}{{
112+
1@ true
113+
}}
114+
--_mtable-regex-SystemTap=main/%\(//{tenter=cfuncStmt}{{
115+
false
116+
}}
112117
--_mtable-extend-SystemTap=main+any
113118

114119
#
@@ -153,7 +158,12 @@
153158

154159
--_mtable-regex-SystemTap=funcBody/[^\{%'"#]+//
155160
--_mtable-regex-SystemTap=funcBody/\{//{tenter=funcStmt,stmtend}
156-
--_mtable-regex-SystemTap=funcBody/%[\{(]//{tenter=cfuncStmt,stmtend}
161+
--_mtable-regex-SystemTap=funcBody/(%\{)//{tenter=cfuncStmt,stmtend}{{
162+
1@ true
163+
}}
164+
--_mtable-regex-SystemTap=funcBody/%\(//{tenter=cfuncStmt,stmtend}{{
165+
false
166+
}}
157167
--_mtable-extend-SystemTap=funcBody+comment
158168
--_mtable-extend-SystemTap=funcBody+any
159169

@@ -164,15 +174,33 @@
164174
--_mtable-regex-SystemTap=funcStmt/\}//{tleave}
165175
--_mtable-extend-SystemTap=funcStmt+skipLiteral
166176
--_mtable-extend-SystemTap=funcStmt+comment
167-
--_mtable-regex-SystemTap=funcStmt/%[\{(]//{tenter=cfuncStmt}
177+
--_mtable-regex-SystemTap=funcStmt/(%\{)//{tenter=cfuncStmt}{{
178+
1@ true
179+
}}
180+
--_mtable-regex-SystemTap=funcStmt/%\(//{tenter=cfuncStmt}{{
181+
false
182+
}}
168183
--_mtable-regex-SystemTap=funcStmt/\{//{tenter=funcStmt}
169184
--_mtable-extend-SystemTap=funcStmt+any
170185

171186
--_mtable-regex-SystemTap=cfuncStmt/[^%\/#'"]+//
172187
--_mtable-extend-SystemTap=cfuncStmt+comment
173188
--_mtable-extend-SystemTap=cfuncStmt+skipLiteral
174-
--_mtable-regex-SystemTap=cfuncStmt/%[\})]//{tleave}
175-
--_mtable-regex-SystemTap=cfuncStmt/%[\{(]//{tenter=cfuncStmt}
189+
--_mtable-regex-SystemTap=cfuncStmt/%\)//{tleave}
190+
--_mtable-regex-SystemTap=cfuncStmt/(%\})//{tleave}{{
191+
{
192+
% TODO: If the function name of SystemTap side can be passed to
193+
% the C code area, running C parser is meaningfully.
194+
% However, we have not implemented such a feature yet.
195+
(CPreProcessor) exch @1 _makepromise { pop } if
196+
} if
197+
}}
198+
--_mtable-regex-SystemTap=cfuncStmt/(%\{)//{tenter=cfuncStmt}{{
199+
1@ true
200+
}}
201+
--_mtable-regex-SystemTap=cfuncStmt/%\(//{tenter=cfuncStmt}{{
202+
false
203+
}}
176204
--_mtable-extend-SystemTap=cfuncStmt+any
177205

178206
#

0 commit comments

Comments
 (0)