Issue 142197
Summary [lldb] `command script import -c` fails on path containing slashes
Labels new issue
Assignees
Reporter 190n
    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`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to