I am using "Support/Debug.h" to introduce debug statements in my pass. In order to enable the debug mode, I am required to run opt with the -debug flag, however opt has no such flag.
opt: Unknown command line argument '-debug'. Try: 'opt -help'
opt: Did you mean '-debugify'?
I tried both with the releasebuild and the debugBuild version of the opt binary.
It looks like the -debug flag does not exist if you build llvm with the NDEBUG macro set, which I assume most versions shipped with Linux distros will do. I haven't tested, but you probably have to build llvm from source if you haven't already done so.
You need a debug build of LLVM (i.e. opt) and your pass (i.e. use -DCMAKE_BUILD_TYPE=Debug instead of -DCMAKE_BUILD_TYPE=Release)
Related
I'm trying to compile Valgring3.16.1 with aarch64-linux-gnu-gcc (for xilinx zynq-mp board)
the ./configure stage passed ok.
when I run:
make CC= ..... /bin/aarch64-linux-gnu-gcc
I got this error:
aarch64-linux-gnu-gcc: error: unrecognized command line option '-m64'
How can I fix it?
any help will be appreciated,
Tzipi Kluska
If you need to change compiler or flags, you should do that when you run configure, not when you run make. Otherwise configure sees and detects a different environment than what you get with make.
The docs have the answer you ask for.
-m64 is available for other architectures than AArch64.
If you need the "Machine-Dependent Options" you should read AArch64 options.
I am building LLVM with cmake and Ninja build generator as following:
cmake path/to/llvm/ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=1 -DLLVM_ENABLE_CXX1Y=1 -DLLVM_ENABLE_RTTI=1 -DLLVM_TARGETS_TO_BUILD="X86" -G Ninja
Now I a am trying to use the -debug-only=mytype option of opt to print some debug information about my own passes: using the following in my passes code:
define DEBUG_TYPE "mytype"
DEBUG(errs() << "My debug message\n");
Running opt as following doesn't generate any output messages:
opt < a.bc > /dev/null -mypass -debug-only=mytype
According to LLVM documentation:
For performance reasons, -debug-only is not available in optimized build (--enable-optimized) of LLVM.
I suspect this to be the root of my issue, but I can't find how to turn on/off this option when using cmake to build llvm.
It is controlled by enabling assertions.
cmake -DLLVM_ENABLE_ASSERTIONS=ON is enough to turn it on. If you don't see your debug output, then your code is not executed.
I am adding here a complement answer to my question. As #Joky said, cmake -DLLVM_ENABLE_ASSERTIONS=ON must be specified when compiling llvm. Also, because my passes are built outside the llvm source tree, assertions must also be enabled when building the passes.
How can I increase the verbosity of the build process?
Bazel seems to print compiler commands only if something goes wrong during the build.
I would like to see which compiler comands the cc_library rule fires, even if everything seems to be fine, to debug linking problems.
I already tried various bazel command line parameters but nothing gives me the compiler commands :(
This is probably what you are looking for:
bazel build --subcommands //my:target
The --subcommands option causes Bazel's execution phase to print the full command line for each command prior to executing it.
Useful information taken from Envoy's bazel readme (https://github.com/envoyproxy/envoy/blob/master/bazel/README.md)
When trying to understand what Bazel is doing, the -s and --explain options are useful. To have Bazel provide verbose output on which commands it is executing:
bazel build -s //source/...
To have Bazel emit to a text file the rationale for rebuilding a target:
bazel build --explain=file.txt //source/...
To get more verbose explanations:
bazel build --explain=file.txt --verbose_explanations //source/...
Maybe you can generate the compile_commands.json file. I have created Shell scripts (under Linux) to automate that: https://github.com/vincent-picaud/Bazel_and_CompileCommands.
You might also find the following useful in addition to the accepted answer of using --subcommands (-s):
bazel build --subcommands --verbose_failures //my:target
The --verbose_failures option causes Bazel's execution phase to print the full command line for commands that failed.
Although it would seem the --subcommands option supercedes it given it is documented to display prior to command execution, I have found cases (with bazel 5.2.0) where for a failing command, --subcommands alone shows only a portion of the command along with <remaining N arguments skipped>. Using both --subcommands and --verbose_failures displays the full command line in these cases.
I'm trying to debug my first program in D compiled using
dmd -debug hello.d
but when I run the executable through GDB-7.6 it doesn't seem to know where to find the source code and decode the format of the stack trace (and its name-demangling).
Is GDB-debugging DMD-generated executables not yet supported or have I missed something?
The -debug flag means that debug code is enabled, which is not the same as having debug symbols. The flag you are looking for is -g or -gc.
See http://dlang.org/dmd-linux.html#switches for more info on the compiler flags.
Perhaps a very trivial question:
I need to compile a program as 64-bit (earlier makefile written to compile it as 32-bit).
I saw the option -m32 appearing in command line parameters with each file compilation. So, I modified the makefile to get rid of -m32 in OPTFLAG, but again when the program compiles, I still see -m32 showing up and binaries are still 32-bit. Does this m32 come from somewhere else as well?
-m32 can only be coming from somewhere in your makefiles, you'll have to track it down (use a recursive grep) and remove it.
When I am able to force -m64, I get "CPU you selected does not support x86-64 instruction set".Any clues?. uname -a gives x86_64
That error means there is an option like -march=i686 in the makefiles, which is not valid for 64-bit compilation, try removing that too.
If you can't remove it (try harder!) then adding -march=x86-64 after it on the command line will specify a generic 64-bit CPU type.
If the software you are trying to build is autotools-based, this should do the trick:
./configure "CFLAGS=-m64" "CXXFLAGS=-m64" "LDFLAGS=-m64" && make
Or, for just a plain Makefile:
env CFLAGS=-m64 CXXFLAGS=-m64 LDFLAGS=-m64 make
If you are using CMake, you can add m64 compile options by this:
add_compile_options(-m64)