@@ -104,19 +104,14 @@ var LibraryStackTrace = {
104104 var match ;
105105
106106 if ( match = / \b w a s m - f u n c t i o n \[ \d + \] : ( 0 x [ 0 - 9 a - f ] + ) / . exec ( frame ) ) {
107- // some engines give the binary offset directly, so we use that as return address
107+ // Wasm engines give the binary offset directly, so we use that as return address
108108 return + match [ 1 ] ;
109- } else if ( match = / \b w a s m - f u n c t i o n \[ ( \d + ) \] : ( \d + ) / . exec ( frame ) ) {
110- // Older versions of v8 give function index and offset in the function,
111- // so we try using the offset converter. If that doesn't work,
112- // we pack index and offset into a "return address"
113- #if ! USE_OFFSET_CONVERTER
114- abort ( 'Legacy backtrace format detected but -sUSE_OFFSET_CONVERTER not present.' )
115- #else
116109#if ASSERTIONS
117- assert ( wasmOffsetConverter , 'wasmOffsetConverter global not found' ) ;
118- #endif
119- return wasmOffsetConverter . convert ( + match [ 1 ] , + match [ 2 ] ) ;
110+ } else if ( match = / \b w a s m - f u n c t i o n \[ ( \d + ) \] : ( \d + ) / . exec ( frame ) ) {
111+ // Older versions of v8 (e.g node v10) give function index and offset in
112+ // the function. That format is not supported since it does not provide
113+ // the information we need to map the frame to a global program counter.
114+ warnOnce ( 'legacy backtrace format detected, this version of v8 is no longer supported by the emscripten backtrace mechanism' )
120115#endif
121116 } else if ( match = / : ( \d + ) : \d + (?: \) | $ ) / . exec ( frame ) ) {
122117 // If we are in js, we can use the js line number as the "return address".
@@ -205,12 +200,12 @@ var LibraryStackTrace = {
205200 $saveInUnwindCache__deps : [ '$UNWIND_CACHE' , '$convertFrameToPC' ] ,
206201 $saveInUnwindCache__internal : true ,
207202 $saveInUnwindCache : ( callstack ) => {
208- callstack . forEach ( ( frame ) => {
209- var pc = convertFrameToPC ( frame ) ;
203+ for ( var line of callstack ) {
204+ var pc = convertFrameToPC ( line ) ;
210205 if ( pc ) {
211- UNWIND_CACHE [ pc ] = frame ;
206+ UNWIND_CACHE [ pc ] = line ;
212207 }
213- } ) ;
208+ }
214209 } ,
215210
216211 // Unwinds the stack from a cached PC value. See emscripten_stack_snapshot for
@@ -242,32 +237,25 @@ var LibraryStackTrace = {
242237 } ,
243238
244239 // Look up the function name from our stack frame cache with our PC representation.
245- emscripten_pc_get_function__deps : [ '$UNWIND_CACHE' , 'free' , '$stringToNewUTF8' ] ,
240+ emscripten_pc_get_function__deps : [ '$UNWIND_CACHE' , 'free' , '$stringToNewUTF8' , 'emscripten_stack_snapshot' ] ,
246241 // Don't treat allocation of _emscripten_pc_get_function.ret as a leak
247242 emscripten_pc_get_function__noleakcheck : true ,
248243 emscripten_pc_get_function : ( pc ) => {
249- var name ;
250- if ( pc & 0x80000000 ) {
251- // If this is a JavaScript function, try looking it up in the unwind cache.
252- var frame = UNWIND_CACHE [ pc ] ;
253- if ( ! frame ) return 0 ;
244+ var frame = UNWIND_CACHE [ pc ] ;
245+ if ( ! frame ) return 0 ;
254246
255- var match ;
256- if ( match = / ^ \s + a t ( . * ) \( . * \) $ / . exec ( frame ) ) {
257- name = match [ 1 ] ;
258- } else if ( match = / ^ ( . + ? ) @ / . exec ( frame ) ) {
259- name = match [ 1 ] ;
260- } else {
261- return 0 ;
262- }
247+ var name ;
248+ var match ;
249+ if ( match = / ^ \s + a t . * \. w a s m \. ( . * ) \( . * \) $ / . exec ( frame ) ) {
250+ name = match [ 1 ] ;
251+ } else if ( match = / ^ \s + a t ( . * ) \( . * \) $ / . exec ( frame ) ) {
252+ name = match [ 1 ] ;
253+ } else if ( match = / ^ ( . + ? ) @ / . exec ( frame ) ) {
254+ name = match [ 1 ] ;
263255 } else {
264- #if ! USE_OFFSET_CONVERTER
265- abort ( 'Cannot use emscripten_pc_get_function on native functions without -sUSE_OFFSET_CONVERTER' ) ;
266256 return 0 ;
267- #else
268- name = wasmOffsetConverter . getName ( pc ) ;
269- #endif
270257 }
258+
271259 _free ( _emscripten_pc_get_function . ret ?? 0 ) ;
272260 _emscripten_pc_get_function . ret = stringToNewUTF8 ( name ) ;
273261 return _emscripten_pc_get_function . ret ;
0 commit comments