]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionGroupOutputFile.cpp
MFV r331712:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionGroupOutputFile.cpp
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 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Host/OptionParser.h"
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21 OptionGroupOutputFile::OptionGroupOutputFile()
22     : m_file(), m_append(false, false) {}
23
24 OptionGroupOutputFile::~OptionGroupOutputFile() {}
25
26 static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
27
28 static OptionDefinition g_option_table[] = {
29     {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
30      nullptr, nullptr, 0, eArgTypeFilename,
31      "Specify a path for capturing command output."},
32     {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
33      OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
34      "Append to the file specified with '--outfile <path>'."},
35 };
36
37 llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
38   return llvm::makeArrayRef(g_option_table);
39 }
40
41 Status
42 OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
43                                       llvm::StringRef option_arg,
44                                       ExecutionContext *execution_context) {
45   Status error;
46   const int short_option = g_option_table[option_idx].short_option;
47
48   switch (short_option) {
49   case 'o':
50     error = m_file.SetValueFromString(option_arg);
51     break;
52
53   case SHORT_OPTION_APND:
54     m_append.SetCurrentValue(true);
55     break;
56
57   default:
58     error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
59     break;
60   }
61
62   return error;
63 }
64
65 void OptionGroupOutputFile::OptionParsingStarting(
66     ExecutionContext *execution_context) {
67   m_file.Clear();
68   m_append.Clear();
69 }