cdbdebugengine_p.h 5.93 KB
Newer Older
1
/**************************************************************************
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6 7 8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
** Commercial Usage
10
**
11 12 13 14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25 26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
27
**
28
**************************************************************************/
29 30 31 32 33 34

#ifndef DEBUGGER_CDBENGINEPRIVATE_H
#define DEBUGGER_CDBENGINEPRIVATE_H

#include "cdbdebugeventcallback.h"
#include "cdbdebugoutput.h"
35
#include "cdboptions.h"
36
#include "cdbdumperhelper.h"
37 38
#include "stackhandler.h"
#include "debuggermanager.h"
39

40
#include <utils/consoleprocess.h>
41
#include <QtCore/QSharedPointer>
42 43 44 45 46 47

namespace Debugger {
namespace Internal {

class DebuggerManager;
class IDebuggerManagerAccessForEngines;
48
class WatchHandler;
49
class CdbStackFrameContext;
50
class CdbStackTraceContext;
51

Friedemann Kleint's avatar
Friedemann Kleint committed
52 53 54
// Thin wrapper around the 'DBEng' debugger engine shared library
// which is loaded at runtime.

hjk's avatar
hjk committed
55 56
class DebuggerEngineLibrary
{
Friedemann Kleint's avatar
Friedemann Kleint committed
57 58
public:
    DebuggerEngineLibrary();
59
    bool init(const QString &path, QString *errorMessage);
Friedemann Kleint's avatar
Friedemann Kleint committed
60 61 62 63 64 65

    inline HRESULT debugCreate(REFIID interfaceId, PVOID *interfaceHandle) const
        { return m_debugCreate(interfaceId, interfaceHandle); }

private:
    // The exported functions of the library
66
    typedef HRESULT (STDAPICALLTYPE *DebugCreateFunction)(REFIID, PVOID *);
Friedemann Kleint's avatar
Friedemann Kleint committed
67 68 69 70

    DebugCreateFunction m_debugCreate;
};

71 72 73 74 75
// A class that sets an expression syntax on the debug control while in scope.
// Can be nested as it checks for the old value.
class SyntaxSetter {
    Q_DISABLE_COPY(SyntaxSetter)
public:
76
    explicit inline SyntaxSetter(CIDebugControl *ctl, ULONG desiredSyntax);
77 78 79
    inline  ~SyntaxSetter();
private:
    const ULONG m_desiredSyntax;
80
    CIDebugControl *m_ctl;
81 82 83 84 85 86 87
    ULONG m_oldSyntax;
};

// helper struct to pass interfaces around
struct CdbComInterfaces
{
    CdbComInterfaces();
88 89 90 91 92 93
    CIDebugClient*          debugClient;
    CIDebugControl*         debugControl;
    CIDebugSystemObjects*   debugSystemObjects;
    CIDebugSymbols*         debugSymbols;
    CIDebugRegisters*       debugRegisters;
    CIDebugDataSpaces*      debugDataSpaces;
94 95
};

96 97
struct CdbDebugEnginePrivate
{    
98 99 100
    enum HandleBreakEventMode { // Special modes for break event handler.
        BreakEventHandle,
        BreakEventIgnoreOnce,
101 102 103 104
        // We hit main (and the user intended it)
        BreakEventMain,
        // We hit main (and the user did not intend it, just load dumpers)
        BreakEventMainLoadDumpers,
105 106 107
        BreakEventSyncBreakPoints,
    };

108 109 110
    explicit CdbDebugEnginePrivate(DebuggerManager *parent,
                                   const QSharedPointer<CdbOptions> &options,
                                   CdbDebugEngine* engine);
111
    bool init(QString *errorMessage);
112 113
    ~CdbDebugEnginePrivate();

114
    void processCreatedAttached(ULONG64 processHandle, ULONG64 initialThreadHandle);
115 116
    void setDebuggeeHandles(HANDLE hDebuggeeProcess,  HANDLE hDebuggeeThread);

117 118
    bool isDebuggeeRunning() const { return m_watchTimer != -1; }
    void handleDebugEvent();
119
    void updateThreadList();    
120
    void updateStackTrace();
121
    bool updateLocals(int frameIndex, WatchHandler *wh, QString *errorMessage);
122 123
    void updateModules();

124
    void handleBreakpointEvent(PDEBUG_BREAKPOINT2 pBP);
125
    void cleanStackTrace();
126
    void clearForRun();
127
    void handleModuleLoad(const QString &);
128
    CdbStackFrameContext *getStackFrameContext(int frameIndex, QString *errorMessage) const;
129
    void clearDisplay();
130

131 132
    bool interruptInterferiorProcess(QString *errorMessage);

133
    bool continueInferiorProcess(QString *errorMessage = 0);
134 135 136 137
    bool continueInferior(QString *errorMessage);

    bool attemptBreakpointSynchronization(QString *errorMessage);

138
    static bool executeDebuggerCommand(CIDebugControl *ctrl, const QString &command, QString *errorMessage);
139
    static bool evaluateExpression(CIDebugControl *ctrl, const QString &expression, DEBUG_VALUE *v, QString *errorMessage);
140

141
    const QSharedPointer<CdbOptions>  m_options;
142 143 144
    HANDLE                  m_hDebuggeeProcess;
    HANDLE                  m_hDebuggeeThread;
    int                     m_currentThreadId;
145
    HandleBreakEventMode    m_breakEventMode;
146 147

    int                     m_watchTimer;
148
    CdbComInterfaces        m_cif;
149
    CdbDebugEventCallback   m_debugEventCallBack;
150
    CdbDebugOutput          m_debugOutputCallBack;    
151
    QSharedPointer<CdbDumperHelper> m_dumper;
152 153

    CdbDebugEngine* m_engine;
Friedemann Kleint's avatar
Friedemann Kleint committed
154 155
    DebuggerManager *m_debuggerManager;
    IDebuggerManagerAccessForEngines *m_debuggerManagerAccess;
156
    CdbStackTraceContext *m_currentStackTrace;
Friedemann Kleint's avatar
Friedemann Kleint committed
157
    bool m_firstActivatedFrame;
158

159
    DebuggerStartMode m_mode;
160
    Core::Utils::ConsoleProcess m_consoleStubProc;
161 162
};

163 164 165 166 167 168
// helper functions

bool getExecutionStatus(CIDebugControl *ctl, ULONG *executionStatus, QString *errorMessage = 0);
const char *executionStatusString(ULONG executionStatus);
const char *executionStatusString(CIDebugControl *ctl);

169 170 171 172
// Message
QString msgDebugEngineComResult(HRESULT hr);
QString msgComFailed(const char *func, HRESULT hr);

Friedemann Kleint's avatar
Friedemann Kleint committed
173 174
enum { debugCDB = 0 };

175 176 177 178
} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_CDBENGINEPRIVATE_H
Friedemann Kleint's avatar
Friedemann Kleint committed
179