Intel® System Debugger User Guide

ID 648476
Date 06/13/2024
Confidential
Document Table of Contents

Creating Simple Commands for Frequent Debug Tasks

Create simple commands for performing frequent debug tasks in the CLI. You can define custom functions in any of the following ways:

  • Define functions directly in the IPython console.

    Use the ISD Shell view (it support proper indentation for defining functions), for example:

    In [1]: def step_into():
    ...:     return threads[0].step_into(instruction=True)
    ...:
    
    In [2]: step_into()
    
  • Define functions in a separate file that will be imported automatically after the Sysdbg CLI is connected.

    1. Create a new .py file and define all required functions there.

      Do not forget to reference global variables properly. See the example file below.

    2. Specify the path of the custom script in any of the following ways:

      • If the ISD Shell view is used, set the environment variable ISYSDBG_​CLI_​CUSTOM_​SCRIPT before launching the Intel(R) System Debugger.

        ISYSDBG_​CLI_​CUSTOM_​SCRIPT = <custom_​script_​path>/<custom_​script_​name>.py

        The environment variable can be declared in the same terminal before launching the Intel(R) System Debugger, in the system environment variables, or in the environment file:

        • For Windows* OS: <install_​dir>/system_​debugger/<version>/env.d/win32/*-isysdbg-env.bat

        • For Linux* OS: <install_​dir>/system_​debugger/<version>/env.d/linux/*-isysdbg-env.sh

      • If the ISD CLI is used, the custom script can be specified in the connect command as follows:

        sysdbg.connect(custom_​script="<custom_​script_​dir>/<custom_​script_​name>.py")

      • If the Sysdbg CLI entry point is used, the custom script can be specified as follows:

        intel_​sysdbg --custom_​script="<custom_​script_​path>/<custom_​script_​name>.py"

    3. For example, in the ISD Shell view, the custom module can be used in the following way:

      [INFO    ] Custom module <custom_script_name> was imported.
      In [1]: sysdbg.<custom_script_name>.step_into()
      In [2]: bp=sysdbg.<custom_script_name>.set_bp(0x18000135c)
      [INFO    ] Breakpoint added {ID: 0, Contexts: ['P1.100b'], Enabled: True, Location: 0x18000135c, Type: Software}.
      In [3]: sysdbg.<custom_script_name>.remove_bp(bp)
      [INFO    ] Breakpoint with ID 0 removed.
      Out[4]: True
      

Example Commands

The snippet below contains example script with basic debug functions. You can copy the script into your custom .py file and use it as explained above.

_target = None
_threads = None

def on_launch(target):
    """
    Define in this function actions to be executed on launch during
    the connection attempt. This function is automatically executed
    after the Sysdbg CLI is started. For example, global variables
    _target and _threads used in this module can be initialized.
    If defined, this function must have the definition above, so
    that it can be correctly executed: "def on_launch(target)".

    :param target: target variable on global scope
    :type target: Session
    :returns: None
    """

    # If _target and _threads global variables are used in
    # other functions in this module, initialize them here.
    global _target
    global _threads
    _target = target
    _threads = target.threads
    # Add here other actions to be executed on launch (optionally).

def read_ioport(port):
    """
    Read an IO port on the first thread of the target.
    :param port: address of the IO port (port number)
    :type port: int
    :returns: int value of the IO port
    """

    return _threads[0].io(1, port)

def write_ioport(port, value):
    """
    Write an IO port on the first thread of the target.
    :param port: address of the IO port (port number)
    :type port: int
    :param value: value to be written
    :type value: int
    :returns: None on successful operation
    """

    return _threads[0].io(1, port, value)

def go():
    """
    Resume the target.
    :returns: True on successful operation
    """

    return _target.go()

def halt():
    """
    Halt the target.
    :returns: True on successful operation
    """

    return _target.halt()

def step_into():
    """
    Perform a step into operation on the first thread of the target.
    :returns: None on successful operation
    """

    return _threads[0].step_into(instruction=True)

def set_bp(address):
    """
    Add a breakpoint on the first thread of the target.
    :param address: address of the breakpoint to add
    :type address: int
    :returns: the Breakpoint object added
    """

    return _threads[0].set_breakpoint(address=address)

def remove_bp(bp):
    """
    Remove a breakpoint on the first thread of the target.
    :param bp: Breakpoint object or breakpoint ID to remove
    :type bp: Breakpoint object or str
    :returns: True on successful operation
    """

    return _threads[0].remove_breakpoint(bp)
See also:

Automating Tasks on Launch