[dolphin][1.4] can not dump js stack in gdb and can not get the complete callstacks when involving js stack

NEW
Unassigned

Status

Firefox OS
General
4 years ago
4 years ago

People

(Reporter: ying.xu, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

4 years ago
for 1.3,we can use the way below to get js stack in gdb. 
(gdb) set print elements 0
(gdb) p nsXPConnect::gSelf->GetCurrentJSContext()
$1 = (struct JSContext *) 0x436197c0
(gdb) printf "%s", xpc_PrintJSStack(0x436197c0,0,0,0)

but for 1.4, we meet some problems.
we get stuck at GetCurrentJSContext, and can not get the result.

So, how to get js stack for 1.4?
(Reporter)

Updated

4 years ago
Flags: needinfo?(cyu)
I don't see this problem. It's working on 1.4 and m-c.

Breakpoint 1, nsFrameLoader::ReallyStartLoadingInternal (this=0x444c8be0) at ../../../dist/include/nsCOMPtr.h:863
863               return reinterpret_cast<T*>(mRawPtr);
(gdb) printf "%s", nsXPConnect::gSelf->DebugPrintJSStack(0,0,0)
0 aw__render() ["app://system.gaiamobile.org/js/app_window.js":504]
1 aw_render() ["app://system.gaiamobile.org/js/app_window.js":532]
2 AppWindow() ["app://system.gaiamobile.org/js/app_window.js":44]
3 awf_launch() ["app://system.gaiamobile.org/js/app_window_factory.js":109]
4 awf_handleEvent() ["app://system.gaiamobile.org/js/app_window_factory.js":62]
(gdb)
Flags: needinfo?(cyu)
(Reporter)

Comment 2

4 years ago
OK, I will try it agian

And I find I can not get the complete callstack when involving js stack,such as:

#0  nsFrameLoader::SetVisible (this=0xb239f1c0, aVisible=true) at ../../../../gecko/content/base/src/nsFrameLoader.cpp:2632
#1  0xb4d853ea in NS_InvokeByIndex (that=<optimized out>, methodIndex=<optimized out>, paramCount=<optimized out>, params=<optimized out>)
    at ../../../../../../../gecko/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_arm.cpp:164
#2  0xb533e564 in Invoke (this=0xbeb4d158) at ../../../../gecko/js/xpconnect/src/XPCWrappedNative.cpp:2393
#3  Call (this=0xbeb4d158) at ../../../../gecko/js/xpconnect/src/XPCWrappedNative.cpp:1734
#4  XPCWrappedNative::CallMethod (ccx=..., mode=<optimized out>) at ../../../../gecko/js/xpconnect/src/XPCWrappedNative.cpp:1701
#5  0xb5341174 in XPC_WN_GetterSetter (cx=0xa9ff81c0, argc=1, vp=0xbeb4d5d0)
    at ../../../../gecko/js/xpconnect/src/XPCWrappedNativeJSOps.cpp:1307
#6  0xb5c8e8d2 in CallJSNative (args=..., 
    native=0xb534104d <XPC_WN_Shared_Convert(JSContext*, JS::HandleObject, JSType, JS::MutableHandleValue)+340>, cx=0xa9ff81c0)
    at ../../../gecko/js/src/jscntxtinlines.h:239
#7  js::Invoke (cx=cx@entry=0xa9ff81c0, args=..., construct=construct@entry=js::NO_CONSTRUCT) at ../../../gecko/js/src/vm/Interpreter.cpp:476
#8  0xb5c8f302 in js::Invoke (cx=cx@entry=0xa9ff81c0, thisv=..., fval=..., argc=argc@entry=1, argv=argv@entry=0xbeb4d760, rval=rval@entry=...)
    at ../../../gecko/js/src/vm/Interpreter.cpp:532
#9  0xb5c8f3dc in js::InvokeGetterOrSetter (cx=cx@entry=0xa9ff81c0, obj=0xaa3b4760, fval=..., argc=argc@entry=1, argv=argv@entry=0xbeb4d760, 
    rval=rval@entry=...) at ../../../gecko/js/src/vm/Interpreter.cpp:604
#10 0xb5c2acfe in set (vp=..., strict=true, receiver=..., obj=..., cx=0xa9ff81c0, this=<optimized out>)
    at ../../../gecko/js/src/vm/Shape-inl.h:95
#11 js::NativeSet<(js::ExecutionMode)0> (cxArg=cxArg@entry=0xa9ff81c0, obj=obj@entry=..., receiver=..., receiver@entry=..., 
    shape=shape@entry=..., strict=strict@entry=true, vp=...) at ../../../gecko/js/src/jsobj.cpp:4401
#12 0xb5c2cf00 in js::baseops::SetPropertyHelper<(js::ExecutionMode)0> (cxArg=0xa9ff81c0, obj=obj@entry=..., receiver=..., id=..., 
    defineHow=defineHow@entry=0, vp=..., strict=strict@entry=true) at ../../../gecko/js/src/jsobj.cpp:5076
#13 0xb5c85f16 in setGeneric (strict=true, vp=..., id=..., receiver=..., obj=..., cx=<optimized out>) at ../../../gecko/js/src/jsobj.h:1041
#14 js::SetProperty<true> (cx=<optimized out>, obj=..., id=..., value=...) at ../../../gecko/js/src/vm/Interpreter.cpp:3732
#15 0xb5d65646 in js::jit::DoSetPropFallback (cx=0xa9ff81c0, frame=<optimized out>, stub=0xaaf38370, lhs=..., rhs=..., res=...)
    at ../../../gecko/js/src/jit/BaselineIC.cpp:7263
#16 0xb37a4a20 in ?? ()    //here, something wrong
#17 0xb37a4a20 in ?? ()
(Reporter)

Updated

4 years ago
Summary: [dolphin][1.4] how to dump js stack in gdb → [dolphin][1.4] can not dump js stack in gdb and can not get the complete callstacks when involving js stack
(In reply to ying.xu from comment #2)
> #16 0xb37a4a20 in ?? ()    //here, something wrong
> #17 0xb37a4a20 in ?? ()

This is because of JIT. If you really want the stack below it, you can turn off JIT.
(Reporter)

Comment 4

4 years ago
you mean these macros?
I don't know how to turn off JIT

MOZ_ARG_DISABLE_BOOL(ion,
[  --disable-ion      Disable use of the IonMonkey JIT],
  ENABLE_ION= )

MOZ_ARG_DISABLE_BOOL(yarr-jit,
[  --disable-yarr-jit    Disable YARR JIT support],
  ENABLE_YARR_JIT= )
 You don't need to rebuild. A quick solution is to pref off "javascript.options.baselinejit". JavaScript will run much slower, but if you only want to get the full stack then it's fine.
This is quite simple if you are not running jitted code at the moment.

1. Find a |JSContext *| on the current stack, often named |cx|.

(In reply to ying.xu from comment #2)
> #15 0xb5d65646 in js::jit::DoSetPropFallback (cx=0xa9ff81c0,
> frame=<optimized out>, stub=0xaaf38370, lhs=..., rhs=..., res=...)
>     at ../../../gecko/js/src/jit/BaselineIC.cpp:7263
> #16 0xb37a4a20 in ?? ()    //here, something wrong
> #17 0xb37a4a20 in ?? ()

Here, cx = 0xa9ff81c0.

2. then run "(gdb) call js_DumpBacktrace((JSContext*) 0xa9ff81c0)"

And this should print a gdb-like backtrace which show the location of the calls.

If you want something which behaves more like "(gdb) where full", then do "(gdb) call dumpJSStack()"



If you are in the middle of jitted code, then you should try to see if you can reproduce it without Ion / baseline.  If you cannot then you need to know a bit more about the stack layout[1] that we produce.

In such case I recommend doing:

(gdb) x /128 $sp

and locate sections of the stack which are alternating large and small numbers.


Also, as this is a recurrent kind of question, we have a web page[2] which is listing common tricks which are useful to know when debugging the JIT / around the JITs.  Feel free to contribute back if you have your own trick ;)

[1] http://dxr.mozilla.org/mozilla-central/source/js/src/jit/IonFrames.h#322
[2] https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Hacking_Tips
(Reporter)

Comment 7

4 years ago
another problem
If I run a command like below, I will get error

(gdb) printf "%s", xpc_PrintJSStack(0xaa712b00,0,0,0)
Cannot resolve function xpc_PrintJSStack to any overloaded instance

But If I call like this, I can get the js stack
Did I mis-use the function xpc_PrintJSStack?

(gdb) p xpc_PrintJSStack                             
$3 = {char *(JSContext *, bool, bool, bool)} 0xb529240c <xpc_PrintJSStack(JSContext*, bool, bool, bool)>
(gdb) printf "%s", 0xb529240c(0xaa712b00,0,0,0)
0 bm_focus() ["app://system.gaiamobile.org/js/browser_mixin.js":129]
1 anonymous() ["app://system.gaiamobile.org/js/app_transition_controller.js":273]
2 atc_handle_opened() ["app://system.gaiamobile.org/js/app_transition_controller.js":258]
3 atc_handleEvent() ["app://system.gaiamobile.org/js/app_transition_controller.js":335]
4 aw_broadcast() ["app://system.gaiamobile.org/js/app_window.js":1162]
5 anonymous() ["app://system.gaiamobile.org/js/app_window.js":1134]
6 atc_changeTransitionState() ["app://system.gaiamobile.org/js/app_transition_controller.js":110]
7 anonymous() ["app://system.gaiamobile.org/js/app_transition_controller.js":281]
8 aw_open() ["app://system.gaiamobile.org/js/app_window.js":1645]
9 anonymous() ["app://system.gaiamobile.org/js/app_window_manager.js":195]
(In reply to ying.xu from comment #7)
> But If I call like this, I can get the js stack
> Did I mis-use the function xpc_PrintJSStack?
> 
> (gdb) p xpc_PrintJSStack                             
> $3 = {char *(JSContext *, bool, bool, bool)} 0xb529240c
> <xpc_PrintJSStack(JSContext*, bool, bool, bool)>
> (gdb) printf "%s", 0xb529240c(0xaa712b00,0,0,0)

Yes, you have to free the buffer. in addition for printing it, or call xpc_DumpJSStack, or following what I mentioned in comment 6.

If nothing is printed, then have a look at the logcat.
You need to log in before you can comment on or make changes to this bug.