cdbdumperhelper.h 4.98 KB
Newer Older
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
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact:  Qt Software Information (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 qt-sales@nokia.com.
**
**************************************************************************/

#ifndef CDBDUMPERHELPER_H
#define CDBDUMPERHELPER_H

33
34
#include "watchutils.h"
#include "cdbcom.h"
hjk's avatar
hjk committed
35

36
#include <QtCore/QStringList>
37
#include <QtCore/QMap>
38
39
40
41
42

namespace Debugger {
namespace Internal {

struct CdbComInterfaces;
43
44
45
class IDebuggerManagerAccessForEngines;
class DebuggerManager;

hjk's avatar
hjk committed
46
/* For code clarity, all the stuff related to custom dumpers goes here.
47
48
 * "Custom dumper" is a library compiled against the current
 * Qt containing functions to evaluate values of Qt classes
49
50
51
52
53
54
55
56
57
58
59
 * (such as QString), taking pointers to their addresses.
 * The dumper functions produce formatted string output which is
 * converted into WatchData items with the help of QtDumperHelper.
 *
 * Usage: When launching the debugger, call reset() with path to dumpers
 * and enabled flag. From the module load event callback, call
 * moduleLoadHook() to initialize.
 * dumpType() is the main query function to obtain a list  of WatchData from
 * WatchData item produced by the smbol context.
 * Call disable(), should the debuggee crash (as performing debuggee
 * calls is no longer possible, then).*/
60
61
62

class CdbDumperHelper
{
63
    Q_DISABLE_COPY(CdbDumperHelper)
64
65
public:
   enum State {
66
        Disabled, // Disabled or failed
67
        NotLoaded,
68
69
        InjectLoadFailed,
        InjectLoading,
70
        Loaded,
71
        Initialized, // List of types, etc. retrieved
72
73
    };

74
    explicit CdbDumperHelper(DebuggerManager *manager,
75
                             CdbComInterfaces *cif);
76
77
    ~CdbDumperHelper();

78
79
80
81
82
    State state() const    { return m_state; }
    bool isEnabled() const { return m_state != Disabled; }

    // Disable in case of a debuggee crash.
    void disable();
83
84
85
86

    // Call before starting the debugger
    void reset(const QString &library, bool enabled);

87
88
    // Call from the module load callback to perform initialization.
    void moduleLoadHook(const QString &module, HANDLE debuggeeHandle);
89

90
    // Dump a WatchData item.
91
92
93
94
95
96
97
    enum DumpResult { DumpNotHandled, DumpOk, DumpError };
    DumpResult dumpType(const WatchData &d, bool dumpChildren, int source,
                        QList<WatchData> *result, QString *errorMessage);

    inline CdbComInterfaces *comInterfaces() const { return m_cif; }

private:
98
99
    enum CallLoadResult { CallLoadOk, CallLoadError, CallLoadNoQtApp, CallLoadAlreadyLoaded };

100
    void clearBuffer();
101
102
103
104
105
106

    bool ensureInitialized(QString *errorMessage);
    CallLoadResult initCallLoad(QString *errorMessage);
    bool initResolveSymbols(QString *errorMessage);
    bool initKnownTypes(QString *errorMessage);

107
108
    bool getTypeSize(const QString &typeName, int *size, QString *errorMessage);
    bool runTypeSizeQuery(const QString &typeName, int *size, QString *errorMessage);
109
110
    bool callDumper(const QString &call, const QByteArray &inBuffer, const char **outputPtr,
                    bool ignoreAccessViolation, QString *errorMessage);
111

112
113
114
115
116
117
118
    enum DumpExecuteResult { DumpExecuteOk, DumpExecuteSizeFailed, DumpExecuteCallFailed };
    DumpExecuteResult executeDump(const WatchData &wd,
                                  const QtDumperHelper::TypeData& td, bool dumpChildren, int source,
                                  QList<WatchData> *result, QString *errorMessage);

    static bool writeToDebuggee(CIDebugDataSpaces *ds, const QByteArray &buffer, quint64 address, QString *errorMessage);

119
    const bool m_tryInjectLoad;
120
    const QString m_messagePrefix;
121
    State m_state;
122
    DebuggerManager *m_manager;
123
    IDebuggerManagerAccessForEngines *m_access;
124
125
126
127
    CdbComInterfaces *m_cif;

    QString m_library;
    QString m_dumpObjectSymbol;
128
129
130
131
132
133

    quint64 m_inBufferAddress;
    unsigned long m_inBufferSize;
    quint64 m_outBufferAddress;
    unsigned long m_outBufferSize;
    char *m_buffer;
134
135
136
137

    QStringList m_failedTypes;

    QtDumperHelper m_helper;
138
139
140
141
142
143
};

} // namespace Internal
} // namespace Debugger

#endif // CDBDUMPERHELPER_H