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