File: registercontroller.h

package info (click to toggle)
kdevelop 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 73,508 kB
  • sloc: cpp: 291,803; python: 4,322; javascript: 3,518; sh: 1,316; ansic: 703; xml: 414; php: 95; lisp: 66; makefile: 31; sed: 12
file content (232 lines) | stat: -rw-r--r-- 7,159 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
    SPDX-FileCopyrightText: 2013 Vlas Puhov <vlas.puhov@mail.ru>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef _REGISTERCONTROLLER_H_
#define _REGISTERCONTROLLER_H_

#include <QHash>
#include <QVector>
#include <QObject>
#include <QStringList>
#include <QString>

namespace KDevMI {
namespace MI
{
struct ResultRecord;
}

class MIDebugSession;

enum RegisterType {general, structured, flag, floatPoint};

class GroupsName
{
public:
    QString name() const { return _name;}
    int index() const {return _index;}
    RegisterType type() const{return _type; }
    QString flagName() const{return _flagName;}

    bool operator==(const GroupsName& g) const {return _name == g.name();}

    GroupsName() {}

private:
    GroupsName(const QString& name, int idx, RegisterType type = general, const QString& flag = QString()): _name(name), _index(idx), _type(type), _flagName(flag) {}

private:
    QString _name;
    int _index = -1; ///Should be unique for each group for current architecture (0, 1...n).
    RegisterType _type = general;
    QString _flagName; ///Used only for flag registers.

    friend class IRegisterController;
    friend struct RegistersGroup;
};

enum Format {
    Binary,
    Octal,
    Decimal,
    Hexadecimal,
    Raw,
    Unsigned,

    LAST_FORMAT
};

enum Mode {
    natural,

    v4_float,
    v2_double,
    v4_int32,
    v2_int64,

    u32,
    u64,
    f32,
    f64,

    LAST_MODE
};

struct FormatsModes {
    QVector<Format> formats;
    QVector<Mode> modes;
};

///Register in format: @p name, @p value - space separated list of values
struct Register {
    Register() {}
    Register(const QString& _name, const QString& _value): name(_name), value(_value) {}
    QString name;
    QString value;
};
///List of @p registers for @p groupName in @p format
struct RegistersGroup {
    RegistersGroup()

    {}

    GroupsName groupName;
    QVector<Register> registers;
    Format format = Binary; ///<Current format
    bool flag = false; ///<true if this group is flags group.
};

struct FlagRegister {
    QStringList flags;
    QStringList bits;
    QString registerName;
    GroupsName groupName;
};

/** @brief Class for managing registers: it can retrieve, change and send registers back to the debugger.*/
class IRegisterController : public QObject
{
    Q_OBJECT

public:
    ///Sets session @p debugSession to send commands to.
    void setSession(MIDebugSession* debugSession);

    ///There'll be at least 2 groups: "General" and "Flags", also "XMM", "FPU", "Segment" for x86, x86_64 architectures.
    virtual QVector<GroupsName> namesOfRegisterGroups() const = 0;

    ///Returns all supported formats for @p group (bin, dec, hex ...)
    QVector<Format> formats(const GroupsName& group);

    ///Sets current format for the @p group, if format is supported. Does nothing otherwise.
    void setFormat(Format f, const GroupsName& group);

    ///Returns all supported modes for @p group (i.e. how to display group: 2 int, 4 float or other number of columns)
    QVector<Mode> modes(const GroupsName& group);

    ///Sets current mode for the @p group, if mode is supported. Does nothing otherwise.
    void setMode(Mode m, const GroupsName& group);

Q_SIGNALS:
    ///Emits @p group with updated registers.
    void registersChanged(const RegistersGroup& g);

public Q_SLOTS:
    ///Updates registers in @p group. If @p group is empty - updates all registers.
    virtual void updateRegisters(const GroupsName& group = GroupsName());

    ///Sends updated register's @p reg value to the debugger.
    virtual void setRegisterValue(const Register& reg);

protected:
    explicit IRegisterController(MIDebugSession* debugSession = nullptr, QObject* parent = nullptr);

    ///Returns registers from the @p group, or empty registers group if @p group is invalid.
    virtual RegistersGroup registersFromGroup(const GroupsName& group) const = 0;

    ///Sets value for @p register from @p group.
    virtual void setRegisterValueForGroup(const GroupsName& group, const Register& reg) = 0;

    ///Returns names of all registers for @p group.
    virtual QStringList registerNamesForGroup(const GroupsName& group) const = 0;

    /**Updates value for each register in the group.
     * @param [out] registers Registers which values should be updated.
     */
    virtual void updateValuesForRegisters(RegistersGroup* registers) const;

    ///Returns value for the given @p name, empty string if the name is incorrect or there is no registers yet.
    QString registerValue(const QString& name) const;

    /** Sets a flag register.
     * @param reg register to set
     * @param flag flag register @p reg belongs to.
     */
    void setFlagRegister(const Register& reg, const FlagRegister& flag);

    ///Sets new value for register @p reg, from group @p group.
    void setGeneralRegister(const Register& reg, const GroupsName& group);

    ///Sets new value for structured register(XMM, VFP quad and other) @p reg, from group @p group.
    void setStructuredRegister(const Register& reg, const GroupsName& group);

    ///Updates values in @p flagsGroup for @p flagRegister.
    void updateFlagValues(RegistersGroup* flagsGroup, const FlagRegister& flagRegister) const;

    ///Returns group that given register belongs to.
    GroupsName groupForRegisterName(const QString& name) const;

    ///Initializes registers, that is gets names of all available registers. Returns true is succeed.
    bool initializeRegisters();

    GroupsName createGroupName(const QString& name, int idx, RegisterType t = general, const QString& flag = QString()) const;

    ///Returns register's number for @p name.
    QString numberForName(const QString& name) const;

public:
    ~IRegisterController() override;

private :
    ///Handles initialization of register's names.
    void registerNamesHandler(const MI::ResultRecord& r);

    ///Parses new values for general registers from @p r and updates it in m_registers.
    ///Emits registersChanged signal.
    void generalRegistersHandler(const MI::ResultRecord& r);

    ///Parses new values for structured registers from @p r and updates it in m_registers.
    ///Emits registersChanged signal.
    virtual void structuredRegistersHandler(const MI::ResultRecord& r);

private:

    ///Groups that should be updated(emitted @p registersInGroupChanged signal), if empty - all.
    QVector<GroupsName> m_pendingGroups;

protected:
    ///Register names as it sees debugger (in format: number, name).
    QVector<QString > m_rawRegisterNames;

    ///Registers in format: name, value
    QHash<QString, QString > m_registers;

    ///Supported formats and modes for each register's group. First format/mode is current.
    QVector<FormatsModes > m_formatsModes;

    ///Current debug session;
    MIDebugSession* m_debugSession;
};

} // end of namespace KDevMI

Q_DECLARE_TYPEINFO(KDevMI::Register, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(KDevMI::RegistersGroup, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(KDevMI::FlagRegister, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(KDevMI::GroupsName, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(KDevMI::FormatsModes, Q_MOVABLE_TYPE);

#endif