-
-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bear created empty compile_commands.json file #468
Comments
Does this wiki page help? |
@rizsotto , I don't think so... I don't know what changes have been made to the project, but back to the time when calling "bear make xxx", it works perfectly with the same configuration. |
@fuzhen011 the "old" 2.x version of Bear works differently than the "new" 3.x version. The new version is using compiler wrappers, that your build system has to support. ( |
@rizsotto , is there a way to create a local configuration to recognize the compiler, where I used arm-none-eabi-gcc? |
yes, there is... read |
Any update on this @fuzhen011 ? |
Hi @rizsotto, I think I'm having a similar issue to @fuzhen011's. I'm working on an embedded project, so my case involves a cross-compiler (
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
# ...
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
After making sure that the makefile works without bear, I read through relevant issues on GitHub, and have tried:
That Edit: Prior to switching to MacBook I was working on a Linux laptop with zero issue with this project + |
Thanks @mistrpokr , the log was really useful. I've found a bug in the intercept session initialization. Will make a fix on the weekend. |
Glad to help! ;) |
It turned out there is no problem with the session initialization... It's about that you've been passing the
|
Thanks for the update. I've upgraded I guess keeping the env vars in the log might be helpful as well. Here are the outputs of
|
The problem can be reproduced on
|
I did also notice that invalid config files are not checked before compilation is run, which is unfortunate. At least for me though, gcc worked fine. |
@matu3ba the problem with zig, that |
@mistrpokr thanks for the follow up. Can you show some of those lines that you've cropped out from the build output. I am curious how the build is calling the compiler. |
Getting empty output with a simple file compilation on a Mac.
|
Hey @huixie90 , that's a not supported use case. Sorry. |
Ah thanks for the reply. It used to work on Linux this way but not on my Mac. I was wondering why. But this is not my real use case. My real use case is for generating json for llvm lit test envinronment. I used to do
this works on Linux machines but not on my Mac. I was wondering if it just used to work by luck. |
Bear has two interception strategies. One is using compiler wrappers, and the other is using the dynamic linker library preload functionality. The first one is for systems which has not dynamic linker, or disabled the preload for security reasons. (Mac is in this group.) The compiler wrapper solution has limitations and won't cover use cases that the other approach will. |
I see. Thanks for the explanation. In order to make it working for my case , I guess I need to set DCMAKE_CXX_COMPILER to the compiler wrapper instead of my compiler under test? (Note I don’t need the json generated from building llvm using CMAKE, I need to use bear to generate the one for the lit testing environment.) is there any doc that I can follow to create compiler wrapper around the real compiler-under-test |
Yes, forcing the compiler to be the wrapper seems to be a good idea. (Or better, just add the wrapper directory to |
Managed to get it working on mac to generate the json file for llvm tests
|
hi @rizsotto , I'm having a similar issue when attempting the following on an M1 Mac where I get an empty compile_commands.json: bear -- make
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o main.o main.cpp
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o imgui.o imgui/imgui.cpp
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o imgui_draw.o imgui/imgui_draw.cpp
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o imgui_tables.o imgui/imgui_tables.cpp
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o imgui_widgets.o imgui/imgui_widgets.cpp
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o imgui_demo.o imgui/imgui_demo.cpp
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o imgui_impl_sdl.o imgui/backends/imgui_impl_sdl.cpp
em++ -DIMGUI_DISABLE_FILE_FUNCTIONS -I./imgui -I./imgui/backends -Wall -Wformat -Os -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1 -c -o imgui_impl_opengl3.o imgui/backends/imgui_impl_opengl3.cpp
mkdir web
em++ -o web/index.html main.o imgui.o imgui_draw.o imgui_tables.o imgui_widgets.o imgui_demo.o imgui_impl_sdl.o imgui_impl_opengl3.o -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1 -sLLD_REPORT_UNDEFINED -s NO_FILESYSTEM=1 --shell-file shell_minimal.html -s USE_SDL=2 -s DISABLE_EXCEPTION_CATCHING=1
Build complete for web/index.html this works fine (as in this project builds fine without bear) yet when I do: cat compile_commands.json
> [] I'm using this for an Emscripten project. Could that be the issue? I also tried using the |
Hey @spartacoos , your use case might worth a separate ticket. 😄 (Emscripten was not on my radar when I was writing Bear.) I would try to create a wrapper. Check out the Try to run the command with a couple of ps.: The |
Has the original issue been resolved/is there a workaround? With the following MWE: Makefile CC=arm-none-eabi-gcc
main: main.c
$(CC) $< -o $@ main.c int main() {
return 0;
}
void _close(void) {}
void _lseek(void) {}
void _read(void) {}
void _write(void) {}
void _sbrk(void) {}
void _exit(int code) {
while (1) {
}
} citnames-config.json {
"compilation": {
"compilers_to_recognize": [
{
"executable": "/opt/homebrew/bin/arm-none-eabi-gcc",
"flags_to_add": [],
"flags_to_remove": []
}
],
"compilers_to_exclude": []
},
"output": {
"content": {
"include_only_existing_source": true,
"paths_to_include": [],
"paths_to_exclude": []
},
"format": {
"command_as_array": true,
"drop_output_field": false
}
}
}
|
@frankplow thanks for this report. Could you try this change?
And call If this is not working, try to create a new link in |
@rizsotto Running the command with compile_commands.json [
{
"arguments": [
"/opt/homebrew/bin/arm-none-eabi-gcc",
"-c",
"-o",
"main",
"main.c"
],
"directory": "/private/var/folders/1v/j907_dgn2_33jx8ghf8s7h900000gn/T/tmp.dbtypHNA",
"file": "/private/var/folders/1v/j907_dgn2_33jx8ghf8s7h900000gn/T/tmp.dbtypHNA/main.c",
"output": "/private/var/folders/1v/j907_dgn2_33jx8ghf8s7h900000gn/T/tmp.dbtypHNA/main"
}
] stderr
Is there any way I can get it to work while still setting |
That's good news @frankplow ! Thanks to come back with it. I believe keeping the This is not a limitation if you are using Linux, where the interception is based on the dynamic linker preload feature. That will work with |
This would be covered in upstream. ziglang/zig#9323 |
For m1 macs when compiling with arm-none-eabi, I found that adding a wrapper to the wrapper.d folder with the specific tool names fixes the empty compile commands file issue. wrapper.d folder: /opt/homebrew/Cellar/bear/3.1.2_5/lib/bear I had to add: You may need to add other wrappers in your case. |
Also experiencing this issue when trying to use the arm gnu compiler. @rizsotto are you placing the arm-none-eabi-* binaries into the |
I have not planned to add them. I think it's more like a packaging task. (The package maker is more familiar what compilers are available or commonly used.) |
This works for me thanks. I added the mentioned files as symlinks to |
Describe the bug
I'm using MacOS and cross-compiling an ARM project using GNU GCC compiler.
To Reproduce
Not easy to reproduce on your side because you need to do a big amount of work to set up the environment, but I can 100% reproduce the issue.
Expected behavior
complete compile_commands.json file
Environment:
Additional context
Older version of Bear works perfectly in my setup, I don't remember what the version is, but back to then, it issues "bear make xxx" instead of "bear -- make xxx". I updated it yesterday and found it didn't work after update.
Below is the output from the compiling when added "--verbose"
[16:46:43.665769, ic, 78289] Process wait request: done. [pid: 78290]
[16:46:43.665820, ic, 78289] Running command. [Exited with 0]
[16:46:43.665838, ic, 78289] Stopping gRPC server.
[16:46:43.666223, ic, 78289] succeeded with: 0
[16:46:43.667186, br, 78288] Process wait request: done. [pid: 78289]
[16:46:43.667215, br, 78288] Running intercept finished. [Exited with 0]
[16:46:43.667947, br, 78288] Process spawned. [pid: 91668, command: [/usr/local/Cellar/bear/3.0.19_2/bin/citnames, --input, compile_commands.events.json, --output, compile_commands.json, --run-checks, --verbose]]
[16:46:43.667977, br, 78288] Process wait requested. [pid: 91668]
[16:46:43.690705, cs, 91668] citnames: 3.0.19
[16:46:43.691149, cs, 91668] arguments: ["/usr/local/Cellar/bear/3.0.19_2/bin/citnames", "--input", "compile_commands.events.json", "--output", "compile_commands.json", "--run-checks", "--verbose"]
[16:46:43.691180, cs, 91668] environment: ["ANDROID_HOME=/Users/zhfu/Library/Android/sdk", "ANDROID_PLATFORM_TOOLS=/Users/zhfu/Library/Android/sdk/platform-tools", "ANDROID_TOOLS=/Users/zhfu/Library/Android/sdk/tools", "AUTOJUMP_ERROR_PATH=/Users/zhfu/Library/autojump/errors.log", "AUTOJUMP_SOURCED=1", "COLORFGBG=15;0", "COLORTERM=truecolor", "EDITOR=vim", "GNUARMEMB_TOOLCHAIN_PATH=", "HOME=/Users/zhfu", "ITERM_PROFILE=Kevin", "ITERM_SESSION_ID=w0t0p0:1B14DE1C-E553-49FB-A3BF-80E8B4270016", "LANG=zh_CN.UTF-8", "LC_TERMINAL=iTerm2", "LC_TERMINAL_VERSION=3.4.15", "LESS=-R", "LOGNAME=zhfu", "LSCOLORS=Gxfxcxdxbxegedabagacad", "MAKEFLAGS=", "MAKELEVEL=1", "META_UTIL_PATH=/Users/zhfu/work/super", "MFLAGS=", "OLDPWD=/Users/zhfu/SimplicityStudio/v5_workspace_new", "PAGER=less", "PATH=/Users/zhfu/Library/Android/sdk/tools:/Users/zhfu/Library/Android/sdk/platform-tools:/Users/zhfu/work/repos/bt_support/tools:/Applications/Doxygen.app/Contents/Resources:/Applications/Simplicity Studio.app/Contents/Eclipse//developer/toolchains/gnu_arm/7.2_2017q4/bin:/usr/local/Cellar/ctags/5.8_1/bin:/Users/zhfu/work/repos/py_bgapi/pybgapi:/usr/local/opt/openssl:/usr/local/opt/openssl/lib::/Applications/Simplicity Studio.app/Contents/Eclipse/:/usr/local/Cellar/gcc/10.1.0/bin/:/Applications/Simplicity Studio.app/Contents/Eclipse//developer/adapter_packs/commander/Commander.app/Contents/MacOS:/usr/local/Cellar/[email protected]/1.1.1d/bin:/Users/zhfu/Library/Python/2.7/bin:/Users/zhfu/Library/Python/3.9/bin:/Users/zhfu/work/gconfig/scripts:/usr/local/opt/binutils/bin:/Users/zhfu/work/repos/uc_cli:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS:/Users/zhfu/Library/Android/sdk/tools:/Users/zhfu/Library/Android/sdk/platform-tools:/Users/zhfu/work/repos/bt_support/tools:/Applications/Doxygen.app/Contents/Resources:/Applications/Simplicity Studio.app/Contents/Eclipse//developer/toolchains/gnu_arm/7.2_2017q4/bin:/usr/local/Cellar/ctags/5.8_1/bin:/Users/zhfu/work/repos/py_bgapi/pybgapi:/usr/local/opt/openssl:/usr/local/opt/openssl/lib:/Applications/Simplicity Studio.app/Contents/Eclipse/:/usr/local/Cellar/gcc/10.1.0/bin/:/Applications/Simplicity Studio.app/Contents/Eclipse//developer/adapter_packs/commander/Commander.app/Contents/MacOS:/usr/local/Cellar/[email protected]/1.1.1d/bin:/Users/zhfu/Library/Python/2.7/bin:/Users/zhfu/Library/Python/3.9/bin:/Users/zhfu/work/gconfig/scripts:/usr/local/opt/binutils/bin:/Users/zhfu/work/repos/uc_cli", "PATH_ARMGCC=/Applications/Simplicity Studio.app/Contents/Eclipse//developer/toolchains/gnu_arm/7.2_2017q4/bin", "PATH_BINUTILS=/usr/local/opt/binutils/bin", "PATH_BLE_SDK=/Applications/Simplicity\ Studio.app/Contents/Eclipse/developer/sdks/gecko_sdk_suite/v2.7/app/bluetooth", "PATH_BTMESH_SDK=/Applications/Simplicity\ Studio.app/Contents/Eclipse/developer/sdks/blemesh/v1.7/app/bluetooth", "PATH_COMMANDER=/Applications/Simplicity Studio.app/Contents/Eclipse//developer/adapter_packs/commander/Commander.app/Contents/MacOS", "PATH_CTAGS=/usr/local/Cellar/ctags/5.8_1/bin", "PATH_DOCXGEN=/Applications/Doxygen.app/Contents/Resources", "PATH_GCC_=/usr/local/Cellar/gcc/10.1.0/bin/", "PATH_MY_SCRIPT=/Users/zhfu/work/gconfig/scripts", "PATH_OPENSSL=/usr/local/opt/openssl:/usr/local/opt/openssl/lib", "PATH_PYBGAPI=/Users/zhfu/work/repos/py_bgapi/pybgapi", "PATH_PYBIN=/usr/local/Cellar/[email protected]/1.1.1d/bin:/Users/zhfu/Library/Python/2.7/bin:/Users/zhfu/Library/Python/3.9/bin", "PATH_STUDIO=/Applications/Simplicity Studio.app/Contents/Eclipse/", "PATH_SUP_TOOLS=/Users/zhfu/work/repos/bt_support/tools", "PATH_UC_CLI=/Users/zhfu/work/repos/uc_cli", "PWD=/Users/zhfu/SimplicityStudio/v5_workspace_new/bt_soc_empty", "PYBGAPI_DIR=/Users/zhfu/work/pybgapi", "PYTHONPATH=/Users/zhfu/work/repos/py_bgapi/pybgapi", "SCRIPT_DIR=/Users/zhfu/work/super/protocol/bluetooth/scripts", "SHELL=/bin/zsh", "SHLVL=2", "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.zdeGghBHCL/Listeners", "STUDIO_WORKSPACE=/Users/zhfu/SimplicityStudio", "SUPER_DIR=/Users/zhfu/work/super", "TERM=screen-256color", "TERM_PROGRAM=iTerm.app", "TERM_PROGRAM_VERSION=3.4.15", "TERM_SESSION_ID=w0t0p0:1B14DE1C-E553-49FB-A3BF-80E8B4270016", "TMPDIR=/var/folders/w4/9d8q2nf52rl9tslbgmgz83hw0000gn/T/", "TMUX=/tmp//tmux-501/default,674,0", "TMUX_PANE=%0", "UNCRUSTIFY_CHECK_SCRIPT=/Users/zhfu/work/super/tool/script/uncrustify/uncrustifyCheck.py", "USER=zhfu", "XPC_FLAGS=0x0", "XPC_SERVICE_NAME=0", "ZEPHYR_BASE=/Users/zhfu/work/repos/zephyrproject/zephyr", "ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb", "ZSH=/Users/zhfu/.oh-my-zsh", "_=/usr/bin/make", "__CF_USER_TEXT_ENCODING=0x1F5:0x19:0x34"]
[16:46:43.691514, cs, 91668] sysname: Darwin
[16:46:43.691517, cs, 91668] release: 19.6.0
[16:46:43.691519, cs, 91668] version: Darwin Kernel Version 19.6.0: Sun Nov 14 19:58:51 PST 2021; root:xnu-6153.141.50~1/RELEASE_X86_64
[16:46:43.691521, cs, 91668] machine: x86_64
[16:46:43.691532, cs, 91668] arguments parsed: {program: /usr/local/Cellar/bear/3.0.19_2/bin/citnames, arguments: [{--input: [compile_commands.events.json]}, {--output: [compile_commands.json]}, {--run-checks: []}, {--verbose: []}]}
[16:46:43.691764, cs, 91668] Configuration: {"compilation":null,"output":{"content":{"include_only_existing_source":true},"format":{"command_as_array":true,"drop_output_field":false}}}
[16:46:43.691958, cs, 91668] compilation entries created. [size: 0]
[16:46:43.691964, cs, 91668] compilation entries to output. [size: 0]
[16:46:43.692236, cs, 91668] compilation entries written. [size: 0]
[16:46:43.692252, cs, 91668] succeeded with: 0
[16:46:43.692941, br, 78288] Process wait request: done. [pid: 91668]
[16:46:43.692967, br, 78288] Running citnames finished. [Exited with 0]
[16:46:43.693039, br, 78288] succeeded with: 0
Before you send...
README.md
file orman bear
?The text was updated successfully, but these errors were encountered: