pyocd / pyOCD

Open source Python library for programming and debugging Arm Cortex-M microcontrollers
https://pyocd.io
Apache License 2.0
1.13k stars 484 forks source link

pyocd commander fails if an elf is provided #969

Closed saagit closed 4 years ago

saagit commented 4 years ago
$ pyocd commander --target=stm32g031j6mx --elf DISCO.elf 
0001015:CRITICAL:__main__:uncaught exception: name 'os' is not defined
Traceback (most recent call last):
  File "/home/saa/.local/lib/python3.7/site-packages/pyocd-0.28.1.dev6-py3.7.egg/pyocd/__main__.py", line 398, in run
    self._COMMANDS[self._args.cmd](self)
  File "/home/saa/.local/lib/python3.7/site-packages/pyocd-0.28.1.dev6-py3.7.egg/pyocd/__main__.py", line 802, in do_commander
    PyOCDCommander(self._args, cmds).run()
  File "/home/saa/.local/lib/python3.7/site-packages/pyocd-0.28.1.dev6-py3.7.egg/pyocd/commands/commander.py", line 63, in run
    if not self.connect():
  File "/home/saa/.local/lib/python3.7/site-packages/pyocd-0.28.1.dev6-py3.7.egg/pyocd/commands/commander.py", line 178, in connect
    self._post_connect()
  File "/home/saa/.local/lib/python3.7/site-packages/pyocd-0.28.1.dev6-py3.7.egg/pyocd/commands/commander.py", line 218, in _post_connect
    self.target.elf = os.path.expanduser(self.args.elf)
NameError: name 'os' is not defined

There are actually two problems:

  1. The os module is not imported, and
  2. self.target.elf should be self.session.target.elf

The attached patch resolves these problems. Sorry I didn't do a pull request, but figuring out the test suite and everything was too much for me to do for a one-liner.

commander_elf.txt

flit commented 4 years ago

Thanks for reporting, and thanks for the patch! This looks like a regression. I'll try to get a fix with your patch out shortly.