# Buggy code
def __init__(self, probe, options=None, **kwargs):
    self._probe = probe
    self._closed = True
    self._inited = False
    self._user_script_proxy = None
    self._delegate = None

    # Update options.
    self._options = options or {}
    self._options.update(kwargs)

    # Init project directory.
    if self._options.get("project_dir", None) is None:
        self._project_dir = os.getcwd()
    else:
        self._project_dir = os.path.abspath(
            os.path.expanduser(self._options["project_dir"])
        )
    LOG.debug("Project directory: %s", self.project_dir)

    # Apply common configuration settings from the config file.
    config = self._get_config()
    probesConfig = config.pop("probes", None)
    self._options.update(config)

    # Pick up any config file options for this board.
    if (probe is not None) and (probesConfig is not None):
        for uid, settings in probesConfig.items():
            if str(uid).lower() in probe.unique_id.lower():
                LOG.info("Using config settings for board %s" % (probe.unique_id))
                self._options.update(settings)

    # Bail early if we weren't provided a probe.
    if probe is None:
        self._board = None
        return

    # Ask the probe if it has an associated board, and if not then we create a generic one.
    self._board = probe.create_associated_board(self) or Board(
        self, self._options.get("target_override", None)
    )


# Traceback (TypeError)
pyocd gdb -t stm32f401re --pack /Users/matost01/Downloads/CMSIS/STM32F4xx_DFP.2.13.0.pack
0000355:INFO:pack_target:Loading CMSIS-Pack: /Users/matost01/Downloads/CMSIS/STM32F4xx_DFP.2.13.0.pack
0000457:INFO:board:Target type is stm32f401re
0000464:WARNING:flash_algo:Not enough space for flash algorithm
0000464:ERROR:__main__:uncaught exception: unsupported operand type(s) for -: 'tuple' and 'int'
Traceback (most recent call last):
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/__main__.py", line 304, in run
self._commands[self._args.cmd]()
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/__main__.py", line 463, in do_gdbserver
**sessionOptions)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/core/helpers.py", line 196, in session_with_chosen_probe
session = Session(allProbes[0], options=options, **kwargs)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/core/session.py", line 127, in __init__
or Board(self, self._options.get('target_override', None))
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/board/board.py", line 47, in __init__
self.target = TARGET[self._target_type](session)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/target/pack/pack_target.py", line 31, in _pack_target__init__
super(self.__class__, self).__init__(session, self._pack_device.memory_map)
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/target/pack/cmsis_pack.py", line 454, in memory_map
self._build_flash_regions()
File "/Users/matost01/mbed-studio-tools/python/lib/python2.7/site-packages/pyocd/target/pack/cmsis_pack.py", line 386, in _build_flash_regions
length = nextStart - start
TypeError: unsupported operand type(s) for -: 'tuple' and 'int'```

# Fixed code
def __init__(self, probe, options=None, **kwargs):
    Session._current_session = weakref.ref(self)

    self._probe = probe
    self._closed = True
    self._inited = False
    self._user_script_proxy = None
    self._delegate = None

    # Update options.
    self._options = options or {}
    self._options.update(kwargs)

    # Init project directory.
    if self._options.get("project_dir", None) is None:
        self._project_dir = os.getcwd()
    else:
        self._project_dir = os.path.abspath(
            os.path.expanduser(self._options["project_dir"])
        )
    LOG.debug("Project directory: %s", self.project_dir)

    # Apply common configuration settings from the config file.
    config = self._get_config()
    probesConfig = config.pop("probes", None)
    self._options.update(config)

    # Pick up any config file options for this board.
    if (probe is not None) and (probesConfig is not None):
        for uid, settings in probesConfig.items():
            if str(uid).lower() in probe.unique_id.lower():
                LOG.info("Using config settings for board %s" % (probe.unique_id))
                self._options.update(settings)

    # Bail early if we weren't provided a probe.
    if probe is None:
        self._board = None
        return

    # Ask the probe if it has an associated board, and if not then we create a generic one.
    self._board = probe.create_associated_board(self) or Board(
        self, self._options.get("target_override", None)
    )