首页 > 解决方案 > 显示详细的转储

问题描述

嗨,我正在尝试使用 dart ffi,但我遇到了以下转储的问题


===== CRASH =====
si_signo=Segmentation fault(11), si_code=1, si_addr=(nil)
version=2.12.0-157.0.dev (dev) (Wed Dec 16 01:04:40 2020 -0800) on "linux_x64"
pid=262571, thread=262578, isolate_group=main(0x373e8c0), isolate=main(0x373f140)
isolate_instructions=17fde20, vm_instructions=17fde20
  pc 0x00007f1633a00543 fp 0x00007f1656c1d540 wasm_instance_exports+0x13
  pc 0x00007f163ce30505 fp 0x00007f1656c1d578 Unknown symbol
  pc 0x00007f163ce3023f fp 0x00007f1656c1d5e0 Unknown symbol
  pc 0x00007f163ce25553 fp 0x00007f1656c1d6b8 Unknown symbol
  pc 0x00007f163ce2453c fp 0x00007f1656c1d700 Unknown symbol
  pc 0x00007f163ce24233 fp 0x00007f1656c1d728 Unknown symbol
  pc 0x00007f163ce2419f fp 0x00007f1656c1d750 Unknown symbol
  pc 0x00007f163ce240cf fp 0x00007f1656c1d7a8 Unknown symbol
  pc 0x00007f163ce2300e fp 0x00007f1656c1d7d8 Unknown symbol
  pc 0x00007f163ce22d72 fp 0x00007f1656c1d838 Unknown symbol
  pc 0x00007f163ce2276e fp 0x00007f1656c1d870 Unknown symbol
  pc 0x00007f1656d8265f fp 0x00007f1656c1d8e8 Unknown symbol
-- End of DumpStackTrace
[exit     : sp(0) fp(0x7f1656c1d540) pc(0)]
[dart     : sp(0x7f1656c1d550) fp(0x7f1656c1d578) pc(0x7f163ce30505) *dart:ffi_::_FfiTrampoline ]
[dart     : sp(0x7f1656c1d588) fp(0x7f1656c1d5e0) pc(0x7f163ce3023f) file:///home/kingwill101/code/wasm-dart/generated_bindings.dart_Wasmer_wasm_instance_exports ]
[dart     : sp(0x7f1656c1d5f0) fp(0x7f1656c1d6b8) pc(0x7f163ce25553) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_helloWorld__async_op ]
[dart     : sp(0x7f1656c1d6c8) fp(0x7f1656c1d700) pc(0x7f163ce2453c) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_helloWorld ]
[dart     : sp(0x7f1656c1d710) fp(0x7f1656c1d728) pc(0x7f163ce24233) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_main ]
[dart     : sp(0x7f1656c1d738) fp(0x7f1656c1d750) pc(0x7f163ce2419f) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_main_main ]
[dart     : sp(0x7f1656c1d760) fp(0x7f1656c1d7a8) pc(0x7f163ce240cf) dart:core__Closure@0150898_dyn_call ]
[dart     : sp(0x7f1656c1d7b8) fp(0x7f1656c1d7d8) pc(0x7f163ce2300e) dart:isolate_::__delayEntrypointInvocation@1026248_<anonymous closure> ]
[dart     : sp(0x7f1656c1d7e8) fp(0x7f1656c1d838) pc(0x7f163ce22d72) dart:core__Closure@0150898_dyn_call ]
[dart     : sp(0x7f1656c1d848) fp(0x7f1656c1d870) pc(0x7f163ce2276e) dart:isolate__RawReceivePortImpl@1026248__handleMessage@1026248 ]
[entry    : sp(0x7f1656c1d880) fp(0x7f1656c1d8e8) pc(0x7f1656d8265f)]
Aborted (core dumped)

我不确定如何更好地输出究竟是什么导致了错误,因为它感觉有点神秘。

代码在这里崩溃

 Pointer<wasm_extern_vec_t> exports = allocate<wasm_extern_vec_t>();
  w.wasm_extern_vec_new_empty(exports);
  w.wasm_instance_exports(instance, exports);

ffi胶水代码

typedef _c_wasm_instance_exports = ffi.Void Function(
  ffi.Pointer<wasm_instance_t> arg0,
  ffi.Pointer<wasm_extern_vec_t> out,
);

typedef _dart_wasm_instance_exports = void Function(
  ffi.Pointer<wasm_instance_t> arg0,
  ffi.Pointer<wasm_extern_vec_t> out,
);

void wasm_instance_exports(
    ffi.Pointer<wasm_instance_t> arg0,
    ffi.Pointer<wasm_extern_vec_t> out,
  ) {
    _wasm_instance_exports ??= _dylib.lookupFunction<_c_wasm_instance_exports,
        _dart_wasm_instance_exports>('wasm_instance_exports');
    return _wasm_instance_exports(
      arg0,
      out,
    );
  }

所以,是的,我可以参考有关调查这些崩溃的任何资源吗?

##编辑##

该 api 是 rust wasmer 项目的 C 导出 api

导出的标题是

#ifndef WASM_API_EXTERN
#ifdef _WIN32
#define WASM_API_EXTERN __declspec(dllimport)
#else
#define WASM_API_EXTERN
#endif
#endif

WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);

锈实施在

https://github.com/wasmerio/wasmer/blob/0a4a2c7d24d718e48eb9aa895292d3cbf950f7ed/lib/c-api/src/wasm_c_api/instance.rs#L178

更详细的代码

Pointer<wasm_byte_vec_t> wat = allocate<wasm_byte_vec_t>() ;
  Pointer<wasm_byte_vec_t> wasm_bytes  = allocate<wasm_byte_vec_t>();

  w.wasm_byte_vec_new(wat, code.length, Utf8.toUtf8(code).cast());
  w.wat2wasm(wat, wasm_bytes);

  var engine = w.wasm_engine_new();
  var store = w.wasm_store_new(engine);
  var module = w.wasm_module_new(store, wasm_bytes);

  if (module == nullptr) {
    print("> Error compiling module!\n");
    return;
  }

  w.wasm_byte_vec_delete(wasm_bytes);

  Pointer<wasm_extern_vec_t> imports = allocate<wasm_extern_vec_t>();
  w.wasm_extern_vec_new_empty(imports);

 var  instance = w.wasm_instance_new(store, module, imports, nullptr);

  if (instance != nullptr) {
    print("> Error instantiating module %d!\n");

    return ;
  }
  //
 Pointer<wasm_extern_vec_t> exports = allocate<wasm_extern_vec_t>();
  w.wasm_extern_vec_new_empty(exports);
  w.wasm_instance_exports(instance, exports);
  
  if (exports.ref.size == 0) {
    print("> Error accessing exports!\n");
  
    return;
  }

标签: dartdart-ffi

解决方案


推荐阅读