Makefile and debugging

Lab  – Makefile and debugging


  1. Create a simple hello application
  2. Write a Makefile to build it

.PHONY: clean all

all: test

x.o: x.c
            $(CC) $(CFLAGS) -c x.c

test: x.o
            $(CC) $(LDFLAGS) x.o -o test

            @rm -f *.o *~ test
  1. Change the debug level
  2. Change the compiler to arm compiler
  3. Add install target to the file and run make install to copy executable to root file system
  4. Add another file to your project with a simple add function and update the makefile
  5. Run the program on target using gdbserver
# gdbserver      ./test
  1. Run gdb debugger on host and load the executable
# arm-none-linux-gnueabi-gdb    ./test
  1. Connect to target and debug the code
(gdb) target remote
(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
  1. Strip the code and run it again on target
# arm-none-linux-gnueabi-strip –d ./test
  1. Change the code to access a wrong address
  2. Run the code to get an error
  3. Create a core dump
# ulimit -c unlimited
  1. Run the gdb debugger using the core dump and examine the error
  2. Write a fault handler to catch common errors and print useful information