rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

thread 'main' panicked Not able to resolve vector element?: Continue ty.rs:1135

Open davehorner opened this issue 6 months ago • 2 comments

Ran into this the issue this evening.

  thread 'main' panicked at C:\Users\\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bindgen-0.59.2\src\ir\ty.rs:1135:22:
  Not able to resolve vector element?: Continue
  stack backtrace:
     0:     0x7ff7d10ab181 - std::backtrace_rs::backtrace::win64::trace
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\..\..\backtrace\src\backtrace\win64.rs:85
     1:     0x7ff7d10ab181 - std::backtrace_rs::backtrace::trace_unsynchronized
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
     2:     0x7ff7d10ab181 - std::sys::backtrace::_print_fmt
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\sys\backtrace.rs:66
     3:     0x7ff7d10ab181 - std::sys::backtrace::impl$0::print::impl$0::fmt
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\sys\backtrace.rs:39
     4:     0x7ff7d10cd06a - core::fmt::rt::Argument::fmt
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\core\src\fmt\rt.rs:177
     5:     0x7ff7d10cd06a - core::fmt::write
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\core\src\fmt\mod.rs:1449
     6:     0x7ff7d10a5fe7 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\io\mod.rs:1890
     7:     0x7ff7d10aafc5 - std::sys::backtrace::BacktraceLock::print
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\sys\backtrace.rs:42
     8:     0x7ff7d10ad192 - std::panicking::default_hook::closure$0
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panicking.rs:298
     9:     0x7ff7d10acf83 - std::panicking::default_hook
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panicking.rs:325
    10:     0x7ff7d10add6f - std::panicking::rust_panic_with_hook
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panicking.rs:831
    11:     0x7ff7d10adb09 - std::panicking::begin_panic_handler::closure$0
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panicking.rs:704
    12:     0x7ff7d10abcef - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\sys\backtrace.rs:168
    13:     0x7ff7d10ad70e - std::panicking::begin_panic_handler
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panicking.rs:695
    14:     0x7ff7d10d5b31 - core::panicking::panic_fmt
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\core\src\panicking.rs:75
    15:     0x7ff7d10d5fe0 - core::result::unwrap_failed
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\core\src\result.rs:1704
    16:     0x7ff7d0bccc2c - core::result::Result<T,E>::expect::h33c9635f1502dcb8
    17:     0x7ff7d0c3dd97 - bindgen::ir::ty::Type::from_clang_ty::hcbe8b5638cc2a240
    18:     0x7ff7d0c7f714 - <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty_with_id::hcd8709a0900c64a8
    19:     0x7ff7d0c7eb63 - <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty::h43ff05c4b88e8330
    20:     0x7ff7d0c8e34f - bindgen::ir::context::BindgenContext::collected_typerefs::h569744002b8def45
    21:     0x7ff7d0c8ff58 - bindgen::ir::context::BindgenContext::gen::h2e81ad3c7e94221c
    22:     0x7ff7d0c67501 - bindgen::codegen::codegen::h939a648876fae95b
    23:     0x7ff7d0bc4044 - <bindgen::BindgenOptions as core::default::Default>::default::h6a4d93f9fb54ac07
    24:     0x7ff7d0bc16cf - bindgen::Builder::generate::heb1b7f39e52da1b0
    25:     0x7ff7d0ba21bc - std::io::error::Error::is_interrupted::hd87c026066b5234b
    26:     0x7ff7d0ba3936 - core::ops::function::FnOnce::call_once::hdf24b0b09d39af80
    27:     0x7ff7d0ba10e9 - std::sys::backtrace::__rust_begin_short_backtrace::h49bdbdca75f5e856
    28:     0x7ff7d0ba357c - std::rt::lang_start::{{closure}}::h8e698a1f81fd1172
    29:     0x7ff7d10a076c - std::rt::lang_start_internal::closure$0
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\rt.rs:168
    30:     0x7ff7d10a076c - std::panicking::try::do_call
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panicking.rs:587
    31:     0x7ff7d10a076c - std::panicking::try
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panicking.rs:550
    32:     0x7ff7d10a076c - std::panic::catch_unwind
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\panic.rs:358
    33:     0x7ff7d10a076c - std::rt::lang_start_internal
                                 at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library\std\src\rt.rs:164
    34:     0x7ff7d0ba3567 - std::rt::lang_start::hd98bf51f734ee66e
    35:     0x7ff7d0ba25f9 - main
    36:     0x7ff7d10d3770 - invoke_main
                                 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    37:     0x7ff7d10d3770 - __scrt_common_main_seh
                                 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    38:     0x7ffb642ce8d7 - BaseThreadInitThunk
    39:     0x7ffb64e1c5dc - RtlUserThreadStart

https://processhacker.sourceforge.io/doc/native_8c_source.html#l01353 https://github.com/winsiderss/systeminformer/tree/master I am trying to write a wrapper for phlib.

use std::env;
use std::path::PathBuf;
use glob::glob;

fn main() {
    let mut cfg = cc::Build::new();
    cfg.include("../phlib/include")
       .include("../phnt/include")
       .include("../kphlib/include") // kphapi.h
       .cpp(true)
       .define("BUILDING_PHLIB", "1") // Define macro to fix dllimport/export
       .flag("-wd4706") // Suppress assignment warnings
       .flag("-wd4273") // Suppress inconsistent DLL linkage warnings
       .flag("-wd4013") // Suppress undefined function warnings
       .flag_if_supported("/std:c++17"); // Enable C++17

    for entry in glob("../phlib/*.c").unwrap() {
        cfg.file(entry.unwrap());
    }
    for entry in glob("../phlib/*.cpp").unwrap() {
        cfg.file(entry.unwrap());
    }
    cfg.compile("phlib");

    let bindings = bindgen::Builder::default()
        .header("../phlib/include/ph.h")
        .clang_arg("-I../phlib/include")
        .clang_arg("-I../phnt/include")
        .header("../kphlib/include/kphapi.h")
        .blocklist_type("std::vector") // Example: Block problematic type
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .layout_tests(false) // Disable layout tests if they cause issues
        .generate_comments(false) // Disable comments if they cause issues
        .generate()
        .expect("Unable to generate bindings");

    let out = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings.write_to_file(out.join("bindings.rs")).unwrap();
}

I'm not using autocxx-bindgen and the panic has been reported before in https://github.com/rust-lang/rust-bindgen/issues/2325 I'm not sure how to proceed this is my first bindgen of my own authorship.

also here: https://github.com/TheButlah/ovr_overlay/issues/24

davehorner avatar May 28 '25 01:05 davehorner

To debug this it'd be great to debug what C/C++ code are we really crashing in. See https://github.com/rust-lang/rust-bindgen/blob/main/CONTRIBUTING.md#using-creduce-to-minimize-test-cases for example.

emilio avatar May 28 '25 14:05 emilio

Thank you for the response. That's the issue based on the output I cant see what code is actually crashing.

https://github.com/winsiderss/systeminformer/compare/master...davehorner:systeminformer:master

I will look into creduce on my mac (nvm this is windows only..I will look into this though.) and see what that helps. above is the code; i decided to work on a separate c binary since I couldnt get the bindgen to work. would love to continue work on the sys. find phlib-sys in toplevel and env_search is my attempt reading env of other processes. which is giving me access violation; if anyone has any ideas on that.. i would appreciate. I see systeminformer perform this feat; so I know its possible.

davehorner avatar May 28 '25 14:05 davehorner

I'm not going to pursue this effort and I will close the ticket. thanks.

davehorner avatar Jun 19 '25 04:06 davehorner