【问题标题】:lldb debug v8: how to get the v8 the type T value of handle<T> typelldb调试v8:如何获取v8的handle<T>类型的类型T值
【发布时间】:2021-07-19 06:31:40
【问题描述】:

我正在使用 lldb 调试 v8。

如何打印Handle&lt;String&gt; Source 中的字符串?

调试过程如下:

(lldb) r
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
    frame #0: 0x000000010100536b libv8.dylib`v8::internal::Compiler::GetSharedFunctionInfoForScript(isolate=0x0000000118008000, source=Handle<v8::internal::String> @ 0x00007ffeefbfd4a0, script_details=0x00007ffeefbfd730, origin_options=(flags_ = 0), extension=0x0000000000000000, cached_data=0x0000000000000000, compile_options=kNoCompileOptions, no_cache_reason=kNoCacheNoReason, natives=NOT_NATIVES_CODE) at compiler.cc:2806:27
   2803     MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
   2804     solate* isolate, Handle<String> source,
   2805     ScriptCompiler::NoCacheReason no_cache_reason, NativesFlag natives) {
-> 2806   ScriptCompileTimerScope compile_timer(isolate, no_cache_reason);
   2807 
   2808   if (compile_options == ScriptCompiler::kNoCompileOptions ||
   2809       compile_options == ScriptCompiler::kEagerCompile) {
Target 0: (d8) stopped.
(lldb) p source
(v8::internal::Handle<v8::internal::String>) $9 = {
  v8::internal::HandleBase = {
    location_ = 0x000000010f009a60
  }
}
(lldb) p *$9 
(v8::internal::String) $10 = {
  v8::internal::TorqueGeneratedString<v8::internal::String, v8::internal::Name> = {
    .....
  }
}

【问题讨论】:

    标签: v8 lldb


    【解决方案1】:

    看看tools/lldb_commands.py。简而言之:配置您的 LLDB 以加载该脚本:

    echo "command script import /path/to/v8/tools/lldb_commands.py" >> ~/.lldbinit
    

    然后使用它提供的便捷命令,最重要的是job,它是“JavaScript 对象”的助记符。它需要原始指针值,您将在p *$9 的输出中某处看到ptr_ = ...,但您不需要手动检索它。示例:

    (lldb) job source->ptr_
    0x28c008109019: [String]: "console.log('hello world');"
    

    (旁注:tools/gdbinit 的功能往往比 tools/lldbinit 多,因为团队中的大多数人都使用 GDB。我们很乐意 accept patches 改进 LLDB 支持;与案例相关hand 将是 gdbinit 的 jh 快捷方式(仅允许 jh source),目前在 lldbinit 中没有等效项。)

    【讨论】:

    • 还有一个问题:使用gdb出现错误,所以我转向使用lldb。我使用了gdb ./d8; set args test.js; set directory /path/v8/src,然后我设置了断点b interpreter.cc:268,但它返回了No source file named interpreter.cc。你知道为什么吗?
    • 如果您使用的是共享库构建(这是调试模式下的默认设置),那么这是正常的。当 GDB 询问 Make breakpoint pending on future shared library load? (y or [n]) 时,只需说 'y'。我以gdb -args out/x64.debug/d8 test.js 启动GDB,我不确定你什么时候需要set directory,或者它是否应该包含/src 部分,所以你也可以尝试删除它。
    • 为什么在某些函数job source-&gt;ptr_ 运行良好,而在其他函数中它的输出是Failed to evaluate command _v8_internal_Print_Object((void*)(source-&gt;ptr_)) : error: &lt;user expression 2&gt;:1:50: no member named 'ptr_' in 'v8::internal::String' (void) _v8_internal_Print_Object((void*)(source-&gt;ptr_))(源与v8::internal::Handle&lt;v8::internal::String&gt; 的结构相同)。
    • 不知道,我自己没遇到过。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多