Remove EventRegistry::Used and EventRegistry::SetUsed

This commit is contained in:
Tim Wojtulewicz 2024-08-02 11:05:56 -07:00
parent 97fa7cdc0a
commit e2b03681d1
11 changed files with 6 additions and 111 deletions

View file

@ -5259,9 +5259,6 @@ const likely_server_ports: set[port] &redef;
## If true, output profiling for Time-Machine queries. ## If true, output profiling for Time-Machine queries.
const time_machine_profiling = F &redef &deprecated="Remove in v7.1. Unused."; const time_machine_profiling = F &redef &deprecated="Remove in v7.1. Unused.";
## If true, warns about unused event handlers at startup.
const check_for_unused_event_handlers = F &redef &deprecated="Remove in v7.1. This has been replaced by usage analyzer functionality.";
## Holds the filename of the trace file given with ``-w`` (empty if none). ## Holds the filename of the trace file given with ``-w`` (empty if none).
## ##
## .. zeek:see:: record_all_packets ## .. zeek:see:: record_all_packets

View file

@ -44,13 +44,6 @@ public:
// Returns true if there is at least one local or remote handler. // Returns true if there is at least one local or remote handler.
explicit operator bool() const; explicit operator bool() const;
[[deprecated("Remove in v7.1 - Unused event handlers are now found via UsageAnalyzer.")]] void SetUsed() {
used = true;
}
[[deprecated("Remove in v7.1 - Unused event handlers are now found via UsageAnalyzer.")]] bool Used() const {
return used;
}
// Handlers marked as error handlers will not be called recursively to // Handlers marked as error handlers will not be called recursively to
// avoid infinite loops if they trigger a similar error themselves. // avoid infinite loops if they trigger a similar error themselves.
void SetErrorHandler() { error_handler = true; } void SetErrorHandler() { error_handler = true; }

View file

@ -21,23 +21,12 @@ EventHandlerPtr EventRegistry::Register(std::string_view name, bool is_from_scri
if ( ! is_from_script ) if ( ! is_from_script )
not_only_from_script.insert(std::string(name)); not_only_from_script.insert(std::string(name));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
// Remove in v7.1
h->SetUsed();
#pragma GCC diagnostic pop
return h; return h;
} }
h = new EventHandler(std::string(name)); h = new EventHandler(std::string(name));
event_registry->Register(h, is_from_script); event_registry->Register(h, is_from_script);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
// Remove in v7.1
h->SetUsed();
#pragma GCC diagnostic pop
return h; return h;
} }
@ -74,36 +63,6 @@ EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern) {
return names; return names;
} }
EventRegistry::string_list EventRegistry::UnusedHandlers() {
string_list names;
for ( const auto& entry : handlers ) {
EventHandler* v = entry.second.get();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if ( v->GetFunc() && ! v->Used() )
names.push_back(entry.first);
#pragma GCC diagnostic pop
}
return names;
}
EventRegistry::string_list EventRegistry::UsedHandlers() {
string_list names;
for ( const auto& entry : handlers ) {
EventHandler* v = entry.second.get();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if ( v->GetFunc() && v->Used() )
names.push_back(entry.first);
#pragma GCC diagnostic pop
}
return names;
}
EventRegistry::string_list EventRegistry::AllHandlers() { EventRegistry::string_list EventRegistry::AllHandlers() {
string_list names; string_list names;

View file

@ -69,8 +69,6 @@ public:
// themselves. // themselves.
void SetErrorHandler(std::string_view name); void SetErrorHandler(std::string_view name);
[[deprecated("Remove in v7.1 - Unused handlers are now found via UsageAnalyzer.")]] string_list UnusedHandlers();
[[deprecated("Remove in v7.1 - UsedHandlers() is unreliable - use AllHandlers().")]] string_list UsedHandlers();
string_list AllHandlers(); string_list AllHandlers();
void PrintDebug(); void PrintDebug();

View file

@ -414,13 +414,6 @@ NameExpr::NameExpr(IDPtr arg_id, bool const_init) : Expr(EXPR_NAME), id(std::mov
SetType(make_intrusive<TypeType>(id->GetType())); SetType(make_intrusive<TypeType>(id->GetType()));
else else
SetType(id->GetType()); SetType(id->GetType());
EventHandler* h = event_registry->Lookup(id->Name());
if ( h )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
h->SetUsed();
#pragma GCC diagnostic pop
} }
bool NameExpr::CanDel() const { bool NameExpr::CanDel() const {
@ -4417,11 +4410,6 @@ EventExpr::EventExpr(const char* arg_name, ListExprPtr arg_args)
event_registry->Register(h, true); event_registry->Register(h, true);
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
h->SetUsed();
#pragma GCC diagnostic pop
handler = h; handler = h;
if ( args->IsError() ) { if ( args->IsError() ) {

View file

@ -182,8 +182,6 @@ int dpd_match_only_beginning;
int dpd_late_match_stop; int dpd_late_match_stop;
int dpd_ignore_ports; int dpd_ignore_ports;
int check_for_unused_event_handlers;
int record_all_packets; int record_all_packets;
zeek_uint_t bits_per_uid; zeek_uint_t bits_per_uid;
@ -229,7 +227,6 @@ void init_general_global_var() {
table_incremental_step = id::find_val("table_incremental_step")->AsCount(); table_incremental_step = id::find_val("table_incremental_step")->AsCount();
packet_filter_default = id::find_val("packet_filter_default")->AsBool(); packet_filter_default = id::find_val("packet_filter_default")->AsBool();
sig_max_group_size = id::find_val("sig_max_group_size")->AsCount(); sig_max_group_size = id::find_val("sig_max_group_size")->AsCount();
check_for_unused_event_handlers = id::find_val("check_for_unused_event_handlers")->AsBool();
record_all_packets = id::find_val("record_all_packets")->AsBool(); record_all_packets = id::find_val("record_all_packets")->AsBool();
bits_per_uid = id::find_val("bits_per_uid")->AsCount(); bits_per_uid = id::find_val("bits_per_uid")->AsCount();
} }

View file

@ -85,8 +85,6 @@ extern int dpd_match_only_beginning;
extern int dpd_late_match_stop; extern int dpd_late_match_stop;
extern int dpd_ignore_ports; extern int dpd_ignore_ports;
extern int check_for_unused_event_handlers;
extern int record_all_packets; extern int record_all_packets;
extern zeek_uint_t bits_per_uid; extern zeek_uint_t bits_per_uid;

View file

@ -131,13 +131,8 @@ void activate_bodies__CPP(const char* fn, const char* module, bool exported, Typ
events.insert(cs.events.begin(), cs.events.end()); events.insert(cs.events.begin(), cs.events.end());
} }
for ( const auto& e : events ) { for ( const auto& e : events )
auto eh = event_registry->Register(e); event_registry->Register(e);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
eh->SetUsed();
#pragma GCC diagnostic pop
}
} }
IDPtr lookup_global__CPP(const char* g, const TypePtr& t, bool exported) { IDPtr lookup_global__CPP(const char* g, const TypePtr& t, bool exported) {
@ -191,13 +186,8 @@ FuncValPtr lookup_func__CPP(string name, int num_bodies, vector<p_hash_type> has
// This might register the same event more than once, // This might register the same event more than once,
// if it's used in multiple bodies, but that's okay as // if it's used in multiple bodies, but that's okay as
// the semantics for Register explicitly allow it. // the semantics for Register explicitly allow it.
for ( auto& e : f.events ) { for ( auto& e : f.events )
auto eh = event_registry->Register(e); event_registry->Register(e);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
eh->SetUsed();
#pragma GCC diagnostic pop
}
} }
auto sf = make_intrusive<ScriptFunc>(std::move(name), std::move(ft), std::move(bodies), std::move(priorities)); auto sf = make_intrusive<ScriptFunc>(std::move(name), std::move(ft), std::move(bodies), std::move(priorities));

View file

@ -417,13 +417,8 @@ static void use_CPP() {
f.SetBody(b); f.SetBody(b);
} }
for ( auto& e : s->second.events ) { for ( auto& e : s->second.events )
auto h = event_registry->Register(e); event_registry->Register(e);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
h->SetUsed();
#pragma GCC diagnostic pop
}
auto finish = s->second.finish_init_func; auto finish = s->second.finish_init_func;
if ( finish ) if ( finish )

View file

@ -996,16 +996,6 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
if ( zeek_init ) if ( zeek_init )
event_mgr.Enqueue(zeek_init, Args{}); event_mgr.Enqueue(zeek_init, Args{});
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
EventRegistry::string_list dead_handlers = event_registry->UnusedHandlers();
#pragma GCC diagnostic pop
if ( ! dead_handlers.empty() && check_for_unused_event_handlers ) {
for ( const string& handler : dead_handlers )
reporter->Warning("event handler never invoked: %s", handler.c_str());
}
// Enable LeakSanitizer before zeek_init() and even before executing // Enable LeakSanitizer before zeek_init() and even before executing
// top-level statements. Even though it's not bad if a leak happens only // top-level statements. Even though it's not bad if a leak happens only
// once at initialization, we have to assume that script-layer code causing // once at initialization, we have to assume that script-layer code causing

View file

@ -1,10 +0,0 @@
# This test should print a warning that the event handler is never invoked.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# @TEST-REQUIRES: $SCRIPTS/have-spicy # This test logs uninvoked event handlers, so disable it if Spicy and its plugin is unavailable.
# @TEST-EXEC: zeek -b %INPUT check_for_unused_event_handlers=T
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort-and-remove-abspath btest-diff .stderr
event this_is_never_used()
{
print "not even once";
}