Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -3229,11 +3229,16 @@ LLDBSwigPyInit(); - // Update the path python uses to search for modules to include the current - // directory. - + // We need to call this before AddToSysPath as it uses the sys module. PyRun_SimpleString("import sys"); + + // Update the path python uses to search for modules to include the current + // directory and the home directory. AddToSysPath(AddLocation::End, "."); + FileSpec home_dir_spec; + llvm::SmallString<128> home_dir; + if (FileSystem::Instance().GetHomeDirectory(home_dir)) + AddToSysPath(AddLocation::End, std::string(home_dir)); // Don't denormalize paths when calling file_spec.GetPath(). On platforms // that use a backslash as the path separator, this will result in executing Index: lldb/test/Shell/ScriptInterpreter/Python/Inputs/zip.py =================================================================== --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Python/Inputs/zip.py @@ -0,0 +1,7 @@ +import lldb + +def zip(debugger, command, result, internal_dict): + print("95126") + +def __lldb_init_module(debugger, internal_dict): + debugger.HandleCommand('command script add -f zip.zip zip') Index: lldb/test/Shell/ScriptInterpreter/Python/relative_import.test =================================================================== --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Python/relative_import.test @@ -0,0 +1,6 @@ +# REQUIRES: python + +# RUN: rm -rf %t && mkdir -p %t +# RUN: cp %S/Inputs/zip.py %t +# RUN: env HOME=%t %lldb --script-language python -o 'command script import zip' -o 'zip' 2>&1 | FileCheck %s +# CHECK: 95126