blob: 35e6f52d549572ea2b12ef155e395b12a7e8d038 [file] [log] [blame]
Greg Clayton84c39662011-04-27 22:04:39 +00001//===-- 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
Johnny Chen4bee32e2011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupOutputFile.h"
Greg Clayton84c39662011-04-27 22:04:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16
17using namespace lldb;
18using namespace lldb_private;
19
Kate Stoneb9c1b512016-09-06 20:57:50 +000020OptionGroupOutputFile::OptionGroupOutputFile()
21 : m_file(), m_append(false, false) {}
Greg Clayton84c39662011-04-27 22:04:39 +000022
Kate Stoneb9c1b512016-09-06 20:57:50 +000023OptionGroupOutputFile::~OptionGroupOutputFile() {}
Greg Clayton84c39662011-04-27 22:04:39 +000024
Kate Stoneb9c1b512016-09-06 20:57:50 +000025static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
Saleem Abdulrasool44edda02014-03-18 04:43:47 +000026
Kate Stoneb9c1b512016-09-06 20:57:50 +000027static OptionDefinition g_option_table[] = {
28 {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
29 nullptr, nullptr, 0, eArgTypeFilename,
30 "Specify a path for capturing command output."},
31 {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
32 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
33 "Append to the file specified with '--outfile <path>'."},
Greg Clayton84c39662011-04-27 22:04:39 +000034};
35
Zachary Turner1f0f5b52016-09-22 20:22:55 +000036llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +000037 return llvm::makeArrayRef(g_option_table);
Greg Clayton84c39662011-04-27 22:04:39 +000038}
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040Error OptionGroupOutputFile::SetOptionValue(
Zachary Turner8cef4b02016-09-23 17:48:13 +000041 uint32_t option_idx, llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 ExecutionContext *execution_context) {
43 Error error;
44 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton84c39662011-04-27 22:04:39 +000045
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 switch (short_option) {
47 case 'o':
48 error = m_file.SetValueFromString(option_arg);
49 break;
Greg Clayton84c39662011-04-27 22:04:39 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 case SHORT_OPTION_APND:
52 m_append.SetCurrentValue(true);
53 break;
Greg Clayton84c39662011-04-27 22:04:39 +000054
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 default:
56 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
57 break;
58 }
Greg Clayton84c39662011-04-27 22:04:39 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 return error;
Greg Clayton84c39662011-04-27 22:04:39 +000061}
62
Kate Stoneb9c1b512016-09-06 20:57:50 +000063void OptionGroupOutputFile::OptionParsingStarting(
64 ExecutionContext *execution_context) {
65 m_file.Clear();
66 m_append.Clear();
Greg Clayton84c39662011-04-27 22:04:39 +000067}