Skip to content

Commit

Permalink
SystemTap: run CPreProcessor parser as a guest on %{...%} areas
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 23, 2022
1 parent cec8bae commit 1005128
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 14 deletions.
1 change: 1 addition & 0 deletions Units/parser-systemtap.r/probes.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--sort=no
--fields=+ner
--extras=+r
--extras=+g
31 changes: 31 additions & 0 deletions Units/parser-systemtap.r/probes.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,34 @@ tcp.ipv6.setsockopt.return input.stp /^probe tcp.ipv6.setsockopt.return = kernel
tcp.receive input.stp /^probe tcp.receive = tcp.ipv4.receive, tcp.ipv6.receive$/;" p line:667 roles:def end:669
tcp.ipv4.receive input.stp /^probe tcp.ipv4.receive = kernel.function("tcp_v4_rcv")$/;" p line:671 roles:def end:694
tcp.ipv6.receive input.stp /^probe tcp.ipv6.receive = kernel.function("tcp_v6_rcv")!,$/;" p line:696 roles:def end:730
linux/version.h input.stp /^#include <linux\/version.h>/;" h line:22 roles:system
net/sock.h input.stp /^#include <net\/sock.h>/;" h line:23 roles:system
net/tcp.h input.stp /^#include <net\/tcp.h>/;" h line:24 roles:system
net/ip.h input.stp /^#include <net\/ip.h>/;" h line:25 roles:system
linux/skbuff.h input.stp /^#include <linux\/skbuff.h>/;" h line:26 roles:system
TCP_CONGESTION input.stp /^#define TCP_CONGESTION /;" d line:229 file: roles:def end:229
TCP_MD5SIG input.stp /^#define TCP_MD5SIG /;" d line:232 file: roles:def end:232
TCP_COOKIE_TRANSACTIONS input.stp /^#define TCP_COOKIE_TRANSACTIONS /;" d line:235 file: roles:def end:235
TCP_THIN_LINEAR_TIMEOUTS input.stp /^#define TCP_THIN_LINEAR_TIMEOUTS /;" d line:238 file: roles:def end:238
TCP_THIN_DUPACK input.stp /^#define TCP_THIN_DUPACK /;" d line:241 file: roles:def end:241
TCP_USER_TIMEOUT input.stp /^#define TCP_USER_TIMEOUT /;" d line:244 file: roles:def end:244
linux/in6.h input.stp /^#include <linux\/in6.h>/;" h line:289 roles:system
IPV6_2292PKTINFO input.stp /^#define IPV6_2292PKTINFO /;" d line:291 file: roles:def end:291
IPV6_2292HOPOPTS input.stp /^#define IPV6_2292HOPOPTS /;" d line:294 file: roles:def end:294
IPV6_2292DSTOPTS input.stp /^#define IPV6_2292DSTOPTS /;" d line:297 file: roles:def end:297
IPV6_2292RTHDR input.stp /^#define IPV6_2292RTHDR /;" d line:300 file: roles:def end:300
IPV6_2292PKTOPTIONS input.stp /^#define IPV6_2292PKTOPTIONS /;" d line:303 file: roles:def end:303
IPV6_2292HOPLIMIT input.stp /^#define IPV6_2292HOPLIMIT /;" d line:306 file: roles:def end:306
IPV6_RECVPKTINFO input.stp /^#define IPV6_RECVPKTINFO /;" d line:309 file: roles:def end:309
IPV6_RECVHOPLIMIT input.stp /^#define IPV6_RECVHOPLIMIT /;" d line:312 file: roles:def end:312
IPV6_RECVHOPOPTS input.stp /^#define IPV6_RECVHOPOPTS /;" d line:315 file: roles:def end:315
IPV6_RTHDRDSTOPTS input.stp /^#define IPV6_RTHDRDSTOPTS /;" d line:318 file: roles:def end:318
IPV6_RECVRTHDR input.stp /^#define IPV6_RECVRTHDR /;" d line:321 file: roles:def end:321
IPV6_RECVDSTOPTS input.stp /^#define IPV6_RECVDSTOPTS /;" d line:324 file: roles:def end:324
IPV6_RECVPATHMTU input.stp /^#define IPV6_RECVPATHMTU /;" d line:327 file: roles:def end:327
IPV6_PATHMTU input.stp /^#define IPV6_PATHMTU /;" d line:330 file: roles:def end:330
IPV6_DONTFRAG input.stp /^#define IPV6_DONTFRAG /;" d line:333 file: roles:def end:333
IPV6_ADDR_PREFERENCES input.stp /^#define IPV6_ADDR_PREFERENCES /;" d line:336 file: roles:def end:336
IPV6_MINHOPCOUNT input.stp /^#define IPV6_MINHOPCOUNT /;" d line:339 file: roles:def end:339
IPV6_RECVORIGDSTADDR input.stp /^#define IPV6_RECVORIGDSTADDR /;" d line:342 file: roles:def end:342
IPV6_TRANSPARENT input.stp /^#define IPV6_TRANSPARENT /;" d line:345 file: roles:def end:345
20 changes: 20 additions & 0 deletions docs/man/ctags-lang-systemtap.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ DESCRIPTION
-----------
This man page gathers random notes about tagging SystemTap scripts.

Guests
~~~~~~~~~~~
The SystemTap parser runs CPreProcessor as a guest parser on the areas
surrounded by `%{` and `%}`.

"input.stp"

.. code-block:: SystemTap
%{
#define X 1
%}
"output.tags"
with "--options=NONE -o - --sort=no --extras=+{guest} input.stp"

.. code-block:: tags
X input.stp /^#define X /;" d file:
VERSIONS
--------

Expand Down
20 changes: 20 additions & 0 deletions man/ctags-lang-systemtap.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ DESCRIPTION
-----------
This man page gathers random notes about tagging SystemTap scripts.

Guests
~~~~~~~~~~~
The SystemTap parser runs CPreProcessor as a guest parser on the areas
surrounded by `%{` and `%}`.

"input.stp"

.. code-block:: SystemTap

%{
#define X 1
%}

"output.tags"
with "--options=NONE -o - --sort=no --extras=+{guest} input.stp"

.. code-block:: tags

X input.stp /^#define X /;" d file:

VERSIONS
--------

Expand Down
65 changes: 56 additions & 9 deletions optlib/systemtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ static void initializeSystemTapParser (const langType language)
"^global[[:space:]]+",
"", "", "{tenter=vars}", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^%[\\{(]",
"", "", "{tenter=cfuncStmt}", NULL);
"^(%\\{)",
"", "", "{tenter=cfuncStmt}"
"{{\n"
" 1@ true\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^%\\(",
"", "", "{tenter=cfuncStmt}"
"{{\n"
" false\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^.",
"", "", "", NULL);
Expand Down Expand Up @@ -199,8 +208,17 @@ static void initializeSystemTapParser (const langType language)
"^\\{",
"", "", "{tenter=funcStmt,stmtend}", NULL);
addLanguageTagMultiTableRegex (language, "funcBody",
"^%[\\{(]",
"", "", "{tenter=cfuncStmt,stmtend}", NULL);
"^(%\\{)",
"", "", "{tenter=cfuncStmt,stmtend}"
"{{\n"
" 1@ true\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "funcBody",
"^%\\(",
"", "", "{tenter=cfuncStmt,stmtend}"
"{{\n"
" false\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "funcBody",
"^\\#",
"", "", "{tenter=comment_oneline}", NULL);
Expand Down Expand Up @@ -235,8 +253,17 @@ static void initializeSystemTapParser (const langType language)
"^//",
"", "", "{tenter=comment_oneline}", NULL);
addLanguageTagMultiTableRegex (language, "funcStmt",
"^%[\\{(]",
"", "", "{tenter=cfuncStmt}", NULL);
"^(%\\{)",
"", "", "{tenter=cfuncStmt}"
"{{\n"
" 1@ true\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "funcStmt",
"^%\\(",
"", "", "{tenter=cfuncStmt}"
"{{\n"
" false\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "funcStmt",
"^\\{",
"", "", "{tenter=funcStmt}", NULL);
Expand All @@ -262,11 +289,31 @@ static void initializeSystemTapParser (const langType language)
"^'",
"", "", "{tenter=ssliteral}", NULL);
addLanguageTagMultiTableRegex (language, "cfuncStmt",
"^%[\\})]",
"^%\\)",
"", "", "{tleave}", NULL);
addLanguageTagMultiTableRegex (language, "cfuncStmt",
"^%[\\{(]",
"", "", "{tenter=cfuncStmt}", NULL);
"^(%\\})",
"", "", "{tleave}"
"{{\n"
" {\n"
" % TODO: If the function name of SystemTap side can be passed to\n"
" % the C code area, running C parser is meaningfully.\n"
" % However, we have not implemented such a feature yet.\n"
" (CPreProcessor) exch @1 _makepromise { pop } if\n"
" } if\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "cfuncStmt",
"^(%\\{)",
"", "", "{tenter=cfuncStmt}"
"{{\n"
" 1@ true\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "cfuncStmt",
"^%\\(",
"", "", "{tenter=cfuncStmt}"
"{{\n"
" false\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "cfuncStmt",
"^.",
"", "", "", NULL);
Expand Down
38 changes: 33 additions & 5 deletions optlib/systemtap.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@
--_mtable-regex-SystemTap=main/@define[[:space:]]+//{tenter=macro}
--_mtable-regex-SystemTap=main/function[[:space:]]+//{tenter=func}
--_mtable-regex-SystemTap=main/global[[:space:]]+//{tenter=vars}
--_mtable-regex-SystemTap=main/%[\{(]//{tenter=cfuncStmt}
--_mtable-regex-SystemTap=main/(%\{)//{tenter=cfuncStmt}{{
1@ true
}}
--_mtable-regex-SystemTap=main/%\(//{tenter=cfuncStmt}{{
false
}}
--_mtable-extend-SystemTap=main+any

#
Expand Down Expand Up @@ -153,7 +158,12 @@

--_mtable-regex-SystemTap=funcBody/[^\{%'"#]+//
--_mtable-regex-SystemTap=funcBody/\{//{tenter=funcStmt,stmtend}
--_mtable-regex-SystemTap=funcBody/%[\{(]//{tenter=cfuncStmt,stmtend}
--_mtable-regex-SystemTap=funcBody/(%\{)//{tenter=cfuncStmt,stmtend}{{
1@ true
}}
--_mtable-regex-SystemTap=funcBody/%\(//{tenter=cfuncStmt,stmtend}{{
false
}}
--_mtable-extend-SystemTap=funcBody+comment
--_mtable-extend-SystemTap=funcBody+any

Expand All @@ -164,15 +174,33 @@
--_mtable-regex-SystemTap=funcStmt/\}//{tleave}
--_mtable-extend-SystemTap=funcStmt+skipLiteral
--_mtable-extend-SystemTap=funcStmt+comment
--_mtable-regex-SystemTap=funcStmt/%[\{(]//{tenter=cfuncStmt}
--_mtable-regex-SystemTap=funcStmt/(%\{)//{tenter=cfuncStmt}{{
1@ true
}}
--_mtable-regex-SystemTap=funcStmt/%\(//{tenter=cfuncStmt}{{
false
}}
--_mtable-regex-SystemTap=funcStmt/\{//{tenter=funcStmt}
--_mtable-extend-SystemTap=funcStmt+any

--_mtable-regex-SystemTap=cfuncStmt/[^%\/#'"]+//
--_mtable-extend-SystemTap=cfuncStmt+comment
--_mtable-extend-SystemTap=cfuncStmt+skipLiteral
--_mtable-regex-SystemTap=cfuncStmt/%[\})]//{tleave}
--_mtable-regex-SystemTap=cfuncStmt/%[\{(]//{tenter=cfuncStmt}
--_mtable-regex-SystemTap=cfuncStmt/%\)//{tleave}
--_mtable-regex-SystemTap=cfuncStmt/(%\})//{tleave}{{
{
% TODO: If the function name of SystemTap side can be passed to
% the C code area, running C parser is meaningfully.
% However, we have not implemented such a feature yet.
(CPreProcessor) exch @1 _makepromise { pop } if
} if
}}
--_mtable-regex-SystemTap=cfuncStmt/(%\{)//{tenter=cfuncStmt}{{
1@ true
}}
--_mtable-regex-SystemTap=cfuncStmt/%\(//{tenter=cfuncStmt}{{
false
}}
--_mtable-extend-SystemTap=cfuncStmt+any

#
Expand Down

0 comments on commit 1005128

Please sign in to comment.