1 //===-- OptionGroupOutputFile.cpp -----------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Interpreter/OptionGroupOutputFile.h" 10 11 #include "lldb/Host/OptionParser.h" 12 13 using namespace lldb; 14 using namespace lldb_private; 15 16 OptionGroupOutputFile::OptionGroupOutputFile() 17 : m_file(), m_append(false, false) {} 18 19 static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' 20 21 static constexpr OptionDefinition g_option_table[] = { 22 {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument, 23 nullptr, {}, 0, eArgTypeFilename, 24 "Specify a path for capturing command output."}, 25 {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND, 26 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, 27 "Append to the file specified with '--outfile <path>'."}, 28 }; 29 30 llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() { 31 return llvm::makeArrayRef(g_option_table); 32 } 33 34 Status 35 OptionGroupOutputFile::SetOptionValue(uint32_t option_idx, 36 llvm::StringRef option_arg, 37 ExecutionContext *execution_context) { 38 Status error; 39 const int short_option = g_option_table[option_idx].short_option; 40 41 switch (short_option) { 42 case 'o': 43 error = m_file.SetValueFromString(option_arg); 44 break; 45 46 case SHORT_OPTION_APND: 47 m_append.SetCurrentValue(true); 48 break; 49 50 default: 51 llvm_unreachable("Unimplemented option"); 52 } 53 54 return error; 55 } 56 57 void OptionGroupOutputFile::OptionParsingStarting( 58 ExecutionContext *execution_context) { 59 m_file.Clear(); 60 m_append.Clear(); 61 } 62