Arduino Forum

Forum 2005-2010 (read only) => Software => Bugs & Suggestions => Topic started by: avandalen on Apr 30, 2009, 08:48 pm

Title: Automatic disassembling
Post by: avandalen on Apr 30, 2009, 08:48 pm
Optimizing c++ code requires that we can view the generated machine code (hex) in assembly language. With the program avr-objdump.exe in \hardware\tools\avr\bin we can disassemble the machine code. The input is the .elf file in the applet folder.
The avr-objdump.exe program has some limitations:

One has to create a separate batchfile for each project
The batchfile must be run manually
File / folder names with spaces are not supported because of DOS limitations

Here is an example batchfile that I use:
Code: [Select]
@echo off
cls
echo Disassembler for the .elf file in \applet by avr-objdump.exe
rem Place avr-objdump.exe and this batch file in the same folder
rem Don't use filenames with spaces

avr-objdump -S ..\code\Streaming\Streaming\applet\Blablabla1234567890.elf > Blablabla1234567890_assembler.txt
pause

It would be very handy that the disassembler would run automatically after compiling.

Who has the experience to help me with this?
Title: Re: Automatic disassembling
Post by: AlphaBeta on Apr 30, 2009, 08:52 pm
See this: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207951658/2#2
Title: Re: Automatic disassembling
Post by: westfw on May 01, 2009, 09:48 am
I usually keep a shell window around when I'm optimizing, connected to the appropriate directory:
Code: [Select]
BillW-MacOSX-2<1415> cd ~/Documents/Arduino/loop_example/applet/
BillW-MacOSX-2<1416> /Applications/arduino/arduino-0014/hardware/tools/avr/bin/avr-objdump  -S *.elf > foo.S
BillW-MacOSX-2<1417>

You seem to already have avr-objdump in your path, so it's even easier.  I just use the reverse-search-through-history feature of "bash" to find the last time I used it.  You CAN install bash on windows (cygwin or similar), but the basic idea should work even with the normal windows command line shell.
Title: Re: Automatic disassembling
Post by: carl47 on May 20, 2010, 11:59 pm
I'm using windows XP and I have found the best way for me.

1. Bring up command prompt. Mine is

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\carl>

2. Copy avr-objdump from \hardware\tools\avr\avr\bin into
   C:\Documents and Settings\carl.

    It will now be accessable from your command line.

3. When you want to disassemble copy the required .elf file into the
    same folder as above .
   From the command line type:

C:\Documents and Settings\carl>avr-objdump -S BlinkASM.cpp.elf > disasm.txt

4. the lising is now in the same folder.

Here is the loop function from blink after disassembly:

00000100 <loop>:
// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
 digitalWrite(ledPin, HIGH);   // set the LED on
100:      80 91 00 01       lds      r24, 0x0100
104:      61 e0             ldi      r22, 0x01      ; 1
106:      0e 94 70 01       call      0x2e0      ; 0x2e0 <digitalWrite>
 delay(1000);                  // wait for a second
10a:      68 ee             ldi      r22, 0xE8      ; 232
10c:      73 e0             ldi      r23, 0x03      ; 3
10e:      80 e0             ldi      r24, 0x00      ; 0
110:      90 e0             ldi      r25, 0x00      ; 0
112:      0e 94 ec 00       call      0x1d8      ; 0x1d8 <delay>
 digitalWrite(ledPin, LOW);    // set the LED off
116:      80 91 00 01       lds      r24, 0x0100
11a:      60 e0             ldi      r22, 0x00      ; 0
11c:      0e 94 70 01       call      0x2e0      ; 0x2e0 <digitalWrite>
 delay(1000);                  // wait for a second
120:      68 ee             ldi      r22, 0xE8      ; 232
122:      73 e0             ldi      r23, 0x03      ; 3
124:      80 e0             ldi      r24, 0x00      ; 0
126:      90 e0             ldi      r25, 0x00      ; 0
128:      0e 94 ec 00       call      0x1d8      ; 0x1d8 <delay>
}
12c:      08 95             ret

Other options available:

Usage: avr-objdump <option(s)> <file(s)>
Display information from object <file(s)>.
At least one of the following switches must be given:
 -a, --archive-headers    Display archive header information
 -f, --file-headers       Display the contents of the overall file header
 -p, --private-headers    Display object format specific file header contents
 -h, --[section-]headers  Display the contents of the section headers
 -x, --all-headers        Display the contents of all headers
 -d, --disassemble        Display assembler contents of executable sections
 -D, --disassemble-all    Display assembler contents of all sections
 -S, --source             Intermix source code with disassembly
 -s, --full-contents      Display the full contents of all sections requested
 -g, --debugging          Display debug information in object file
 -e, --debugging-tags     Display debug information using ctags style
 -G, --stabs              Display (in raw form) any STABS info in the file
 -W, --dwarf              Display DWARF info in the file
 -t, --syms               Display the contents of the symbol table(s)
 -T, --dynamic-syms       Display the contents of the dynamic symbol table
 -r, --reloc              Display the relocation entries in the file
 -R, --dynamic-reloc      Display the dynamic relocation entries in the file
 @<file>                  Read options from <file>
 -v, --version            Display this program's version number
 -i, --info               List object formats and architectures supported
 -H, --help               Display this information

Title: Re: Automatic disassembling
Post by: PaulS on May 21, 2010, 12:48 am
@carl47
Do me a favor, please. Never use green text. On a white background, that hurts my eyes and is hard to read.
Title: Re: Automatic disassembling
Post by: carl47 on May 21, 2010, 09:35 pm
How about a nice soft pink?
Title: Re: Automatic disassembling
Post by: PaulS on May 21, 2010, 10:04 pm
That works.
Title: Re: Automatic disassembling
Post by: donone on Oct 18, 2010, 09:27 pm
Can I please resurrect this thread.
Can somebody please translate what looks like superb information, to work with Windows 7, which does not permit access to what appears to be legacy Documents and Settings/username
Thank you
Title: Re: Automatic disassembling
Post by: mirzas on Oct 18, 2010, 09:48 pm
Try: C:\users\username

or copy/move the files to some other directory outside of C:\users path. For example C:\temp
Title: Re: Automatic disassembling
Post by: Coding Badly on Oct 18, 2010, 09:50 pm

Two things...

1. Microsoft moved the user documents folder to \Users.  Typically the path for you will be "C:\Users\{Your Login}\Documents".

2. The Arduino folks changed the IDE so it no longer outputs the Applet subdirectory.  You can find the ELF file in a subdirectory in the %TEMP% folder.
Title: Re: Automatic disassembling
Post by: carl47 on Oct 18, 2010, 11:48 pm
I have just moved to window 7. I am the administrator.

The command prompt is still under accessories.
It is now run from:

C:\users\carl>

So just copy as before:

2. Copy objdump from \hardware\tools\avr\avr\bin into
  C:\users\carl.

It will now be accessible from your command line.

Coding Badly.

I've just started using 21 and I did not realise until your reply that the applet had  disappeared.

You can find the tempory folder by doing a search with  %TEMP%

Mine is at:

C:\Users\carl\AppData\Local\Temp

There are many folders in this windows tempory file location.

I compiled a arduino sketch but I can find no sign of a arduino tempory folder.

There were a whole bunch of folders like:

untitled329976128171923035.tmp

which contained blank .pde files.


Help!

Title: Re: Automatic disassembling
Post by: donone on Oct 19, 2010, 07:41 am
Thank you all for your excellent redirection, hopefully I will have success.
Title: Re: Automatic disassembling
Post by: carl47 on Oct 19, 2010, 07:46 am
I found out how to find the applet(which has the .elf file) with help from:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1287332515

Compile or upload the sketch and do not close the sketch. Then look in:

C:\Users\carl\AppData\Local\Temp

you will find a folder like:


build6586865351983244490.tmp  or

build4306609694168305606.tmp

The "build" is always common to the applet file.

The folder is deleted when you close the sketch.

So now you just:

3. When you want to disassemble copy the required .elf file into the
   same folder as above .
  From the command line type:

C:\Users\carl>objdump -S BlinkASM.cpp.elf > disasm.txt

4. the lising is now in the same folder.
Title: Re: Automatic disassembling
Post by: donone on Oct 19, 2010, 07:50 am
Thank you carl47, this will take me a while to sort out but I am sure that all this info will help me achieve my goal.