Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 4bee32e | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 10 | #include "lldb/Interpreter/OptionGroupOutputFile.h" |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Johnny Chen | 7c575b3 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | OptionGroupOutputFile::OptionGroupOutputFile() |
| 22 | : m_file(), m_append(false, false) {} |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 23 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | OptionGroupOutputFile::~OptionGroupOutputFile() {} |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 25 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' |
Saleem Abdulrasool | 44edda0 | 2014-03-18 04:43:47 +0000 | [diff] [blame] | 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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>'."}, |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 37 | llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame^] | 38 | return llvm::makeArrayRef(g_option_table); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | Error OptionGroupOutputFile::SetOptionValue( |
| 42 | uint32_t option_idx, const char *option_arg, |
| 43 | ExecutionContext *execution_context) { |
| 44 | Error error; |
| 45 | const int short_option = g_option_table[option_idx].short_option; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | switch (short_option) { |
| 48 | case 'o': |
| 49 | error = m_file.SetValueFromString(option_arg); |
| 50 | break; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | case SHORT_OPTION_APND: |
| 53 | m_append.SetCurrentValue(true); |
| 54 | break; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | default: |
| 57 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 58 | break; |
| 59 | } |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | return error; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | void OptionGroupOutputFile::OptionParsingStarting( |
| 65 | ExecutionContext *execution_context) { |
| 66 | m_file.Clear(); |
| 67 | m_append.Clear(); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 68 | } |