Add script-layer call stack to internal errors messages that abort

This commit is contained in:
Jon Siwek 2018-11-02 17:41:46 -05:00
parent a7ba44089b
commit b2560384c4
7 changed files with 66 additions and 12 deletions

View file

@ -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 2.6-beta2-65 | 2018-11-02 09:36:30 -0500
* Improve Travis script to show multiple core dump stacks (Jon Siwek, Corelight) * Improve Travis script to show multiple core dump stacks (Jon Siwek, Corelight)

View file

@ -1 +1 @@
2.6-beta2-65 2.6-beta2-67

View file

@ -56,6 +56,32 @@ bool did_builtin_init = false;
vector<Func*> Func::unique_ids; vector<Func*> Func::unique_ids;
static const std::pair<bool, Val*> empty_hook_result(false, NULL); 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) Func::Func() : scope(0), type(0)
{ {
unique_id = unique_ids.size(); unique_id = unique_ids.size();

View file

@ -147,6 +147,8 @@ struct CallInfo {
extern vector<CallInfo> call_stack; extern vector<CallInfo> call_stack;
extern std::string render_call_stack();
// This is set to true after the built-in functions have been initialized. // This is set to true after the built-in functions have been initialized.
extern bool did_builtin_init; extern bool did_builtin_init;

View file

@ -6,6 +6,7 @@
#include "Obj.h" #include "Obj.h"
#include "Serializer.h" #include "Serializer.h"
#include "Func.h"
#include "File.h" #include "File.h"
#include "plugin/Manager.h" #include "plugin/Manager.h"
@ -139,7 +140,13 @@ void BroObj::Internal(const char* msg) const
{ {
ODesc d; ODesc d;
DoMsg(&d, msg); DoMsg(&d, msg);
reporter->InternalError("%s", d.Description()); 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(); reporter->PopLocation();
} }

View file

@ -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

View file

@ -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 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
@load base/utils/queue @load base/utils/queue
@ -11,11 +13,18 @@ type myrec: record {
c: string &optional; c: string &optional;
}; };
function foo(mr: myrec) function bar()
{ {
print mr$a; local rval: vector of string = vector();
print mr$c; Queue::get_vector(q, rval);
print mr$b; print rval;
Queue::get_vector(q, rval);
print rval;
}
function foo()
{
bar();
} }
event bro_init() event bro_init()
@ -24,8 +33,8 @@ event bro_init()
Queue::put(q, "goodbye"); Queue::put(q, "goodbye");
Queue::put(q, "test"); Queue::put(q, "test");
Queue::put(q, myrec()); Queue::put(q, myrec());
Queue::put(q, "asdf");
local rval: vector of string = vector(); Queue::put(q, 3);
Queue::get_vector(q, rval); Queue::put(q, "jkl;");
print rval; foo();
} }