What is the xc16 command to obtain disassembly (listing.disasm) file? - disassembly

I want to obtain disassembly (listing.disasm) file for my project. My current compilation commands produces .elf, .map and .hex files.
How do I (Or what commands) produce a single listing.disasm?
Note: I have multiple C files, but I need a single disassembly file.
I know that there is a option in MPLAB X IDE to create listing.disasm while building. But I'm building using batch file.
Compiler: XC16
Processor Family: PIC24F

If you are using MPLABX, go to Project Properties -> Building, check "Execute this line after build", then add this:
${MP_CC_DIR}\xc16-objdump -S ${ImageDir}\${PROJECTNAME}.${IMAGE_TYPE}.elf > list.lst
Know you should find the list file in your x-folder.
If you work with a batch file, maybe try this:
if "%1" == "cof" goto coff_file_format
:elf_file_format
#echo dump for ELF/DWARF
xc16-objdump -omf=elf -S %2\%3.%4.elf > %2\%3.%4.lst
goto end
:coff_file_format
#echo dump for COFF
xc16-objdump -omf=coff -S %2\%3.%4.cof > %2\%3.%4.lst
:end

Related

How to create a batch script which takes list of files as argument and passes to an exe

I am trying to create a batch file which runs an exe with arguments.
The exe needs an input file as argument.
Instead of specifying file name as argument, I would like to consider all files residing in that folder as input to exe.
Below is the syntax I have used in the batch script and executed it. Upon running below code batch script stopping suddenly.
However, when I specify the file name and run from command prompt the execution is successful.
Example:
Example.exe -i c:\Test\*.wav -o c:\result
I have looked at few of the examples in Google and found that I can use *.fileextension to refer that particular files in the folder.
I am thinking if there is a better approach to achieve this.
I am assuming you will run the same command and switch for multiple wav files.
#echo off
for %%i in (*.wav) do (
example.exe -i %%i -o c:\result
)

Eclipse CDT - how to use an argfile for the linker for a too long command line

I'm using Eclipse CDT 9 Neon with GCC 6.3 on Windows 7 for a STM32 project.
I have installed the GNU ARM Plug-in and use sh.exe for long command line management (cmd.exe from windows have a limite of 8192 char) for calling make.exe (GNU Coreutils date: 04.06.2009).
I'm working on a big project.
Without build exclusion my linker command line is over 33 000 char and generate an error on the linker command line.
With builds exclusions and a reduced version of my project, I have reduce the linker command line to 15 600 char, compilation worked fine and my binary file is operational.
At first, for the full version of my project, the linker command line is bigger than 20 000 char and generate an ACCESS VIOLATION on sh.exe.
With an other version of sh.exe (from Microsemi IDE) I have no more ACCESS VIOLATION on sh.exe and be able to link more file.
But for the full version of my project I have a link error :
make (e=87): Paramètre incorrect.
This error come from a to long command line (more than 32 000 char).
Other IDE (Winidea with GCC) use an argument file that combine linker file (.ld) and the obj files list to have a very short linker command line.
How can I configure GCC in Eclipse to use an argument file for the linker ?
I found a solution, not perfect but fully operational. I have writen an bat file to generate obj listing file.
Instructions to use it are in rem.
I have writen the file "gen__link_ld.bat" :
echo off
rem ***************************************************************************
rem Generate script file for the linker to go throuth linker command line too
rem long trouble under windows (32 000 char max)
rem ***************************************************************************
rem Lunch in pre-build step is not advised, this commande is run in paralel
rem with build step that can temporarie supress obj file need to run
rem compilation a 2nd time to have a script file up to date for the linker.
rem Run in pre-build step generate trouble in debug mode.
rem
rem Use manual lunch with 2 parameters :
rem create a .bat file per build with the folowing commande :
rem gen__link_ld.bat ./project relative path and .ld file name ./project relative build path
rem in linker commande line pattern replace {INPUT}
rem by -Xlinker --script=${ProjDirPath}/${ConfigName}/___link.ld
rem and add manualy librairie after ___link.ld, in this case library include
rem throuth graphical build setting don't work, they may use {INPUT} from the
rem standard commande
rem ***************************************************************************
echo **************************************************************************
echo ***************************** *****************************
echo ***************************** WARNING *****************************
echo ***************************** *****************************
echo **************************************************************************
echo Generate script file for the linker to go throuth linker command line too
echo long trouble under windows (32 000 char max)
echo
echo List only existing obj file.
echo The best way is to use manual lunch with one .bat file per build.
echo follow information in r e m above to use it.
echo
echo Run this commande evry time that obj liste is modified.
echo WARNING this function don't delete obj file for file recently exclude
echo frome build.
echo To secure the compilation need a clean to suppress all obj, run a first
echo build witch compile all file without error (with only linker error) to
echo generate an obj file listing up to date and run a second buid for a
echo successful linker step. When the OJB file listing is up to date, only
echo eclipse build commande is needed
echo **************************************************************************
echo Linker file use : %1
echo Build path use : %2
echo **************************************************************************
setlocal ENABLEDELAYEDEXPANSION
set destination=%2
set destination=%destination:/=\%
rem *** Generate obj file listing ***
echo INPUT(>%destination%\___link.ld
dir %destination%\*.o /s /b >>%destination%\___link.ld
echo )>>%destination%\___link.ld
rem *** Concatenat obj file listing with ld file from parameter 1 ***
set str=%1
set str=%str:/=\%
type %str%>>%destination%\___link.ld
echo *** OBJ file listing up to date
echo **************************************************************************
pause
Thanks
Here's a simple workaround I've found for the issue (using a small python script), on the same line of thought of separating the object listing in another file - note that these kind of files are called response files in the GNU world: https://gcc.gnu.org/wiki/Response_Files and they separate the entire command-line rather than only the object files and libraries.
Assuming you're using the GNU Make builder+GNU linker:
You'll need to create a python script and place it somewhere in your project, I'll assume the path to the script is build/link_with_rsp_file.py. Place in it the contents below.
Go to project properties -> C/C++ Build -> Settings. Make sure the appropriate build configuration is selected. You should find the toolchain settings there.
Select the linker item. Depending on your build configuration, you should have a Command/Command line pattern pair such as g++/${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}. We'll assume it looks just like this, adjust accordingly.
Change the command-line pattern to #$(file >linkcl.rsp,${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS})python ../build/link_with_rsp_file.py linkcl.rsp ${COMMAND}. This effectively tells GNU make to take all the linker arguments, put them in the response file linkcl.rsp (using the $(file) function) and then run the linker (${COMMAND}) using the generated response file instead.
Python script:
import sys, subprocess
def cmd_exec(full_cmd):
print(full_cmd)
sys.stdout.flush(); sys.stderr.flush()
p = subprocess.Popen(full_cmd.split(' '))
p.communicate()
return p.returncode == 0
rsp_file, cmd = sys.argv[1], sys.argv[2:]
cmd = ' '.join(cmd)
# First replace all '\' with '/' in the response file (bash doesn't deal well with '\')
with open(rsp_file, "r") as f: linkcl = f.read()
linkcl = linkcl.replace('\\', '/')
with open(rsp_file, "w") as f: f.write(linkcl)
# Call the linker
cmd_exec("{cmd} #{rsp_file}".format(cmd=cmd, rsp_file=rsp_file))
I've improved the way in https://stackoverflow.com/a/61644057/5789722 :
Go to project properties -> C/C++ Build, and ensure Builder type is External builder and enable Generate Makefiles automatically
Go to project properties -> C/C++ Build -> Settings, select Tool Settings -> a linker like Cygwin C++ Linker
fill Command line pattern with:
#$(file >linkcl.rsp,$(subst \,/,${FLAGS}) ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}) ${COMMAND} #linkcl.rsp
here I use subst to replace \ with /, then link_with_rsp_file.py is not needed any more

Why is atprogram not working from within a batch file?

I am working with an embedded system developed specifically for the company I work at. I want to use Atmel's command prompt to program the target processor which is pretty easy.
But, in the future, the technician building our products will do it themselves so I thought of a batch file they could run with the scrips for programming and checking the code for them automatically.
Here is the problem, I don't manage to get it running trough the *.bat file.
When I do it without I just start the Atmel console and type
atprogram -i ...
I have tried writing the batch file like:
"C:\...\StudioCommandPrompt.exe" atprogram -i ...
Which gives me the result atprogram is neither a file nor a program
I also tried with:
START "C:\...\StudioCommandPrompt.exe" atprogram -i ...
Then the program starts in a separate prompt, and produces the same error as above.
The empty set as suggested in the comments:
START "" "C:\...\StudioCommandPrompt.exe" atprogram -i ...
Gives the same result as without the empty set.
Does anyone know how to resolve this?
SOLUTION:
START "programTool" /B /WAIT "C:\...\atprogram.exe" -i ...
I.E. refering to the correct software (cred: http://www.avrfreaks.net/forum/just-run-programmer hobbss)

Command Prompt Error 'C:\Program' is not recognized as an internal or external command, operable program or batch file

I am trying to run the following batch command. The command has been extracted from the IDE so is confirmed working. Getting the error mentioned below.
I have tried a few variations with double quotes but they haven't worked.
Even on powershell it has the same message.
C:\Program Files\IAR Systems\Embedded Workbench 7.0\430\bin\icc430.exe F:\CP001\source\Meter\Main.c -D Hardware_P20E -D Calibration_code -D _Optical -D _Configuration_TS0382 -o F:\CP001\Temp\C20EO\Obj\ --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F425 -e --double=32 --dlib_config C:\Program Files\IAR Systems\Embedded Workbench 7.0\430\lib\dlib\dl430fn.h -Ol --multiplier=16 --segment __data16=DATA16 --segment __data20=DATA20
Update:
Trying the solution with quotes confuses the compiler in some way
If a directory has spaces in, put quotes around it. This includes the program you're calling, not just the arguments
"C:\Program Files\IAR Systems\Embedded Workbench 7.0\430\bin\icc430.exe" "F:\CP001\source\Meter\Main.c" -D Hardware_P20E -D Calibration_code -D _Optical -D _Configuration_TS0382 -o "F:\CP001\Temp\C20EO\Obj\" --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F425 -e --double=32 --dlib_config "C:\Program Files\IAR Systems\Embedded Workbench 7.0\430\lib\dlib\dl430fn.h" -Ol --multiplier=16 --segment __data16=DATA16 --segment __data20=DATA20
You just need to keep Program Files in double quote & rest of the command don't need any quote.
C:\"Program Files"\IAR Systems\Embedded Workbench 7.0\430\bin\icc430.exe F:\CP00 .....
This seems to happen from time to time with programs that are very sensitive to command lines, but one option is to just use the DOS path instead of the Windows path. This means that C:\Program Files\ would resolve to C:\PROGRA~1\ and generally avoid any issues with spacing.
To get the short path you can create a quick Batch file that echos the short path:
#ECHO OFF
echo %~s1
Which is then called as follows:
C:\>shortPath.bat "C:\Program Files"
C:\PROGRA~1
Try putting cd before the file path.
Example:
C:\Users\user>cd C:\Program Files\MongoDB\Server\4.4\bin
If a directory has spaces in, put quotes around it. This includes the
program you're calling, not just the arguments
"C:\Program Files\IAR Systems\Embedded Workbench
7.0\430\bin\icc430.exe"
Also - SPACES in your "${workspaceFolder}" (dir to your project) can confuse the compiler!
At least mine was throwing various errors (like that above, but I had fixed the compiler path), I finally noticed it compiled on PC 1 (dir without spaces) and would NOT compile PC 2 (dir with spaces).
Actually don't know where to put quotes ("") to make this work because ${workspaceFolder} or ${fileDirname} are a predefined variable reference in VSC...
I encountered a similar problem using windows command line for R script, Rscript.exe, which is very sensitive to spaces in the path. The solution was to create a virtual path to the binary folder using the windows subst command.
The following fails: "C:\Program Files\R\R-3.4.0\bin\Rscript.exe"
Doing following succeeds:
subst Z: "C:\Program Files\R\R-3.4.0"
Z:\bin\Rscript.exe
The reason the above-proposed solutions didn't work, evidently, has to do with the Rscript.exe executable's own internal path resolution from its working directory (which has a space in it) rather the windows command line being confused with the space. So using ~ or " to resolve the issue at the command line is moot. The executable must be called within a path lacking spaces.
Most of the times, the issue is with the paths you have mentioned for 'java home' and 'javac' tags in settings.xml which is present in your .m2 repository and the issue is not with your path variable or Java_Home variable.
If you check and correct the same, you should be able to execute your commands successfully.
- Jaihind
Just go to the folder path and type cmd on it. Then press ENTER
enter image description here
You can go to folder by doing on first line and next line call exe like below.
cd 'c:\program files\....'
.\abc.exe --install service
I believe James Hunt's answer will solve the problem.
#user3731784: In your new message, the compiler seems to be confused because of the "C:\Program Files\IAR systems\Embedded Workbench 7.0\430\lib\dlib\d1430fn.h" argument. Why are you giving this header file at the middle of other compiler switches?
Please correct this and try again.
Also, it probably is a good idea to give the source file name after all the compiler switches and not at the beginning.
Go to Start and search for cmd. Right click on it, properties then set the Target path in quotes. This worked fine for me.

Batch file: Reading and activate commands from unknown files

I know the title doesn't make sense, but I have one question. I have made this file called Test.bin and here's whats inside the .bin file:
echo Hello World
Since its a test file, I've been trying to see if i can make a batch file that can read the commands in the .bin file and output it onto the console.
Not sure what you are trying to do exactly, but I think you have two options:
Rename test.bin as test.bat and run it with:
test
Start a new command interpreter and send it your commands:
cmd < test.bin
You could also use the copy command. However, for this to work the test.bin file should be
in the same directory/folder. Alternatively, you can specify the file's path.
Your code should look something like this:
#echo off
copy test.bin
Or, using the filepath method (pretending its on your desktop):
#echo off
copy C:/users/me/Desktop/test.bin

Resources