Lab – Makefile and debugging
- Create a simple hello application
- Write a Makefile to build it
CC=gcc CFLAGS=-g LDFLAGS=-lpthread .PHONY: clean all all: test x.o: x.c $(CC) $(CFLAGS) -c x.c test: x.o $(CC) $(LDFLAGS) x.o -o test clean: @rm -f *.o *~ test
- Change the debug level
- Change the compiler to arm compiler
- Add install target to the file and run make install to copy executable to root file system
- Add another file to your project with a simple add function and update the makefile
- Run the program on target using gdbserver
# gdbserver 0.0.0.0:8000 ./test
- Run gdb debugger on host and load the executable
# arm-none-linux-gnueabi-gdb ./test
- Connect to target and debug the code
(gdb) target remote 192.168.24.30:8000 (gdb) b main (gdb) c (gdb) n (gdb) info registers (gdb) print i (gdb) n (gdb) n (gdb) display i (gdb) n (gdb) n (gdb) x/20w $sp (gdb) c
- Strip the code and run it again on target
# arm-none-linux-gnueabi-strip –d ./test
- Change the code to access a wrong address
- Run the code to get an error
- Create a core dump
# ulimit -c unlimited
- Run the gdb debugger using the core dump and examine the error
- Write a fault handler to catch common errors and print useful information