Move all debugger code into the zeek::detail namespace

This commit is contained in:
Tim Wojtulewicz 2020-07-16 10:56:15 -07:00
parent 834b76f94f
commit 35c61697d9
17 changed files with 525 additions and 419 deletions

View file

@ -15,6 +15,8 @@
using namespace std; using namespace std;
namespace zeek::detail {
Brofiler::Brofiler() Brofiler::Brofiler()
: ignoring(0), delim('\t') : ignoring(0), delim('\t')
{ {
@ -154,3 +156,5 @@ bool Brofiler::WriteStats()
fclose(f); fclose(f);
return true; return true;
} }
} // namespace zeek::detail

View file

@ -8,6 +8,8 @@
#include "util.h" #include "util.h"
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
namespace zeek::detail {
/** /**
* A simple class for managing stats of Bro script coverage across Bro runs. * A simple class for managing stats of Bro script coverage across Bro runs.
*/ */
@ -83,3 +85,8 @@ private:
}; };
extern Brofiler brofiler; extern Brofiler brofiler;
} // namespace zeek::detail
using Brofiler [[deprecated("Remove in v4.1. Use zeek::detail::Brofiler.")]] = zeek::detail::Brofiler;
extern zeek::detail::Brofiler& brofiler [[deprecated("Remove in v4.1. Use zeek::detail::brofiler.")]];

View file

@ -19,6 +19,8 @@
#include "Reporter.h" #include "Reporter.h"
#include "module_util.h" #include "module_util.h"
namespace zeek::detail {
// BreakpointTimer used for time-based breakpoints // BreakpointTimer used for time-based breakpoints
class BreakpointTimer final : public Timer { class BreakpointTimer final : public Timer {
public: public:
@ -121,13 +123,13 @@ void DbgBreakpoint::RemoveFromStmt()
bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str) bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str)
{ {
if ( plr.type == plrUnknown ) if ( plr.type == PLR_UNKNOWN )
{ {
debug_msg("Breakpoint specifier invalid or operation canceled.\n"); debug_msg("Breakpoint specifier invalid or operation canceled.\n");
return false; return false;
} }
if ( plr.type == plrFileAndLine ) if ( plr.type == PLR_FILE_AND_LINE )
{ {
kind = BP_LINE; kind = BP_LINE;
source_filename = plr.filename; source_filename = plr.filename;
@ -146,7 +148,7 @@ bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str)
debug_msg("Breakpoint %d set at %s\n", GetID(), Description()); debug_msg("Breakpoint %d set at %s\n", GetID(), Description());
} }
else if ( plr.type == plrFunction ) else if ( plr.type == PLR_FUNCTION )
{ {
std::string loc_s(loc_str); std::string loc_s(loc_str);
kind = BP_FUNC; kind = BP_FUNC;
@ -211,7 +213,7 @@ bool DbgBreakpoint::Reset()
case BP_FUNC: case BP_FUNC:
case BP_STMT: case BP_STMT:
case BP_LINE: case BP_LINE:
plr.type = plrFunction; plr.type = PLR_FUNCTION;
//### How to deal with wildcards? //### How to deal with wildcards?
//### perhaps save user choices?--tough... //### perhaps save user choices?--tough...
break; break;
@ -240,7 +242,7 @@ BreakCode DbgBreakpoint::HasHit()
if ( temporary ) if ( temporary )
{ {
SetEnable(false); SetEnable(false);
return bcHitAndDelete; return BC_HIT_AND_DELETE;
} }
if ( condition.size() ) if ( condition.size() )
@ -254,7 +256,7 @@ BreakCode DbgBreakpoint::HasHit()
condition.c_str()); condition.c_str());
SetCondition(""); SetCondition("");
PrintHitMsg(); PrintHitMsg();
return bcHit; return BC_HIT;
} }
if ( ! zeek::IsIntegral(yes->GetType()->Tag()) && if ( ! zeek::IsIntegral(yes->GetType()->Tag()) &&
@ -262,13 +264,13 @@ BreakCode DbgBreakpoint::HasHit()
{ {
PrintHitMsg(); PrintHitMsg();
debug_msg("Breakpoint condition should return an integral type"); debug_msg("Breakpoint condition should return an integral type");
return bcHitAndDelete; return BC_HIT_AND_DELETE;
} }
yes->CoerceToInt(); yes->CoerceToInt();
if ( yes->IsZero() ) if ( yes->IsZero() )
{ {
return bcNoHit; return BC_NO_HIT;
} }
} }
@ -279,26 +281,26 @@ BreakCode DbgBreakpoint::HasHit()
{ {
hit_count = 0; hit_count = 0;
PrintHitMsg(); PrintHitMsg();
return bcHit; return BC_HIT;
} }
return bcNoHit; return BC_NO_HIT;
} }
PrintHitMsg(); PrintHitMsg();
return bcHit; return BC_HIT;
} }
BreakCode DbgBreakpoint::ShouldBreak(zeek::detail::Stmt* s) BreakCode DbgBreakpoint::ShouldBreak(zeek::detail::Stmt* s)
{ {
if ( ! IsEnabled() ) if ( ! IsEnabled() )
return bcNoHit; return BC_NO_HIT;
switch ( kind ) { switch ( kind ) {
case BP_STMT: case BP_STMT:
case BP_FUNC: case BP_FUNC:
if ( at_stmt != s ) if ( at_stmt != s )
return bcNoHit; return BC_NO_HIT;
break; break;
case BP_LINE: case BP_LINE:
@ -330,10 +332,10 @@ BreakCode DbgBreakpoint::ShouldBreak(double t)
reporter->InternalError("Calling ShouldBreak(time) on a non-time breakpoint"); reporter->InternalError("Calling ShouldBreak(time) on a non-time breakpoint");
if ( t < at_time ) if ( t < at_time )
return bcNoHit; return BC_NO_HIT;
if ( ! IsEnabled() ) if ( ! IsEnabled() )
return bcNoHit; return BC_NO_HIT;
BreakCode code = HasHit(); BreakCode code = HasHit();
if ( code ) if ( code )
@ -371,3 +373,5 @@ void DbgBreakpoint::PrintHitMsg()
reporter->InternalError("Missed a case in DbgBreakpoint::PrintHitMsg\n"); reporter->InternalError("Missed a case in DbgBreakpoint::PrintHitMsg\n");
} }
} }
} // namespace zeek::detail

View file

@ -5,11 +5,12 @@
#include <string> #include <string>
#include "util.h" #include "util.h"
struct ParseLocationRec;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ParseLocationRec, zeek::detail);
enum BreakCode { bcNoHit, bcHit, bcHitAndDelete }; namespace zeek::detail {
enum BreakCode { BC_NO_HIT, BC_HIT, BC_HIT_AND_DELETE };
class DbgBreakpoint { class DbgBreakpoint {
enum Kind { BP_STMT = 0, BP_FUNC, BP_LINE, BP_TIME }; enum Kind { BP_STMT = 0, BP_FUNC, BP_LINE, BP_TIME };
@ -81,3 +82,15 @@ protected:
std::string condition; // condition to evaluate; nil for none std::string condition; // condition to evaluate; nil for none
}; };
} // namespace zeek::detail
using DbgBreakPoint [[deprecated("Remove in v4.1. Use zeek::detail::DbgBreakpoint.")]] = zeek::detail::DbgBreakpoint;
using BreakCode [[deprecated("Remove in v4.1. Use zeek::detail::BreakCode.")]] = zeek::detail::BreakCode;
[[deprecated("Remove in v4.1. Use zeek::detail::BC_NO_HIT.")]]
constexpr auto bcNoHit = zeek::detail::BC_NO_HIT;
[[deprecated("Remove in v4.1. Use zeek::detail::BC_HIT.")]]
constexpr auto bcHit = zeek::detail::BC_HIT;
[[deprecated("Remove in v4.1. Use zeek::detail::BC_HIT_AND_DELETE.")]]
constexpr auto bcHitAndDelete = zeek::detail::BC_HIT_AND_DELETE;

View file

@ -2,7 +2,9 @@
#pragma once #pragma once
class Expr; ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
namespace zeek::detail {
// Automatic displays: display these at each stoppage. // Automatic displays: display these at each stoppage.
class DbgDisplay { class DbgDisplay {
@ -23,3 +25,7 @@ protected:
bool enabled; bool enabled;
Expr* expression; Expr* expression;
}; };
} // namespace zeek::detail
using DbgDisplay [[deprecated("Remove in v4.1. Use zeek::detail::DbgDisplay.")]] = zeek::detail::DbgDisplay;

View file

@ -7,16 +7,12 @@
#include "Reporter.h" #include "Reporter.h"
// Support classes // Support classes
DbgWatch::DbgWatch(zeek::Obj* var_to_watch) zeek::detail::DbgWatch::DbgWatch(zeek::Obj* var_to_watch)
{ {
reporter->InternalError("DbgWatch unimplemented"); reporter->InternalError("DbgWatch unimplemented");
} }
DbgWatch::DbgWatch(zeek::detail::Expr* expr_to_watch) zeek::detail::DbgWatch::DbgWatch(zeek::detail::Expr* expr_to_watch)
{ {
reporter->InternalError("DbgWatch unimplemented"); reporter->InternalError("DbgWatch unimplemented");
} }
DbgWatch::~DbgWatch()
{
}

View file

@ -8,13 +8,19 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
namespace zeek { class Obj; } namespace zeek { class Obj; }
using BroObj [[deprecated("Remove in v4.1. Use zeek:Obj instead.")]] = zeek::Obj; using BroObj [[deprecated("Remove in v4.1. Use zeek:Obj instead.")]] = zeek::Obj;
namespace zeek::detail {
class DbgWatch { class DbgWatch {
public: public:
explicit DbgWatch(zeek::Obj* var_to_watch); explicit DbgWatch(zeek::Obj* var_to_watch);
explicit DbgWatch(zeek::detail::Expr* expr_to_watch); explicit DbgWatch(zeek::detail::Expr* expr_to_watch);
~DbgWatch(); ~DbgWatch() = default;
protected: protected:
zeek::Obj* var; zeek::Obj* var;
zeek::detail::Expr* expr; zeek::detail::Expr* expr;
}; };
} // namespace zeek::detail
using DbgWatch [[deprecated("Remove in v4.1. Using zeek::detail::DbgWatch.")]] = zeek::detail::DbgWatch;

View file

@ -35,10 +35,17 @@ using namespace std;
#include <readline/history.h> #include <readline/history.h>
#endif #endif
bool g_policy_debug = false; bool zeek::detail::g_policy_debug = false;
DebuggerState g_debugger_state; bool& g_policy_debug = zeek::detail::g_policy_debug;
TraceState g_trace_state;
std::map<string, Filemap*> g_dbgfilemaps; zeek::detail::DebuggerState zeek::detail::g_debugger_state;
zeek::detail::DebuggerState& g_debugger_state = zeek::detail::g_debugger_state;
zeek::detail::TraceState zeek::detail::g_trace_state;
zeek::detail::TraceState& g_trace_state = zeek::detail::g_trace_state;
std::map<string, zeek::detail::Filemap*> zeek::detail::g_dbgfilemaps;
std::map<string, zeek::detail::Filemap*>& g_dbgfilemaps = zeek::detail::g_dbgfilemaps;
// These variables are used only to decide whether or not to print the // These variables are used only to decide whether or not to print the
// current context; you don't want to do it after a step or next // current context; you don't want to do it after a step or next
@ -46,6 +53,24 @@ std::map<string, Filemap*> g_dbgfilemaps;
static bool step_or_next_pending = false; static bool step_or_next_pending = false;
static zeek::detail::Frame* last_frame; static zeek::detail::Frame* last_frame;
// The following values are needed by parse.y.
// Evaluates the given expression in the context of the currently selected
// frame. Returns the resulting value, or nil if none (or there was an error).
zeek::detail::Expr* g_curr_debug_expr = nullptr;
const char* g_curr_debug_error = nullptr;
bool in_debug = false;
// ### fix this hardwired access to external variables etc.
struct yy_buffer_state;
typedef struct yy_buffer_state* YY_BUFFER_STATE;
YY_BUFFER_STATE bro_scan_string(const char*);
extern YYLTYPE yylloc; // holds start line and column of token
extern int line_number;
extern const char* filename;
namespace zeek::detail {
DebuggerState::DebuggerState() DebuggerState::DebuggerState()
{ {
next_bp_id = next_watch_id = next_display_id = 1; next_bp_id = next_watch_id = next_display_id = 1;
@ -203,21 +228,21 @@ static void parse_function_name(vector<ParseLocationRec>& result,
{ {
string fullname = make_full_var_name(zeek::detail::current_module.c_str(), s.c_str()); string fullname = make_full_var_name(zeek::detail::current_module.c_str(), s.c_str());
debug_msg("Function %s not defined.\n", fullname.c_str()); debug_msg("Function %s not defined.\n", fullname.c_str());
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return; return;
} }
if ( ! id->GetType()->AsFuncType() ) if ( ! id->GetType()->AsFuncType() )
{ {
debug_msg("Function %s not declared.\n", id->Name()); debug_msg("Function %s not declared.\n", id->Name());
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return; return;
} }
if ( ! id->HasVal() ) if ( ! id->HasVal() )
{ {
debug_msg("Function %s declared but not defined.\n", id->Name()); debug_msg("Function %s declared but not defined.\n", id->Name());
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return; return;
} }
@ -227,7 +252,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
if ( bodies.size() == 0 ) if ( bodies.size() == 0 )
{ {
debug_msg("Function %s is a built-in function\n", id->Name()); debug_msg("Function %s is a built-in function\n", id->Name());
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return; return;
} }
@ -256,7 +281,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
char charinput[256]; char charinput[256];
if ( ! fgets(charinput, sizeof(charinput) - 1, stdin) ) if ( ! fgets(charinput, sizeof(charinput) - 1, stdin) )
{ {
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return; return;
} }
@ -270,7 +295,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
if ( input == "n" ) if ( input == "n" )
{ {
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return; return;
} }
@ -283,7 +308,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
} }
} }
plr.type = plrFunction; plr.type = PLR_FUNCTION;
// Find first atomic (non-STMT_LIST) statement // Find first atomic (non-STMT_LIST) statement
zeek::detail::Stmt* first; zeek::detail::Stmt* first;
@ -311,7 +336,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
if ( ! first ) if ( ! first )
continue; continue;
plr.type = plrFunction; plr.type = PLR_FUNCTION;
plr.stmt = first; plr.stmt = first;
plr.filename = stmt_loc.filename; plr.filename = stmt_loc.filename;
plr.line = stmt_loc.last_line; plr.line = stmt_loc.last_line;
@ -326,7 +351,7 @@ vector<ParseLocationRec> parse_location_string(const string& s)
result.push_back(ParseLocationRec()); result.push_back(ParseLocationRec());
ParseLocationRec& plr = result[0]; ParseLocationRec& plr = result[0];
// If plrFileAndLine, set this to the filename you want; for // If PLR_FILE_AND_LINE, set this to the filename you want; for
// memory management reasons, the real filename is set when looking // memory management reasons, the real filename is set when looking
// up the line number to find the corresponding statement. // up the line number to find the corresponding statement.
std::string loc_filename; std::string loc_filename;
@ -334,7 +359,7 @@ vector<ParseLocationRec> parse_location_string(const string& s)
if ( sscanf(s.c_str(), "%d", &plr.line) ) if ( sscanf(s.c_str(), "%d", &plr.line) )
{ // just a line number (implicitly referring to the current file) { // just a line number (implicitly referring to the current file)
loc_filename = g_debugger_state.last_loc.filename; loc_filename = g_debugger_state.last_loc.filename;
plr.type = plrFileAndLine; plr.type = PLR_FILE_AND_LINE;
} }
else else
@ -350,23 +375,23 @@ vector<ParseLocationRec> parse_location_string(const string& s)
string line_string = s.substr(pos_colon + 1, s.length() - pos_colon); string line_string = s.substr(pos_colon + 1, s.length() - pos_colon);
if ( ! sscanf(line_string.c_str(), "%d", &plr.line) ) if ( ! sscanf(line_string.c_str(), "%d", &plr.line) )
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
string path(find_script_file(filename, bro_path())); string path(find_script_file(filename, bro_path()));
if ( path.empty() ) if ( path.empty() )
{ {
debug_msg("No such policy file: %s.\n", filename.c_str()); debug_msg("No such policy file: %s.\n", filename.c_str());
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return result; return result;
} }
loc_filename = path; loc_filename = path;
plr.type = plrFileAndLine; plr.type = PLR_FILE_AND_LINE;
} }
} }
if ( plr.type == plrFileAndLine ) if ( plr.type == PLR_FILE_AND_LINE )
{ {
auto iter = g_dbgfilemaps.find(loc_filename); auto iter = g_dbgfilemaps.find(loc_filename);
if ( iter == g_dbgfilemaps.end() ) if ( iter == g_dbgfilemaps.end() )
@ -376,7 +401,7 @@ vector<ParseLocationRec> parse_location_string(const string& s)
if ( plr.line > how_many_lines_in(loc_filename.data()) ) if ( plr.line > how_many_lines_in(loc_filename.data()) )
{ {
debug_msg("No line %d in %s.\n", plr.line, loc_filename.data()); debug_msg("No line %d in %s.\n", plr.line, loc_filename.data());
plr.type = plrUnknown; plr.type = PLR_UNKNOWN;
return result; return result;
} }
@ -634,7 +659,7 @@ static int dbg_dispatch_cmd(DebugCmd cmd_code, const vector<string>& args)
{ {
switch ( cmd_code ) { switch ( cmd_code ) {
case dcHelp: case dcHelp:
dbg_cmd_help(cmd_code, args); zeek::detail::dbg_cmd_help(cmd_code, args);
break; break;
case dcQuit: case dcQuit:
@ -664,11 +689,11 @@ static int dbg_dispatch_cmd(DebugCmd cmd_code, const vector<string>& args)
break; break;
case dcBreak: case dcBreak:
dbg_cmd_break(cmd_code, args); zeek::detail::dbg_cmd_break(cmd_code, args);
break; break;
case dcBreakCondition: case dcBreakCondition:
dbg_cmd_break_condition(cmd_code, args); zeek::detail::dbg_cmd_break_condition(cmd_code, args);
break; break;
case dcDeleteBreak: case dcDeleteBreak:
@ -676,26 +701,26 @@ static int dbg_dispatch_cmd(DebugCmd cmd_code, const vector<string>& args)
case dcDisableBreak: case dcDisableBreak:
case dcEnableBreak: case dcEnableBreak:
case dcIgnoreBreak: case dcIgnoreBreak:
dbg_cmd_break_set_state(cmd_code, args); zeek::detail::dbg_cmd_break_set_state(cmd_code, args);
break; break;
case dcPrint: case dcPrint:
dbg_cmd_print(cmd_code, args); zeek::detail::dbg_cmd_print(cmd_code, args);
break; break;
case dcBacktrace: case dcBacktrace:
return dbg_cmd_backtrace(cmd_code, args); return zeek::detail::dbg_cmd_backtrace(cmd_code, args);
case dcFrame: case dcFrame:
case dcUp: case dcUp:
case dcDown: case dcDown:
return dbg_cmd_frame(cmd_code, args); return zeek::detail::dbg_cmd_frame(cmd_code, args);
case dcInfo: case dcInfo:
return dbg_cmd_info(cmd_code, args); return zeek::detail::dbg_cmd_info(cmd_code, args);
case dcList: case dcList:
return dbg_cmd_list(cmd_code, args); return zeek::detail::dbg_cmd_list(cmd_code, args);
case dcDisplay: case dcDisplay:
case dcUndisplay: case dcUndisplay:
@ -703,7 +728,7 @@ static int dbg_dispatch_cmd(DebugCmd cmd_code, const vector<string>& args)
break; break;
case dcTrace: case dcTrace:
return dbg_cmd_trace(cmd_code, args); return zeek::detail::dbg_cmd_trace(cmd_code, args);
default: default:
debug_msg("INTERNAL ERROR: " debug_msg("INTERNAL ERROR: "
@ -932,22 +957,6 @@ bool post_execute_stmt(zeek::detail::Stmt* stmt, zeek::detail::Frame* f, zeek::V
return true; return true;
} }
// Evaluates the given expression in the context of the currently selected
// frame. Returns the resulting value, or nil if none (or there was an error).
zeek::detail::Expr* g_curr_debug_expr = nullptr;
const char* g_curr_debug_error = nullptr;
bool in_debug = false;
// ### fix this hardwired access to external variables etc.
struct yy_buffer_state;
typedef struct yy_buffer_state* YY_BUFFER_STATE;
YY_BUFFER_STATE bro_scan_string(const char*);
extern YYLTYPE yylloc; // holds start line and column of token
extern int line_number;
extern const char* filename;
zeek::ValPtr dbg_eval_expr(const char* expr) zeek::ValPtr dbg_eval_expr(const char* expr)
{ {
// Push the current frame's associated scope. // Push the current frame's associated scope.
@ -1011,3 +1020,5 @@ zeek::ValPtr dbg_eval_expr(const char* expr)
return result; return result;
} }
} // namespace zeek::detail

View file

@ -14,15 +14,22 @@
ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(DbgBreakpoint, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(DbgWatch, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(DbgDisplay, zeek::detail);
namespace zeek { namespace zeek {
template <class T> class IntrusivePtr; template <class T> class IntrusivePtr;
using ValPtr = zeek::IntrusivePtr<Val>; using ValPtr = zeek::IntrusivePtr<Val>;
}
extern std::string current_module;
namespace detail {
// This needs to be defined before we do the includes that come after it. // This needs to be defined before we do the includes that come after it.
enum ParseLocationRecType { plrUnknown, plrFileAndLine, plrFunction }; enum ParseLocationRecType { PLR_UNKNOWN, PLR_FILE_AND_LINE, PLR_FUNCTION };
struct ParseLocationRec { class ParseLocationRec {
public:
ParseLocationRecType type; ParseLocationRecType type;
int32_t line; int32_t line;
zeek::detail::Stmt* stmt; zeek::detail::Stmt* stmt;
@ -30,19 +37,10 @@ struct ParseLocationRec {
}; };
class StmtLocMapping; class StmtLocMapping;
typedef zeek::PQueue<StmtLocMapping> Filemap; // mapping for a single file using Filemap = zeek::PQueue<StmtLocMapping>; // mapping for a single file
class DbgBreakpoint; using BPIDMapType = std::map<int, zeek::detail::DbgBreakpoint*>;
class DbgWatch; using BPMapType = std::multimap<const zeek::detail::Stmt*, zeek::detail::DbgBreakpoint*>;
class DbgDisplay;
class StmtHashFn;
typedef std::map<int, DbgBreakpoint*> BPIDMapType;
typedef std::multimap<const zeek::detail::Stmt*, DbgBreakpoint*> BPMapType;
namespace zeek {
extern std::string current_module;
}
class TraceState { class TraceState {
public: public:
@ -92,8 +90,8 @@ public:
zeek::detail::Location last_loc; // used by 'list'; the last location listed zeek::detail::Location last_loc; // used by 'list'; the last location listed
BPIDMapType breakpoints; // BPID -> Breakpoint BPIDMapType breakpoints; // BPID -> Breakpoint
std::vector<DbgWatch*> watches; std::vector<zeek::detail::DbgWatch*> watches;
std::vector<DbgDisplay*> displays; std::vector<zeek::detail::DbgDisplay*> displays;
BPMapType breakpoint_map; // maps Stmt -> Breakpoints on it BPMapType breakpoint_map; // maps Stmt -> Breakpoints on it
protected: protected:
@ -122,7 +120,6 @@ protected:
zeek::detail::Stmt* stmt; zeek::detail::Stmt* stmt;
}; };
extern bool g_policy_debug; // enable debugging facility extern bool g_policy_debug; // enable debugging facility
extern DebuggerState g_debugger_state; extern DebuggerState g_debugger_state;
@ -183,3 +180,36 @@ extern std::map<std::string, Filemap*> g_dbgfilemaps; // filename => filemap
// Perhaps add a code/priority argument to do selective output. // Perhaps add a code/priority argument to do selective output.
int debug_msg(const char* fmt, ...) __attribute__ ((format (printf, 1, 2))); int debug_msg(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
} // namespace zeek::detail
} // namespace zeek
constexpr auto plrUnknown [[deprecated("Remove in v4.1. Use zeek::detail::PLR_UNKNOWN.")]] = zeek::detail::PLR_UNKNOWN;
constexpr auto plrFileAndLine [[deprecated("Remove in v4.1. Use zeek::detail::PLR_FILE_AND_LINE.")]] = zeek::detail::PLR_FILE_AND_LINE;
constexpr auto plrFunction [[deprecated("Remove in v4.1. Use zeek::detail::PLR_FUNCTION.")]] = zeek::detail::PLR_FUNCTION;
using ParseLocationRec [[deprecated("Remove in v4.1. Use zeek::detail::ParseLocationRec.")]] = zeek::detail::ParseLocationRec;
using Filemap [[deprecated("Remove in v4.1. Use zeek::detail::Filemap.")]] = zeek::detail::Filemap;
using BPIDMapType [[deprecated("Remove in v4.1. Use zeek::detail::BPIDMapType.")]] = zeek::detail::BPIDMapType;
using BPMapType [[deprecated("Remove in v4.1. Use zeek::detail::BPMapType.")]] = zeek::detail::BPMapType;
using TraceState [[deprecated("Remove in v4.1. Use zeek::detail::TraceState.")]] = zeek::detail::TraceState;
using DebuggerState [[deprecated("Remove in v4.1. Use zeek::detail::DebuggerState.")]] = zeek::detail::DebuggerState;
using StmtLocMapping [[deprecated("Remove in v4.1. Use zeek::detail::StmtLocMapping.")]] = zeek::detail::StmtLocMapping;
constexpr auto parse_location_string [[deprecated("Remove in v4.1. Use zeek::detail::parse_location_string.")]] = zeek::detail::parse_location_string;
constexpr auto pre_execute_stmt [[deprecated("Remove in v4.1. Use zeek::detail::pre_execute_stmt.")]] = zeek::detail::pre_execute_stmt;
constexpr auto post_execute_stmt [[deprecated("Remove in v4.1. Use zeek::detail::post_execute_stmt.")]] = zeek::detail::post_execute_stmt;
constexpr auto dbg_init_debugger [[deprecated("Remove in v4.1. Use zeek::detail::dbg_init_debugger.")]] = zeek::detail::dbg_init_debugger;
constexpr auto dbg_shutdown_debugger [[deprecated("Remove in v4.1. Use zeek::detail::dbg_shutdown_debugger.")]] = zeek::detail::dbg_shutdown_debugger;
constexpr auto dbg_handle_debug_input [[deprecated("Remove in v4.1. Use zeek::detail::dbg_handle_debug_input.")]] = zeek::detail::dbg_handle_debug_input;
constexpr auto dbg_execute_command [[deprecated("Remove in v4.1. Use zeek::detail::dbg_execute_command.")]] = zeek::detail::dbg_execute_command;
constexpr auto dbg_eval_expr [[deprecated("Remove in v4.1. Use zeek::detail::dbg_eval_expr.")]] = zeek::detail::dbg_eval_expr;
constexpr auto dbg_read_internal_state [[deprecated("Remove in v4.1. Use zeek::detail::dbg_read_internal_state.")]] = zeek::detail::dbg_read_internal_state;
constexpr auto get_context_description [[deprecated("Remove in v4.1. Use zeek::detail::get_context_description.")]] = zeek::detail::get_context_description;
constexpr auto debug_msg [[deprecated("Remove in v4.1. Use zeek::detail::debug_msg.")]] = zeek::detail::debug_msg;
extern bool& g_policy_debug [[deprecated("Remove in v4.1. Use zeek::detail:g_policy_debug")]];
extern zeek::detail::DebuggerState& g_debugger_state [[deprecated("Remove in v4.1. Use zeek::detail:g_debugger_state")]];
extern std::string& current_module [[deprecated("Remove in v4.1. Use zeek::current_module.")]];
extern zeek::detail::TraceState& g_trace_state [[deprecated("Remove in v4.1. Use zeek::detail::g_trace_state.")]];
extern zeek::detail::Frame*& g_dbg_locals [[deprecated("Remove in v4.1. Use zeek::detail::g_dbg_locals.")]];
extern std::map<std::string, zeek::detail::Filemap*>& g_dbgfilemaps [[deprecated("Remove in v4.1. Use zeek::detail::g_dbgfilemaps.")]];

View file

@ -1,284 +1,282 @@
// //
// This file was automatically generated from ./DebugCmdInfoConstants.in // This file was automatically generated from DebugCmdInfoConstants.in
// DO NOT EDIT. // DO NOT EDIT.
// //
#include "util.h" #include "util.h"
void init_global_dbg_constants () { void zeek::detail::init_global_dbg_constants () {
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = { };
}; info = new zeek::detail::DebugCmdInfo(dcInvalid, names, 0, false, "This function should not be called",
info = new DebugCmdInfo (dcInvalid, names, 0, false, "This function should not be called",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"help" "help"
}; };
info = new DebugCmdInfo (dcHelp, names, 1, false, "Get help with debugger commands", info = new zeek::detail::DebugCmdInfo(dcHelp, names, 1, false, "Get help with debugger commands",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"quit" "quit"
}; };
info = new DebugCmdInfo (dcQuit, names, 1, false, "Exit Zeek", info = new zeek::detail::DebugCmdInfo(dcQuit, names, 1, false, "Exit Zeek",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"next" "next"
}; };
info = new DebugCmdInfo (dcNext, names, 1, true, "Step to the following statement, skipping function calls", info = new zeek::detail::DebugCmdInfo(dcNext, names, 1, true, "Step to the following statement, skipping function calls",
true); true);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"step", "step",
"s" "s"
}; };
info = new DebugCmdInfo (dcStep, names, 2, true, "Step to following statements, stepping in to function calls", info = new zeek::detail::DebugCmdInfo(dcStep, names, 2, true, "Step to following statements, stepping in to function calls",
true); true);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"continue", "continue",
"c" "c"
}; };
info = new DebugCmdInfo (dcContinue, names, 2, true, "Resume execution of the policy script", info = new zeek::detail::DebugCmdInfo(dcContinue, names, 2, true, "Resume execution of the policy script",
true); true);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"finish" "finish"
}; };
info = new DebugCmdInfo (dcFinish, names, 1, true, "Run until the currently-executing function completes", info = new zeek::detail::DebugCmdInfo(dcFinish, names, 1, true, "Run until the currently-executing function completes",
true); true);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"break", "break",
"b" "b"
}; };
info = new DebugCmdInfo (dcBreak, names, 2, false, "Set a breakpoint", info = new zeek::detail::DebugCmdInfo(dcBreak, names, 2, false, "Set a breakpoint",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"cond" "cond"
}; };
info = new DebugCmdInfo (dcBreakCondition, names, 1, false, "", info = new zeek::detail::DebugCmdInfo(dcBreakCondition, names, 1, false, "",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"delete", "delete",
"d" "d"
}; };
info = new DebugCmdInfo (dcDeleteBreak, names, 2, false, "Delete the specified breakpoints; delete all if no arguments", info = new zeek::detail::DebugCmdInfo(dcDeleteBreak, names, 2, false, "Delete the specified breakpoints; delete all if no arguments",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"clear" "clear"
}; };
info = new DebugCmdInfo (dcClearBreak, names, 1, false, "", info = new zeek::detail::DebugCmdInfo(dcClearBreak, names, 1, false, "",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"disable", "disable",
"dis" "dis"
}; };
info = new DebugCmdInfo (dcDisableBreak, names, 2, false, "", info = new zeek::detail::DebugCmdInfo(dcDisableBreak, names, 2, false, "",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"enable" "enable"
}; };
info = new DebugCmdInfo (dcEnableBreak, names, 1, false, "", info = new zeek::detail::DebugCmdInfo(dcEnableBreak, names, 1, false, "",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"ignore" "ignore"
}; };
info = new DebugCmdInfo (dcIgnoreBreak, names, 1, false, "", info = new zeek::detail::DebugCmdInfo(dcIgnoreBreak, names, 1, false, "",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"print", "print",
"p", "p",
"set" "set"
}; };
info = new DebugCmdInfo (dcPrint, names, 3, false, "Evaluate an expression and print the result (also aliased as 'set')", info = new zeek::detail::DebugCmdInfo(dcPrint, names, 3, false, "Evaluate an expression and print the result (also aliased as 'set')",
true); true);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"backtrace", "backtrace",
"bt", "bt",
"where" "where"
}; };
info = new DebugCmdInfo (dcBacktrace, names, 3, false, "Print a stack trace (with +- N argument, inner/outer N frames only)", info = new zeek::detail::DebugCmdInfo(dcBacktrace, names, 3, false, "Print a stack trace (with +- N argument, inner/outer N frames only)",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"frame" "frame"
}; };
info = new DebugCmdInfo (dcFrame, names, 1, false, "Select frame number N", info = new zeek::detail::DebugCmdInfo(dcFrame, names, 1, false, "Select frame number N",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"up" "up"
}; };
info = new DebugCmdInfo (dcUp, names, 1, false, "Select the stack frame one level up", info = new zeek::detail::DebugCmdInfo(dcUp, names, 1, false, "Select the stack frame one level up",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"down" "down"
}; };
info = new DebugCmdInfo (dcDown, names, 1, false, "Select the stack frame one level down", info = new zeek::detail::DebugCmdInfo(dcDown, names, 1, false, "Select the stack frame one level down",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"info" "info"
}; };
info = new DebugCmdInfo (dcInfo, names, 1, false, "Get information about the debugging environment", info = new zeek::detail::DebugCmdInfo(dcInfo, names, 1, false, "Get information about the debugging environment",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"list", "list",
"l" "l"
}; };
info = new DebugCmdInfo (dcList, names, 2, false, "Print source lines surrounding specified context", info = new zeek::detail::DebugCmdInfo(dcList, names, 2, false, "Print source lines surrounding specified context",
true); true);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"display" "display"
}; };
info = new DebugCmdInfo (dcDisplay, names, 1, false, "", info = new zeek::detail::DebugCmdInfo(dcDisplay, names, 1, false, "",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"undisplay" "undisplay"
}; };
info = new DebugCmdInfo (dcUndisplay, names, 1, false, "", info = new zeek::detail::DebugCmdInfo(dcUndisplay, names, 1, false, "",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
{ {
DebugCmdInfo* info; zeek::detail::DebugCmdInfo* info;
const char * const names[] = { const char * const names[] = {
"trace" "trace"
}; };
info = new DebugCmdInfo (dcTrace, names, 1, false, "Turn on or off execution tracing (with no arguments, prints current state.)", info = new zeek::detail::DebugCmdInfo(dcTrace, names, 1, false, "Turn on or off execution tracing (with no arguments, prints current state.)",
false); false);
g_DebugCmdInfos.push_back(info); zeek::detail::g_DebugCmdInfos.push_back(info);
} }
} }

View file

@ -53,7 +53,7 @@ static void lookup_global_symbols_regex(const string& orig_regex, vector<zeek::d
regex_t re; regex_t re;
if ( regcomp(&re, regex.c_str(), REG_EXTENDED|REG_NOSUB) ) if ( regcomp(&re, regex.c_str(), REG_EXTENDED|REG_NOSUB) )
{ {
debug_msg("Invalid regular expression: %s\n", regex.c_str()); zeek::detail::debug_msg("Invalid regular expression: %s\n", regex.c_str());
return; return;
} }
@ -80,14 +80,14 @@ static void choose_global_symbols_regex(const string& regex, vector<zeek::detail
while ( true ) while ( true )
{ {
debug_msg("There were multiple matches, please choose:\n"); zeek::detail::debug_msg("There were multiple matches, please choose:\n");
for ( size_t i = 0; i < choices.size(); i++ ) for ( size_t i = 0; i < choices.size(); i++ )
debug_msg("[%lu] %s\n", i+1, choices[i]->Name()); zeek::detail::debug_msg("[%lu] %s\n", i+1, choices[i]->Name());
debug_msg("[a] All of the above\n"); zeek::detail::debug_msg("[a] All of the above\n");
debug_msg("[n] None of the above\n"); zeek::detail::debug_msg("[n] None of the above\n");
debug_msg("Enter your choice: "); zeek::detail::debug_msg("Enter your choice: ");
char charinput[256]; char charinput[256];
if ( ! fgets(charinput, sizeof(charinput) - 1, stdin) ) if ( ! fgets(charinput, sizeof(charinput) - 1, stdin) )
@ -123,7 +123,10 @@ static void choose_global_symbols_regex(const string& regex, vector<zeek::detail
// DebugCmdInfo implementation // DebugCmdInfo implementation
// //
zeek::PQueue<DebugCmdInfo> g_DebugCmdInfos; zeek::PQueue<zeek::detail::DebugCmdInfo> zeek::detail::g_DebugCmdInfos;
zeek::PQueue<zeek::detail::DebugCmdInfo>& g_DebugCmdInfos = zeek::detail::g_DebugCmdInfos;
namespace zeek::detail {
DebugCmdInfo::DebugCmdInfo(const DebugCmdInfo& info) DebugCmdInfo::DebugCmdInfo(const DebugCmdInfo& info)
: cmd(info.cmd), helpstring(nullptr) : cmd(info.cmd), helpstring(nullptr)
@ -663,7 +666,7 @@ int dbg_cmd_list(DebugCmd cmd, const vector<string>& args)
{ {
vector<ParseLocationRec> plrs = parse_location_string(args[0]); vector<ParseLocationRec> plrs = parse_location_string(args[0]);
ParseLocationRec plr = plrs[0]; ParseLocationRec plr = plrs[0];
if ( plr.type == plrUnknown ) if ( plr.type == PLR_UNKNOWN )
{ {
debug_msg("Invalid location specifier\n"); debug_msg("Invalid location specifier\n");
return false; return false;
@ -722,3 +725,5 @@ int dbg_cmd_trace(DebugCmd cmd, const vector<string>& args)
debug_msg("Invalid argument"); debug_msg("Invalid argument");
return 0; return 0;
} }
} // namespace zeek::detail

View file

@ -10,6 +10,8 @@
#include "Queue.h" #include "Queue.h"
#include "DebugCmdConstants.h" #include "DebugCmdConstants.h"
namespace zeek::detail {
class DebugCmdInfo { class DebugCmdInfo {
public: public:
DebugCmdInfo(const DebugCmdInfo& info); DebugCmdInfo(const DebugCmdInfo& info);
@ -74,3 +76,23 @@ DbgCmdFn dbg_cmd_print;
DbgCmdFn dbg_cmd_info; DbgCmdFn dbg_cmd_info;
DbgCmdFn dbg_cmd_list; DbgCmdFn dbg_cmd_list;
DbgCmdFn dbg_cmd_trace; DbgCmdFn dbg_cmd_trace;
} // namespace zeek::detail
using DebugCmdInfo [[deprecated("Remove in v4.1. Use zeek::detail::DebugCmdInfo.")]] = zeek::detail::DebugCmdInfo;
constexpr auto init_global_dbg_constants [[deprecated("Remove in v4.1. Use zeek::detail::init_global_dbg_constants.")]] = zeek::detail::init_global_dbg_constants;
constexpr auto get_debug_cmd_info [[deprecated("Remove in v4.1. Use zeek::detail::get_debug_cmd_info.")]] = zeek::detail::get_debug_cmd_info;
constexpr auto find_all_matching_cmds [[deprecated("Remove in v4.1. Use zeek::detail::find_all_matching_cmds.")]] = zeek::detail::find_all_matching_cmds;
constexpr auto dbg_cmd_backtrace [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_backtrace")]] = zeek::detail::dbg_cmd_backtrace;
constexpr auto dbg_cmd_frame [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_frame")]] = zeek::detail::dbg_cmd_frame;
constexpr auto dbg_cmd_help [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_help")]] = zeek::detail::dbg_cmd_help;
constexpr auto dbg_cmd_break [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_break")]] = zeek::detail::dbg_cmd_break;
constexpr auto dbg_cmd_break_condition [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_break_condition")]] = zeek::detail::dbg_cmd_break_condition;
constexpr auto dbg_cmd_break_set_state [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_break_set_state")]] = zeek::detail::dbg_cmd_break_set_state;
constexpr auto dbg_cmd_print [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_print")]] = zeek::detail::dbg_cmd_print;
constexpr auto dbg_cmd_info [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_info")]] = zeek::detail::dbg_cmd_info;
constexpr auto dbg_cmd_list [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_list")]] = zeek::detail::dbg_cmd_list;
constexpr auto dbg_cmd_trace [[deprecated("Remove in v4.1. Use zeek::detail::dbg_cmd_trace")]] = zeek::detail::dbg_cmd_trace;
extern zeek::PQueue<zeek::detail::DebugCmdInfo>& g_DebugCmdInfos [[deprecated("Remove in v4.1. Use zeek::detail::g_DebugCmdInfos.")]];

View file

@ -37,7 +37,7 @@ int how_many_lines_in(const char* policy_filename)
FILE* throwaway = fopen(policy_filename, "r"); FILE* throwaway = fopen(policy_filename, "r");
if ( ! throwaway ) if ( ! throwaway )
{ {
debug_msg("No such policy file: %s.\n", policy_filename); zeek::detail::debug_msg("No such policy file: %s.\n", policy_filename);
return -1; return -1;
} }
@ -51,7 +51,7 @@ int how_many_lines_in(const char* policy_filename)
match = policy_files.find(policy_filename); match = policy_files.find(policy_filename);
if ( match == policy_files.end() ) if ( match == policy_files.end() )
{ {
debug_msg("Policy file %s was not loaded.\n", policy_filename); zeek::detail::debug_msg("Policy file %s was not loaded.\n", policy_filename);
return -1; return -1;
} }
} }
@ -69,14 +69,14 @@ bool LoadPolicyFileText(const char* policy_filename)
if ( ! f ) if ( ! f )
{ {
debug_msg("No such policy file: %s.\n", policy_filename); zeek::detail::debug_msg("No such policy file: %s.\n", policy_filename);
return false; return false;
} }
PolicyFile* pf = new PolicyFile; PolicyFile* pf = new PolicyFile;
if ( policy_files.find(policy_filename) != policy_files.end() ) if ( policy_files.find(policy_filename) != policy_files.end() )
debug_msg("Policy file %s already loaded\n", policy_filename); zeek::detail::debug_msg("Policy file %s already loaded\n", policy_filename);
policy_files.insert(PolicyFileMap::value_type(policy_filename, pf)); policy_files.insert(PolicyFileMap::value_type(policy_filename, pf));
@ -129,7 +129,7 @@ bool PrintLines(const char* policy_filename, unsigned int start_line,
FILE* throwaway = fopen(policy_filename, "r"); FILE* throwaway = fopen(policy_filename, "r");
if ( ! throwaway ) if ( ! throwaway )
{ {
debug_msg("No such policy file: %s.\n", policy_filename); zeek::detail::debug_msg("No such policy file: %s.\n", policy_filename);
return false; return false;
} }
@ -143,7 +143,7 @@ bool PrintLines(const char* policy_filename, unsigned int start_line,
match = policy_files.find(policy_filename); match = policy_files.find(policy_filename);
if ( match == policy_files.end() ) if ( match == policy_files.end() )
{ {
debug_msg("Policy file %s was not loaded.\n", policy_filename); zeek::detail::debug_msg("Policy file %s was not loaded.\n", policy_filename);
return false; return false;
} }
} }
@ -155,7 +155,7 @@ bool PrintLines(const char* policy_filename, unsigned int start_line,
if ( start_line > pf->lines.size() ) if ( start_line > pf->lines.size() )
{ {
debug_msg("Line number %d out of range; %s has %d lines\n", zeek::detail::debug_msg("Line number %d out of range; %s has %d lines\n",
start_line, policy_filename, int(pf->lines.size())); start_line, policy_filename, int(pf->lines.size()));
return false; return false;
} }
@ -166,10 +166,10 @@ bool PrintLines(const char* policy_filename, unsigned int start_line,
for ( unsigned int i = 0; i < how_many_lines; ++i ) for ( unsigned int i = 0; i < how_many_lines; ++i )
{ {
if ( show_numbers ) if ( show_numbers )
debug_msg("%d\t", i + start_line); zeek::detail::debug_msg("%d\t", i + start_line);
const char* line = pf->lines[start_line + i - 1]; const char* line = pf->lines[start_line + i - 1];
debug_msg("%s\n", line); zeek::detail::debug_msg("%s\n", line);
} }
return true; return true;

View file

@ -25,13 +25,13 @@ import sys
inputfile = sys.argv[1] inputfile = sys.argv[1]
init_tmpl = ''' init_tmpl = '''
{ \t{
DebugCmdInfo* info; \t\tzeek::detail::DebugCmdInfo* info;
%(name_init)s \t\t%(name_init)s
info = new DebugCmdInfo (%(cmd)s, names, %(num_names)s, %(resume)s, "%(help)s", \t\tinfo = new zeek::detail::DebugCmdInfo(%(cmd)s, names, %(num_names)s, %(resume)s, "%(help)s",
%(repeatable)s); \t\t %(repeatable)s);
g_DebugCmdInfos.push_back(info); \t\tzeek::detail::g_DebugCmdInfos.push_back(info);
} \t}
''' '''
enum_str = ''' enum_str = '''
@ -49,13 +49,16 @@ init_str = '''
// //
#include "util.h" #include "util.h"
void init_global_dbg_constants () { void zeek::detail::init_global_dbg_constants () {
''' % inputfile ''' % inputfile
def outputrecord(): def outputrecord():
global init_str, enum_str global init_str, enum_str
dbginfo["name_init"] = "const char * const names[] = {\n\t%s\n };\n" % ",\n\t".join(dbginfo["names"]) if dbginfo["names"]:
dbginfo["name_init"] = "const char * const names[] = {\n\t\t\t%s\n\t\t};\n" % ",\n\t\t\t".join(dbginfo["names"])
else:
dbginfo["name_init"] = "const char * const names[] = { };\n"
dbginfo["num_names"] = len(dbginfo["names"]) dbginfo["num_names"] = len(dbginfo["names"])
@ -102,8 +105,8 @@ for line in inputf:
# output the last record # output the last record
outputrecord() outputrecord()
init_str += " \n}\n" init_str += "\t\n}\n"
enum_str += " dcLast\n};\n" enum_str += "\tdcLast\n};\n"
debugcmds = open("DebugCmdConstants.h", "w") debugcmds = open("DebugCmdConstants.h", "w")
debugcmds.write(enum_str) debugcmds.write(enum_str)

View file

@ -1416,7 +1416,7 @@ stmt:
zeek::detail::set_location(@1, @4); zeek::detail::set_location(@1, @4);
$$ = $3; $$ = $3;
if ( $2 ) if ( $2 )
brofiler.DecIgnoreDepth(); zeek::detail::brofiler.DecIgnoreDepth();
} }
| TOK_PRINT expr_list ';' opt_no_test | TOK_PRINT expr_list ';' opt_no_test
@ -1424,7 +1424,7 @@ stmt:
zeek::detail::set_location(@1, @3); zeek::detail::set_location(@1, @3);
$$ = new zeek::detail::PrintStmt(zeek::IntrusivePtr{zeek::AdoptRef{}, $2}); $$ = new zeek::detail::PrintStmt(zeek::IntrusivePtr{zeek::AdoptRef{}, $2});
if ( ! $4 ) if ( ! $4 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_EVENT event ';' opt_no_test | TOK_EVENT event ';' opt_no_test
@ -1432,7 +1432,7 @@ stmt:
zeek::detail::set_location(@1, @3); zeek::detail::set_location(@1, @3);
$$ = new zeek::detail::EventStmt({zeek::AdoptRef{}, $2}); $$ = new zeek::detail::EventStmt({zeek::AdoptRef{}, $2});
if ( ! $4 ) if ( ! $4 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_IF '(' expr ')' stmt | TOK_IF '(' expr ')' stmt
@ -1468,7 +1468,7 @@ stmt:
zeek::detail::set_location(@1, @2); zeek::detail::set_location(@1, @2);
$$ = new zeek::detail::NextStmt; $$ = new zeek::detail::NextStmt;
if ( ! $3 ) if ( ! $3 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_BREAK ';' opt_no_test | TOK_BREAK ';' opt_no_test
@ -1476,7 +1476,7 @@ stmt:
zeek::detail::set_location(@1, @2); zeek::detail::set_location(@1, @2);
$$ = new zeek::detail::BreakStmt; $$ = new zeek::detail::BreakStmt;
if ( ! $3 ) if ( ! $3 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_FALLTHROUGH ';' opt_no_test | TOK_FALLTHROUGH ';' opt_no_test
@ -1484,7 +1484,7 @@ stmt:
zeek::detail::set_location(@1, @2); zeek::detail::set_location(@1, @2);
$$ = new zeek::detail::FallthroughStmt; $$ = new zeek::detail::FallthroughStmt;
if ( ! $3 ) if ( ! $3 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_RETURN ';' opt_no_test | TOK_RETURN ';' opt_no_test
@ -1492,7 +1492,7 @@ stmt:
zeek::detail::set_location(@1, @2); zeek::detail::set_location(@1, @2);
$$ = new zeek::detail::ReturnStmt(0); $$ = new zeek::detail::ReturnStmt(0);
if ( ! $3 ) if ( ! $3 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_RETURN expr ';' opt_no_test | TOK_RETURN expr ';' opt_no_test
@ -1500,7 +1500,7 @@ stmt:
zeek::detail::set_location(@1, @2); zeek::detail::set_location(@1, @2);
$$ = new zeek::detail::ReturnStmt({zeek::AdoptRef{}, $2}); $$ = new zeek::detail::ReturnStmt({zeek::AdoptRef{}, $2});
if ( ! $4 ) if ( ! $4 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_ADD expr ';' opt_no_test | TOK_ADD expr ';' opt_no_test
@ -1508,7 +1508,7 @@ stmt:
zeek::detail::set_location(@1, @3); zeek::detail::set_location(@1, @3);
$$ = new zeek::detail::AddStmt({zeek::AdoptRef{}, $2}); $$ = new zeek::detail::AddStmt({zeek::AdoptRef{}, $2});
if ( ! $4 ) if ( ! $4 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_DELETE expr ';' opt_no_test | TOK_DELETE expr ';' opt_no_test
@ -1516,7 +1516,7 @@ stmt:
zeek::detail::set_location(@1, @3); zeek::detail::set_location(@1, @3);
$$ = new zeek::detail::DelStmt({zeek::AdoptRef{}, $2}); $$ = new zeek::detail::DelStmt({zeek::AdoptRef{}, $2});
if ( ! $4 ) if ( ! $4 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_LOCAL local_id opt_type init_class opt_init opt_attr ';' opt_no_test | TOK_LOCAL local_id opt_type init_class opt_init opt_attr ';' opt_no_test
@ -1527,7 +1527,7 @@ stmt:
std::unique_ptr<std::vector<zeek::detail::AttrPtr>>{$6}, std::unique_ptr<std::vector<zeek::detail::AttrPtr>>{$6},
VAR_REGULAR).release(); VAR_REGULAR).release();
if ( ! $8 ) if ( ! $8 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_CONST local_id opt_type init_class opt_init opt_attr ';' opt_no_test | TOK_CONST local_id opt_type init_class opt_init opt_attr ';' opt_no_test
@ -1538,7 +1538,7 @@ stmt:
std::unique_ptr<std::vector<zeek::detail::AttrPtr>>{$6}, std::unique_ptr<std::vector<zeek::detail::AttrPtr>>{$6},
VAR_CONST).release(); VAR_CONST).release();
if ( ! $8 ) if ( ! $8 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| TOK_WHEN '(' expr ')' stmt | TOK_WHEN '(' expr ')' stmt
@ -1554,7 +1554,7 @@ stmt:
$$ = new zeek::detail::WhenStmt({zeek::AdoptRef{}, $3}, {zeek::AdoptRef{}, $5}, $$ = new zeek::detail::WhenStmt({zeek::AdoptRef{}, $3}, {zeek::AdoptRef{}, $5},
{zeek::AdoptRef{}, $10}, {zeek::AdoptRef{}, $7}, false); {zeek::AdoptRef{}, $10}, {zeek::AdoptRef{}, $7}, false);
if ( $9 ) if ( $9 )
brofiler.DecIgnoreDepth(); zeek::detail::brofiler.DecIgnoreDepth();
} }
@ -1571,7 +1571,7 @@ stmt:
$$ = new zeek::detail::WhenStmt({zeek::AdoptRef{}, $4}, {zeek::AdoptRef{}, $6}, $$ = new zeek::detail::WhenStmt({zeek::AdoptRef{}, $4}, {zeek::AdoptRef{}, $6},
{zeek::AdoptRef{}, $11}, {zeek::AdoptRef{}, $8}, true); {zeek::AdoptRef{}, $11}, {zeek::AdoptRef{}, $8}, true);
if ( $10 ) if ( $10 )
brofiler.DecIgnoreDepth(); zeek::detail::brofiler.DecIgnoreDepth();
} }
| index_slice '=' expr ';' opt_no_test | index_slice '=' expr ';' opt_no_test
@ -1581,7 +1581,7 @@ stmt:
{zeek::AdoptRef{}, $3}, in_init)); {zeek::AdoptRef{}, $3}, in_init));
if ( ! $5 ) if ( ! $5 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| expr ';' opt_no_test | expr ';' opt_no_test
@ -1589,7 +1589,7 @@ stmt:
zeek::detail::set_location(@1, @2); zeek::detail::set_location(@1, @2);
$$ = new zeek::detail::ExprStmt({zeek::AdoptRef{}, $1}); $$ = new zeek::detail::ExprStmt({zeek::AdoptRef{}, $1});
if ( ! $3 ) if ( ! $3 )
brofiler.AddStmt($$); zeek::detail::brofiler.AddStmt($$);
} }
| ';' | ';'
@ -1881,7 +1881,7 @@ opt_no_test:
opt_no_test_block: opt_no_test_block:
TOK_NO_TEST TOK_NO_TEST
{ $$ = true; brofiler.IncIgnoreDepth(); } { $$ = true; zeek::detail::brofiler.IncIgnoreDepth(); }
| |
{ $$ = false; } { $$ = false; }

View file

@ -602,10 +602,10 @@ static int load_files(const char* orig_file)
f = stdin; f = stdin;
file_path = canonical_stdin_path; file_path = canonical_stdin_path;
if ( g_policy_debug ) if ( zeek::detail::g_policy_debug )
{ {
debug_msg("Warning: can't use debugger while reading policy from stdin; turning off debugging.\n"); zeek::detail::debug_msg("Warning: can't use debugger while reading policy from stdin; turning off debugging.\n");
g_policy_debug = false; zeek::detail::g_policy_debug = false;
} }
} }
@ -635,12 +635,12 @@ static int load_files(const char* orig_file)
files_scanned.push_back(std::move(sf)); files_scanned.push_back(std::move(sf));
if ( g_policy_debug && ! file_path.empty() ) if ( zeek::detail::g_policy_debug && ! file_path.empty() )
{ {
// Add the filename to the file mapping table (Debug.h). // Add the filename to the file mapping table (Debug.h).
Filemap* map = new Filemap; zeek::detail::Filemap* map = new zeek::detail::Filemap;
HashKey* key = new HashKey(file_path.c_str()); HashKey* key = new HashKey(file_path.c_str());
g_dbgfilemaps.emplace(file_path, map); zeek::detail::g_dbgfilemaps.emplace(file_path, map);
LoadPolicyFileText(file_path.c_str()); LoadPolicyFileText(file_path.c_str());
} }

View file

@ -67,7 +67,8 @@ extern "C" {
#define DOCTEST_CONFIG_IMPLEMENT #define DOCTEST_CONFIG_IMPLEMENT
#include "3rdparty/doctest.h" #include "3rdparty/doctest.h"
Brofiler brofiler; zeek::detail::Brofiler zeek::detail::brofiler;
zeek::detail::Brofiler& brofiler = zeek::detail::brofiler;
#ifndef HAVE_STRSEP #ifndef HAVE_STRSEP
extern "C" { extern "C" {
@ -272,7 +273,7 @@ void terminate_bro()
// the termination process. // the termination process.
file_mgr->Terminate(); file_mgr->Terminate();
brofiler.WriteStats(); zeek::detail::brofiler.WriteStats();
if ( zeek_done ) if ( zeek_done )
mgr.Enqueue(zeek_done, zeek::Args{}); mgr.Enqueue(zeek_done, zeek::Args{});
@ -424,7 +425,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
if ( zeek::Supervisor::ThisNode() ) if ( zeek::Supervisor::ThisNode() )
zeek::Supervisor::ThisNode()->Init(&options); zeek::Supervisor::ThisNode()->Init(&options);
brofiler.ReadStats(); zeek::detail::brofiler.ReadStats();
auto dns_type = options.dns_mode; auto dns_type = options.dns_mode;