1 //===-- OptionGroupFormat.h -------------------------------------*- 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 #ifndef LLDB_INTERPRETER_OPTIONGROUPFORMAT_H
10 #define LLDB_INTERPRETER_OPTIONGROUPFORMAT_H
11 
12 #include "lldb/Interpreter/OptionValueFormat.h"
13 #include "lldb/Interpreter/OptionValueSInt64.h"
14 #include "lldb/Interpreter/OptionValueUInt64.h"
15 #include "lldb/Interpreter/Options.h"
16 
17 namespace lldb_private {
18 
19 // OptionGroupFormat
20 
21 class OptionGroupFormat : public OptionGroup {
22 public:
23   static const uint32_t OPTION_GROUP_FORMAT = LLDB_OPT_SET_1;
24   static const uint32_t OPTION_GROUP_GDB_FMT = LLDB_OPT_SET_2;
25   static const uint32_t OPTION_GROUP_SIZE = LLDB_OPT_SET_3;
26   static const uint32_t OPTION_GROUP_COUNT = LLDB_OPT_SET_4;
27 
28   OptionGroupFormat(
29       lldb::Format default_format,
30       uint64_t default_byte_size =
31           UINT64_MAX, // Pass UINT64_MAX to disable the "--size" option
32       uint64_t default_count =
33           UINT64_MAX); // Pass UINT64_MAX to disable the "--count" option
34 
35   ~OptionGroupFormat() override = default;
36 
37   llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
38 
39   Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
40                         ExecutionContext *execution_context) override;
41 
42   void OptionParsingStarting(ExecutionContext *execution_context) override;
43 
GetFormat()44   lldb::Format GetFormat() const { return m_format.GetCurrentValue(); }
45 
GetFormatValue()46   OptionValueFormat &GetFormatValue() { return m_format; }
47 
GetFormatValue()48   const OptionValueFormat &GetFormatValue() const { return m_format; }
49 
GetByteSizeValue()50   OptionValueUInt64 &GetByteSizeValue() { return m_byte_size; }
51 
GetByteSizeValue()52   const OptionValueUInt64 &GetByteSizeValue() const { return m_byte_size; }
53 
GetCountValue()54   OptionValueUInt64 &GetCountValue() { return m_count; }
55 
GetCountValue()56   const OptionValueUInt64 &GetCountValue() const { return m_count; }
57 
HasGDBFormat()58   bool HasGDBFormat() const { return m_has_gdb_format; }
59 
AnyOptionWasSet()60   bool AnyOptionWasSet() const {
61     return m_format.OptionWasSet() || m_byte_size.OptionWasSet() ||
62            m_count.OptionWasSet();
63   }
64 
65 protected:
66   bool ParserGDBFormatLetter(ExecutionContext *execution_context,
67                              char format_letter, lldb::Format &format,
68                              uint32_t &byte_size);
69 
70   OptionValueFormat m_format;
71   OptionValueUInt64 m_byte_size;
72   OptionValueUInt64 m_count;
73   char m_prev_gdb_format;
74   char m_prev_gdb_size;
75   bool m_has_gdb_format;
76 };
77 
78 } // namespace lldb_private
79 
80 #endif // LLDB_INTERPRETER_OPTIONGROUPFORMAT_H
81