File: abstract_generator.h

package info (click to toggle)
plasma-workspace 4%3A5.8.6-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 54,996 kB
  • sloc: cpp: 70,006; sh: 868; xml: 867; python: 46; makefile: 16
file content (121 lines) | stat: -rw-r--r-- 4,788 bytes parent folder | download | duplicates (5)
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
/******************************************************************
 *
 * kdbgwin - Helper application for DrKonqi
 *
 * This file is part of the KDE project
 *
 * Copyright (C) 2010 Ilie Halip <lupuroshu@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) version 3, or any
 * later version accepted by the membership of KDE e.V. (or its
 * successor approved by the membership of KDE e.V.), which shall
 * act as a proxy defined in Section 6 of version 3 of the license.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>
 *****************************************************************/

#pragma once

#include "common.h"
#include "process.h"

const static char*      BACKTRACE_FORMAT    = "%1!%2() [%3 @ %4] at 0x%5";
// module.dll!KClass::function() [c:\file.cpp @ 10] at 0x0001000

const static char*      DEFAULT_MODULE  = "[unknown]";
const static char*      DEFAULT_FUNC    = "[unknown]";
const static char*      DEFAULT_FILE    = "[unknown]";
const static int        DEFAULT_LINE    = -1;

/**
 * \brief Base generator class
 *
 * This class gives the definition of a backtrace generator. There are 2 subclasses: one for
 * MSVC and one for MinGW. The reason why implementation differs is the fact that executables
 * use different debugging formats: PDBs (for MSVC) and Dwarf-2/Stabs and possibly more I don't
 * know too much about for MinGW, which are embedded in the executable itself.
 */
class AbstractBTGenerator : public QObject
{
    Q_OBJECT
protected:
    /// A Process instance, corresponding to the process for which we generate the backtrace
    Process m_process;

    /// The current stack frame. It is kept as a member 
    STACKFRAME64 m_currentFrame;

    /// The definition of a map of symbols
    typedef QMap<QString, bool> TSymbolsMap;
    /// A map of symbols (the full path to the module, and a bool which specifies if
    /// symbols were loaded for it)
    TSymbolsMap m_symbolsMap;

public:
    /// Constructor
    AbstractBTGenerator(const Process& process);
    virtual ~AbstractBTGenerator();

    /// Abstract virtual: Initialize this generator
    virtual bool Init() = 0;

    /// Abstract virtual: Uninitialize this generator
    virtual void UnInit() = 0;

    /// Start generating the backtrace
    virtual void Run(HANDLE hTread, bool bFaultingThread);

    /// This method acts like a callback and will be called when the stack frame changed
    virtual void FrameChanged() = 0;

    /// Abstract virtual: get current module name
    /// @return the name of the current module (eg: kdecore.dll)
    virtual QString GetModuleName();

    /// Abstract virtual: get current module path
    /// @return the full path to the current module (eg: N:\\kde\\bin\\kdecore.dll)
    virtual QString GetModulePath();

    /// Abstract virtual: get current function/method name. The name is undecorated internally by this method.
    /// @return the current function or method (eg: KCmdLineArgs::args)
    virtual QString GetFunctionName() = 0;

    /// Abstract virtual: get the full path to the current file
    /// @return the path to the file (eg: N:\\kde\\svn\\KDE\\trunk\\kdelibs\\kcmdlineargs\\kcmdlineargs.cpp)
    virtual QString GetFile() = 0;

    /// Abstract virtual: get current line
    /// @return the current line in the file
    virtual int     GetLine() = 0;

    /// Checks if symbols are loaded for the specified module
    /// @return true if symbols are loaded
    virtual bool IsSymbolLoaded(const QString& module);

    /// Tries to load symbols for all loaded modules
    virtual void LoadSymbols();

    /// Tries to load a symbol file for a module loaded at dwBaseAddr
    virtual void LoadSymbol(const QString& module, DWORD64 dwBaseAddr) = 0;
signals:
    /// This will be emitted whenever the generator wishes to output information. It can either be
    /// module information (in the form: "Loaded C:\path\to.dll (symbols loaded)", a stack frame line,
    /// or newlines
    void DebugLine(const QString&);

    /// This signal is emitted when a module is loaded, and its symbols are missing. This is
    /// caught by the PackageSuggester
    void MissingSymbol(const QString&);

    /// Will be emitted when the generation finishes
    void Finished();
};