andreasfertig / cppinsights

C++ Insights - See your source code with the eyes of a compiler
https://cppinsights.io
MIT License
4.09k stars 241 forks source link

crash when parse cpp file #602

Closed lovelyzzc closed 7 months ago

lovelyzzc commented 10 months ago

When I convert CPP files in the project, it causes a coredump. Below is the printout:

#0 0x00007ff1d7f6f503 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM-16.so+0xe1f503)
#1 0x00007ff1d7f6c7bf llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-16.so+0xe1c7bf)
#2 0x00007ff1d7f6c90d (/usr/lib/libLLVM-16.so+0xe1c90d)
#3 0x00007ff1d6c1f710 (/usr/lib/libc.so.6+0x3e710)
#4 0x00007ff1dfcb1c6c (/usr/lib/libclang-cpp.so.16+0x780c6c)
#5 0x00007ffe703c08f0 
fish: Job 1, 'insights ../src/app.cpp' terminated by signal SIGSEGV (Address boundary error)

But I can successfully convert HPP files. Below is the printout of insights --version.

cpp-insights 0.10 https://cppinsights.io (https://github.com/andreasfertig/cppinsights.git 9147b894b814a3d7dcf82ac9b16965680baffeb1)
  LLVM  Revision: 
  Clang Revision: Clang 16.0.6

I used the tag v_0.10 for compilation, and the cmake compile command is as follows.

cmake -G"Ninja" .. -DINSIGHTS_USE_SYSTEM_INCLUDES=off -DCLANG_LINK_CLANG_DYLIB=on -DLLVM_LINK_LLVM_DYLIB=on

Below is the printout of ldd.

lovelyzzc@DRW-DZ0569 ~/c/build ((v_0.10))> ldd insights
        linux-vdso.so.1 (0x00007fff49de2000)
        libclang-cpp.so.16 => /usr/lib/libclang-cpp.so.16 (0x00007fd4a367c000)
        libLLVM-16.so => /usr/lib/libLLVM-16.so (0x00007fd49b29b000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fd49b020000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007fd49af33000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fd49af0e000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007fd49ad2c000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fd4a6ed4000)
        libffi.so.8 => /usr/lib/libffi.so.8 (0x00007fd49ad1f000)
        libedit.so.0 => /usr/lib/libedit.so.0 (0x00007fd49ace3000)
        libz.so.1 => /usr/lib/libz.so.1 (0x00007fd49acc9000)
        libzstd.so.1 => /usr/lib/libzstd.so.1 (0x00007fd49abf6000)
        libncursesw.so.6 => /usr/lib/libncursesw.so.6 (0x00007fd49ab7f000)
        libxml2.so.2 => /usr/lib/libxml2.so.2 (0x00007fd49aa15000)
        liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007fd49a9e0000)
        libicuuc.so.74 => /usr/lib/libicuuc.so.74 (0x00007fd49a7d2000)
        libicudata.so.74 => /usr/lib/libicudata.so.74 (0x00007fd498a74000)

Below is the printout from lldb.

(lldb) target create "insights"
Current executable set to '/usr/local/bin/insights' (x86_64).
(lldb) r ../src/app.cpp -p ../build/ --use-libc++
Process 11488 launched: '/usr/local/bin/insights' (x86_64)
/home/lovelyzzc/vehicle_end/safety/src/app.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
Process 11488 stopped
* thread #1, name = 'insights', stop reason = signal SIGSEGV: address access protected (fault address: 0x7ffff5298c6c)
    frame #0: 0x00007ffff5298c6c libclang-cpp.so.16`___lldb_unnamed_symbol29515 + 6
libclang-cpp.so.16`___lldb_unnamed_symbol29515:
->  0x7ffff5298c6c <+6>: addb   %al, (%rax)
    0x7ffff5298c6e <+8>: ud2    

libclang-cpp.so.16`___lldb_unnamed_symbol29516:
    0x7ffff5298c70 <+0>: movl   0x8, %eax
    0x7ffff5298c77 <+7>: andl   $-0x9, %eax
(lldb) bt
* thread #1, name = 'insights', stop reason = signal SIGSEGV: address access protected (fault address: 0x7ffff5298c6c)
  * frame #0: 0x00007ffff5298c6c libclang-cpp.so.16`___lldb_unnamed_symbol29515 + 6
    frame #1: 0x00007fffffff8170

Where should I start to troubleshoot this issue? Thanks!

andreasfertig commented 10 months ago

Hello @lovelyzzc,

sorry for the trouble!

In your lldb printout, this line sticks out:

/home/lovelyzzc/vehicle_end/safety/src/app.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~

C++ Insights cannot find the iostream header. This would be the starting point. The option INSIGHTS_USE_SYSTEM_INCLUDES is probably named in a hard-to-guess way. What it means is that all -I includes become -isystem with the option on and otherwise remain untouched. I'm not sure whether this option does what you're expecting.

Andreas