blob: d9eccb9709b3515839160c280c6224e2be71c49a [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
Johnny Chen7c575b32011-09-10 00:48:33 +000016#include "lldb/Utility/Utils.h"
Greg Clayton84c39662011-04-27 22:04:39 +000017
18using namespace lldb;
19using namespace lldb_private;
20
Kate Stoneb9c1b512016-09-06 20:57:50 +000021OptionGroupOutputFile::OptionGroupOutputFile()
22 : m_file(), m_append(false, false) {}
Greg Clayton84c39662011-04-27 22:04:39 +000023
Kate Stoneb9c1b512016-09-06 20:57:50 +000024OptionGroupOutputFile::~OptionGroupOutputFile() {}
Greg Clayton84c39662011-04-27 22:04:39 +000025
Kate Stoneb9c1b512016-09-06 20:57:50 +000026static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
Saleem Abdulrasool44edda02014-03-18 04:43:47 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028static 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>'."},
Greg Clayton84c39662011-04-27 22:04:39 +000035};
36
Kate Stoneb9c1b512016-09-06 20:57:50 +000037uint32_t OptionGroupOutputFile::GetNumDefinitions() {
38 return llvm::array_lengthof(g_option_table);
Greg Clayton84c39662011-04-27 22:04:39 +000039}
40
Kate Stoneb9c1b512016-09-06 20:57:50 +000041const OptionDefinition *OptionGroupOutputFile::GetDefinitions() {
42 return g_option_table;
Greg Clayton84c39662011-04-27 22:04:39 +000043}
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045Error OptionGroupOutputFile::SetOptionValue(
46 uint32_t option_idx, const char *option_arg,
47 ExecutionContext *execution_context) {
48 Error error;
49 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton84c39662011-04-27 22:04:39 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 switch (short_option) {
52 case 'o':
53 error = m_file.SetValueFromString(option_arg);
54 break;
Greg Clayton84c39662011-04-27 22:04:39 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 case SHORT_OPTION_APND:
57 m_append.SetCurrentValue(true);
58 break;
Greg Clayton84c39662011-04-27 22:04:39 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 default:
61 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
62 break;
63 }
Greg Clayton84c39662011-04-27 22:04:39 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 return error;
Greg Clayton84c39662011-04-27 22:04:39 +000066}
67
Kate Stoneb9c1b512016-09-06 20:57:50 +000068void OptionGroupOutputFile::OptionParsingStarting(
69 ExecutionContext *execution_context) {
70 m_file.Clear();
71 m_append.Clear();
Greg Clayton84c39662011-04-27 22:04:39 +000072}