xref: /llvm-project/lldb/source/Commands/CommandObjectDisassemble.h (revision f109517d153609d4a8a3a3d3d3cc06da1b629364)
1 //===-- CommandObjectDisassemble.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_SOURCE_COMMANDS_COMMANDOBJECTDISASSEMBLE_H
10 #define LLDB_SOURCE_COMMANDS_COMMANDOBJECTDISASSEMBLE_H
11 
12 #include "lldb/Interpreter/CommandObject.h"
13 #include "lldb/Interpreter/Options.h"
14 #include "lldb/Utility/ArchSpec.h"
15 
16 namespace lldb_private {
17 
18 // CommandObjectDisassemble
19 
20 class CommandObjectDisassemble : public CommandObjectParsed {
21 public:
22   class CommandOptions : public Options {
23   public:
24     CommandOptions();
25 
26     ~CommandOptions() override;
27 
28     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
29                           ExecutionContext *execution_context) override;
30 
31     void OptionParsingStarting(ExecutionContext *execution_context) override;
32 
33     llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
34 
35     const char *GetPluginName() {
36       return (plugin_name.empty() ? nullptr : plugin_name.c_str());
37     }
38 
39     const char *GetFlavorString() {
40       if (flavor_string.empty() || flavor_string == "default")
41         return nullptr;
42       return flavor_string.c_str();
43     }
44 
45     const char *GetCPUString() {
46       if (cpu_string.empty() || cpu_string == "default")
47         return nullptr;
48       return cpu_string.c_str();
49     }
50 
51     const char *GetFeaturesString() {
52       if (features_string.empty() || features_string == "default")
53         return nullptr;
54       return features_string.c_str();
55     }
56 
57     Status OptionParsingFinished(ExecutionContext *execution_context) override;
58 
59     bool show_mixed; // Show mixed source/assembly
60     bool show_bytes;
61     bool show_control_flow_kind;
62     uint32_t num_lines_context = 0;
63     uint32_t num_instructions = 0;
64     bool raw;
65     std::string func_name;
66     bool current_function = false;
67     lldb::addr_t start_addr = 0;
68     lldb::addr_t end_addr = 0;
69     bool at_pc = false;
70     bool frame_line = false;
71     std::string plugin_name;
72     std::string flavor_string;
73     std::string cpu_string;
74     std::string features_string;
75     ArchSpec arch;
76     bool some_location_specified = false; // If no location was specified, we'll
77                                           // select "at_pc".  This should be set
78     // in SetOptionValue if anything the selects a location is set.
79     lldb::addr_t symbol_containing_addr = 0;
80     bool force = false;
81   };
82 
83   CommandObjectDisassemble(CommandInterpreter &interpreter);
84 
85   ~CommandObjectDisassemble() override;
86 
87   Options *GetOptions() override { return &m_options; }
88 
89 protected:
90   void DoExecute(Args &command, CommandReturnObject &result) override;
91 
92   llvm::Expected<std::vector<AddressRange>>
93   GetRangesForSelectedMode(CommandReturnObject &result);
94 
95   llvm::Expected<std::vector<AddressRange>> GetContainingAddressRanges();
96   llvm::Expected<std::vector<AddressRange>> GetCurrentFunctionRanges();
97   llvm::Expected<std::vector<AddressRange>> GetCurrentLineRanges();
98   llvm::Expected<std::vector<AddressRange>>
99   GetNameRanges(CommandReturnObject &result);
100   llvm::Expected<std::vector<AddressRange>> GetPCRanges();
101   llvm::Expected<std::vector<AddressRange>> GetStartEndAddressRanges();
102 
103   llvm::Error CheckRangeSize(const AddressRange &range, llvm::StringRef what);
104 
105   CommandOptions m_options;
106 };
107 
108 } // namespace lldb_private
109 
110 #endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTDISASSEMBLE_H
111