> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xsiam-developer-guide/cortex-xsiam-development-guide/testing/debugging.md).

# Debugging

During the development phase of integrations and scripts, debugging allows you to understand what is happening behind the scenes when your code exhibits unexpected behavior. There are a few strategies that you can implement to debug code in Cortex XSIAM, described in the following sections.

#### Printing to the War Room

Seeing your statements in print is often useful when diagnosing issues. To do this, add the following to your integration/script code:

```programlisting
error_msg = "Here's your completely broken code"
demisto.log(error_msg)
```

This prints the statements in the War Room, for you to review. Remove the error messages when you are done debugging, so that they do not appear in the final code.

#### Debugging using the IDE

Sometimes debugging via printing or using the logs is not sufficient. In that case you might want to use the debugger and go through the code line by line or breakpoint by breakpoint. See [Debugging configurations for Python Apps in Visual Studio Code](https://code.visualstudio.com/docs/python/debugging).

{% hint style="info" %}

### Note

We recommend using the [Visual Studio Code extension](/cortex-xsiam-developer-guide/cortex-xsiam-development-guide/readme/content-development-environments/visual-studio-code-extension.md) when you are developing content.
{% endhint %}

**Python Environment**

1. Prepare a Python environment with all the base dependencies. Follow the instructions in [Set up a local development environment](/cortex-xsiam-developer-guide/cortex-xsiam-development-guide/readme/content-development-environments/set-up-a-local-development-environment.md).
2. After the Python environment is prepared, [open the integration in a virtual environment](/cortex-xsiam-developer-guide/cortex-xsiam-development-guide/readme/content-development-environments/visual-studio-code-extension.md#UUID-d7fd8217-1650-6334-4962-493fce34f1af_section-idm461090704812003367092331445) using the Cortex XSIAM Visual Studio Code Extension in VS Code.

**Using demistomock (the demisto object)**

The content repository includes [**demistomock.py**](https://github.com/demisto/content/blob/master/Tests/demistomock/demistomock.py) file, which usually appears as the first import in an integration or script:&#x20;

```programlisting
import demistomock as demisto
from CommonServerPython import *
from CommonServerUserPython import *
```

The **demistomock** module can be used to mock integration configuration, arguments and commands passed.

| Function            | Description                                                                 |
| ------------------- | --------------------------------------------------------------------------- |
| `demisto.params()`  | Returns the connection details inserted into the create instance in the UI. |
| `demisto.command()` | Returns the name of the command you want to run.                            |
| `demisto.args()`    | Returns the arguments for that command.                                     |

In some cases, you might need to use other functions, and the following guidelines applies to those as well. In the `demistomock` file we can see a `params` function defined:

```programlisting
def params():
    return {}
```

This is what is returned if we run the Python file. Instead, we can fill it with the connection credentials needed to connect to our instance.

```programlisting
def params():
    return {
        "credentials":{
            "identifier": "demisto",
            "password": "password"
        },
        "server": "https://1.2.3.4/",
        "insecure": True
    }
```

and now commands such as:

```programlisting
    params: dict = demisto.params()
    username = params.get('credentials').get('identifier')  # demisto
    password = params.get('credentials').get('password')  # password
    verify_certificate = not params.get('insecure', False)
```

take their information from there.

This is called mocking demisto.

Verify that all Cortex XSIAM functions used in the functions we are testing are mocked correctly. Now we can use the debugger from the IDE or ipdb to debug the code as we would any other simple Python file.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xsiam-developer-guide/cortex-xsiam-development-guide/testing/debugging.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
