rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.67k stars 308 forks source link

'std::bad_alloc' error was generated #515

Closed GeekerFeng closed 1 year ago

GeekerFeng commented 1 year ago

Describe the bug std::bad_alloc

To Reproduce 100%

Environment:

Additional context

linux:tiovx$/usr/local/./bin/bear --verbose -- make [14:42:07.526254, br, 23349] bear: 3.1.1 [14:42:07.526374, br, 23349] arguments: ["/usr/local/./bin/bear", "--verbose", "--", "make"] [14:42:07.526406, br, 23349] environment: ["LC_MEASUREMENT=zh_CN.UTF-8", "SSH_CONNECTION=10.179.6.136 14077 10.179.5.238 22", "LC_PAPER=zh_CN.UTF-8", "LC_MONETARY=zh_CN.UTF-8", "LANG=en_US.UTF-8", "OLDPWD=/home/samba/shoufeng.chen/Project/memdisk/DCU_ProcessorSDK_Rtos_08_05_00_11_FAW", "S_COLORS=auto", "LC_NAME=zh_CN.UTF-8", "XDG_SESSION_ID=39376", "USER=shoufeng.chen", "PWD=/home/samba/shoufeng.chen/Project/memdisk/DCU_ProcessorSDK_Rtos_08_05_00_11_FAW/tiovx", "HOME=/home/samba/shoufeng.chen", "SSH_CLIENT=10.179.6.136 14077 22", "XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop", "LC_ADDRESS=zh_CN.UTF-8", "LC_NUMERIC=zh_CN.UTF-8", "SSH_TTY=/dev/pts/1", "MAIL=/var/mail/shoufeng.chen", "TERM=xterm", "SHELL=/bin/bash", "SHLVL=1", "LANGUAGE=en_US:en", "LC_TELEPHONE=zh_CN.UTF-8", "LOGNAME=shoufeng.chen", "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1019/bus", "XDG_RUNTIME_DIR=/run/user/1019", "PATH=/home/samba/shoufeng.chen/localbin/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/samba/shoufeng.chen/Shell:/usr/local/ffmpeg/bin", "LC_IDENTIFICATION=zh_CN.UTF-8", "PS1=\u:\W$", "LC_TIME=zhCN.UTF-8", "=/usr/local/./bin/bear"] [14:42:07.526418, br, 23349] sysname: Linux [14:42:07.526422, br, 23349] release: 4.15.0-192-generic [14:42:07.526440, br, 23349] version: #203-Ubuntu SMP Wed Aug 10 17:40:03 UTC 2022 [14:42:07.526443, br, 23349] machine: x86_64 [14:42:07.526466, br, 23349] arguments parsed: {program: /usr/local/./bin/bear, arguments: [{--: [make]}, {--bear-path: [/usr/local/bin/bear]}, {--library: [/usr/local/lib/bear/libexec.so]}, {--output: [compile_commands.json]}, {--verbose: []}, {--wrapper: [/usr/local/lib/bear/wrapper]}, {--wrapper-dir: [/usr/local/lib/bear/wrapper.d]}]} terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)

rizsotto commented 1 year ago

Can you send backtrace (from the core file) @GeekerFeng ?

GeekerFeng commented 1 year ago

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

Program received signal SIGABRT, Aborted. __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51 51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt

0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51

1 0x00007ffff6fda7f1 in __GI_abort () at abort.c:79

2 0x00007ffff76400a9 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

3 0x00007ffff764b506 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

4 0x00007ffff764b571 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

5 0x00007ffff764b7f5 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

6 0x00007ffff7642713 in std::__throw_bad_alloc() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

7 0x0000555555566aab in std::filesystem::cxx11::path::path(std::filesystem::cxx11::path const&) ()

8 0x0000555555560e8f in (anonymous namespace)::Application::command(flags::Arguments const&, char const**) const ()

9 0x000055555557813a in ps::ApplicationFromArgs::command(int, char const, char const) const ()

10 0x000055555555f1be in main ()

(gdb) Quit (gdb) q A debugging session is active.

Inferior 1 [process 65424] will be killed.

Quit anyway? (y or n) n

GeekerFeng commented 1 year ago

Looks like the problem is in the initialization part

rizsotto commented 1 year ago

Thanks @GeekerFeng for the stack trace! Does it also crash when you just call bear --help or bear -- make?

(Sorry for these questions, but I could not reproduce this crash.)

GeekerFeng commented 1 year ago

image

It's okay, we can look at the problem together. phenomenon in the above picture

rizsotto commented 1 year ago

Thanks. This is confusing, because you wrote that the version you have is 3.1.1 (compiled from sources), but this output does not look like a 3.1.x output. Are you sure that you have only one version installed on your machine?

GeekerFeng commented 1 year ago

Sorry, I posted the wrong picture, it's this one image

GeekerFeng commented 1 year ago

The previous picture is version 3.0.20 and has the same problem

rizsotto commented 1 year ago

How do you manage multiple versions on the same host?

GeekerFeng commented 1 year ago

I compiled two versions and used make install to switch versions. For example, if you want to use 3.1.1, run make install under 3.1.1。 I used 3.1.1 first. After having problems, I tried again with 3.0.20

GeekerFeng commented 1 year ago

My compile command is like this cmake -DENABLE_UNIT_TESTS=OFF -DENABLE_FUNC_TESTS=OFF -DENABLE_MULTILIB=ON ..

rizsotto commented 1 year ago

Do you need mulilib for your project? (The flag -DENABLE_MULTILIB=ON might be the one which causing it.)

GeekerFeng commented 1 year ago

Yes. I use TI's TDA4 chip with multi-core heterogeneous architecture code.

rizsotto commented 1 year ago

Your report said that x86_64 is the architecture you've been built Bear. Is any of the build tools (compiler or linker) is not a 64 bit intel executable? (Your target still can be anything, you need multilib from Bear only if your tools are mixing 64 or 32 bit executables.)

Anyway, bad::alloc from the standard library comes, when there is not enough memory available. Or there is a library mismatch (compiled against something, and running with something else). Could you look at if any of these are the case?

GeekerFeng commented 1 year ago

Wait a minute, I can try to write a simple makefile using x86_64 gcc

GeekerFeng commented 1 year ago

image image

rizsotto commented 1 year ago

Well, I am not sure then what it cause it. I can't reproduce it on my machine.

Please create a PR if you found a solution that fixes this error.