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

feat(tracer): Record function calls and returns #36

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

smanilov
Copy link
Collaborator

@smanilov smanilov commented Jul 8, 2024

This commit also records function calls and returns from functions, without passing the actual arguments and values in either direction. That would be a follow-up.

Details:

  • get_variables is now public in tooling/debugger/src/context.rs; it is needed to extract the stack frame from the debugger;
  • drive-by: trace_metadata.json is also stored, because the frontend expects that too;
  • tail_diff_vecs is a generic utility function to extract the difference between two vectors; it has good documentation, so details within;
  • a local structure StackFrame is introduced, because the StackFrame in the debugger does not own its data; here, we need to remember the previous stack trace (a vector of StackFrame's) in order to discover function calls or returns, so we need to own the data;
  • a stack_trace field is added to TracingContext; see previous point;
  • the new fn get_stack_trace performs the conversion mentioned;
  • the old contents of update_record are the basis for tail_diff_vecs; the new contents use that function to perform the same operation as before; in addition, the core logic of the PR is here: return events are registered for dropped stack frames and call events are registered for new stack frames;
  • all tracing tests are updated, to reflect the new traces that are generated.

To test:

cargo test trace

@smanilov smanilov force-pushed the feat/trace-function-calls branch 3 times, most recently from 8797550 to b40f710 Compare July 9, 2024 06:57
This commit also records function calls and returns from functions,
without passing the actual arguments and values in either direction.
That would be a follow-up.

Details:
 * `get_variables` is now public in `tooling/debugger/src/context.rs`;
   it is needed to extract the stack frame from the debugger;
 * drive-by: `trace_metadata.json` is also stored, because the frontend
   expects that too;
 * `tail_diff_vecs` is a generic utility function to extract the
   difference between two vectors; it has good documentation, so details
   within;
 * a local structure `StackFrame` is introduced, because the `StackFrame` in
   the debugger does not own its data; here, we need to remember the
   previous stack trace (a vector of `StackFrame`'s) in order to discover
   function calls or returns, so we need to own the data;
 * a `stack_trace` field is added to `TracingContext`; see previous point;
 * the new `fn get_stack_trace` performs the conversion mentioned;
 * the old contents of `update_record` are the basis for
   `tail_diff_vecs`; the new contents use that function to perform the
   same operation as before; in addition, the core logic of the PR is
   here: return events are registered for dropped stack frames and call
   events are registered for new stack frames;
 * all tracing tests are updated, to reflect the new traces that are
   generated.

To test:

```
cargo test trace
```
@smanilov smanilov force-pushed the feat/trace-function-calls branch from b40f710 to 6f731db Compare July 9, 2024 07:15
@smanilov smanilov merged commit 38bfd20 into plonky2 Jul 9, 2024
@smanilov smanilov deleted the feat/trace-function-calls branch July 9, 2024 07:53
@@ -3,8 +3,10 @@
{ "Function": { "path_id": 0, "line": -1, "name": "<toplevel>" } },
{ "Call": { "function_id": 0, "args": [] } },
{ "Type": { "kind": 30, "lang_type": "None", "specific_info": { "kind": "None" } } },
{ "Path": "it-does-not-matter" },
{ "Path": "<relative-to-this>/src/main.nr" },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

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

Successfully merging this pull request may close these issues.

3 participants