mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Add script-layer call stack to internal errors messages that abort
This commit is contained in:
parent
a7ba44089b
commit
b2560384c4
7 changed files with 66 additions and 12 deletions
6
CHANGES
6
CHANGES
|
@ -1,4 +1,10 @@
|
|||
|
||||
2.6-beta2-67 | 2018-11-02 17:41:46 -0500
|
||||
|
||||
* Add script-layer call stack to internal errors messages that abort (Jon Siwek, Corelight)
|
||||
|
||||
* Improve error message of index assignment expression failures (Jon Siwek, Corelight)
|
||||
|
||||
2.6-beta2-65 | 2018-11-02 09:36:30 -0500
|
||||
|
||||
* Improve Travis script to show multiple core dump stacks (Jon Siwek, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
2.6-beta2-65
|
||||
2.6-beta2-67
|
||||
|
|
26
src/Func.cc
26
src/Func.cc
|
@ -56,6 +56,32 @@ bool did_builtin_init = false;
|
|||
vector<Func*> Func::unique_ids;
|
||||
static const std::pair<bool, Val*> empty_hook_result(false, NULL);
|
||||
|
||||
std::string render_call_stack()
|
||||
{
|
||||
std::string rval;
|
||||
int lvl = 0;
|
||||
|
||||
if ( ! call_stack.empty() )
|
||||
rval += "| ";
|
||||
|
||||
for ( auto it = call_stack.rbegin(); it != call_stack.rend(); ++it )
|
||||
{
|
||||
if ( lvl > 0 )
|
||||
rval += " | ";
|
||||
|
||||
auto& ci = *it;
|
||||
auto loc = ci.call->GetLocationInfo();
|
||||
auto name = ci.func->Name();
|
||||
rval += fmt("#%d %s() at %s:%d", lvl, name, loc->filename, loc->first_line);
|
||||
++lvl;
|
||||
}
|
||||
|
||||
if ( ! call_stack.empty() )
|
||||
rval += " |";
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
Func::Func() : scope(0), type(0)
|
||||
{
|
||||
unique_id = unique_ids.size();
|
||||
|
|
|
@ -147,6 +147,8 @@ struct CallInfo {
|
|||
|
||||
extern vector<CallInfo> call_stack;
|
||||
|
||||
extern std::string render_call_stack();
|
||||
|
||||
// This is set to true after the built-in functions have been initialized.
|
||||
extern bool did_builtin_init;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "Obj.h"
|
||||
#include "Serializer.h"
|
||||
#include "Func.h"
|
||||
#include "File.h"
|
||||
#include "plugin/Manager.h"
|
||||
|
||||
|
@ -139,7 +140,13 @@ void BroObj::Internal(const char* msg) const
|
|||
{
|
||||
ODesc d;
|
||||
DoMsg(&d, msg);
|
||||
auto rcs = render_call_stack();
|
||||
|
||||
if ( rcs.empty() )
|
||||
reporter->InternalError("%s", d.Description());
|
||||
else
|
||||
reporter->InternalError("%s, call stack: %s", d.Description(), rcs.data());
|
||||
|
||||
reporter->PopLocation();
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
internal error in /Users/jon/projects/bro/bro/scripts/base/utils/queue.bro, line 152: vector index assignment failed for invalid type 'myrec', value: [a=T, b=hi, c=<uninitialized>] (Queue::ret[Queue::j])
|
||||
internal error in /Users/jon/projects/bro/bro/scripts/base/utils/queue.bro, line 152: vector index assignment failed for invalid type 'myrec', value: [a=T, b=hi, c=<uninitialized>] (Queue::ret[Queue::j]), call stack:
|
||||
#0 Queue::get_vector() at /Users/jon/projects/bro/bro/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.bro:19
|
||||
#1 bar() at /Users/jon/projects/bro/bro/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.bro:27
|
||||
#2 foo() at /Users/jon/projects/bro/bro/testing/btest/.tmp/language.index-assignment-invalid/index-assignment-invalid.bro:39
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# @TEST-EXEC-FAIL: bro -b %INPUT >out 2>&1
|
||||
# @TEST-EXEC-FAIL: bro -b %INPUT >output 2>&1
|
||||
# @TEST-EXEC: grep "internal error" output >output2
|
||||
# @TEST-EXEC: for i in {1..5}; do cat output2 | cut -d'|' -f$i >>out; done
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||
|
||||
@load base/utils/queue
|
||||
|
@ -11,11 +13,18 @@ type myrec: record {
|
|||
c: string &optional;
|
||||
};
|
||||
|
||||
function foo(mr: myrec)
|
||||
function bar()
|
||||
{
|
||||
print mr$a;
|
||||
print mr$c;
|
||||
print mr$b;
|
||||
local rval: vector of string = vector();
|
||||
Queue::get_vector(q, rval);
|
||||
print rval;
|
||||
Queue::get_vector(q, rval);
|
||||
print rval;
|
||||
}
|
||||
|
||||
function foo()
|
||||
{
|
||||
bar();
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
|
@ -24,8 +33,8 @@ event bro_init()
|
|||
Queue::put(q, "goodbye");
|
||||
Queue::put(q, "test");
|
||||
Queue::put(q, myrec());
|
||||
|
||||
local rval: vector of string = vector();
|
||||
Queue::get_vector(q, rval);
|
||||
print rval;
|
||||
Queue::put(q, "asdf");
|
||||
Queue::put(q, 3);
|
||||
Queue::put(q, "jkl;");
|
||||
foo();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue