Skip to content

[lldb] command script import -c fails on path containing slashes #142197

Open
@190n

Description

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions