Skip to content

Some statements (assignment?) have no line representation in debug.pc2line_buf table and don't work with find_line_num #458

@chmeyer-ms

Description

@chmeyer-ms

I've been using find_line_num to get line numbers from opcodes. I noticed that certain lines don't have the correct line number in the table.

For example, given this snippet:

let str1 = 'my string';
let str2 = 'another str';
let str3 = '3 string';
let str4 = str1 + str2 + str3;

The opcodes (from js_dump_function_bytecode) are:

opcodes:
      push_this
      if_false8 4
      return_undef
  4:  push_atom_value "my string"
      put_var_ref0 0: str1
      push_atom_value "another str"
      put_var_ref1 1: str2
      push_atom_value "3 string"
      put_var_ref2 2: str3
      get_var_ref_check 0: str1
      get_var_ref_check 1: str2
      add
      get_var_ref_check 2: str3
      add
      put_var_ref3 3: str4
      undefined
      return_async

And the PC to Line output (from 'dump_pc2line') is:

 PC  LINE   COL
  -     1     1
 22     4    12 <-- no 2 or 3
 25     4    19
 28     4    17
 29     4    26
 32     4    24

No line 2 or 3.

But if the snippet is altered to do more than simple assignment like so:

let str1 = 'my' + 'string';
let str2 = 'another' + 'str';
let str3 = '3' + 'string';
let str4 = str1 + str2 + str3;

The opcodes are:

opcodes:
    push_this
    if_false8 4
    return_undef
4:  push_atom_value my
    push_atom_value string
    add
    put_var_ref0 0: str1
    push_atom_value another
    push_atom_value str
    add
    put_var_ref1 1: str2
    push_const8 0: "3"
    push_atom_value string
    add
    put_var_ref2 2: str3
    get_var_ref_check 0: str1
    get_var_ref_check 1: str2
    add
    get_var_ref_check 2: str3
    add
    put_var_ref3 3: str4
    undefined
    return_async

The PC to Line output is:

PC  LINE   COL
 -     1     1
14     1    17
26     2    22 <-- line 2 and 3 are back
35     3    16
37     4    12
40     4    19
43     4    17
44     4    26
47     4    24

This is problematic for our custom debugging solution.

I haven't verified the bisect, but it worked in the 2024-01-13 release and I suspect it was changed with this commit that added column support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions