lldb debug v8: 如何获取 v8 handle<T> 类型的类型 T 值

lldb debug v8: how to get the v8 the type T value of handle<T> type

我正在使用 lldb 调试 v8。

如何打印 Handle<String> 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>)  = {
  v8::internal::HandleBase = {
    location_ = 0x000000010f009a60
  }
}
(lldb) p * 
(v8::internal::String)  = {
  v8::internal::TorqueGeneratedString<v8::internal::String, v8::internal::Name> = {
    .....
  }
}

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

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

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

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

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