1 //===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Interpreter/OptionGroupOutputFile.h" 11 12 #include "lldb/Host/OptionParser.h" 13 14 using namespace lldb; 15 using namespace lldb_private; 16 17 OptionGroupOutputFile::OptionGroupOutputFile() 18 : m_file(), m_append(false, false) {} 19 20 OptionGroupOutputFile::~OptionGroupOutputFile() {} 21 22 static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' 23 24 static constexpr OptionDefinition g_option_table[] = { 25 {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument, 26 nullptr, {}, 0, eArgTypeFilename, 27 "Specify a path for capturing command output."}, 28 {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND, 29 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, 30 "Append to the file specified with '--outfile <path>'."}, 31 }; 32 33 llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() { 34 return llvm::makeArrayRef(g_option_table); 35 } 36 37 Status 38 OptionGroupOutputFile::SetOptionValue(uint32_t option_idx, 39 llvm::StringRef option_arg, 40 ExecutionContext *execution_context) { 41 Status error; 42 const int short_option = g_option_table[option_idx].short_option; 43 44 switch (short_option) { 45 case 'o': 46 error = m_file.SetValueFromString(option_arg); 47 break; 48 49 case SHORT_OPTION_APND: 50 m_append.SetCurrentValue(true); 51 break; 52 53 default: 54 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); 55 break; 56 } 57 58 return error; 59 } 60 61 void OptionGroupOutputFile::OptionParsingStarting( 62 ExecutionContext *execution_context) { 63 m_file.Clear(); 64 m_append.Clear(); 65 } 66