new function for getting the location, if any, associated with the current call

This commit is contained in:
Vern Paxson 2021-03-18 10:00:01 -07:00
parent 8fb30f1d62
commit 8f2637decb
6 changed files with 14 additions and 8 deletions

View file

@ -616,6 +616,11 @@ void Frame::CaptureClosure(Frame* c, IDPList arg_outer_ids)
// if (c) closure = c->SelectiveClone(outer_ids); // if (c) closure = c->SelectiveClone(outer_ids);
} }
const detail::Location* Frame::GetCallLocation() const
{
return call ? call->GetLocationInfo() : nullptr;
}
void Frame::SetTrigger(trigger::TriggerPtr arg_trigger) void Frame::SetTrigger(trigger::TriggerPtr arg_trigger)
{ {
trigger = std::move(arg_trigger); trigger = std::move(arg_trigger);

View file

@ -262,6 +262,7 @@ public:
void SetCall(const CallExpr* arg_call) { call = arg_call; } void SetCall(const CallExpr* arg_call) { call = arg_call; }
void ClearCall() { call = nullptr; } void ClearCall() { call = nullptr; }
const CallExpr* GetCall() const { return call; } const CallExpr* GetCall() const { return call; }
const detail::Location* GetCallLocation() const;
void SetDelayed() { delayed = true; } void SetDelayed() { delayed = true; }
bool HasDelayed() const { return delayed; } bool HasDelayed() const { return delayed; }

View file

@ -1177,7 +1177,7 @@ broker::data& opaque_field_to_data(RecordVal* v, zeek::detail::Frame* f)
const auto& d = v->GetField(0); const auto& d = v->GetField(0);
if ( ! d ) if ( ! d )
reporter->RuntimeError(f->GetCall()->GetLocationInfo(), reporter->RuntimeError(f->GetCallLocation(),
"Broker::Data's opaque field is not set"); "Broker::Data's opaque field is not set");
// RuntimeError throws an exception which causes this line to never exceute. // RuntimeError throws an exception which causes this line to never exceute.

View file

@ -194,7 +194,7 @@ T& require_data_type(broker::data& d, zeek::TypeTag tag, zeek::detail::Frame* f)
{ {
auto ptr = caf::get_if<T>(&d); auto ptr = caf::get_if<T>(&d);
if ( ! ptr ) if ( ! ptr )
zeek::reporter->RuntimeError(f->GetCall()->GetLocationInfo(), zeek::reporter->RuntimeError(f->GetCallLocation(),
"data is of type '%s' not of type '%s'", "data is of type '%s' not of type '%s'",
caf::visit(type_name_getter{tag}, d), caf::visit(type_name_getter{tag}, d),
zeek::type_name(tag)); zeek::type_name(tag));

View file

@ -74,7 +74,7 @@ int Manager::script_scope = 0;
struct scoped_reporter_location { struct scoped_reporter_location {
scoped_reporter_location(zeek::detail::Frame* frame) scoped_reporter_location(zeek::detail::Frame* frame)
{ {
reporter->PushLocation(frame->GetCall()->GetLocationInfo()); reporter->PushLocation(frame->GetCallLocation());
} }
~scoped_reporter_location() ~scoped_reporter_location()

View file

@ -22,7 +22,7 @@ module Reporter;
## .. zeek:see:: reporter_info ## .. zeek:see:: reporter_info
function Reporter::info%(msg: string%): bool function Reporter::info%(msg: string%): bool
%{ %{
reporter->PushLocation(frame->GetCall()->GetLocationInfo()); reporter->PushLocation(frame->GetCallLocation());
reporter->Info("%s", msg->CheckString()); reporter->Info("%s", msg->CheckString());
reporter->PopLocation(); reporter->PopLocation();
return zeek::val_mgr->True(); return zeek::val_mgr->True();
@ -37,7 +37,7 @@ function Reporter::info%(msg: string%): bool
## .. zeek:see:: reporter_warning ## .. zeek:see:: reporter_warning
function Reporter::warning%(msg: string%): bool function Reporter::warning%(msg: string%): bool
%{ %{
reporter->PushLocation(frame->GetCall()->GetLocationInfo()); reporter->PushLocation(frame->GetCallLocation());
reporter->Warning("%s", msg->CheckString()); reporter->Warning("%s", msg->CheckString());
reporter->PopLocation(); reporter->PopLocation();
return zeek::val_mgr->True(); return zeek::val_mgr->True();
@ -53,7 +53,7 @@ function Reporter::warning%(msg: string%): bool
## .. zeek:see:: reporter_error ## .. zeek:see:: reporter_error
function Reporter::error%(msg: string%): bool function Reporter::error%(msg: string%): bool
%{ %{
reporter->PushLocation(frame->GetCall()->GetLocationInfo()); reporter->PushLocation(frame->GetCallLocation());
reporter->Error("%s", msg->CheckString()); reporter->Error("%s", msg->CheckString());
reporter->PopLocation(); reporter->PopLocation();
return zeek::val_mgr->True(); return zeek::val_mgr->True();
@ -66,7 +66,7 @@ function Reporter::error%(msg: string%): bool
## Returns: Always true. ## Returns: Always true.
function Reporter::fatal%(msg: string%): bool function Reporter::fatal%(msg: string%): bool
%{ %{
reporter->PushLocation(frame->GetCall()->GetLocationInfo()); reporter->PushLocation(frame->GetCallLocation());
reporter->FatalError("%s", msg->CheckString()); reporter->FatalError("%s", msg->CheckString());
reporter->PopLocation(); reporter->PopLocation();
return zeek::val_mgr->True(); return zeek::val_mgr->True();
@ -80,7 +80,7 @@ function Reporter::fatal%(msg: string%): bool
## Returns: Always true. ## Returns: Always true.
function Reporter::fatal_error_with_core%(msg: string%): bool function Reporter::fatal_error_with_core%(msg: string%): bool
%{ %{
reporter->PushLocation(frame->GetCall()->GetLocationInfo()); reporter->PushLocation(frame->GetCallLocation());
reporter->FatalErrorWithCore("%s", msg->CheckString()); reporter->FatalErrorWithCore("%s", msg->CheckString());
reporter->PopLocation(); reporter->PopLocation();
return zeek::val_mgr->True(); return zeek::val_mgr->True();