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);
}
const detail::Location* Frame::GetCallLocation() const
{
return call ? call->GetLocationInfo() : nullptr;
}
void Frame::SetTrigger(trigger::TriggerPtr arg_trigger)
{
trigger = std::move(arg_trigger);

View file

@ -262,6 +262,7 @@ public:
void SetCall(const CallExpr* arg_call) { call = arg_call; }
void ClearCall() { call = nullptr; }
const CallExpr* GetCall() const { return call; }
const detail::Location* GetCallLocation() const;
void SetDelayed() { delayed = true; }
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);
if ( ! d )
reporter->RuntimeError(f->GetCall()->GetLocationInfo(),
reporter->RuntimeError(f->GetCallLocation(),
"Broker::Data's opaque field is not set");
// 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);
if ( ! ptr )
zeek::reporter->RuntimeError(f->GetCall()->GetLocationInfo(),
zeek::reporter->RuntimeError(f->GetCallLocation(),
"data is of type '%s' not of type '%s'",
caf::visit(type_name_getter{tag}, d),
zeek::type_name(tag));

View file

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

View file

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