diff options
author | Jim Ingham <jingham@apple.com> | 2021-09-27 17:51:37 -0700 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2021-09-29 19:33:41 -0700 |
commit | 3bf3b96629e8dfc55d01ba0cb05ca01a467017fa (patch) | |
tree | 023e446d90fe84432962aa83e9bbacb2a427c53a /lldb/source/Commands/CommandObjectCommands.cpp | |
parent | b55a964197bdc651533377bbd0b46fa58edf9196 (diff) | |
download | llvm-3bf3b96629e8dfc55d01ba0cb05ca01a467017fa.zip llvm-3bf3b96629e8dfc55d01ba0cb05ca01a467017fa.tar.gz llvm-3bf3b96629e8dfc55d01ba0cb05ca01a467017fa.tar.bz2 |
Add the --relative-to-command-file to "command source" so you can
have linked command files in a source tree and get to them all from
one main command file.
Differential Revision: https://reviews.llvm.org/D110601
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectCommands.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 9a8b81c..63927987 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -77,7 +77,7 @@ protected: public: CommandOptions() : Options(), m_stop_on_error(true), m_silent_run(false), - m_stop_on_continue(true) {} + m_stop_on_continue(true), m_cmd_relative_to_command_file(false) {} ~CommandOptions() override = default; @@ -95,6 +95,10 @@ protected: error = m_stop_on_continue.SetValueFromString(option_arg); break; + case 'C': + m_cmd_relative_to_command_file = true; + break; + case 's': error = m_silent_run.SetValueFromString(option_arg); break; @@ -110,6 +114,7 @@ protected: m_stop_on_error.Clear(); m_silent_run.Clear(); m_stop_on_continue.Clear(); + m_cmd_relative_to_command_file.Clear(); } llvm::ArrayRef<OptionDefinition> GetDefinitions() override { @@ -121,6 +126,7 @@ protected: OptionValueBoolean m_stop_on_error; OptionValueBoolean m_silent_run; OptionValueBoolean m_stop_on_continue; + OptionValueBoolean m_cmd_relative_to_command_file; }; bool DoExecute(Args &command, CommandReturnObject &result) override { @@ -131,7 +137,29 @@ protected: return false; } + FileSpec source_dir = {}; + if (m_options.m_cmd_relative_to_command_file) { + source_dir = GetDebugger().GetCommandInterpreter().GetCurrentSourceDir(); + if (!source_dir) { + result.AppendError("command source -C can only be specified " + "from a command file"); + result.SetStatus(eReturnStatusFailed); + return false; + } + } + FileSpec cmd_file(command[0].ref()); + if (source_dir) { + // Prepend the source_dir to the cmd_file path: + if (!cmd_file.IsRelative()) { + result.AppendError("command source -C can only be used " + "with a relative path."); + result.SetStatus(eReturnStatusFailed); + return false; + } + cmd_file.MakeAbsolute(source_dir); + } + FileSystem::Instance().Resolve(cmd_file); CommandInterpreterRunOptions options; |