cdbdumperhelper.h 4.62 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"
35
#include <QtCore/QStringList>
36
#include <QtCore/QMap>
37
38
39
40
41

namespace Debugger {
namespace Internal {

struct CdbComInterfaces;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class IDebuggerManagerAccessForEngines;
class DebuggerManager;

/* For code clarity, all the stuff related to custom dumpers
 * goes here.
 * "Custom dumper" is a library compiled against the current
 * Qt containing functions to evaluate values of Qt classes
 * (such as QString, taking pointers to their addresses).
 * The library must be loaded into the debuggee.
 * Loading the dumpers requires making the debuggee call functions
 * (LoadLibrary() and the dumper functions). This only works if the
 * debuggee is in a 'well-defined' breakpoint state (such as at 'main()').
 * Calling the load functions from an IDebugEvent callback causes
 * WaitForEvent() to fail with unknown errors. Calling the load functions from an
 * non 'well-defined' (arbitrary) breakpoint state will cause LoadLibrary
 * to trigger an access violations.
 * Currently, we call the load function when stopping at 'main()' for which
 * we set a temporary break point if the user does not want to stop there. */
60
61
62

class CdbDumperHelper
{
63
    Q_DISABLE_COPY(CdbDumperHelper)
64
65
66
67
68
69
70
71
public:
   enum State {
        Disabled,
        NotLoaded,
        Loaded,
        Failed
    };

72
73
    explicit CdbDumperHelper(IDebuggerManagerAccessForEngines *access,
                             CdbComInterfaces *cif);
74
75
76
77
    ~CdbDumperHelper();

    State state() const { return m_state; }
    operator bool() const { return m_state == Loaded; }
78
79
80
81

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

82
    // Call in a temporary breakpoint state to actually load.
83
    void load(DebuggerManager *manager);
84

85
86
87
88
89
    enum DumpResult { DumpNotHandled, DumpOk, DumpError };
    DumpResult dumpType(const WatchData &d, bool dumpChildren, int source,
                        QList<WatchData> *result, QString *errorMessage);

    // bool handlesType(const QString &typeName) const;
90

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

private:
94
    void clearBuffer();
95
    bool resolveSymbols(QString *errorMessage);
96
    bool getKnownTypes(QString *errorMessage);
97
98
99
    bool getTypeSize(const QString &typeName, int *size, QString *errorMessage);
    bool runTypeSizeQuery(const QString &typeName, int *size, QString *errorMessage);
    bool callDumper(const QString &call, const QByteArray &inBuffer, const char **outputPtr, QString *errorMessage);
100

101
102
103
104
105
106
107
108
    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);

    const QString m_messagePrefix;
109
    State m_state;
110
    IDebuggerManagerAccessForEngines *m_access;
111
112
113
114
    CdbComInterfaces *m_cif;

    QString m_library;
    QString m_dumpObjectSymbol;
115
116
117
118
119
120

    quint64 m_inBufferAddress;
    unsigned long m_inBufferSize;
    quint64 m_outBufferAddress;
    unsigned long m_outBufferSize;
    char *m_buffer;
121
122
123
124

    QStringList m_failedTypes;

    QtDumperHelper m_helper;
125
126
127
128
129
130
};

} // namespace Internal
} // namespace Debugger

#endif // CDBDUMPERHELPER_H