aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectCommands.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2020-10-27 09:14:40 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2020-10-27 09:20:45 -0700
commit00bb397b0dc79fcad27bfe63456a2100039706f2 (patch)
treec1b5cddc681cb2104a68409abcafe6fce70d1c6e /lldb/source/Commands/CommandObjectCommands.cpp
parentd028d2b376a1a01404e9766f9303a24771baab1f (diff)
downloadllvm-00bb397b0dc79fcad27bfe63456a2100039706f2.zip
llvm-00bb397b0dc79fcad27bfe63456a2100039706f2.tar.gz
llvm-00bb397b0dc79fcad27bfe63456a2100039706f2.tar.bz2
[lldb] Support Python imports relative the to the current file being sourced
Make it possible to use a relative path in command script import to the location of the file being sourced. This allows the user to put Python scripts next to LLDB command files and importing them without having to specify an absolute path. To enable this behavior pass `-c` to `command script import`. The argument can only be used when sourcing the command from a file. rdar://68310384 Differential revision: https://reviews.llvm.org/D89334
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectCommands.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 96ce82d..0c441dd 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1272,6 +1272,9 @@ protected:
case 'r':
// NO-OP
break;
+ case 'c':
+ relative_to_command_file = true;
+ break;
default:
llvm_unreachable("Unimplemented option");
}
@@ -1280,11 +1283,13 @@ protected:
}
void OptionParsingStarting(ExecutionContext *execution_context) override {
+ relative_to_command_file = false;
}
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::makeArrayRef(g_script_import_options);
}
+ bool relative_to_command_file = false;
};
bool DoExecute(Args &command, CommandReturnObject &result) override {
@@ -1294,6 +1299,17 @@ protected:
return false;
}
+ FileSpec source_dir = {};
+ if (m_options.relative_to_command_file) {
+ source_dir = GetDebugger().GetCommandInterpreter().GetCurrentSourceDir();
+ if (!source_dir) {
+ result.AppendError("command script import -c can only be specified "
+ "from a command file");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
for (auto &entry : command.entries()) {
Status error;
@@ -1308,7 +1324,7 @@ protected:
// more)
m_exe_ctx.Clear();
if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule(
- entry.c_str(), init_session, error)) {
+ entry.c_str(), init_session, error, nullptr, source_dir)) {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.AppendErrorWithFormat("module importing failed: %s",