"objdump --source" doesn't intermix source code

Inspired by another thread, what I did in the Windows XP command prompt, after having verified a sketch:

>CD %TEMP%\build2041587001917497488.tmp
>C:\Temp\arduino-1.0.4\hardware\tools\avr\avr\bin\objdump.exe -x -d -S keyboard.cpp.o >keyboard.asm

The output is only showing some hints but not actual source code snippets. Am I missing something?

keyboard.asm: (trimmed to stay in message size limits)

keyboard.cpp.o:     file format elf32-avr
keyboard.cpp.o
architecture: avr:5, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000034  2**0
                  ALLOC
  3 .debug_abbrev 000001c8  00000000  00000000  00000034  2**0
                  CONTENTS, READONLY, DEBUGGING
  4 .debug_info   0000034c  00000000  00000000  000001fc  2**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
  5 .debug_line   0000023c  00000000  00000000  00000548  2**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
  6 .text._GLOBAL__I_keys 000001d2  00000000  00000000  00000784  2**0
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  7 .ctors        00000002  00000000  00000000  00000956  2**0
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
  8 .text.loop    000000a2  00000000  00000000  00000958  2**0
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  9 .text.setup   0000001a  00000000  00000000  000009fa  2**0
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
 10 .bss.keys     00000060  00000000  00000000  00000a14  2**0
                  ALLOC
 11 .debug_frame  00000040  00000000  00000000  00000a14  2**2
                  CONTENTS, RELOC, READONLY, DEBUGGING
 12 .debug_loc    00000056  00000000  00000000  00000a54  2**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
 13 .debug_pubnames 0000002e  00000000  00000000  00000aaa  2**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
 14 .debug_aranges 00000030  00000000  00000000  00000ad8  2**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
 15 .debug_ranges 00000058  00000000  00000000  00000b08  2**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
 16 .debug_str    00000209  00000000  00000000  00000b60  2**0
                  CONTENTS, READONLY, DEBUGGING
SYMBOL TABLE:
00000000 l    df *ABS*	00000000 keyboard.cpp
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
0000003f l       *ABS*	00000000 __SREG__
0000003e l       *ABS*	00000000 __SP_H__
0000003d l       *ABS*	00000000 __SP_L__
00000034 l       *ABS*	00000000 __CCP__
00000000 l       *ABS*	00000000 __tmp_reg__
00000001 l       *ABS*	00000000 __zero_reg__
00000000 l    d  .debug_abbrev	00000000 .debug_abbrev
00000000 l    d  .debug_info	00000000 .debug_info
00000000 l    d  .debug_line	00000000 .debug_line
00000000 l    d  .text._GLOBAL__I_keys	00000000 .text._GLOBAL__I_keys
00000000 l     F .text._GLOBAL__I_keys	000001d2 _GLOBAL__I_keys
00000000 l    d  .ctors	00000000 .ctors
00000000 l    d  .text.loop	00000000 .text.loop
00000000 l    d  .text.setup	00000000 .text.setup
00000000 l    d  .bss.keys	00000000 .bss.keys
00000000 l    d  .debug_frame	00000000 .debug_frame
00000000 l    d  .debug_loc	00000000 .debug_loc
00000000 l    d  .debug_pubnames	00000000 .debug_pubnames
00000000 l    d  .debug_aranges	00000000 .debug_aranges
00000000 l    d  .debug_ranges	00000000 .debug_ranges
00000000 l    d  .debug_str	00000000 .debug_str
00000000         *UND*	00000000 __do_copy_data
00000000         *UND*	00000000 __do_clear_bss
00000000 g     O .bss.keys	00000060 keys
00000000         *UND*	00000000 __do_global_ctors
00000000 g     F .text.loop	000000a2 loop
00000000         *UND*	00000000 digitalWrite
00000000         *UND*	00000000 Keyboard
00000000         *UND*	00000000 _ZN9Keyboard_5pressEh
00000000         *UND*	00000000 _ZN9Keyboard_7releaseEh
00000000 g     F .text.setup	0000001a setup
00000000         *UND*	00000000 pinMode
00000000         *UND*	00000000 _ZN9Keyboard_5beginEv



Disassembly of section .text._GLOBAL__I_keys:

00000000 <_GLOBAL__I_keys>:
[...]

Disassembly of section .text.loop:

[...]

Disassembly of section .text.setup:

00000000 <setup>:
   0:	8d e0       	ldi	r24, 0x0D	; 13
   2:	61 e0       	ldi	r22, 0x01	; 1
   4:	0e 94 00 00 	call	0	; 0x0 <setup>
			4: R_AVR_CALL	pinMode
   8:	8c e0       	ldi	r24, 0x0C	; 12
   a:	61 e0       	ldi	r22, 0x01	; 1
   c:	0e 94 00 00 	call	0	; 0x0 <setup>
			c: R_AVR_CALL	pinMode
  10:	80 e0       	ldi	r24, 0x00	; 0
			10: R_AVR_LO8_LDI	Keyboard
  12:	90 e0       	ldi	r25, 0x00	; 0
			12: R_AVR_HI8_LDI	Keyboard
  14:	0e 94 00 00 	call	0	; 0x0 <setup>
			14: R_AVR_CALL	_ZN9Keyboard_5beginEv
  18:	08 95       	ret

keyboard.cpp: (trimmed)

[...]

inline void processKey(bool keyIsDown, struct key_s &key) {
  if (keyIsDown) {
    if (!key.isPressed) {
      Keyboard.press(key.code);
      key.isPressed = true;
    } // else: no change
  } else { // key is up
    if (key.isPressed) {
      Keyboard.release(key.code);
      key.isPressed = false;
    } // else: no change
  }
}

inline void processRow(char pinStates, struct key_s *key_p) {
  pinStates >>= 2; // first two pins not used for columns

  while (pinStates) {
    processKey(pinStates & 1, *key_p);
    pinStates >>= 1;
    key_p++;
  }
}

void setup() {
  pinMode(decadeCounterClockPin, OUTPUT);
  pinMode(decadeCounterResetPin, OUTPUT);
  Keyboard.begin();
}

void loop(){
  resetDecadeCounter();

  for (struct key_s *key_p = keys; key_p < keys + 8 * 6; key_p += 6) {
    char pinStates = PIND;
    processRow(pinStates, key_p);
    incrementDecadeCounter();
  }
}

Hmm, I just tested my v1.5.1r2 and it does add the source, but my 1.0.4 does not. Very strange!
Maybe one of the new compiler/linker options prematurely removes symbols necessary to produce the output.

pYro_65:
I just tested my v1.5.1r2 and it does add the source

Thanks, but for me it doesn't work either with v1.5.2. See below.

Command that I executed:

>C:\Temp\arduino-1.5.2\hardware\tools\avr\avr\bin\objdump.exe --all-headers --disassemble --source keyboard.cpp.o >keyboard.asm

keyboard.asm: (trimmed)

[...]

Disassembly of section .text.loop:

00000000 <loop>:
   0:	df 92       	push	r13
   2:	ef 92       	push	r14
   4:	ff 92       	push	r15
   6:	0f 93       	push	r16
   8:	1f 93       	push	r17
   a:	cf 93       	push	r28
   c:	df 93       	push	r29
   e:	8c e0       	ldi	r24, 0x0C	; 12
  10:	61 e0       	ldi	r22, 0x01	; 1
  12:	0e 94 00 00 	call	0	; 0x0 <loop>
			12: R_AVR_CALL	digitalWrite
  16:	8c e0       	ldi	r24, 0x0C	; 12
  18:	60 e0       	ldi	r22, 0x00	; 0
  1a:	0e 94 00 00 	call	0	; 0x0 <loop>
			1a: R_AVR_CALL	digitalWrite
  1e:	90 e0       	ldi	r25, 0x00	; 0
			1e: R_AVR_LO8_LDI	.bss.keys
  20:	e9 2e       	mov	r14, r25
  22:	90 e0       	ldi	r25, 0x00	; 0
			22: R_AVR_HI8_LDI	.bss.keys
  24:	f9 2e       	mov	r15, r25
  26:	dd 24       	eor	r13, r13
  28:	d3 94       	inc	r13
  2a:	89 b1       	in	r24, 0x09	; 9
  2c:	85 95       	asr	r24
  2e:	85 95       	asr	r24
  30:	e7 01       	movw	r28, r14
  32:	00 c0       	rjmp	.+0      	; 0x34 <loop+0x34>
			32: R_AVR_13_PCREL	.text.loop+0x6c
  34:	08 2f       	mov	r16, r24
  36:	11 27       	eor	r17, r17
  38:	07 fd       	sbrc	r16, 7
  3a:	10 95       	com	r17
  3c:	89 81       	ldd	r24, Y+1	; 0x01
  3e:	00 ff       	sbrs	r16, 0
  40:	00 c0       	rjmp	.+0      	; 0x42 <loop+0x42>
			40: R_AVR_13_PCREL	.text.loop+0x54
  42:	88 23       	and	r24, r24
  44:	01 f4       	brne	.+0      	; 0x46 <loop+0x46>
			44: R_AVR_7_PCREL	.text.loop+0x64
  46:	80 e0       	ldi	r24, 0x00	; 0
			46: R_AVR_LO8_LDI	Keyboard
  48:	90 e0       	ldi	r25, 0x00	; 0
			48: R_AVR_HI8_LDI	Keyboard
  4a:	68 81       	ld	r22, Y
  4c:	0e 94 00 00 	call	0	; 0x0 <loop>
			4c: R_AVR_CALL	_ZN9Keyboard_5pressEh
  50:	d9 82       	std	Y+1, r13	; 0x01
  52:	00 c0       	rjmp	.+0      	; 0x54 <loop+0x54>
			52: R_AVR_13_PCREL	.text.loop+0x64
  54:	88 23       	and	r24, r24
  56:	01 f0       	breq	.+0      	; 0x58 <loop+0x58>
			56: R_AVR_7_PCREL	.text.loop+0x64
  58:	80 e0       	ldi	r24, 0x00	; 0
			58: R_AVR_LO8_LDI	Keyboard
  5a:	90 e0       	ldi	r25, 0x00	; 0
			5a: R_AVR_HI8_LDI	Keyboard
  5c:	68 81       	ld	r22, Y
  5e:	0e 94 00 00 	call	0	; 0x0 <loop>
			5e: R_AVR_CALL	_ZN9Keyboard_7releaseEh
  62:	19 82       	std	Y+1, r1	; 0x01
  64:	15 95       	asr	r17
  66:	07 95       	ror	r16
  68:	80 2f       	mov	r24, r16
  6a:	22 96       	adiw	r28, 0x02	; 2
  6c:	88 23       	and	r24, r24
  6e:	01 f4       	brne	.+0      	; 0x70 <loop+0x70>
			6e: R_AVR_7_PCREL	.text.loop+0x34
  70:	8d e0       	ldi	r24, 0x0D	; 13
  72:	61 e0       	ldi	r22, 0x01	; 1
  74:	0e 94 00 00 	call	0	; 0x0 <loop>
			74: R_AVR_CALL	digitalWrite
  78:	8d e0       	ldi	r24, 0x0D	; 13
  7a:	60 e0       	ldi	r22, 0x00	; 0
  7c:	0e 94 00 00 	call	0	; 0x0 <loop>
			7c: R_AVR_CALL	digitalWrite
  80:	8c e0       	ldi	r24, 0x0C	; 12
  82:	90 e0       	ldi	r25, 0x00	; 0
  84:	e8 0e       	add	r14, r24
  86:	f9 1e       	adc	r15, r25
  88:	90 e0       	ldi	r25, 0x00	; 0
			88: R_AVR_LO8_LDI	.bss.keys+0x60
  8a:	e9 16       	cp	r14, r25
  8c:	90 e0       	ldi	r25, 0x00	; 0
			8c: R_AVR_HI8_LDI	.bss.keys+0x60
  8e:	f9 06       	cpc	r15, r25
  90:	01 f4       	brne	.+0      	; 0x92 <loop+0x92>
			90: R_AVR_7_PCREL	.text.loop+0x2a
  92:	df 91       	pop	r29
  94:	cf 91       	pop	r28
  96:	1f 91       	pop	r17
  98:	0f 91       	pop	r16
  9a:	ff 90       	pop	r15
  9c:	ef 90       	pop	r14
  9e:	df 90       	pop	r13
  a0:	08 95       	ret

Disassembly of section .text.setup:

00000000 <setup>:
   0:	8d e0       	ldi	r24, 0x0D	; 13
   2:	61 e0       	ldi	r22, 0x01	; 1
   4:	0e 94 00 00 	call	0	; 0x0 <setup>
			4: R_AVR_CALL	pinMode
   8:	8c e0       	ldi	r24, 0x0C	; 12
   a:	61 e0       	ldi	r22, 0x01	; 1
   c:	0e 94 00 00 	call	0	; 0x0 <setup>
			c: R_AVR_CALL	pinMode
  10:	80 e0       	ldi	r24, 0x00	; 0
			10: R_AVR_LO8_LDI	Keyboard
  12:	90 e0       	ldi	r25, 0x00	; 0
			12: R_AVR_HI8_LDI	Keyboard
  14:	0e 94 00 00 	call	0	; 0x0 <setup>
			14: R_AVR_CALL	_ZN9Keyboard_5beginEv
  18:	08 95       	ret

Try this way -

Let me know if it works for you

Duane B

rcarduino.blogspot.com

DuaneB:
RCArduino: How To View Arduino and Arduino Due Assembly

Long story cut short:

>C:\Temp\arduino-1.5.2\hardware\tools\avr\bin\avr-objdump.exe -S keyboard.cpp.elf >keyboard.dmp

Indeed assembler instructions are now intermixed with source code, but: not for my code (loop, setup) :frowning:

pYro_65:
Hmm, I just tested my v1.5.1r2 and it does add the source, but my 1.0.4 does not. Very strange!
Maybe one of the new compiler/linker options prematurely removes symbols necessary to produce the output.

Could you post an example sketch and the generated Assembler with intermixed source code?

See here: #line directive interferes with disassembly. · Issue #1337 · arduino/Arduino · GitHub

The quick workaround is to copy your .ino file to the temp directory.

westfw:
The quick workaround is to copy your .ino file to the temp directory.

That doesn't work either, unfortunately:

>COPY %PROJECT_PATH%\keyboard.ino .
>%ARDUINO_1.5.2_PATH%\hardware\tools\avr\avr\bin\objdump.exe --all-headers --disassemble --source keyboard.cpp.o >keyboard.asm
>%ARDUINO_1.5.2_PATH%\hardware\tools\avr\bin\avr-objdump.exe -S keyboard.cpp.elf >keyboard.dmp

Neither the asm nor the dmp file contain source code intermixed into the assembler code.

Try giving it a search path as well:
%ARDUINO_1.5.2_PATH%\hardware\tools\avr\avr\bin\objdump.exe -I. --all-headers --disassemble --source keyboard.cpp.o >keyboard.asm
Specifying both --disassemble AND --source shouldn't be necessary; --source implies --disassemble

westfw:
Try giving it a search path as well: [...]

That's it - thanks!

Summary, how I proceeded:

  • Opened the .ino file in the Arduino 1.5.2 IDE.
  • In the IDE, clicked the verify button.
  • Entered the temporary directory to which output files were written during the verification process:
CD %TEMP%\build7509943983578216208.tmp
  • Copied the ino source file into the temporary directory:
CP %PROJECT_PATH%\keyboard.ino .
  • Created the desired asm file containing Assembler intermixed with the source code:
%ARDUINO_1.5.2_PATH%\hardware\tools\avr\avr\bin\objdump.exe -I. --all-headers --source keyboard.cpp.o >keyboard.asm