summaryrefslogtreecommitdiff
path: root/src/plugins/debugger/cdb/cdbsymbolgroupcontext.h
blob: ac276f5e5b4371f6582ae68cabce9ee5048e7a66 (plain)
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
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef CDBSYMBOLGROUPCONTEXT_H
#define CDBSYMBOLGROUPCONTEXT_H

#include "cdbcom.h"
#include "symbolgroupcontext.h"

#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QList>
#include <QtCore/QStringList>
#include <QtCore/QSharedPointer>
#include <QtCore/QPair>
#include <QtCore/QMap>
#include <QtCore/QSet>

namespace Debugger {
namespace Internal {

class WatchData;
class WatchHandler;
struct CdbSymbolGroupRecursionContext;
class CdbDumperHelper;


/* CdbSymbolGroupContext manages a symbol group context and
 * a dumper context. It dispatches calls between the local items
 * that are handled by the symbol group and those that are handled by the dumpers. */

class CdbSymbolGroupContext : public CdbCore::SymbolGroupContext
{
    Q_DISABLE_COPY(CdbSymbolGroupContext);
     explicit CdbSymbolGroupContext(const QString &prefix,
                                    CIDebugSymbolGroup *symbolGroup,
                                    const QSharedPointer<CdbDumperHelper> &dumper,
                                    const QStringList &uninitializedVariables);

public:
     // Mask bits for the source field of watch data.
     enum { SourceMask = 0xFF,
            // We know the children although the WatchModel does not believe us.
            ChildrenKnownBit = 0x0100,
            // Is a pointer to a potentially dumpeable class.
            ClassPointerBit = 0x0200 };

     static CdbSymbolGroupContext *create(const QString &prefix,
                                          CIDebugSymbolGroup *symbolGroup,
                                          const QSharedPointer<CdbDumperHelper> &dumper,
                                          const QStringList &uninitializedVariables,
                                          QString *errorMessage);

     bool editorToolTip(const QString &iname, QString *value, QString *errorMessage);

     bool populateModelInitially(WatchHandler *wh, QString *errorMessage);

     bool completeData(const WatchData &incompleteLocal,
                       WatchHandler *wh,
                       QString *errorMessage);     

private:
    // Initially populate the locals model for a new stackframe.
    // Write a sequence of WatchData to it, recurse down if the
    // recursionPredicate agrees. The ignorePredicate can be used
    // to terminate processing after insertion of an item (if the calling
    // routine wants to insert another subtree).
    template <class OutputIterator, class RecursionPredicate, class IgnorePredicate>
    static bool populateModelInitiallyHelper(const CdbSymbolGroupRecursionContext &ctx,
                                       OutputIterator it,
                                       RecursionPredicate recursionPredicate,
                                       IgnorePredicate ignorePredicate,
                                       QString *errorMessage);

    // Complete children of a WatchData item.
    // Write a sequence of WatchData to it, recurse if the
    // recursionPredicate agrees. The ignorePredicate can be used
    // to terminate processing after insertion of an item (if the calling
    // routine wants to insert another subtree).
    template <class OutputIterator, class RecursionPredicate, class IgnorePredicate>
    static bool completeDataHelper (const CdbSymbolGroupRecursionContext &ctx,
                              WatchData incompleteLocal,
                              OutputIterator it,
                              RecursionPredicate recursionPredicate,
                              IgnorePredicate ignorePredicate,
                              QString *errorMessage);

    // Retrieve child symbols of prefix as a sequence of WatchData.
    template <class OutputIterator>
            bool getChildSymbols(const QString &prefix, OutputIterator it, QString *errorMessage)
            { return getDumpChildSymbols(0, prefix, 0, it, errorMessage); }
    // Retrieve child symbols of prefix as a sequence of WatchData.
    // Is CIDebugDataSpaces is != 0, try internal dumper and set owner
    template <class OutputIterator>
            bool getDumpChildSymbols(const QString &prefix,
                                     int dumpedOwner,
                                     OutputIterator it, QString *errorMessage);

    template <class OutputIterator, class RecursionPredicate, class IgnorePredicate>
    static bool insertSymbolRecursion(WatchData wd,
                                      const CdbSymbolGroupRecursionContext &ctx,
                                      OutputIterator it,
                                      RecursionPredicate recursionPredicate,
                                      IgnorePredicate ignorePredicate,
                                      QString *errorMessage);

    unsigned watchDataAt(unsigned long index, WatchData *);

    const bool m_useDumpers;
    const QSharedPointer<CdbDumperHelper> m_dumper;
};

// A convenience struct to save parameters for the model recursion.
struct CdbSymbolGroupRecursionContext {
    explicit CdbSymbolGroupRecursionContext(CdbSymbolGroupContext *ctx, int internalDumperOwner);

    CdbSymbolGroupContext *context;
    int internalDumperOwner;
};

// Helper to a sequence of  WatchData into a list.
class WatchDataBackInserter
{
public:
    explicit WatchDataBackInserter(QList<WatchData> &wh) : m_wh(wh) {}

    inline WatchDataBackInserter & operator*() { return *this; }
    inline WatchDataBackInserter &operator=(const WatchData &wd) {
        m_wh.push_back(wd);
        return *this;
    }
    inline WatchDataBackInserter &operator++() { return *this; }

private:
    QList<WatchData> &m_wh;
};

} // namespace Internal
} // namespace Debugger

#include "cdbsymbolgroupcontext_tpl.h"

#endif // CDBSYMBOLGROUPCONTEXT_H