-
Notifications
You must be signed in to change notification settings - Fork 39
fix(codegen): emit trace events to fix stack traces in debugger #507
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use midenc_dialect_hir::HirOpBuilder; | ||
use midenc_hir::{ | ||
dialects::builtin::FunctionRef, | ||
interner::{symbols, Symbol}, | ||
smallvec, Builder, SmallVec, SourceSpan, SymbolNameComponent, ValueRef, | ||
}; | ||
|
||
use crate::{error::WasmResult, module::function_builder_ext::FunctionBuilderExt}; | ||
|
||
pub(crate) const MODULE_ID: &str = "intrinsics::debug"; | ||
pub(crate) const MODULE_PREFIX: &[SymbolNameComponent] = &[ | ||
SymbolNameComponent::Root, | ||
SymbolNameComponent::Component(symbols::Intrinsics), | ||
SymbolNameComponent::Component(symbols::Debug), | ||
]; | ||
|
||
/// Convert a call to a debugging intrinsic function into instruction(s) | ||
pub(crate) fn convert_debug_intrinsics<B: ?Sized + Builder>( | ||
function: Symbol, | ||
_function_ref: Option<FunctionRef>, | ||
args: &[ValueRef], | ||
builder: &mut FunctionBuilderExt<'_, B>, | ||
span: SourceSpan, | ||
) -> WasmResult<SmallVec<[ValueRef; 1]>> { | ||
match function.as_str() { | ||
"break" => { | ||
assert_eq!(args.len(), 0, "{function} takes exactly one argument"); | ||
builder.breakpoint(span)?; | ||
Ok(smallvec![]) | ||
} | ||
_ => panic!("no debug intrinsics found named '{function}'"), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,7 @@ ub = {} | |
account = {} | ||
blake3 = {} | ||
crypto = {} | ||
debug = {} | ||
dsa = {} | ||
hashes = {} | ||
intrinsics = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[link(wasm_import_module = "miden:core-import/[email protected]")] | ||
extern "C" { | ||
#[link_name = "break"] | ||
fn extern_break(); | ||
} | ||
|
||
/// Sets a breakpoint in the emitted Miden Assembly at the point this function is called. | ||
#[inline(always)] | ||
#[track_caller] | ||
pub fn breakpoint() { | ||
unsafe { | ||
extern_break(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use core::ops::{Deref, DerefMut}; | ||
|
||
pub mod debug; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that I understand why it's public. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unlike the other two modules, which we're wildcard re-exporting the contents of from the root, we only need to export the |
||
mod felt; | ||
mod word; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface with the
break
function should be in our core-import WIT file attests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit
, otherwise wit-component errors on core module import. I'm in the middle of splitting our WIT files and moving them to SDK crates at #505, and I can take care of it there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah noted, I'll leave the fix to you then!