mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
--no-usage-warnings flag to suppress analysis
This commit is contained in:
parent
763b448aef
commit
d9479c0502
7 changed files with 29 additions and 7 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
// See the file "COPYING" in the main distribution directory for copyright.
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#include "zeek/ID.h"
|
#include "zeek/ID.h"
|
||||||
|
@ -18,6 +17,7 @@
|
||||||
#include "zeek/Val.h"
|
#include "zeek/Val.h"
|
||||||
#include "zeek/module_util.h"
|
#include "zeek/module_util.h"
|
||||||
#include "zeek/script_opt/IDOptInfo.h"
|
#include "zeek/script_opt/IDOptInfo.h"
|
||||||
|
#include "zeek/script_opt/UsageAnalyzer.h"
|
||||||
#include "zeek/zeekygen/IdentifierInfo.h"
|
#include "zeek/zeekygen/IdentifierInfo.h"
|
||||||
#include "zeek/zeekygen/Manager.h"
|
#include "zeek/zeekygen/Manager.h"
|
||||||
#include "zeek/zeekygen/ScriptInfo.h"
|
#include "zeek/zeekygen/ScriptInfo.h"
|
||||||
|
@ -167,6 +167,9 @@ void ID::SetVal(ValPtr v)
|
||||||
handler = new EventHandler(name);
|
handler = new EventHandler(name);
|
||||||
handler->SetFunc(func);
|
handler->SetFunc(func);
|
||||||
event_registry->Register(handler);
|
event_registry->Register(handler);
|
||||||
|
|
||||||
|
if ( ! IsExport() )
|
||||||
|
register_new_event({NewRef{}, this});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,6 +107,7 @@ void usage(const char* prog, int code)
|
||||||
fprintf(stderr, " -s|--rulefile <rulefile> | read rules from given file\n");
|
fprintf(stderr, " -s|--rulefile <rulefile> | read rules from given file\n");
|
||||||
fprintf(stderr, " -t|--tracefile <tracefile> | activate execution tracing\n");
|
fprintf(stderr, " -t|--tracefile <tracefile> | activate execution tracing\n");
|
||||||
fprintf(stderr, " -u|--usage-issues | find variable usage issues and exit\n");
|
fprintf(stderr, " -u|--usage-issues | find variable usage issues and exit\n");
|
||||||
|
fprintf(stderr, " --no-usage-warnings | suppress warnings of unused functions/hooks/events\n");
|
||||||
fprintf(stderr, " -v|--version | print version and exit\n");
|
fprintf(stderr, " -v|--version | print version and exit\n");
|
||||||
fprintf(stderr, " -w|--writefile <writefile> | write to given tcpdump file\n");
|
fprintf(stderr, " -w|--writefile <writefile> | write to given tcpdump file\n");
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -367,6 +368,7 @@ Options parse_cmdline(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
int profile_scripts = 0;
|
int profile_scripts = 0;
|
||||||
|
int no_usage_warnings = 0;
|
||||||
|
|
||||||
struct option long_opts[] = {
|
struct option long_opts[] = {
|
||||||
{"parse-only", no_argument, nullptr, 'a'},
|
{"parse-only", no_argument, nullptr, 'a'},
|
||||||
|
@ -410,6 +412,7 @@ Options parse_cmdline(int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{"profile-scripts", optional_argument, &profile_scripts, 1},
|
{"profile-scripts", optional_argument, &profile_scripts, 1},
|
||||||
|
{"no-usage-warnings", no_argument, &no_usage_warnings, 1},
|
||||||
{"pseudo-realtime", optional_argument, nullptr, '~'},
|
{"pseudo-realtime", optional_argument, nullptr, '~'},
|
||||||
{"jobs", optional_argument, nullptr, 'j'},
|
{"jobs", optional_argument, nullptr, 'j'},
|
||||||
{"test", no_argument, nullptr, '#'},
|
{"test", no_argument, nullptr, '#'},
|
||||||
|
@ -613,6 +616,9 @@ Options parse_cmdline(int argc, char** argv)
|
||||||
activate_script_profiling(optarg);
|
activate_script_profiling(optarg);
|
||||||
profile_scripts = 0;
|
profile_scripts = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( no_usage_warnings )
|
||||||
|
rval.no_usage_warnings = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
|
|
|
@ -58,6 +58,7 @@ struct Options
|
||||||
bool perftools_profile = false;
|
bool perftools_profile = false;
|
||||||
bool deterministic_mode = false;
|
bool deterministic_mode = false;
|
||||||
bool abort_on_scripting_errors = false;
|
bool abort_on_scripting_errors = false;
|
||||||
|
bool no_usage_warnings = false;
|
||||||
|
|
||||||
bool run_unit_tests = false;
|
bool run_unit_tests = false;
|
||||||
std::vector<std::string> doctest_args;
|
std::vector<std::string> doctest_args;
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "zeek/Traverse.h"
|
#include "zeek/Traverse.h"
|
||||||
#include "zeek/Val.h"
|
#include "zeek/Val.h"
|
||||||
#include "zeek/module_util.h"
|
#include "zeek/module_util.h"
|
||||||
#include "zeek/script_opt/ScriptOpt.h"
|
|
||||||
#include "zeek/script_opt/StmtOptInfo.h"
|
#include "zeek/script_opt/StmtOptInfo.h"
|
||||||
|
#include "zeek/script_opt/UsageAnalyzer.h"
|
||||||
|
|
||||||
namespace zeek::detail
|
namespace zeek::detail
|
||||||
{
|
{
|
||||||
|
@ -658,6 +658,9 @@ void begin_func(IDPtr id, const char* module_name, FunctionFlavor flavor, bool i
|
||||||
id->Error("event cannot yield a value", t.get());
|
id->Error("event cannot yield a value", t.get());
|
||||||
|
|
||||||
t->ClearYieldType(flavor);
|
t->ClearYieldType(flavor);
|
||||||
|
|
||||||
|
if ( ! event_registry->Lookup(id->Name()) )
|
||||||
|
register_new_event(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<FuncType::Prototype> prototype;
|
std::optional<FuncType::Prototype> prototype;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "zeek/script_opt/Inline.h"
|
#include "zeek/script_opt/Inline.h"
|
||||||
#include "zeek/script_opt/ProfileFunc.h"
|
#include "zeek/script_opt/ProfileFunc.h"
|
||||||
#include "zeek/script_opt/Reduce.h"
|
#include "zeek/script_opt/Reduce.h"
|
||||||
|
#include "zeek/script_opt/UsageAnalyzer.h"
|
||||||
#include "zeek/script_opt/UseDefs.h"
|
#include "zeek/script_opt/UseDefs.h"
|
||||||
#include "zeek/script_opt/ZAM/Compile.h"
|
#include "zeek/script_opt/ZAM/Compile.h"
|
||||||
|
|
||||||
|
@ -519,7 +520,7 @@ static void analyze_scripts_for_ZAM(std::unique_ptr<ProfileFuncs>& pfs)
|
||||||
finalize_functions(funcs);
|
finalize_functions(funcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void analyze_scripts()
|
void analyze_scripts(bool no_usage_warnings)
|
||||||
{
|
{
|
||||||
static bool did_init = false;
|
static bool did_init = false;
|
||||||
|
|
||||||
|
@ -529,6 +530,10 @@ void analyze_scripts()
|
||||||
did_init = true;
|
did_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<UsageAnalyzer> ua;
|
||||||
|
if ( ! no_usage_warnings )
|
||||||
|
ua = std::make_unique<UsageAnalyzer>(funcs);
|
||||||
|
|
||||||
auto& ofuncs = analysis_options.only_funcs;
|
auto& ofuncs = analysis_options.only_funcs;
|
||||||
auto& ofiles = analysis_options.only_files;
|
auto& ofiles = analysis_options.only_files;
|
||||||
|
|
||||||
|
|
|
@ -182,8 +182,9 @@ extern void add_file_analysis_pattern(AnalyOpt& opts, const char* pat);
|
||||||
// it should be skipped.
|
// it should be skipped.
|
||||||
extern bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body);
|
extern bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body);
|
||||||
|
|
||||||
// Analyze all of the parsed scripts collectively for optimization.
|
// Analyze all of the parsed scripts collectively for usage issues (unless
|
||||||
extern void analyze_scripts();
|
// suppressed by the flag) and optimization.
|
||||||
|
extern void analyze_scripts(bool no_usage_warnings);
|
||||||
|
|
||||||
// Called when Zeek is terminating.
|
// Called when Zeek is terminating.
|
||||||
extern void finish_script_execution();
|
extern void finish_script_execution();
|
||||||
|
|
|
@ -589,6 +589,9 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
plugin_mgr = new plugin::Manager();
|
plugin_mgr = new plugin::Manager();
|
||||||
fragment_mgr = new detail::FragmentManager();
|
fragment_mgr = new detail::FragmentManager();
|
||||||
|
|
||||||
|
if ( options.no_usage_warnings && options.analysis_options.usage_issues > 0 )
|
||||||
|
reporter->FatalError("-u incompatible with --no-usage-warnings");
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if ( options.debug_log_streams )
|
if ( options.debug_log_streams )
|
||||||
{
|
{
|
||||||
|
@ -926,7 +929,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
if ( options.parse_only )
|
if ( options.parse_only )
|
||||||
{
|
{
|
||||||
if ( analysis_options.usage_issues > 0 )
|
if ( analysis_options.usage_issues > 0 )
|
||||||
analyze_scripts();
|
analyze_scripts(options.no_usage_warnings);
|
||||||
|
|
||||||
early_shutdown();
|
early_shutdown();
|
||||||
exit(reporter->Errors() != 0);
|
exit(reporter->Errors() != 0);
|
||||||
|
@ -934,7 +937,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
|
|
||||||
auto init_stmts = stmts ? analyze_global_stmts(stmts) : nullptr;
|
auto init_stmts = stmts ? analyze_global_stmts(stmts) : nullptr;
|
||||||
|
|
||||||
analyze_scripts();
|
analyze_scripts(options.no_usage_warnings);
|
||||||
|
|
||||||
if ( analysis_options.report_recursive )
|
if ( analysis_options.report_recursive )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue