rust-lang / rust-lang/rust-bindgen

Bad clang flags results in "libclang: crash detected during parsing" but we can report better errors than this

Open
#629 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-error-reporting A-libclang
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Hello, looks like I have some kind of infrastructure problem.

Every time I invoke bindgen it complains in the same way, i.e. it does not depend on the input file:

$ RUST_BACKTRACE=full bindgen Input.h  -- -x  
libclang: crash detected during parsing: {
  'source_filename' : ''
  'command_line_args' : ['-x', '-isystem', '/usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0/../../../../include/c++/6.2.0', '-isystem', '/usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0/../../../../include/x86_64-linux-gnu/c++/6.2.0', '-isystem', '/usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0/../../../../include/c++/6.2.0/backward', '-isystem', '/usr/local/include', '-isystem', '/usr/lib/llvm-3.9/bin/../lib/clang/3.9.0/include', '-isystem', '/usr/include/x86_64-linux-gnu', '-isystem', '/usr/include', 'Input.h'],
  'unsaved_files' : [],
  'options' : 1,
}
thread 'main' panicked at 'TranslationUnit::parse', /checkout/src/libcore/option.rs:794
stack backtrace:
   0:     0x559fa4225c83 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::h0c49f46a3545f908
                               at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x559fa4221fe4 - std::sys_common::backtrace::_print::hcef39a9816714c4c
                               at /checkout/src/libstd/sys_common/backtrace.rs:71
   2:     0x559fa4229837 - std::panicking::default_hook::{{closure}}::h7c3c94835e02f846
                               at /checkout/src/libstd/sys_common/backtrace.rs:60
                               at /checkout/src/libstd/panicking.rs:355
   3:     0x559fa42293bb - std::panicking::default_hook::h0bf7bc3112fb107d
                               at /checkout/src/libstd/panicking.rs:371
   4:     0x559fa4229d0b - std::panicking::rust_panic_with_hook::ha27630c950090fec
                               at /checkout/src/libstd/panicking.rs:549
   5:     0x559fa4229be4 - std::panicking::begin_panic::heb97fa3158b71158
                               at /checkout/src/libstd/panicking.rs:511
   6:     0x559fa4229b19 - std::panicking::begin_panic_fmt::h8144403278d84748
                               at /checkout/src/libstd/panicking.rs:495
   7:     0x559fa4229aa7 - rust_begin_unwind
                               at /checkout/src/libstd/panicking.rs:471
   8:     0x559fa425534d - core::panicking::panic_fmt::h3b0cca53e68f9654
                               at /checkout/src/libcore/panicking.rs:69
   9:     0x559fa42553dd - core::option::expect_failed::h7b11713803917d42
                               at /checkout/src/libcore/option.rs:794
  10:     0x559fa3f1b746 - bindgen::ir::context::BindgenContext::new::ha61e71dda9b6b1fd
  11:     0x559fa3f398d8 - bindgen::Bindings::generate::h3172c41878a7aaea
  12:     0x559fa3f390f4 - bindgen::Builder::generate::hb35b757c0afec17a
  13:     0x559fa3e97b95 - std::panicking::try::do_call::h49c85f7e91ad7731
  14:     0x559fa4230b8a - __rust_maybe_catch_panic
                               at /checkout/src/libpanic_unwind/lib.rs:98
  15:     0x559fa3ebb434 - bindgen::main::h9f17fa3fe1757820
  16:     0x559fa4229a05 - std::panicking::try::do_call::h689a21caeeef92aa
                               at /checkout/src/libcore/ops.rs:2606
                               at /checkout/src/libstd/panicking.rs:454
  17:     0x559fa4230b8a - __rust_maybe_catch_panic
                               at /checkout/src/libpanic_unwind/lib.rs:98
  18:     0x559fa422a4aa - std::rt::lang_start::hf63d494cb7dd034c
                               at /checkout/src/libstd/panicking.rs:433
                               at /checkout/src/libstd/panic.rs:361
                               at /checkout/src/libstd/rt.rs:57
  19:     0x7f8fcccd33f0 - __libc_start_main
  20:     0x559fa3e96259 - _start
  21:                0x0 - <unknown>

My versions are:

  • Kubuntu 16.10
  • libclang 3.9 (installed as stated in README)
  • bindgen 0.22.1 (installed using cargo)

Hope this helps.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at bindgen::ir::context::BindgenContext::new, identified in the stack trace, and reproduce the CLI invocation with the invalid -x flag. Trace how the TranslationUnit parse failure is handled and add coverage for this command-line case. Done means invalid clang flags produce a useful error instead of the reported panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.