OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / qtcreatorcdbext / symbolgroup.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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef SYMBOLGROUP_H
34 #define SYMBOLGROUP_H
35
36 #include "common.h"
37 #include "symbolgroupnode.h"
38
39 #include <map>
40
41 class SymbolGroup {
42 public:
43     typedef std::vector<DEBUG_SYMBOL_PARAMETERS> SymbolParameterVector;
44
45 private:
46     SymbolGroup(const SymbolGroup &);
47     SymbolGroup &operator=(const SymbolGroup &);
48
49 protected:
50     explicit SymbolGroup(CIDebugSymbolGroup *,
51                          const SymbolParameterVector &vec,
52                          const std::string &rootModule,
53                          const char *rootName);
54
55 public:
56     typedef AbstractSymbolGroupNode::AbstractSymbolGroupNodePtrVector AbstractSymbolGroupNodePtrVector;
57
58     virtual ~SymbolGroup();
59
60     // Dump all
61     std::string dump(const SymbolGroupValueContext &ctx,
62                      const DumpParameters &p = DumpParameters()) const;
63     // Expand node and dump
64     std::string dump(const std::string &iname, const SymbolGroupValueContext &ctx,
65                      const DumpParameters &p, std::string *errorMessage);
66     std::string debug(const std::string &iname = std::string(),
67                       const std::string &filter = std::string(),
68                       unsigned verbosity = 0) const;
69
70     SymbolGroupNode *root() { return m_root; }
71     const SymbolGroupNode *root() const { return m_root; }
72     AbstractSymbolGroupNode *find(const std::string &iname) const;
73
74     // Expand a single node "locals.A.B" requiring that "locals.A.B" is already visible
75     // (think mkdir without -p).
76     bool expand(const std::string &node, std::string *errorMessage);
77     bool expandRunComplexDumpers(const std::string &node, const SymbolGroupValueContext &ctx, std::string *errorMessage);
78     // Expand a node list "locals.i1,locals.i2", expanding all nested child nodes
79     // (think mkdir -p).
80     unsigned expandList(const std::vector<std::string> &nodes, std::string *errorMessage);
81     unsigned expandListRunComplexDumpers(const std::vector<std::string> &nodes,
82                                          const SymbolGroupValueContext &ctx,
83                                          std::string *errorMessage);
84
85     // Mark uninitialized (top level only)
86     void markUninitialized(const std::vector<std::string> &nodes);
87
88     // Cast an (unexpanded) node
89     bool typeCast(const std::string &iname, const std::string &desiredType, std::string *errorMessage);
90     // Add a symbol by name expression
91     SymbolGroupNode *addSymbol(const std::string &module,
92                                const std::string &name,        // Expression like 'myarray[1]'
93                                const std::string &displayName, // Name to be displayed, defaults to name
94                                const std::string &iname, // Desired iname, defaults to name
95                                std::string *errorMessage);
96     // Convenience overload for name==displayName
97     SymbolGroupNode *addSymbol(const std::string &module,
98                                const std::string &name, // Expression like 'myarray[1]'
99                                const std::string &iname,
100                                std::string *errorMessage);
101
102     bool accept(SymbolGroupNodeVisitor &visitor) const;
103
104     // Assign a value by iname
105     bool assign(const std::string &node,
106                 const std::string &value,
107                 std::string *errorMessage);
108
109     CIDebugSymbolGroup *debugSymbolGroup() const { return m_symbolGroup; }
110
111     static bool getSymbolParameters(CIDebugSymbolGroup *m_symbolGroup,
112                                     unsigned long start,
113                                     unsigned long count,
114                                     SymbolParameterVector *vec,
115                                     std::string *errorMessage);
116
117 protected:
118     static bool getSymbolParameters(CIDebugSymbolGroup *m_symbolGroup,
119                                     SymbolParameterVector *vec,
120                                     std::string *errorMessage);
121     bool removeSymbol(AbstractSymbolGroupNode *n, std::string *errorMessage);
122
123 private:
124     inline AbstractSymbolGroupNode *findI(const std::string &iname) const;
125
126     CIDebugSymbolGroup * const m_symbolGroup;
127     SymbolGroupNode *m_root;
128 };
129
130 class LocalsSymbolGroup : public SymbolGroup {
131 protected:
132     explicit LocalsSymbolGroup(CIDebugSymbolGroup *,
133                                const SymbolParameterVector &vec,
134                                ULONG threadId, unsigned frame,
135                                const std::string &function);
136 public:
137     unsigned frame() const { return m_frame; }
138     std::string function() const { return m_function; }
139     std::string module() const;
140     ULONG threadId() const { return m_threadId; }
141
142     static LocalsSymbolGroup *create(CIDebugControl *control,
143                                      CIDebugSymbols *,
144                                      ULONG threadId,
145                                      unsigned frame,
146                                      std::string *errorMessage);
147
148 private:
149     const unsigned m_frame;
150     const ULONG m_threadId;
151     std::string m_function;
152 };
153
154 class WatchesSymbolGroup : public SymbolGroup {
155 public:
156     typedef std::map<std::string, std::string> InameExpressionMap;
157
158     static const char *watchInamePrefix;
159
160     // Add a symbol as 'watch.0' or '0' with expression
161     bool addWatch(CIDebugSymbols *s, std::string iname, const std::string &expression, std::string *errorMessage);
162     // Synchronize watches passing on a map of '0' -> '*(int *)(0xA0)'
163     bool synchronize(CIDebugSymbols *s, const InameExpressionMap &m, std::string *errorMessage);
164
165     static WatchesSymbolGroup *create(CIDebugSymbols *, std::string *errorMessage);
166
167     static std::string fixWatchExpression(CIDebugSymbols *s, const std::string &ex);
168
169 private:
170     explicit WatchesSymbolGroup(CIDebugSymbolGroup *);
171     InameExpressionMap currentInameExpressionMap() const;
172     inline SymbolGroupNode *rootChildByIname(const std::string &iname) const;
173     static inline std::string fixWatchExpressionI(CIDebugSymbols *s, const std::string &ex);
174 };
175
176 #endif // SYMBOLGROUP_H