Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: How to view generated assembly?

  1. #1

    How to view generated assembly?

    Im using visual studio code to build my project, but some parts i just want to see what the compiler generated.
    There are “start debugging” options in the menu, but it doesn’t do anything. (Need to connect some way other than usb?)
    But i can do without debugging, i just want to view the assembly generated and see if i can optimize better than the compiler.

    I have put in the -S flag in platformio.ini, but it doesn’t seem to do anything.

    [env:teensy40]
    build_flags = "-S"
    platform = teensy
    board = teensy40
    framework = arduino
    monitor_speed = 115200
    upload_port = /dev/cu.usbmodem*
    monitor_port = /dev/cu.usbmodem*

    I was pretty good >20 years ago coding the 68000 on the Amiga in AsmOne and MasterSeka, but things will now be a lot different.
    Any pointers or links to some video’s that can get me up to speed? I’m a bit clueless so anything easy is appreciated….

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,782
    I am sure there are options to give you a list file. Been awhile since I have looked..

    The Arduino build gives you a .sym file which tells you where everything is located...

    I then sometimes will look at... When I do some times, I will sort the file by address in editor

    When I have nothing else available, sometimes I will use tool, like objdump to get a disassemble of everything:
    In my case right now with something like:

    Code:
    C:\Users\kurte\AppData\Local\Temp\arduino-sketch-8D0D1B8976AFFA0186D59F8FFADB7EC2>dir
     Volume in drive C is Windows
     Volume Serial Number is B2F0-35F3
    
     Directory of C:\Users\kurte\AppData\Local\Temp\arduino-sketch-8D0D1B8976AFFA0186D59F8FFADB7EC2
    
    06/28/2022  05:31 AM    <DIR>          .
    06/28/2022  05:31 AM    <DIR>          ..
    06/28/2022  05:31 AM               548 build.options.json
    06/28/2022  05:31 AM           113,945 compile_commands.json
    06/28/2022  05:31 AM    <DIR>          core
    06/28/2022  05:31 AM            12,276 includes.cache
    06/28/2022  05:31 AM    <DIR>          libraries
    06/28/2022  05:31 AM    <DIR>          pch
    06/28/2022  05:31 AM    <DIR>          preproc
    06/28/2022  05:31 AM    <DIR>          sketch
    06/28/2022  05:31 AM                34 tft_picture_view.ino.eep
    06/28/2022  05:31 AM           419,051 tft_picture_view.ino.ehex
    06/28/2022  05:31 AM         2,144,908 tft_picture_view.ino.elf
    06/28/2022  05:31 AM           475,324 tft_picture_view.ino.hex
    06/28/2022  05:31 AM            59,086 tft_picture_view.ino.sym
                   8 File(s)      3,225,172 bytes
                   7 Dir(s)  622,379,573,248 bytes free
    
    C:\Users\kurte\AppData\Local\Temp\arduino-sketch-8D0D1B8976AFFA0186D59F8FFADB7EC2>C:\arduino-1.8.19\hardware\tools\arm\arm-none-eabi\bin\objdump.exe -D tft_picture_view.ino.elf >
    foo
    
    C:\Users\kurte\AppData\Local\Temp\arduino-sketch-8D0D1B8976AFFA0186D59F8FFADB7EC2>subl foo
    
    C:\
    And the subl command loads the file into sublime text... Obviously you can use whatever editor you want...

    So if I wanted to look at lets say:
    Code:
    00013fc4 g     F .text.itcm	00000348 ILI9341_t3n::setRotation(unsigned char)
    0001430c g     F .text.itcm	00000410 ILI9341_t3n::writeRect(short, short, short, short, unsigned short const*)
    0001471c g     F .text.itcm	0000009e ILI9341_t3n::scrollTextArea(unsigned char)
    I could look in the objdump otuput file: for that address and by a munged name:
    Code:
       1430a:	e673      	b.n	13ff4 <_ZN11ILI9341_t3n11setRotationEh+0x30>
    
    0001430c <_ZN11ILI9341_t3n9writeRectEssssPKt>:
       1430c:	e92d 4ff0 	stmdb	sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
       14310:	f242 770e 	movw	r7, #9998	; 0x270e
       14314:	b085      	sub	sp, #20
       14316:	4605      	mov	r5, r0
       14318:	4698      	mov	r8, r3
       1431a:	42b9      	cmp	r1, r7
       1431c:	f9bd 6038 	ldrsh.w	r6, [sp, #56]	; 0x38
       14320:	9c0f      	ldr	r4, [sp, #60]	; 0x3c
       14322:	f000 80a2 	beq.w	1446a <_ZN11ILI9341_t3n9writeRectEssssPKt+0x15e>
       14326:	f242 730e 	movw	r3, #9998	; 0x270e
       1432a:	429a      	cmp	r2, r3
       1432c:	f000 8095 	beq.w	1445a <_ZN11ILI9341_t3n9writeRectEssssPKt+0x14e>
       14330:	8e6f      	ldrh	r7, [r5, #50]	; 0x32
       14332:	f9b5 003a 	ldrsh.w	r0, [r5, #58]	; 0x3a
       14336:	4439      	add	r1, r7
       14338:	b28f      	uxth	r7, r1
       1433a:	b239      	sxth	r1, r7
       1433c:	4281      	cmp	r1, r0
       1433e:	f280 8089 	bge.w	14454 <_ZN11ILI9341_t3n9writeRectEssssPKt+0x148>
       14342:	8eab      	ldrh	r3, [r5, #52]	; 0x34
       14344:	f9b5 e03c 	ldrsh.w	lr, [r5, #60]	; 0x3c
       14348:	4413      	add	r3, r2
       1434a:	b21b      	sxth	r3, r3
    ...
    Again I am sure there is a compiler option to get the list file, but I have not looked it up.

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,850
    As Kurt mentioned the usual way is to use objdump.exe.

    Here an example using PlatformIO:
    After compiling, go to the vsCode terminal and cd to your build directory cd .pio/build/whatever_board_you_are_compiling_for. You should have a firmware.elf in this folder.
    From there call objdump.exe it should be located in your_home_folder/.platformio/packages/toolchain-gccarmnoneeabi\bin\ and is fully called arm-none-eabi-objdump.exe. Call it with options -m arm -d -S --demangle firmware.elf > firmware.lst to get a list file.

    Here the comandline for my installation (windows, translation to linux should be self explanatory)

    Code:
    c:\Users\lutz\.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-objdump -m arm -d -S --demangle firmware.elf > firmware.lst
    If you are only interested in short snippets you can also use the compiler explorer: E.g.: https://godbolt.org/z/98Yc4ETjT

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,568
    Until recently, we had the Arduino build process automatically create a .lst file. The line which does it is still within boards.txt, just commented out.

    It was removed because objdump is extremely slow for certain very large programs. Those cases are rare, but when people encountered them the build process would effectively hang for 30 seconds or longer, which feels like pretty much forever.

    Also turns out the older version of objdump included with Teensyduino has a bug where incorrect disassembly is shown for Cortex M7.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •