<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/142197>142197</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lldb] `command script import -c` fails on path containing slashes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          190n
      </td>
    </tr>
</table>

<pre>
    Create a `.lldbinit` which imports a Python module from a subdirectory, using `-c` to make the path relative:

```
$ tree -a
.
├── .lldbinit
└── nested
    └── commands.py
$ cat .lldbinit
command script import -c nested/commands.py
$ cat nested/commands.py
import lldb

def __lldb_init_module(debugger, _):
    pass
```

Sourcing `.lldbinit` produces this error:

```
$ lldb
(lldb) command source .lldbinit
Executing commands in '/Users/ben/code/lldbtest/.lldbinit'.
(lldb) command script import -c nested/commands.py
error: module importing failed: SyntaxError('invalid syntax', ('<string>', 1, 14, 'import nested/commands\n'))
```

If I remove `-c` it works, but then I cannot load this file when LLDB was run in another directory, because it treats the path to the Python file as relative to the LLDB process's working directory:

```
$ cd ..
$ lldb
(lldb) command source lldbtest/.lldbinit
Executing commands in '/Users/ben/code/lldbtest/.lldbinit'.
(lldb) command script import nested/commands.py
error: module importing failed: invalid pathname 'nested/commands.py'
```

The workaround I've found is to place a file in the same directory as the Python module containing `command script import -c commands.py`, and I can import that file from the main `.lldbinit` with `command source -C`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VcFu2zgQ_Rr6MrBAUbJlHXRInRgI0MMC3T0HFDm2uJVIgaSc5u8XQ8lx0sRFgQUKCAnlGc48vvdGlCGYk0Vs2OYL29yv5BQ755u85nbVOv3S7D3KiCCBbXnW97o11kS25fDcGdWBGUbnYwAJf73EzlkYnJ56hKN3A0gIU6uNRxWdf2FiD1Mw9kSl1opqRAeD_I4QO4RRxg489jKaM7LijvH0bPny8Dsm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