-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdbframestackmodel.cpp
More file actions
123 lines (105 loc) · 4.17 KB
/
Copy pathpdbframestackmodel.cpp
File metadata and controls
123 lines (105 loc) · 4.17 KB
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
/*
This file is part of kdev-python, the python language plugin for KDevelop
Copyright (C) 2012 Sven Brauch <svenbrauch@googlemail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pdbframestackmodel.h"
#include "debugsession.h"
#include <QRegExp>
#include <QDebug>
#include "debuggerdebug.h"
using namespace KDevelop;
namespace Python {
PdbFrameStackModel::PdbFrameStackModel(IDebugSession* session): FrameStackModel(session), m_debuggerAtFrame(0)
{
}
int PdbFrameStackModel::debuggerAtFrame() const
{
return m_debuggerAtFrame;
}
void PdbFrameStackModel::setDebuggerAtFrame(int newFrame)
{
// Q_ASSERT(newFrame >= 0);
m_debuggerAtFrame = newFrame;
}
void PdbFrameStackModel::framesFetched(QByteArray framelist)
{
qCDebug(KDEV_PYTHON_DEBUGGER) << "frames fetched:" << framelist;
QList<QByteArray> lines = framelist.split('\n');
QList<FrameItem> frames;
bool parsingLocation = false;
FrameItem* currentFrame = 0;
int framesCount = 0;
foreach ( const QString& line, lines ) {
if ( line.startsWith("-> ") ) {
parsingLocation = true;
if ( currentFrame ) {
frames << *currentFrame;
}
currentFrame = new FrameItem();
currentFrame->nr = framesCount;
framesCount++;
}
else if ( parsingLocation ) {
QRegExp location("(\\>?)\\s*(.*)\\(([0-9]+)\\)(.*)");
// version 1 has some *really* weird "greedy" ruleset which makes no sense at all for me
location.setPatternSyntax(QRegExp::RegExp2);
if ( location.exactMatch(line) ) {
qCDebug(KDEV_PYTHON_DEBUGGER) << location.capturedTexts();
if ( ! location.capturedTexts().at(1).isEmpty() ) {
m_debuggerAtFrame = framesCount;
}
currentFrame->file = location.capturedTexts().at(2);
currentFrame->line = location.capturedTexts().at(3).toInt() - 1;
currentFrame->name = location.capturedTexts().at(4);
}
else {
qCDebug(KDEV_PYTHON_DEBUGGER) << "regular expression mismatches" << line;
}
}
}
m_debuggerAtFrame = framesCount - m_debuggerAtFrame - 1;
qCDebug(KDEV_PYTHON_DEBUGGER) << "at frame:" << m_debuggerAtFrame;
QList<FrameItem> framesReversed;
for ( int i = frames.length() - 1; i >= 0; i-- ) {
framesReversed.append(frames.at(i));
framesReversed.last().nr = framesCount - i - 2;
}
setFrames(0, framesReversed);
}
void PdbFrameStackModel::threadsFetched(QByteArray threadsData)
{
qCDebug(KDEV_PYTHON_DEBUGGER) << "threads fetched" << threadsData;
qCDebug(KDEV_PYTHON_DEBUGGER) << "Implement me: Thread debugging is not supported by pdb.";
QList<ThreadItem> threads;
ThreadItem mainThread;
mainThread.nr = 0;
mainThread.name = "main thread";
threads << mainThread;
setThreads(threads);
setCurrentThread(0);
}
void PdbFrameStackModel::fetchFrames(int /*threadNumber*/, int /*from*/, int /*to*/)
{
qCDebug(KDEV_PYTHON_DEBUGGER) << "frames requested";
InternalPdbCommand* cmd = new InternalPdbCommand(this, "framesFetched", "where\n");
static_cast<DebugSession*>(session())->addCommand(cmd);
}
void PdbFrameStackModel::fetchThreads()
{
qCDebug(KDEV_PYTHON_DEBUGGER) << "threads requested";
// pdb doesn't support threads.
InternalPdbCommand* cmd = new InternalPdbCommand(this, "threadsFetched", "pass\n");
static_cast<DebugSession*>(session())->addCommand(cmd);
}
}
#include "pdbframestackmodel.moc"