How to emit debug information using llvm ir in Clang? - c

Using clang or clang++ the command of
clang -S -emit-llvm ./source.c
will create a llvm ir document. However debugging information is missing. So when you test and compile things you lose debugging information.
How does one can make clang emit human readable llvm ir document with debug information ?

The standard option to add debug info is -g. So, running clang -g -S -emit-llvm source.c will emit necessary information

Related

How do I make gcc as verbose as possible?

I am currently using the following flags for my gcc compiler:
gcc -std=c99 -pedantic -Wall D_DEFAULT_SOURCE -g -c filename.c
But how can I make the output as verbose as possible? The error messages I am getting in C are not as nice as I am used to from more high level languages and I want to get as much information out of the gcc compiler as possible.
This is a summary of all comments I've received on this post:
These flags are the best you can use to make your compiler as verbose as
possible:
-pedantic -Wall -Wextra -Wwrite-strings -g3
Other flags such as -v and the entire -d* family will make the compilation process more verbose but won't enhance the error messages you are getting.
Check your current version with gcc --version. To get the newest gcc Version (i.e. gcc 12.2 since August 19, 2022) you might have to clone the gcc repository and build it yourself based on the distro (check via lsb_release -d) you are using.
Check this stackoverflow question out to install gcc 12.2 on Ubuntu.
Alternatively you could also directly get gcc-11 from apt without upgrading to the latest bleeding edge ubuntu (don't forget to use gcc-11 instead of gcc afterwards to compile).

How to use GNU gprof profiler on macOS Mojave?

I want to use GNU gprof that comes with GCC to profile my C program. However, it returns __dyld section not supported error when I compile with the -pg flag and try to run the program:
$ gcc -pg main.c
$ ./a.out
dyld: __dyld section not supported in /Users/evgenii/Downloads/c_profile/./a.out
This error has been reported here. Is there a way to use the GNU profiler on macOS Mojave? I'm aware that there are alternative tools for profiling, but I want to use gprof.

how can I debug binutils to check assembler options

how to debug gnu binutils
I want to check code flow for assembler option
I have following assembler option
/gas/as-new --statistics -o dump.o a.s
how can I debug binutils. I have ddd debugger and I have also used -g option in the configuration option which will give me debugging information but what next ??

Settings GCC (ARM-Linux) in Eclipse Mars for 'C project

I am experimenting with cross compiling for ARM-Linux under Windows using Eclipse-Mars. My set-up is as follows:
Win10 x64
Eclipse Mars.2 Release (4.5.2)
GNU Toolchain for RaspberryPi (SysGCC)
Target platform: RaspberryPi2 running Raspian
Source project in 'C (not C++) using Linux Threads (pthreads)
I have knocked up a small 'C project using 'pthreads' which compiles under Eclipse and runs successfully on the Pi.
My problem is that Eclipse shows a number of errors in its Problems TAB to do with Linux's threads:
Type 'pthread_cond_t' could not be resolved
Type 'pthread_mutex_t' could not be resolved
Type 'pthread_t' could not be resolved
I have Eclipse as:
Cross GCC Compiler settings to use g++ with -std=c++11 -O0 -g3 -Wall -c -fmessage-length=0.
Cross G++ Compiler settings to use g++ with -std=c++11 -O0 -g3 -Wall -c -fmessage-length=0.
In other words both are the same.
If I rename my source files from foo.c to foo.cpp and recompile, then the Eclipse errors disappear!!!
This implies that Eclipse's C++ settings are correct, but its 'C settings are not.
Can anybody suggest anything for me to try?
g++ ist a C++ compiler, so you might try to use other settings for the Cross GCC Compiler, eg. gcc.
Also make sure you are linking the pthread library.

How to generate a single LLVM IR from multiple sources

Compiling .c files to a single LLVM IR and link multiple libraries during the compilation.
An example here with gcc:
gcc -c -Wall -g3 -DVERSION=\"1.1.2\" ssl_proxy.c -o ssl_proxy.o
gcc -o ssl_proxy ssl_proxy.o -lssl -lcrypto
Now, I want to compile the ssl_proxy.c to ssl_proxy.ll, simply using llvm-gcc -S -emit-llvm won't work as it will not let me link -lssl -lcrypto libraries.
Through this example I hope people can explain a bit more details about compilation with llvm-gcc (not clang), so that all visitors can learn from it and know how to compile complex multiple sources into one LLVM IR.
Compiling source files into LLVM IR does not perform linking, so it does not require any libraries - it just needs the headers.

Resources