How to generate debug information with Eclipse - c

I have a C project that can be built in the command line (Linux Mint) which generates
debug information. I can use GDB to debug it in the command line interface, which I find very tedious.
I have used: sudo make DEBUG=1 in the command line.
I need to debug the same project in Eclipse (GALILEO). I can build it in Eclipse, but no debug information is generated, and I can't debug the code (with the error "No Debugging Information available"). Also can't place any break point in the code.
I have used gcc -g as the compiler invocation command (compiler > -O2 -g -Wall -c -fmessage-length=0)
and make DEBUG=1 in custom build command, with the
linker as "gcc"
Can anyone tell me how to set up the project so that the debug information is generated just like when it was built in the command line.
------------------BUILD OUTPUT------------------------------------------------------------
Build of configuration Default for project yuma **
make DEBUG=1 STATIC=1 all
for dir in libtecla netconf libtoaster; do\
cd $dir && make && cd ..;\
done
make[1]: Entering directory /home/shuser/workspace2/yuma/libtecla'
make[2]: Entering directory/home/shuser/workspace2/yuma/libtecla'
mkdir normal_obj
cp ./keytab.h normal_obj/keytab.h
gcc -c -O -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SELECT=1 -DHAVE_SYSV_PTY=1 -D_SVID_SOURCE -D_BSD_SOURCE -fpic -o normal_obj/getline.o ./getline.c
[...]
gcc -DLINUX=1 -DGCC=1 -DDEBUG -DHAS_FLOAT=1 -Wall -Wno-long-long -Wformat-y2k -Winit-self -Wswitch-default -Wunused-parameter -Wextra -Wundef -Wshadow -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wcast-qual -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Winvalid-pch -Wredundant-decls -Wnested-externs -Winline -std=gnu99 -fPIC -ggdb3 \
-I. -I../agt -I../mgr -I../ncx -I../platform -I../ydump -I/usr/include -I/usr/include/libxml2 -I/usr/include/libxml2/libxml -c -o ../../target/mgr/mgr.o mgr.c
gcc -DLINUX=1 -DGCC=1 -DDEBUG -DHAS_FLOAT=1 -Wall -Wno-long-long -Wformat-y2k -Winit-self -Wswitch-default -Wunused-parameter -Wextra -Wundef -Wshadow -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wcast-qual -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Winvalid-pch -Wredundant-decls -Wnested-externs -Winline -std=gnu99 -fPIC -ggdb3 \
-I. -I../agt -I../mgr -I../ncx -I../platform -I../ydump -I/usr/include -I/usr/include/libxml2 -I/usr/include/libxml2/libxml -c -o ../../target/mgr/mgr_cap.o mgr_cap.c
[...]
gcc -ggdb3 -DDEBUG=1 -DLINUX=1 -DGCC=1 -DHAS_FLOAT=1 -Wall -Wno-long-long -Wformat-y2k -Winit-self -Wswitch-default -Wunused-parameter -Wextra -Wundef -Wshadow -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wcast-qual -Wcast-align -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Winvalid-pch -Wredundant-decls -Wnested-externs -Winline -std=gnu99 -fPIC \
-I. -I../../netconf/src/platform -I../../netconf/src/ncx -I../../netconf/src/agt -I/usr/include/yuma/platform -I/usr/include/yuma/ncx -I/usr/include/yuma/agt -I/usr/include -I/usr/include/libxml2 -I/usr/include/libxml2/libxml -c -o ../bin/toaster.o toaster.c
----------------------DEBUG CONSOLE---------------------------
No source available for "main() "
[...]
.gdbinit: No such file or directory.
Reading symbols from /home/shuser/yuma-2.2-2/netconf/target/bin/netconfd...(no debugging symbols found)...done.
1-gdb-set confirm off
1^done
(gdb)
2-gdb-set width 0
2^done
[...]
=library-loaded,id="/lib/i386-linux-gnu/libm.so.6",target-name="/lib/i386-linux-gnu/libm.so.6",host-name="/lib/i386-linux-gnu/libm.so.6",symbols-loaded="0",thread-group="i1"
~"Stopped due to shared library event\n"
Stopped due to shared library event
*stopped,thread-id="1",stopped-threads="all",core="0"
22 info sharedlibrary
(gdb)

Related

Why is make not rebuilding when source files are changed?

I am currently attempting problem set 4 (speller) from the CS50 course. It is the first problem set where we have multiple header files and multiple source files, so they gave us a Makefile to use, to compile each .c file into .o, then link the .o files to form the compiled binary.
This is the makefile
speller:
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o speller.o speller.c
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o dictionary.o dictionary.c
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o speller speller.o dictionary.o
Output of ls:
dictionaries dictionary.h keys speller speller.o dictionary.c dictionary.o Makefile speller.c texts
When I run make for the first time, it compiles speller no problems. However, when I make changes in dictionary.c and save it (In particular, I purposely screwed up all my printf() calls to printasdasdsa() yeah you get it) and I run make, it keeps saying make: 'speller' is up to date, and just refuses to rebuild even though I made changes to dictionary.c's source.
Any idea what's wrong with the way I'm building speller? Is there something wrong with my makefile?
I know that there's a way to force make to rebuild by passing the "-B" flag, but is it convention to always do it that way whenever you make a change in your code?
This is the task: https://docs.cs50.net/2019/x/psets/4/speller/hashtable/speller.html
Make only rebuilds a target if the target does not exist, or the target is older than one of its dependencies. In your case you have a target speller, with no dependencies. The first time you run it, make checks, and doesn't find it, so it builds it. The next time you build, it checks, the file exists, and since it does not have any dependencies, it does not rebuild. You would want to do something like:
speller: speller.c dictionary.c
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o speller.o speller.c
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o dictionary.o dictionary.c
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o speller speller.o dictionary.o
Or, better yet:
speller: speller.o dictionary.o
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o speller speller.o dictionary.o
speller.o: speller.c
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o speller.o speller.c
dictionary.o: dictionary.c
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o dictionary.o dictionary.c
Which would not rebuild the .o files unless the .c files changed, and would not rebuild the app unless one of the .o files was rebuilt. Note that neither of these two handle any header files. If your .c files include any local headers, those need to be added to the dependencies as well.
#HardcoreHenry explains make's behavior very well in his answer (do not accept this one over that). I want to point out, however, that make has a fair amount of built-in smarts about building software, to the extent that it can do relatively simple builds without any Makefile at all. Moreover, when you do write a Makefile, it is usually considered good style to minimize repetition.
Thus, I'd suggest this as an even better alternative:
CC = clang
CFLAGS = -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 \
-Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare \
-Wno-unused-parameter -Wno-unused-variable -Wshadow
speller: speller.o dictionary.o
$(CC) -o $# $(CFLAGS) speller.o dictionary.o
That relies on make knowing how to build object files from C source files (which it does) and using the C compiler and and flags specified by the CC and CFLAGS variables when it does so (which it will). It also uses the special variable $#, which, in a rule's recipe, expands to the name of the rule's target. Some versions of make offer even a bit more opportunity to DRY this out.
Among other things, note how the compiler and build flags are specified once each, and near the top. Now if you ever want to change those, you can do it in one easy-to-find place.
You need to add dependencies. When using GNU make, you can skip the .o step for small projects and compile the program as a whole
speller: speller.c dictionary.c
${CLANG} ${CFLAGS} ${LDFLAGS} $(filter %.c,$^) -o $# ${LIBS}

Error in installing ncdf on Linux when ever i want to install ncdf package it show this error

install.packages("ncdf")
* installing source package ‘ncdf’ ...
** package ‘ncdf’ successfully unpacked and MD5 sums checked checking for nc-config... /usr/local/bin/nc-config configure: creating
./config.status config.status: creating src/Makevars
** libs gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c ncdf.c -o ncdf.o gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/local/include
-fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c ncdf2.c -o ncdf2.o gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG
-I/usr/local/include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c ncdf3.c -o ncdf3.o gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions
-Wl,-z,relro -o ncdf.so ncdf.o ncdf2.o ncdf3.o -L/usr/local/lib -lnetcdf -L/usr/lib/R/lib -lR /usr/bin/ld: /usr/local/lib/libnetcdf.a(attr.o): relocation R_X86_64_32 against
`.rodata' can not be used when making a shared object; recompile with
-fPIC /usr/local/lib/libnetcdf.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status make: *** [ncdf.so] Error 1
ERROR: compilation failed for package ‘ncdf’
* removing ‘/home/ayesha/R/x86_64-pc-linux-gnu-library/3.2/ncdf’
The downloaded source packages are in
'/tmp/RtmpSrzd8P/downloaded_packages'

Have linker remove unused object files for avr/gcc

I'm using avr-gcc for an atmega-328p micro controller.
The code is built with:
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o heap.o heap.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o kerneltimer.o kerneltimer.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o message.o message.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o driver.o driver.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o watchdog.o watchdog.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o mutex.o mutex.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o semaphore.o semaphore.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o kernelswi.o kernelswi.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o task.o task.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o kernelwdt.o kernelwdt.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o myfirstapp.o myfirstapp.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o taskport.o taskport.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o timer.o timer.c
And linked with:
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -Wl,-Map,myfirstapp.map -L/usr/avr/lib -Os -o myfirstapp.elf heap.o kerneltimer.o message.o driver.o watchdog.o mutex.o semaphore.o kernelswi.o task.o kernelwdt.o myfirstapp.o taskport.o timer.o
Now- as it turns out for this particular program, nothing in heap.o is used. Yet the code is included in the final binary. Is there anyway I can get the linker to atleast elide complete .o files if nothing in them are used anywhere ?
And while this is just a fun project for learning purposes,
I'd rather learn if the tools can figure this out than tracking down such things myself.
Yes, this is possible. Passing --gc-sections to the linker will direct it to omit sections which are not referenced. Additionally, passing the -ffunction-sections and -fdata-sections flags to the compiler will direct it to generate a section for each function and variable, allowing these to be left out on an individual basis, rather than just at a file level.
Adding --gc-sections to the linker didn't help for me. However adding
-Wl,-gc-sections did work

gcc builds with -o but not -o3?

My Makefile looks like this:
CC=gcc
CFLAGS=-Wall -Wextra -std=c99 -pedantic
OBJECTS=main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o
render: $(OBJECTS)
$(CC) $(CFLAGS) -lm -o render -g $(OBJECTS)
rm $(OBJECTS)
clean:
rm -f render*
This builds my executable with no errors, but when I change -o to -o2 or -o3, I get the error:
gcc -Wall -Wextra -std=c99 -pedantic -c -o main.o main.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Scene.o Scene.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Matrix.o Matrix.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Vector.o Vector.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Triangle.o Triangle.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Color.o Color.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Raster.o Raster.c
gcc -Wall -Wextra -std=c99 -pedantic -lm -o3 render -g main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o
gcc.exe: error: render: No such file or directory
make: *** [render] Error 1
There could be some error in my code detected by the optimization flags, but as I don't get any error messages before this it's hard to know what's going wrong. I'm using MinGW/MSYS on Windows 7.
-o render means create the output file with the name render.
Now you are changing this -o to -o3 which is incorrect. Instead you need to keep -o render as it is and add a -O3 flag for optimization. Note the capital letter O.
-o is the output file flag. You were thinking of -O (capital).

Failed to compile with distcc, but OK without it

I'm trying to compile RaLink drivers for usb wifi dongle. Without using distcc everything is OK but if i use distcc there is error.
Here make log:
make -C UTIL/
cp -f os/linux/Makefile.6.util /home/tobi/RaLink_driver/UTIL/os/linux/Makefile
make -C /home/tobi/linux/ SUBDIRS=/home/tobi/RaLink_driver/UTIL/os/linux modules
mkdir -p /home/tobi/RaLink_driver/UTIL/os/linux/.tmp_versions
rm -f /home/tobi/RaLink_driver/UTIL/os/linux/.tmp_versions/*
make -f scripts/Makefile.build obj=/home/tobi/RaLink_driver/UTIL/os/linux
mipsel-linux-gcc -Wp,-MD,/home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/.rt_linux.o.d -nostdinc -Iinclude -include include/linux/autoconf.h -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -O2 -mabi=32 -G 0 -mno-abicalls -fno-pic -pipe -msoft-float -ffreestanding --trap -Wno-uninitialized -fomit-frame-pointer -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -D__KERNEL__ -I/home/tobi/RaLink_driver/UTIL/include -Wall -O2 -Wundef -Wstrict-prototypes -Wno-trigraphs -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-aliasing -fno-common -fomit-frame-pointer -o -DMODULE -mlong-calls -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(rt_linux)" -D"KBUILD_MODNAME=KBUILD_STR(rtutil3572sta)" -c -o /home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/.tmp_rt_linux.o /home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/rt_linux.c
cc1: error: /home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/.tmp_rt_linux.d: No such file or directory
distcc[29414] ERROR: compile (null) on localhost failed
make[8]: *** [/home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/rt_linux.o] Error 1
make[7]: *** [_module_/home/tobi/RaLink_driver/UTIL/os/linux] Error 2
Without distcc log is the same but without error
cc1: error: /home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/.tmp_rt_linux.d: No such file or directory
Can anyone say what is wrong?
gcc's -Wp,MD does not take an argument. I think you might want to change this line:
-Wp,-MD,/home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/.rt_linux.o.d
to use -Wp,MF:
-Wp,MD -Wp,MF /home/tobi/RaLink_driver/UTIL/os/linux/../../os/linux/.rt_linux.o.d

Resources