Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 22 03:15
    tr4v3ler commented #419
  • Oct 21 08:58
    rizsotto commented #419
  • Oct 21 07:37
    tr4v3ler commented #419
  • Oct 21 07:09
    tr4v3ler commented #419
  • Oct 21 06:33
    tr4v3ler commented #419
  • Oct 21 06:13
    tr4v3ler commented #422
  • Oct 21 04:00
    rizsotto commented #422
  • Oct 21 03:53
    tr4v3ler commented #422
  • Oct 21 03:50
    tr4v3ler commented #422
  • Oct 20 03:57
    tr4v3ler commented #422
  • Oct 20 03:57
    tr4v3ler commented #422
  • Oct 20 02:44
    tr4v3ler commented #422
  • Oct 20 01:59
    rizsotto commented #422
  • Oct 20 01:53
    tr4v3ler commented #422
  • Oct 20 01:48
    rizsotto commented #422
  • Oct 20 01:45
    tr4v3ler commented #422
  • Oct 19 13:03
    rizsotto closed #422
  • Oct 19 13:03
    rizsotto commented #422
  • Oct 19 12:54
    rizsotto commented #422
  • Oct 19 09:08
    tr4v3ler opened #422
László Nagy
@rizsotto
If a project has a build, you can run Bear to observe it and create the compilation database.
But you need a build file to build the project first. Without Bear you need this.
Hugo Lindström
@hugolm84
Hi! I am successfully generating a compile_commands.json file generated by bear --use-cc=arm-none-eabi-gcc make. Running analyze-build --verbose fails due to subProcess.CalledProcessError
subprocess.CalledProcessError: Command '['/home/hlindstrom/clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang-12', '-cc1', '-triple', 'x86_64-unknown-linux-gnu', '-analyze', '-disable-free', '-disable-llvm-verifier', '-discard-value-names', '-main-file-name', ...redacted...]' returned non-zero exit status 1.
The triple is incorrect as it specifies x86_64-unknown-linux-gnu and not arm-none-eabi. However, the database says "arguments": [ "arm-none-eabi-gcc", "-c", "-mcpu=cortex-m3",
Any suggestions to what I'm doing wrong?
Hugo Lindström
@hugolm84
Adding the triple via --analyzer-target=arm-none-eabi seems to work? :)
Hugo Lindström
@hugolm84
anayze-build still spews exceptions though and clang-tidy results are only visible using --verbose. I must be something b0rked
László Nagy
@rizsotto
Hey @hugolm84 , from a quick look, I have the impression that the analyze build picks up the first Clang from the PATH. And that Clang is the host one, not the desired cross compiler... To help analyze-build you can pass a flag --use-analyzer to specify the Clang executable and can pass --analyzer-target with the desired target. (To get more of these flags, you can query these programs with --help option.)
Hugo Lindström
@hugolm84
something like analyze-build --use-analyzer=clang --analyzer-target=arm-none-eabi ?
László Nagy
@rizsotto
or you can pass the full path of the cross compiler to the --use-analyzer flag. but you got the idea.
Hugo Lindström
@hugolm84
Sorry, the cross compiler here is arm-none-eabi-gcc or clang?
László Nagy
@rizsotto
Only the clang can do static analysis. So try with that.
But you probably will need a clang version for ARM.
If you can compile your project with clang, then you'll be able to analyze too
Johannes Wikner
@sktt

I'm trying to make bear not include arguments that are unsupported by i guess clangd.. so i made a config file like this

{
  "flags":  {
    "to_exclude": {
      "-mrecord-mcount": 0,
      "-fconserve-stack": 0,
      "-fno-allow-store-data-races": 0,
      "-mindirect-branch-register": 0,
      "-mindirect-branch=thunk-extern": 0,
      "-mskip-rax-setup": 0,
      "-mno-fp-ret-in-387": 0,
      "-mpreferred-stack-boundary": 0
    }
  }
}

make clean and bear -- make.. but they're still there.. am I doing it wrong?

Johannes Wikner
@sktt
bear 3.0.8
László Nagy
@rizsotto
The config looks good, but the code which would do the filtering is missing. :)
There is a ticket about to implement it, but it's still not done.
Hugo Lindström
@hugolm84
@rizsotto Ok, this is where I struggle to grasp the concept. I export my compile commands for the cross compilation. It specifies arm-none-eabi-gcc, then run analyzer with clang and arm-none-eabi as target. I get clang tidy results, doesn't this mean that I clang-tidy can analyze the AST produced by gcc? I don't think I compile using clang in this case... Sorry if this is off topic
László Nagy
@rizsotto
No worries @hugolm84 , I can share what I know about. It might not cover the whole, but could help...
I know for sure, that gcc created AST is not available for Clang.
The clang-tidy and the Clang SA (static analyzer) are using Clang libraries to build the AST.
László Nagy
@rizsotto
scan-build (which I wrote) ignores the compiler name and uses clang or the compiler specified by the --use-analyzer flag.
I would try to build my project with Clang. If that's working, the SA will work too.
What you need to pay attention, the same header files should be used by Clang as the cross compiler.
Graham Hughes
@graehu
Quick question, is bear supposed to work with clang directly in anyway? Example if I have the following make file:
all:
        clang++ -I ../../../libs/fmt/include/ -I ../../../libs/glad/include/ -I ../../../libs/glfw/include/ -I ../../../libs/glfw/deps/ -g -std=c++17 -Wall -Wpedantic -Wextra -c mpeg_sample.cpp -o /home/graehu/Projects/C++/framework/src/application/objects/clang++/mpeg_sample.cpp.o  -MMD -MF/home/graehu/Projects/C++/framework/src/application/objects/clang++/mpeg_sample.cpp.d
and compile that with bear — make it will produce the correct compile_commands.json
which looks like this:
  {                                                                                                                                                                                 
    "arguments": [
      "/usr/lib/llvm-11/bin/clang",
      "-I",
      "../../../libs/fmt/include/",
      "-I",
      "../../../libs/glad/include/",
      "-I",
      "../../../libs/glfw/include/",
      "-I",
      "../../../libs/glfw/deps/",
      "-g",
      "-std=c++17",
      "-Wall",
      "-Wpedantic",
      "-Wextra",
      "-c",
      "-o",
"/home/graehu/Projects/C++/framework/src/application/objects/clang++/mpeg_sample.cpp.o",                                                                                      
      "mpeg_sample.cpp"                                                                                                                                                             
    ],                                                                                                                                                                              
    "directory": "/home/graehu/Projects/C++/framework/src/application/mpeg_sample",                                                                                                 
    "file": "/home/graehu/Projects/C++/framework/src/application/mpeg_sample/mpeg_sample.cpp",                                                                                      
    "output": "/home/graehu/Projects/C++/framework/src/application/objects/clang++/mpeg_sample.cpp.o"                                                                               
  }                                                                                                                                                                                 
]
Graham Hughes
@graehu
But if I just call bear — clang++ ... it produces []
Graham Hughes
@graehu
I understand that it’s supposed to intercept calls to clang from other processes, just wondering if directly calling clang is also supported in some way.
László Nagy
@rizsotto
Hey @graehu , it depends on the Bear version and the OS you run it on, it makes the right output or an empty one.
But if you can type the command line, you can write that JSON file too. :)
Besides Clang has a parameter to generate the compile_commands.json for a single execution.
Graham Hughes
@graehu
I have a tool that generates the lines and runs them as a subprocess, I was hoping to append bear — but sounds like it might be simpler to just get clang to do it.
alternatively, I might just write it into my tool, seems simple enough.
László Nagy
@rizsotto
yes... or you can run Bear against the tool which runs the compilations (as subprocess)
Graham Hughes
@graehu
I’ll give that a go, I was hoping to do it selectively.
my tool runs a number of builds with different configurations, I don’t necessarily want to use bear with all of them.
László Nagy
@rizsotto
sure
Graham Hughes
@graehu
Thanks!
Graham Hughes
@graehu
Well, using bear — outside does work, so that’s nice to know. I’ll have a think about what works for my usecase. Thanks for the help. :)
László Nagy
@rizsotto
no worries, i'm glad to help
Kiran Gulipalli
@gulipalli123
Hello is bear works with bazel build system? I have taken bear_2.3.11.orig.tar.gz and compiled it with make commands and then I try to run bear -- bazel build .. but I am getting the following error:
bear: ERROR: wrapper: Internal error.
Traceback (most recent call last):
File "/usr/local/bin/bear", line 225, in wrapper
return function(args, **kwargs)
File "/usr/local/bin/bear", line 250, in intercept_build
exit_code, current = capture(args)
File "/usr/local/bin/bear", line 274, in capture
exit_code = run_build(args.build, env=environment)
File "/usr/local/bin/bear", line 149, in run_build
exit_code = subprocess.call(command,
args, kwargs)
File "/usr/lib/python2.7/subprocess.py", line 172, in call
return Popen(*popenargs,
kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 394, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
László Nagy
@rizsotto
Hey @gulipalli123 , I wrote up a short summary why bazel builds are problematic with Bear. https://github.com/rizsotto/Bear/wiki/Usage#bazel
László Nagy
@rizsotto
The error message you got was related to the wrong invocation. bear bazel build ... (The 2.3.x branch was not require -- before the command.)
Kiran Gulipalli
@gulipalli123
Thank you for the inputs