From ed891cf3ae12be8163eb283371d5696c6f7ff1ad Mon Sep 17 00:00:00 2001 From: Martin Cermak Date: Tue, 23 Jun 2015 08:36:46 +0200 Subject: [PATCH] PR18462: Allow library macro deprecation Parts of the tapset code can get deprecated using conditionals as described in the HACKING file. This patch extends this to library macros, which can now get deprecated too. Patch includes example macro deprecation and a testcase. * NEWS: Mention '__int32_compat' library macro deprecation. * parse.cxx: Allow library macro deprecation. * tapset/linux/syscalls.stpm: Deprecate '__int32_compat' macro. * testsuite/parseok/macros09.stp: New testcase. --- NEWS | 5 ++ parse.cxx | 13 ++-- tapset/linux/syscalls.stpm | 2 + testsuite/parseok/macros09.stp | 127 +++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 6 deletions(-) create mode 100755 testsuite/parseok/macros09.stp diff --git a/NEWS b/NEWS index 73a8fae57..a8aa277db 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ * What's new in version 2.9 +- The following tapset variables and functions are deprecated in + version 2.9: + - The '__int32_compat' library macro got deprecated in favor of + new '__compat_long' library macro. + * What's new in version 2.8, 2015-06-17 - SystemTap has improved support for probing golang programs. Work has been diff --git a/parse.cxx b/parse.cxx index 6ce56ff48..3b49288c9 100644 --- a/parse.cxx +++ b/parse.cxx @@ -120,7 +120,7 @@ private: map pp1_namespace; vector pp1_state; const token* next_pp1 (); - const token* scan_pp1 (); + const token* scan_pp1 (bool ignore_macros); const token* slurp_pp1_param (vector& param); const token* slurp_pp1_body (vector& body); @@ -425,7 +425,7 @@ parser::next_pp1 () } const token* -parser::scan_pp1 () +parser::scan_pp1 (bool ignore_macros = false) { while (true) { @@ -442,7 +442,8 @@ parser::scan_pp1 () } // macro definition - if (t->type == tok_operator && t->content == "@define") + // PR18462 don't catalog preprocessor-disabled macros + if (t->type == tok_operator && t->content == "@define" && !ignore_macros) { if (!pp1_state.empty()) throw PARSE_ERROR (_("'@define' forbidden inside macro body"), t); @@ -718,7 +719,7 @@ parser::parse_library_macros () try { - const token* t = scan_pp1 (); + const token* t = scan_pp (); // Currently we only take objection to macro invocations if they // produce a non-whitespace token after being expanded. @@ -726,7 +727,7 @@ parser::parse_library_macros () // XXX should we prevent macro invocations even if they expand to empty?? if (t != 0) - throw PARSE_ERROR (_F("library macro file '%s' contains non-@define construct", input_name.c_str()), t); + throw PARSE_ERROR (_F("unexpected token in library macro file '%s'", input_name.c_str()), t); // We need to first check whether *any* of the macros are duplicates, // then commit to including the entire file in the global namespace @@ -1149,7 +1150,7 @@ parser::skip_pp () { try { - t = scan_pp1 (); + t = scan_pp1 (true); } catch (const parse_error &e) { diff --git a/tapset/linux/syscalls.stpm b/tapset/linux/syscalls.stpm index 3b4accc72..422e33a83 100644 --- a/tapset/linux/syscalls.stpm +++ b/tapset/linux/syscalls.stpm @@ -157,6 +157,7 @@ } %) +%( systemtap_v <= "2.9" %? @define __int32_compat(arg) %( %( CONFIG_64BIT == "y" %? @@ -165,6 +166,7 @@ (__int32(@arg)) %) %) +%) @define __keyctl_argstr(option, arg2, arg3, arg4, arg5) %( diff --git a/testsuite/parseok/macros09.stp b/testsuite/parseok/macros09.stp new file mode 100755 index 000000000..b25d38f77 --- /dev/null +++ b/testsuite/parseok/macros09.stp @@ -0,0 +1,127 @@ +#! /bin/sh + +# Test macro deprecation PR18462. + +# Testcase wrapper (parseok.exp) checks for exitcode, so we need to terminate right after an error occurs. +set -e + +# let's play in temporary directory writable by any user potentially involved +MYTMPD=$( mktemp -d ) +MYSTPM=$MYTMPD/PR18462.stpm + +export SYSTEMTAP_TAPSET=$MYTMPD + +# basic tests +# ______________________________________________________________________________ + +cat > $MYSTPM < $MYSTPM < $MYSTPM < $MYSTPM < $MYSTPM < $MYSTPM < $MYSTPM <