How to use v8 Comment in CSA?

132 views
Skip to first unread message

18楼梦想改造家

unread,
Sep 23, 2024, 11:23:04 AM9/23/24
to v8-dev
Hi, anyone. 

In v8 CSA subsystem, there are some code like this:

``` c++
void AccessorAssembler::GenericPropertyLoad(
    TNode<HeapObject> lookup_start_object, TNode<Map> lookup_start_object_map,
    TNode<Int32T> lookup_start_object_instance_type, const LoadICParameters* p,
    Label* slow, UseStubCache use_stub_cache) {
  DCHECK_EQ(lookup_start_object, p->lookup_start_object());
  ExitPoint direct_exit(this);

  Comment("key is unique name");   // [+] @a  
  Label if_found_on_lookup_start_object(this), if_property_dictionary(this),
      lookup_prototype_chain(this), special_receiver(this);
}
```

At @a, we have a comment , I want to use it to trace the flow. But I don't know how to use it? So I have 2 question.

1. How to enable the Comment, is it worked in release version?
2. If we enable it, where the comment will Print to?

Thanks!

Jakob Kummerow

unread,
Sep 23, 2024, 11:40:25 AM9/23/24
to v8-...@googlegroups.com
These are "code comments". You'll need to enable both the GN arg v8_code_comments = true and the command-line flag --code-comments; since CSA is used only in mksnapshot you need to either:
- pass the latter flag to a manual invocation of mksnapshot
- or enable it by default in flag-definitions.h and recompile normally,
- or, most conveniently, set the GN arg v8_enable_snapshot_code_comments = true (which implies the other GN arg and the command-line flag).
You can then see these comments when disassembling builtins (with the jco GDB macro). You may also want to use --nodebug-code to skip a large number of generated checks that tend to be confusing when reading code.

Code comments cannot be used for tracing control flow at runtime, they're only helpful for making sense of the disassembly of generated code. Control flow can be traced with the various Print(...) overloads in CSA, which will print to stdout.

18楼梦想改造家

unread,
Sep 23, 2024, 11:43:53 AM9/23/24
to v8-dev
It's very useful for me. Thanks very much!

18楼梦想改造家

unread,
Sep 23, 2024, 11:59:53 AM9/23/24
to v8-dev
BTW, is it only worked for gdb, could it worked for windbg?

在2024年9月23日星期一 UTC+8 23:40:25<Jakob Kummerow> 写道:

Jakob Kummerow

unread,
Sep 23, 2024, 12:11:18 PM9/23/24
to v8-...@googlegroups.com
I'm only familiar with tools/gdbinit, which is GDB-specific.
There is tools/v8windbg/ though, which is presumably helpful for windbg.

seth.b...@microsoft.com

unread,
Sep 23, 2024, 1:06:21 PM9/23/24
to v8-dev
v8windbg is mostly focused on making the Locals pane show the fields in V8's heap objects. It also includes a few things you can use in `dx` commands: `dx @$v8object(0x4589af445d)` prints an object, and `dx @$jsstack()` prints some info about the JavaScript frames on the stack. Unfortunately, it doesn't know anything about CSA code comments. The strategy I've used in the past is to invoke `mksnapshot --print-code --code-comments <and the rest of the normal arguments>` and redirect its output to a file, so then I have a complete listing of all builtins.

Best,
Seth

Reply all
Reply to author
Forward
0 new messages