V8 crashes without any stack info in backtrace

115 views
Skip to first unread message

Mark Yap

unread,
Nov 20, 2012, 12:48:54 AM11/20/12
to v8-u...@googlegroups.com
Hi,

My embedded V8 application sometimes crashes without any backtrace info when I debug the crash file in gdb.  Is
there any setting that needs to be enabled to get backtrace info so that it is easier to debug?  I'm using debug version of v8.

The program below crashes with the below back trace if I fail to set the arguments when calling a javascript function. Is there any easier way to debug v8 when crashes with back traces like this occur?

(gdb) bt
#0  0x31a213ea in ?? ()
#1  0x5d334f11 in ?? ()
#2  0x5d3354c5 in ?? ()
#3  0x31a21381 in ?? ()
#4  0x0000000c in ?? ()
#5  0x00000000 in ?? ()


####
Handle<Value> LogCallback(const Arguments& args)
{
    String::Utf8Value val(args[0]);
    cout << *val << endl;
    return v8::Undefined();

}

int main()
{
    char *str = " function myfunc(obj) {    log('in myfunc....' + obj);  } ";

    HandleScope handleScope;

    // set global template
    Handle<ObjectTemplate> globalTemplate = ObjectTemplate::New();
    globalTemplate->Set(String::New("log"),FunctionTemplate::New(LogCallback));

    // Create conext and enter
    Handle<Context> context = Context::New(NULL, globalTemplate);
    Context::Scope contextScope(context);

    // Compile Script
    Handle<String> scriptString = String::New(str);
    Handle<Script> compiledScript  = Script::Compile(scriptString);

    // Run script
    Handle<Value> result = compiledScript->Run();

    Handle<Value> value = context->Global()->Get(String::New("myfunc"));

    Handle<Function> function = Handle<Function>::Cast(value);
    int argc = 1;
    Handle<Value> args[argc];

    // Commenting the below line causes crash with no stack info
    //args[0] = String::New("teststring");


    function->Call(context->Global(), argc, args);




    return 0;
}


####

Thanks,
Mark

Yang Guo

unread,
Nov 26, 2012, 4:41:44 AM11/26/12
to v8-u...@googlegroups.com
There is no stack trace because the crash occurs in generated code. There is no safety check for the argument of the function call, and since it's not set, it's presumably NULL or some other invalid value. Upon access by the function, you get a segfault. At this point, when you are in gdb (running a binary that has debug symbols), you can use 

print v8::internal::Isolate::Current()->PrintStack()

to print the javascript stack trace. I hope this helps.

Yang
Reply all
Reply to author
Forward
0 new messages