1 //===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===// 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 OptionGroupOutputFile::~OptionGroupOutputFile() {} 20 21 static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' 22 23 static constexpr OptionDefinition g_option_table[] = { 24 {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument, 25 nullptr, {}, 0, eArgTypeFilename, 26 "Specify a path for capturing command output."}, 27 {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND, 28 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, 29 "Append to the file specified with '--outfile <path>'."}, 30 }; 31 32 llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() { 33 return llvm::makeArrayRef(g_option_table); 34 } 35 36 Status 37 OptionGroupOutputFile::SetOptionValue(uint32_t option_idx, 38 llvm::StringRef option_arg, 39 ExecutionContext *execution_context) { 40 Status error; 41 const int short_option = g_option_table[option_idx].short_option; 42 43 switch (short_option) { 44 case 'o': 45 error = m_file.SetValueFromString(option_arg); 46 break; 47 48 case SHORT_OPTION_APND: 49 m_append.SetCurrentValue(true); 50 break; 51 52 default: 53 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); 54 break; 55 } 56 57 return error; 58 } 59 60 void OptionGroupOutputFile::OptionParsingStarting( 61 ExecutionContext *execution_context) { 62 m_file.Clear(); 63 m_append.Clear(); 64 } 65