2

Trying to get avr-objdump to generate a listing that interleaves the assembly with the source code. I've tried a bunch of debugging arguments in different configurations but I can't seem to get it. The best I could do was getting it to interleave the object with line numbers from the assembly (avr-objdump -lS spi.o)

Original Makefile

Here's my current Makefile:

PREFIX=avr-
CC=${PREFIX}gcc
OBJCOPY=${PREFIX}objcopy
BIN=knightrider
MCU=attiny85
OBJS=../src/tinySPI.o src/knightrider.o
PROG?=atmelice_isp
PORT?=usb
CFLAGS=-g -mmcu=${MCU} -ffunction-sections -fdata-sections
LDFLAGS=-mmcu=${MCU} -Wl,--gc-sections
${BIN}.hex: ${BIN}.elf
 @mkdir -p bin
 ${OBJCOPY} -O ihex -R .eeprom build/$< bin/$@
${BIN}.elf: ${OBJS}
 @mkdir -p build
 ${CC} ${LDFLAGS} -o build/$@ $?
install: ${BIN}.hex
 avrdude -c ${PROG} -P ${PORT} -p ${MCU} -U flash:w:${BIN}.hex:i -qq
clean:
 rm -f build/*
 rm -f bin/*
fuses:
 avrdude -c ${PROG} -P ${PORT} -p ${MCU} -U lfuse:w:0x62:m -U hfuse:w:0xDF:m -U efuse:w:0xFF:i -qq

What would I need to change in order to run avr-objdump and get an interleaved listing of an .o and its corresponding .c (e.g. spi.o and spi.c)?

asked Dec 4, 2015 at 16:19

1 Answer 1

3

First make sure you add -g to all your compilation commands.

Then you can run avr-objdump -S build/spi.elf (for instance).

Also I see you're missing the MCU definition in your link command. Without that it won't link in the proper C startup routines and your program will most probably not run.

Here is a makefile I use:

PREFIX=avr-
CC=${PREFIX}gcc
CXX=${PREFIX}g++
LD=${PREFIX}ld
AS=${PREFIX}as
OBJCOPY=${PREFIX}objcopy
OBJDUMP=${PREFIX}objdump
BIN=blink
MCU=atmega328p
OBJS=blink.o
CFLAGS=-g -mmcu=${MCU} -ffunction-sections -fdata-sections
CXXFLAGS=-g -mmcu=${MCU} -ffunction-sections -fdata-sections -fno-exceptions
LDFLAGS=-mmcu=${MCU} -Wl,--gc-sections
${BIN}.hex: ${BIN}.elf
 ${OBJCOPY} -O ihex -R .eeprom $< $@
${BIN}.elf: ${OBJS}
 ${CC} ${LDFLAGS} -o $@ $? 
 ${OBJDUMP} -S $@ > ${BIN}.dis
install: ${BIN}.hex
 avrdude -C ./avrdude.conf -c usbasp -p ${MCU} -U flash:w:${BIN}.hex
 -qq
clean:
 rm -f *.o *.elf *.hex
fuses:
 avrdude -c usbasp -p ${MCU} -C avrdude.conf -U lfuse:w:0xff:m -U h
fuse:w:0xd6:m -U efuse:w:0x05:m -qq
answered Dec 4, 2015 at 19:07
5
  • That is some serious make-fu and I'm currently reading "GNU Make" before I come back to it. Commented Dec 5, 2015 at 3:39
  • Nothing that amazing really. It's mostly variable substitution and the use of the fact that Make already knows how to compile files as long as you set the right program and the flags to use with it. No need to specify each and every fole manually, just the list of objrct files and Make works the rest out for itself. Commented Dec 5, 2015 at 10:45
  • I'm back, it works great! Only problem is that it spits objects into the source folder; I want the objects to go into the build folder. Commented Dec 5, 2015 at 16:23
  • For that you're going to need to add a .c.o recipe possibly. Using separate folders like that gets a little tricky with make. Commented Dec 5, 2015 at 17:29
  • Nailed it with a few filename functions, thank you so much! Commented Dec 5, 2015 at 18:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.