File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1
- import { WASI , useAll } from "uwasi" ;
1
+ import { WASI , useAll , useTrace } from "uwasi" ;
2
2
import fs from "node:fs/promises" ;
3
3
4
4
async function main ( ) {
5
5
const wasi = new WASI ( {
6
6
args : process . argv . slice ( 2 ) ,
7
- features : [ useAll ( ) ] ,
7
+ features : [ useTrace ( [ useAll ( ) ] ) ] ,
8
8
} ) ;
9
9
const bytes = await fs . readFile ( process . argv [ 2 ] ) ;
10
10
const { instance } = await WebAssembly . instantiate ( bytes , {
Original file line number Diff line number Diff line change
1
+ import { WASIFeatureProvider } from "../options" ;
2
+
3
+ export function useTrace ( features : WASIFeatureProvider [ ] ) : WASIFeatureProvider {
4
+ return ( options , abi , memoryView ) => {
5
+ let wasiImport : WebAssembly . ModuleImports = { } ;
6
+ for ( const useFeature of features ) {
7
+ const imports = useFeature ( options , abi , memoryView ) ;
8
+ wasiImport = { ...wasiImport , ...imports } ;
9
+ }
10
+ for ( const key in wasiImport ) {
11
+ const original = wasiImport [ key ] ;
12
+ if ( typeof original !== 'function' ) {
13
+ continue ;
14
+ }
15
+ wasiImport [ key ] = ( ...args : any [ ] ) => {
16
+ const result = original ( ...args ) ;
17
+ console . log ( `[uwasi-tracing] ${ key } (${ args . map ( a => JSON . stringify ( a ) ) . join ( ', ' ) } ) => ${ result } ` ) ;
18
+ return result ;
19
+ }
20
+ }
21
+ return wasiImport ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export * from "./features/environ";
8
8
export * from "./features/fd" ;
9
9
export * from "./features/proc" ;
10
10
export * from "./features/random" ;
11
+ export * from "./features/tracing" ;
11
12
12
13
export class WASI {
13
14
/**
You can’t perform that action at this time.
0 commit comments