OSDN Git Service

b067c12131804bf3059b5858a16647b2fb646979
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / gdb / gdbmi.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef DEBUGGER_GDBMI_H
35 #define DEBUGGER_GDBMI_H
36
37 #include <QtCore/QByteArray>
38 #include <QtCore/QList>
39 #include <QtCore/QVariant>
40
41 namespace Debugger {
42 namespace Internal {
43
44 /*
45
46 output ==>
47     ( out-of-band-record )* [ result-record ] "(gdb)" nl
48 result-record ==>
49      [ token ] "^" result-class ( "," result )* nl
50 out-of-band-record ==>
51     async-record | stream-record
52 async-record ==>
53     exec-async-output | status-async-output | notify-async-output
54 exec-async-output ==>
55     [ token ] "*" async-output
56 status-async-output ==>
57     [ token ] "+" async-output
58 notify-async-output ==>
59     [ token ] "=" async-output
60 async-output ==>
61     async-class ( "," result )* nl
62 result-class ==>
63     "done" | "running" | "connected" | "error" | "exit"
64 async-class ==>
65     "stopped" | others (where others will be added depending on the needs--this is still in development).
66 result ==>
67      variable "=" value
68 variable ==>
69      string
70 value ==>
71      const | tuple | list
72 const ==>
73     c-string
74 tuple ==>
75      "{}" | "{" result ( "," result )* "}"
76 list ==>
77      "[]" | "[" value ( "," value )* "]" | "[" result ( "," result )* "]"
78 stream-record ==>
79     console-stream-output | target-stream-output | log-stream-output
80 console-stream-output ==>
81     "~" c-string
82 target-stream-output ==>
83     "@" c-string
84 log-stream-output ==>
85     "&" c-string
86 nl ==>
87     CR | CR-LF
88 token ==>
89     any sequence of digits.
90
91  */
92
93 // FIXME: rename into GdbMiValue
94 class GdbMi
95 {
96 public:
97     GdbMi() : m_type(Invalid) {}
98
99     QByteArray m_name;
100     QByteArray m_data;
101     QList<GdbMi> m_children;
102
103     enum Type {
104         Invalid,
105         Const,
106         Tuple,
107         List
108     };
109
110     Type m_type;
111
112     inline Type type() const { return m_type; }
113     inline QByteArray name() const { return m_name; }
114     inline bool hasName(const char *name) const { return m_name == name; }
115
116     inline bool isValid() const { return m_type != Invalid; }
117     inline bool isConst() const { return m_type == Const; }
118     inline bool isTuple() const { return m_type == Tuple; }
119     inline bool isList() const { return m_type == List; }
120
121
122     inline QByteArray data() const { return m_data; }
123     inline const QList<GdbMi> &children() const { return m_children; }
124     inline int childCount() const { return m_children.size(); }
125
126     const GdbMi &childAt(int index) const { return m_children[index]; }
127     GdbMi &childAt(int index) { return m_children[index]; }
128     GdbMi findChild(const char *name) const;
129
130     QByteArray toString(bool multiline = false, int indent = 0) const;
131     void fromString(const QByteArray &str);
132     void fromStringMultiple(const QByteArray &str);
133     void setStreamOutput(const QByteArray &name, const QByteArray &content);
134
135 private:
136     friend class GdbResponse;
137     friend class GdbEngine;
138
139     static QByteArray parseCString(const char *&from, const char *to);
140     static QByteArray escapeCString(const QByteArray &ba);
141     static QString escapeCString(const QString &ba);
142     void parseResultOrValue(const char *&from, const char *to);
143     void parseValue(const char *&from, const char *to);
144     void parseTuple(const char *&from, const char *to);
145     void parseTuple_helper(const char *&from, const char *to);
146     void parseList(const char *&from, const char *to);
147
148     void dumpChildren(QByteArray *str, bool multiline, int indent) const;
149 };
150
151 enum GdbResultClass
152 {
153     // "done" | "running" | "connected" | "error" | "exit"
154     GdbResultUnknown,
155     GdbResultDone,
156     GdbResultRunning,
157     GdbResultConnected,
158     GdbResultError,
159     GdbResultExit
160 };
161
162 class GdbResponse
163 {
164 public:
165     GdbResponse() : token(-1), resultClass(GdbResultUnknown) {}
166     QByteArray toString() const;
167     static QByteArray stringFromResultClass(GdbResultClass resultClass);
168
169     int            token;
170     GdbResultClass resultClass;
171     GdbMi          data;
172     QVariant       cookie;
173 };
174
175 void extractGdbVersion(const QString &msg,
176     int *gdbVersion, int *gdbBuildVersion, bool *isMacGdb);
177
178 } // namespace Internal
179 } // namespace Debugger
180
181 //Q_DECLARE_METATYPE(GdbDebugger::Internal::GdbMi)
182
183 #endif // DEBUGGER_GDBMI_H