anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: pyocd/pyocd
Issue: BUG: `chooseInterface` function does not exist

I noticed in the `Board` class that there is some interface initialization code that refers to a function called `chooseInterface` that is currently not part of the code base. Here is the relevant piece:

``` python
class Board(object):
    """
    This class associates a target, a flash, a transport and an interface
    to create a board
    """
    def __init__(self, target, flash, interface, transport="cmsis_dap", frequency=1000000):
        if isinstance(interface, str) == False:
            self.interface = interface
        else:
            self.interface = INTERFACE[interface].chooseInterface(INTERFACE[interface])
```

I'm guessing this function just got taken out of the code at some point and was replaced with something else (`MbedBoard.chooseBoard`?).


Changed files:
pyOCD/board/board.py

diff --git a/pyOCD/board/board.py b/pyOCD/board/board.py
index 8325af1c..e7b4bc31 100644
--- a/pyOCD/board/board.py
+++ b/pyOCD/board/board.py
@@ -29,10 +29,7 @@ class Board(object):
     to create a board
     """
     def __init__(self, target, flash, interface, transport="cmsis_dap", frequency=1000000):
-        if isinstance(interface, str) == False:
-            self.interface = interface
-        else:
-            self.interface = INTERFACE[interface].chooseInterface(INTERFACE[interface])
+        self.interface = interface
         self.transport = TRANSPORT[transport](self.interface)
         self.target = TARGET[target](self.transport)
         self.flash = FLASH[flash](self.target)
Repository: pyocd/pyocd
Issue: Missing dependency on cython breaks OS X installation

Tested with homebrew python 2.7.9:

```
e106982-mac:~ jamcro01$ pip install pyOCD
Collecting pyOCD
  Using cached pyOCD-0.4.3.zip
Collecting hidapi (from pyOCD)
  Using cached hidapi-0.7.99-5.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/private/var/folders/yg/wqy54z_s18ng_3q7qndkbg9nszkzrm/T/pip-build-pz8Kjf/hidapi/setup.py", line 4, in <module>
        from Cython.Distutils import build_ext
    ImportError: No module named Cython.Distutils

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/yg/wqy54z_s18ng_3q7qndkbg9nszkzrm/T/pip-build-pz8Kjf/hidapi
```

Try installing cython:

```
e106982-mac:~ jamcro01$ pip install cython
Collecting cython
  Downloading Cython-0.22-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.7MB)
    100% |████████████████████████████████| 3.7MB 120kB/s 
Installing collected packages: cython
Successfully installed cython-0.22
```

Then everything works:

```
e106982-mac:~ jamcro01$ pip install pyOCD
Collecting pyOCD
  Using cached pyOCD-0.4.3.zip
Collecting hidapi (from pyOCD)
  Using cached hidapi-0.7.99-5.tar.gz
Collecting intelhex (from pyOCD)
  Downloading intelhex-2.0-py2.py3-none-any.whl (42kB)
    100% |████████████████████████████████| 45kB 1.5MB/s 
Installing collected packages: hidapi, intelhex, pyOCD
  Running setup.py install for hidapi
  Running setup.py install for pyOCD
Successfully installed hidapi-0.7.99.post5 intelhex-2.0 pyOCD-0.4.3
```


Changed files:
setup.py

diff --git a/setup.py b/setup.py
index f6e3495d..ab4c1e0e 100644
--- a/setup.py
+++ b/setup.py
@@ -18,6 +18,7 @@
 from setuptools import setup, find_packages
 import sys
 
+setup_requires=['setuptools_scm!=1.5.3,!=1.5.4']
 install_requires = ['intelhex']
 if sys.platform.startswith('linux'):
     install_requires.extend([
@@ -28,6 +29,9 @@ elif sys.platform.startswith('win'):
         'pywinusb',
     ])
 elif sys.platform.startswith('darwin'):
+    setup_requires.extend([
+        'cython',
+    ])
     install_requires.extend([
         'hidapi',
     ])
@@ -38,7 +42,7 @@ setup(
         'local_scheme': 'dirty-tag',
         'write_to': 'pyOCD/_version.py'
     },
-    setup_requires=['setuptools_scm!=1.5.3,!=1.5.4'],
+    setup_requires=setup_requires,
     description="CMSIS-DAP debugger for Python",
     long_description=open('README.rst', 'Ur').read(),
     author="samux, emilmont",
Repository: pyocd/pyocd
Issue: Eclipse and pyOCD v0.28.2, pyOCD can not start debugging.

I updated pyCOD to v0.28.2. When I launch the pyOCD debug configuration, pyCOD stop at "0001590:INFO:server:Semihost server started on port 4444 (core 0)" and the there's no debug window. I used pyOCD 0.22.1 before.

Changed files:
pyocd/tools/gdb_server.py

diff --git a/pyocd/tools/gdb_server.py b/pyocd/tools/gdb_server.py
index ca6f6144..bbbaab47 100644
--- a/pyocd/tools/gdb_server.py
+++ b/pyocd/tools/gdb_server.py
@@ -297,7 +297,9 @@ class GDBServerTool(object):
                         gdb = GDBServer(session,
                             core=core_number,
                             server_listening_callback=self.server_listening)
+                        session.gdbservers[core_number] = gdb
                         gdbs.append(gdb)
+                        gdb.start()
                     gdb = gdbs[0]
                     while gdb.is_alive():
                         gdb.join(timeout=0.5)
Repository: pyocd/pyocd
Issue: STM32L475 DBGMCU register addresses.

https://github.com/pyocd/pyOCD/blob/a064d8fb99c44f32123e51d91331859b9030b5c0/pyocd/target/builtin/target_STM32L475xx.py#L29

Should the register address for APB1FZR2 be 0xE004200C?

APB1FZR2 = 0xE004200C

and

APB2FZR = 0xE0042010

I am attempting to use this driver for an STM32L496VGT3 which fails to load the flash even if I make the changes but that might be because of some difference between STM32L475 and STM32L496 so I can't confirm the above with a test. If anyone has a working STM32L496 setup I would be interested to know how you setup pyOCD for it.

Changed files:
pyocd/target/builtin/target_STM32L475xx.py

diff --git a/pyocd/target/builtin/target_STM32L475xx.py b/pyocd/target/builtin/target_STM32L475xx.py
index 0665b22d..7279572a 100644
--- a/pyocd/target/builtin/target_STM32L475xx.py
+++ b/pyocd/target/builtin/target_STM32L475xx.py
@@ -26,10 +26,10 @@ class DBGMCU:
     APB1FZR1 = 0xE0042008
     APB1FZR1_VALUE = 0x86e01c3f
 
-    APB1FZR2 = 0xE0042008
+    APB1FZR2 = 0xE004200C
     APB1FZR2_VALUE = 0x00000022
 
-    APB2FZR = 0xE004200C
+    APB2FZR = 0xE0042010
     APB2FZR_VALUE = 0x00072800
 
 FLASH_ALGO = { 'load_address' : 0x20000000,
Repository: pyocd/pyocd
Issue: [0.27] 'JLinkProbe' object has no attribute '_lock'

Using version 0.27 and JLink, session.open() throws the error below. The previous version was working fine for me.
 
`with ConnectHelper.session_with_chosen_probe() as session:`

```
Traceback (most recent call last):
  -truncated-
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\core\\session.py", line 302, in __enter__
    self.open()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\core\\session.py", line 420, in open
    self._board.init()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\board\\board.py", line 85, in init
    self.target.init()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\core\\coresight_target.py", line 160, in init
    seq.invoke()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\utility\\sequencer.py", line 213, in invoke
    resultSequence.invoke()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\utility\\sequencer.py", line 208, in invoke
    resultSequence = call()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\coresight\\dap.py", line 359, in power_up_debug
    self.write_reg(DP_CTRL_STAT, CSYSPWRUPREQ | CDBGPWRUPREQ | MASKLANE | TRNNORMAL)
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\coresight\\dap.py", line 348, in write_reg
    self.write_dp(addr, data)
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\coresight\\dap.py", line 528, in write_dp
    did_lock = self._set_dpbanksel(addr, True)
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\coresight\\dap.py", line 480, in _set_dpbanksel
    self.lock()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\coresight\\dap.py", line 252, in lock
    self.probe.lock()
  File "C:\\xxx\\pycharm\\lib\\site-packages\\pyocd\\probe\\debug_probe.py", line 173, in lock
    self._lock.acquire()
AttributeError: 'JLinkProbe' object has no attribute '_lock'
```

Changed files:
pyocd/probe/jlink_probe.py

diff --git a/pyocd/probe/jlink_probe.py b/pyocd/probe/jlink_probe.py
index d5957cd0..ef1e7ef6 100644
--- a/pyocd/probe/jlink_probe.py
+++ b/pyocd/probe/jlink_probe.py
@@ -78,6 +78,7 @@ class JLinkProbe(DebugProbe):
             six.raise_from(cls._convert_exception(exc), exc)
 
     def __init__(self, serial_number):
+        super(JLinkProbe, self).__init__()
         self._link = self._get_jlink()
         if self._link is None:
             raise exceptions.ProbeError("unable to open JLink DLL")
Repository: pyocd/pyocd
Issue: CMSISDAPProbe.get_probe_with_id() always returns probe object

I don't fully understand the usage of the DebugProbeAggregator.get_probe_with_id(board_id), for example, in the test/automated_test.py:164.
 As it is now, when I have only st-link probes connected and override the target in the pyocd.yaml, get_probe_with_id() still returns the CMSISDAPProbe probe even if it found no interface and has no probe with such id.
 Shouldn't it return None in that case?

Changed files:
pyocd/probe/stlink_probe.py, pyocd/probe/pydapaccess/dap_access_cmsis_dap.py, pyocd/probe/cmsis_dap_probe.py

diff --git a/pyocd/probe/cmsis_dap_probe.py b/pyocd/probe/cmsis_dap_probe.py
index fb6a5ac8..9a1b53ce 100644
--- a/pyocd/probe/cmsis_dap_probe.py
+++ b/pyocd/probe/cmsis_dap_probe.py
@@ -77,7 +77,11 @@ class CMSISDAPProbe(DebugProbe):
     @classmethod
     def get_probe_with_id(cls, unique_id):
         try:
-            return cls(DAPAccess(unique_id))
+            dap_access = DAPAccess.get_device(unique_id)
+            if dap_access is not None:
+                return cls(dap_access)
+            else:
+                return None
         except DAPAccess.Error as exc:
             six.raise_from(cls._convert_exception(exc), exc)
 
diff --git a/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py b/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py
index 0139682e..0c0e6a7e 100644
--- a/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py
+++ b/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py
@@ -466,7 +466,11 @@ class DAPAccessCMSISDAP(DAPAccessIntf):
     @staticmethod
     def get_device(device_id):
         assert isinstance(device_id, six.string_types)
-        return DAPAccessCMSISDAP(device_id)
+        iface = DAPAccessCMSISDAP._lookup_interface_for_unique_id(device_id)
+        if iface is not None:
+            return DAPAccessCMSISDAP(device_id, iface)
+        else:
+            return None
 
     @staticmethod
     def set_args(arg_list):
@@ -515,6 +519,8 @@ class DAPAccessCMSISDAP(DAPAccessIntf):
         # Search for a matching interface if one wasn't provided.
         if interface is None:
             interface = DAPAccessCMSISDAP._lookup_interface_for_unique_id(unique_id)
+            if interface is None:
+                raise self.DeviceError("no device with ID %s" % unique_id)
 
         if interface is not None:
             self._unique_id = _get_unique_id(interface)
diff --git a/pyocd/probe/stlink_probe.py b/pyocd/probe/stlink_probe.py
index 39a89e3d..5a5112a4 100644
--- a/pyocd/probe/stlink_probe.py
+++ b/pyocd/probe/stlink_probe.py
@@ -34,7 +34,7 @@ class StlinkProbe(DebugProbe):
     def get_probe_with_id(cls, unique_id):
         for dev in STLinkUSBInterface.get_all_connected_devices():
             if dev.serial_number == unique_id:
-                return cls(STLinkUSBInterface(unique_id))
+                return cls(dev)
         else:
             return None
Repository: pyocd/pyocd
Issue: [v0.30]AttributeError: 'NoneType' object has no attribute 'name'

Getting error while trying to connect
 ```
 File "c:\\program files\\python38-32\\lib\\site-packages\\pyocd\\probe\\cmsis_dap_probe.py", line 208, in connect
    TRACE.debug("trace: connect(%s)", protocol.name)
AttributeError: 'NoneType' object has no attribute 'name'
```

Changed files:
pyocd/probe/cmsis_dap_probe.py

diff --git a/pyocd/probe/cmsis_dap_probe.py b/pyocd/probe/cmsis_dap_probe.py
index 6f1c4a4b..1547e21d 100644
--- a/pyocd/probe/cmsis_dap_probe.py
+++ b/pyocd/probe/cmsis_dap_probe.py
@@ -205,7 +205,7 @@ class CMSISDAPProbe(DebugProbe):
     #          Target control functions
     # ------------------------------------------- #
     def connect(self, protocol=None):
-        TRACE.debug("trace: connect(%s)", protocol.name)
+        TRACE.debug("trace: connect(%s)", protocol.name if (protocol is not None) else "None")
         
         # Convert protocol to port enum.
         if protocol is not None:
Repository: pyocd/pyocd
Issue: Wrong r12 offset in FreeRTOS stack frame

Offset of r12 in FreeRTOS stack frame dictionary at line 102 in pyocd/rtos/freertos.py is not correct:
https://github.com/pyocd/pyOCD/blob/f146817ad2233d247e70fbba6adfe03b2c3fd8cc/pyocd/rtos/freertos.py#L101-L103

The correct value should be 52, (42 is, oddly, not the correct answer here).

Changed files:
pyocd/rtos/freertos.py

diff --git a/pyocd/rtos/freertos.py b/pyocd/rtos/freertos.py
index b7dbad17..d9a70d7c 100644
--- a/pyocd/rtos/freertos.py
+++ b/pyocd/rtos/freertos.py
@@ -99,7 +99,7 @@ class FreeRTOSThreadContext(DebugContext):
                  1: 40, # r1
                  2: 44, # r2
                  3: 48, # r3
-                 12: 42, # r12
+                 12: 52, # r12
                  14: 56, # lr
                  15: 60, # pc
                  16: 64, # xpsr
Repository: pyocd/pyocd
Issue: Ignore invalid addresses when programming hex files

`FlashLoader` must skip any addresses in hex files that do not belong to a known memory region (as defined by the target's memory map).

Changed files:
pyocd/flash/loader.py

diff --git a/pyocd/flash/loader.py b/pyocd/flash/loader.py
index 5a5a166b..160d1e76 100755
--- a/pyocd/flash/loader.py
+++ b/pyocd/flash/loader.py
@@ -159,8 +159,15 @@ class FileProgrammer(object):
         for start, end in data_list:
             size = end - start + 1
             data = list(hexfile.tobinarray(start=start, size=size))
-            self._loader.add_data(start, data)
-    
+            # Ignore invalid addresses for HEX files only
+            # Binary files (obviously) don't contain addresses
+            # For ELF files, any metadata that's not part of the application code 
+            # will be held in a section that doesn't have the SHF_WRITE flag set
+            try:
+                self._loader.add_data(start, data)
+            except ValueError as e:
+                logging.warning("Failed to add data chunk: %s", e)
+
     # ELF format
     def _program_elf(self, file_obj, **kwargs):
         elf = ELFBinaryFile(file_obj, self._session.target.memory_map)
Repository: pyocd/pyocd
Issue: do_readback not defined

Running 0.28.3, installed via pip, python 3.7.9.  wreg always causes the error:
```
pyocd> wreg GPIOA.BRR 0xF
writing 0xf to 0x48000028:32 (BRR)
Error: name 'do_readback' is not defined
```


Changed files:
pyocd/commands/commands.py

diff --git a/pyocd/commands/commands.py b/pyocd/commands/commands.py
index 5f468fc4..4d7ada2d 100755
--- a/pyocd/commands/commands.py
+++ b/pyocd/commands/commands.py
@@ -319,7 +319,7 @@ class WriteRegCommand(RegisterCommandBase):
                     else:
                         raise exceptions.CommandError("too many dots")
                     self.context.target.flush()
-                    if do_readback:
+                    if self.do_readback:
                         self._dump_peripheral_register(p, r, True)
                 else:
                     raise exceptions.CommandError("invalid register '%s' for %s" % (subargs[1], p.name))