OptionGroupOutputFile.cpp revision 360784
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 13using namespace lldb; 14using namespace lldb_private; 15 16OptionGroupOutputFile::OptionGroupOutputFile() 17 : m_file(), m_append(false, false) {} 18 19OptionGroupOutputFile::~OptionGroupOutputFile() {} 20 21static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' 22 23static 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 32llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() { 33 return llvm::makeArrayRef(g_option_table); 34} 35 36Status 37OptionGroupOutputFile::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 llvm_unreachable("Unimplemented option"); 54 } 55 56 return error; 57} 58 59void OptionGroupOutputFile::OptionParsingStarting( 60 ExecutionContext *execution_context) { 61 m_file.Clear(); 62 m_append.Clear(); 63} 64