1

I have a C program for the attiny85, that I want to disassemble and display with interleaved source code.

Here's my program: test.c

#include <avr/io.h>
int main() {
    for(int i=0; i<100; i++) {
        PORTB=i;
    }
}

Here's how I compile it: avr-gcc -g -O0 -mmcu=attiny85 -o test.elf test.c

Finally, I generate the disassembly with interleaved source-code with the command: avr-objdump -S -D test.elf

The disassembly of the text section shows the following disassembly without interleaved source code:

00000030 <main>:
  30:   cf 93           push    r28
  32:   df 93           push    r29
  34:   00 d0           rcall   .+0             ; 0x36 <main+0x6>
  36:   cd b7           in      r28, 0x3d       ; 61
  38:   de b7           in      r29, 0x3e       ; 62
  3a:   1a 82           std     Y+2, r1 ; 0x02
  3c:   19 82           std     Y+1, r1 ; 0x01
  3e:   0a c0           rjmp    .+20            ; 0x54 <__SREG__+0x15>
  40:   88 e3           ldi     r24, 0x38       ; 56
  42:   90 e0           ldi     r25, 0x00       ; 0
  44:   29 81           ldd     r18, Y+1        ; 0x01
  46:   fc 01           movw    r30, r24
  48:   20 83           st      Z, r18
  4a:   89 81           ldd     r24, Y+1        ; 0x01
  4c:   9a 81           ldd     r25, Y+2        ; 0x02
  4e:   01 96           adiw    r24, 0x01       ; 1
  50:   9a 83           std     Y+2, r25        ; 0x02
  52:   89 83           std     Y+1, r24        ; 0x01
  54:   89 81           ldd     r24, Y+1        ; 0x01
  56:   9a 81           ldd     r25, Y+2        ; 0x02
  58:   84 36           cpi     r24, 0x64       ; 100
  5a:   91 05           cpc     r25, r1
  5c:   8c f3           brlt    .-30            ; 0x40 <__SREG__+0x1>
  5e:   80 e0           ldi     r24, 0x00       ; 0
  60:   90 e0           ldi     r25, 0x00       ; 0
  62:   0f 90           pop     r0
  64:   0f 90           pop     r0
  66:   df 91           pop     r29
  68:   cf 91           pop     r28
  6a:   08 95           ret

The disassembly makes somewhat sense, only that I miss the interleaved source code.

Interestingly enough, the output also includes a stab section, where I also find the main segment disassembled:

#include <avr/io.h>

int main() {
  30:   20 00           .word   0x0020  ; ????
  32:   00 00           nop
  34:   80 00           .word   0x0080  ; ????
  36:   00 00           nop
  38:   00 00           nop
    for(int i=0; i<100; i++) {
  3a:   00 00           nop
  3c:   40 00           .word   0x0040  ; ????
  3e:   00 00           nop
        PORTB=i;
  40:   80 00           .word   0x0080  ; ????
  42:   00 00           nop
  44:   00 00           nop
  46:   00 00           nop
  48:   5a 00           .word   0x005a  ; ????
    for(int i=0; i<100; i++) {
  4a:   00 00           nop
  4c:   80 00           .word   0x0080  ; ????
  4e:   00 00           nop
  50:   00 00           nop
  52:   00 00           nop
  54:   91 00           .word   0x0091  ; ????
  56:   00 00           nop
  58:   80 00           .word   0x0080  ; ????
  5a:   00 00           nop
  5c:   00 00           nop
  5e:   00 00           nop
  60:   b7 00           .word   0x00b7  ; ????
    }

}

Now the output includes source code, but the disassembly is wrong.

How do I get an output were both is correct: the disassembled instructions and the interleaved source-code?

(avr-gcc (GCC) 9.3.0. Interleave Assembly and Source for avr-objdump does not seem to have the problem, although he's using the same compiler flags...)

1 Answer 1

3

The .stabs section contains debugging info, not actual code. There is no point in trying to “disassemble” it. The -D option of avr-objdump means “disassemble everything, whether or not you believe it's machine code”. Not what you want. For your purpose, -S should be enough.

I do not know why your main() is displayed without source code. I tried your exact same program with the exact same commands and I do see the source interleaved with the assembly. I am using avr-gcc 5.4.0 and avr-objdump 2.26.20160125 as shipped on Ubuntu Eoan.

1
  • 1
    Thanks. Indeed, if I downgrade the compiler to 5.4.0 it works as well. I'll try to pinpoint the version that introduced the problem and report a bug once I'm able to reproduce it in a clean environment.
    – Timo
    Commented Jun 4, 2020 at 12:04

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.