Viewing C and Assembler inline



  • Avatar
    Paul Curtis

    AFAIK, there is no "listing file" generated by GCC.

    Comment actions Permalink
  • Avatar

    I succeded by  adding


    in the Additional Assembler Options to get what I want.

    Don't know if list file is the official term.

    Comment actions Permalink
  • Avatar
    Kelly Painter

    I generate asm (with C code intermingled) list files by adding a python script to call objdump in the Post-Link Command project property:

    python $(ProjectDir)/ 1 "$(ProjectDir)/$(OutDir)"


    Here is my python v.2.6.2 script

    from __future__ import print_function
    import os
    import subprocess
    import sys
    from stat import *

    def gen_lst_files(path):
        file_list = os.walk(path).next()[2]
        for filename in file_list:
            if('.o' in filename):
                run_objdump = False
                st_obj = os.stat(filename)
                fileout = filename.split('.')[0] + '.lst'
                    if os.path.exists(fileout):    
                        #print(fileout, 'exists')
                        st_lst = os.stat(fileout)
                        if st_obj[ST_MTIME] > st_lst[ST_MTIME]: #was object time modified after lst file
                            #print('time delta pos, run objdump')
                            run_objdump = True
                        raise FileError
                    #print('exception, run objdump')
                    run_objdump = True
                if run_objdump == True:
                    arg = '"C:\Program Files\Rowley Associates Limited\CrossWorks for ARM 2.0\gcc\\bin\\objdump.exe" -S ' + filename + " > " + fileout          
          , shell=True)

    if __name__ == '__main__':
        if len(sys.argv) >= 2:
            if(sys.argv[1] == '1'):

    Comment actions Permalink
  • Avatar
    Kelly Painter


    I tried your method and it works but the output is truncated and there are a lot of path statements.  Here is a snipet..



      if(n < 6)
          28:    e15b30bc     ldrh    r3, [fp, #-12]
          2c:    e3530005     cmp    r3, #5    ; 0x5
          30:    8a00002c     bhi    e8 <SetControlReg+0xe8>
        s = NewBlock();
          34:    ebfffffe     bl    0 <NewBlock>
          38:    e1a03000     mov    r3, r0
          3c:    e50b3008     str    r3, [fp, #-8]





      66:C:/DEV/GCC_ARM_PROJECTS/AII_CTL\DdsBoard.c ****   if(n < 6)
      41                  h    r3, [fp, #-12]
      42 0028 BC305BE1         cmp    r3, #5
      43 002c 050053E3         bhi    .L3
      44 0030 2C00008A         .loc 1 68 0
      67:C:/DEV/GCC_ARM_PROJECTS/AII_CTL\DdsBoard.c ****   {
      68:C:/DEV/GCC_ARM_PROJECTS/AII_CTL\DdsBoard.c ****     s = NewBlock();
      45                  NewBlock
      46 0034 FEFFFFEB         mov    r3, r0
      47 0038 0030A0E1         str    r3, [fp, #-8]
      48 003c 08300BE5         .loc 1 69 0


    Comment actions Permalink
  • Avatar
    Andy Heilveil

    under project properties look for Compiler Option "Keep Assembly Source".


    Comment actions Permalink
  • Avatar
    Kelly Painter


    The output isn't terribly readable.  All "C" source is stripped.  OP specifically said that is what he didn't want.  There are a lot of .loc statements that help the compiler but don't really mean much to mere mortals like me.  Pretty hard to beat objdump with the -S option.  The example from above reads as follows from the asm file:


        .loc 1 66 0
        ldrh    r3, [fp, #-12]
        cmp    r3, #5
        bhi    .L3
        .loc 1 68 0
        bl    NewBlock
        mov    r3, r0
        str    r3, [fp, #-8]
        .loc 1 69 0



    Comment actions Permalink
  • Avatar


    Thanks for the objdump.exe -S command.

    FWIW I took this and put it into a windows batch file with these lines:

      @echo off
      echo Generating listing for %3.o.
      "%~1/gcc/bin/objdump.exe" -S "%~2/%3.o" > "%~2/%3.lst"

    Then in the project common options, "User Build Step Options" | "Post-Compile Command" field, say

      makelisting.bat "$(StudioDir)" "$(OutDir)" $(InputName)

    Thus I have a lst file with each successfully compiled C file and I don't need python.  FWIW, I tried entering the objdump command directly in the Post-Compile Command field but CrossStudio mishandled the ">" redirector, hence I had to resort to a batch file.

    PS: for those wondering about the use of tilde "~",
      %~1    This expands %1 and removes any surrounding quotation marks ("")

    Comment actions Permalink

Please sign in to leave a comment.