Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM Backtraces #1450

Open
Bike opened this issue Apr 1, 2023 · 2 comments
Open

VM Backtraces #1450

Bike opened this issue Apr 1, 2023 · 2 comments

Comments

@Bike
Copy link
Member

Bike commented Apr 1, 2023

We would like to support good backtraces for bytecode functions. This means that the existing backtrace machinery for native code needs to be extended so it can also handle bytecode functions.

The idea we've come with to support this is to make VM frames work a little more like native frames, by pushing the IP to the VM stack just before a call. The caller does not actually need this address to return, like you would natively, but its presence on the stack can be used to get the chain of function calls and make a backtrace.

In order to present any useful information we would also need DWARF-like line tables (#1449).

@Bike Bike changed the title Backtraces VM Backtraces Apr 1, 2023
@drmeister
Copy link
Collaborator

To reconstruct a backtrace, we would follow these steps:

  1. Get a system backtrace containing return PC addresses using the C backtrace(void **buffer, int size) function.
  2. We get a VM backtrace containing return IP values using our own backtrace_vm function. To achieve this, we will have to push/pop the IP within bytecode_vm every time we call from the VM. We must also maintain a linked list of VM frame pointers on the VM stack.
  3. We search for return PC addresses that fall within the bytecode_vm function executable code.
  4. For each bytecode_vm return PC address, we look in the VM stack for the corresponding IP value.
    There needs to be a one-to-one correspondence between bytecode_vm PC addresses and IP addresses. This will be violated if an error occurs when we are within the bytecode_vm function. If we could get retain perfect debug information of the IP register within the bytecode_vm function we could recover the IP wherever we are within the bytecode_vm function.

@drmeister
Copy link
Collaborator

With an IP backtrace, we can use DWARF-like line tables that our bytecode compiler will generate to convert IP addresses to source information. When our bytecode compiler generates these line tables along with the bytecode modules, it will register the bytecode line tables with clasp's runtime just like we register object files generated by llvm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants