Skip to content

Debugging Тips аnd Тricks

Martin Bektchiev edited this page Apr 10, 2020 · 1 revision

This is a list of some useful tricks that can be used for easier diagnostics while working with the iOS Runtime.

CMake dump all defined vars:

get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

WebKit CMake options

-DENABLED_COMPILER_SANITIZERS=address | undefined | …

JSC Environment options

JSC_useDollarVM=1, for release builds needs the following in Options.cpp:

#ifdef NDEBUG
bool restrictedOptionsEnabled = true;
#else
bool restrictedOptionsEnabled = true;
#endif
  • JSC_usePoisoning 0 or better
#define ENABLE_POISON 0 in Platform.h
JSC_dumpModuleRecord=1
JSC_dumpModuleLoadingState=1
JSC_dumpOptions=1
JSC_logGC=2

Dynamically set options:

(lldb) p JSC::Options::setOption("logGC=2")
(lldb) p JSC::Options::setOption("logGC=0”)

Debugging internal JS methods

@$vm.print("***** ensureReigsetered Key: " + key + "\n");

Requires JSC_useDollarVM=1. In JSDollarVM::finishCreation are listed all supported functions.

Callstacks

Native callstack:

  • Obj-C Property NSThread.callStackSymbols
  • console.log(NSThread.callStackSymbols)

Getting current JS callstack from an ExecState:

(lldb) p NativeScript::dumpJsCallStack(Inspector::createScriptCallStack(execState, 20).get())
(lldb) p NativeScript::dumpExceptionJsCallStack(execState, exception)

Current thread’s call stack:

(lldb) ex dumpExecJsCallStack((JSC::ExecState*)[TNSRuntime current] -> _globalObject -> globalExec());

In release mode (inlines not available):

(lldb) p createScriptCallStack((JSC::ExecState*)object_getIvar((id)[TNSRuntime current], (id)class_getInstanceVariable([TNSRuntime class], "_globalObject")), 20)

Fill-in pointer value in next cmd

(lldb) p ((WTF::StringImpl*)(((Inspector::ScriptCallStack*)0x0000000109693b40)->m_frames.m_buffer[0].m_functionName.m_impl.m_ptr))->m_data8
dumpJsCallStack(createScriptCallStack((JSC::ExecState*)object_getIvar((id)[TNSRuntime current], (id)class_getInstanceVariable([TNSRuntime class], "_globalObject")).get())
ex dumpExecJsCallStack((JSC::ExecState*)object_getIvar((id)[TNSRuntime current], (id)class_getInstanceVariable([TNSRuntime class], "_globalObject"))
(lldb) p Inspector::createScriptCallStackFromException(execState, scope.m_vm.m_exception, 20)
(WTF::Ref<Inspector::ScriptCallStack, WTF::DumbPtrTraits<Inspector::ScriptCallStack> >) $5 = {
  m_ptr = 0x0000000104cbe100
}
(lldb) p NativeScript::dumpJsCallStack(*(const Inspector::ScriptCallStack*)0x0000000104cbe100))

Dump object’s static/instance methods/properties:

(lldb) po [[UIApplication sharedApplication] _methodDescription]