Previous - Up - Next

7.1   Introduction

Commands in Simics are written in Python, and they access the internal state of Simics by using the Simics API, and by accessing configuration objects and their attributes. Since modules cannot add functions to the Simics API, all commands for devices and extensions use the configuration system.

There are several benefits of using Python to define commands: The code is forced to make its internal state visible, allowing other script users to access it. The module can be distributed in binary form, while the Python commands are still available with source, allowing a user to change them in a way he or she prefers.

The command can be declared in two files that should reside in the same directory as the source code of the module:

commands.py
Contains commands that will be declared when the module is loaded. These are usually commands related to a specific class or interface. For example, <my_class>.info should be declared in this file.
gcommands.py
Contains global commands that will be declared when Simics is started, whether or not the module has been loaded. Commands placed here are often used to create new instances of a class. For example, new-tracer is declared in gcommands.py in the trace/ module source directory.

When the module is compiled, these two files (if they exist) are copied to the simics/host/lib/python directory; e.g., simics/x86-linux/lib/python. The resulting file will get the name mod_module-name_commands.py (respectively _gcommands.py) with any dash (-) characters replaced with underscore (_).

Previous - Up - Next