summaryrefslogtreecommitdiffstats
path: root/languages/ruby/debugger/framestackwidget.cpp
blob: 836350b2ab30b172534f91c57641fb9854c12e28 (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/***************************************************************************
    begin                : Sun Aug 8 1999
    copyright            : (C) 1999 by John Birch
    email                : jbb@kdevelop.org
	
                          Adapted for ruby debugging
                          --------------------------
    begin                : Mon Nov 1 2004
    copyright            : (C) 2004 by Richard Dale
    email                : Richard_Dale@tipitina.demon.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "framestackwidget.h"
#include "rdbparser.h"

#include <klocale.h>
#include <kdebug.h>

#include <qheader.h>
#include <qlistbox.h>
#include <qregexp.h>
#include <qstrlist.h>
#include <qfileinfo.h>

#include <ctype.h>


/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

namespace RDBDebugger
{

FramestackWidget::FramestackWidget(QWidget *parent, const char *name, WFlags f)
        : QListView(parent, name, f),
        viewedThread_(0)
{
    setRootIsDecorated(true);
    setSelectionMode(Single);
    addColumn(QString());
    setSorting(0);
    header()->hide();

    connect( this, SIGNAL(clicked(QListViewItem*)),
             this, SLOT(slotSelectionChanged(QListViewItem*)) );
}


/***************************************************************************/

FramestackWidget::~FramestackWidget()
{
}


// **************************************************************************

void FramestackWidget::clear()
{
    viewedThread_ = 0;
    QListView::clear();
}

/***************************************************************************/

void FramestackWidget::slotSelectionChanged(QListViewItem * item)
{
	if (item == 0) {
		return;
	}
	
	if (item->rtti() == RTTI_THREAD_STACK_ITEM) {
		ThreadStackItem * thread = (ThreadStackItem*) item;
        slotSelectFrame(1, thread->threadNo());
	} else if (item->rtti() == RTTI_FRAME_STACK_ITEM) {
		FrameStackItem * frame = (FrameStackItem*) item;
		slotSelectFrame(frame->frameNo(), frame->threadNo());
	}
	
	return;
}

/***************************************************************************/

void FramestackWidget::slotSelectFrame(int frameNo, int threadNo)
{
    FrameStackItem * frame = findFrame(frameNo, threadNo);
	
	if (frame != 0) {
		setSelected(frame, true);
    	emit selectFrame(frameNo, threadNo, frame->frameName());
	} else {
    	emit selectFrame(frameNo, threadNo, QString());
	}
}

/***************************************************************************/

void FramestackWidget::parseRDBThreadList(char *str)
{
	// on receipt of a thread list we must always clear the list.
    clear();
	
	QRegExp thread_re("(\\+)?\\s*(\\d+)\\s*(#<[^>]+>\\s*[^:]+:\\d+)");
	int pos = thread_re.search(str);
	viewedThread_ = 0;
	
    while (pos != -1) {
		ThreadStackItem* thread;
        thread = new ThreadStackItem(	this,
										thread_re.cap(2).toInt(),
										QString("%1 %2").arg(thread_re.cap(2)).arg(thread_re.cap(3)) );
		// The thread with a '+' is always the viewedthread
        if (thread_re.cap(1) == "+") {
            viewedThread_ = thread;
		}
		
		pos += thread_re.matchedLength();
		pos = thread_re.search(str, pos);
    }
	
	return;
}

/***************************************************************************/

void FramestackWidget::parseRDBBacktraceList(char *str)
{
	QRegExp	frame_re("#(\\d+) ([^:]+):(\\d+)(:in `([^\\n]+)')?");
	int	pos = frame_re.search(str);
	
    while (pos != -1) {
		QString	method(frame_re.cap(5));
		if (method == "") {
			method = "toplevel";
		} else {
			method.append("(...)");
		}
		
		int frameNo = frame_re.cap(1).toInt();
		QString frameName = QString("T%1#%2 %3").arg(viewedThread_->threadNo()).arg(frame_re.cap(1)).arg(method);
		new FrameStackItem(viewedThread_, frameNo, QString(frame_re.cap(0)), frameName);
		
		// Tell the Variable Tree that this frame is active
		emit frameActive(frameNo, viewedThread_->threadNo(), frameName);
				
		pos += frame_re.matchedLength();
		pos = frame_re.search(str, pos);
    }
	
	if (viewedThread_ != 0) {
		viewedThread_->setOpen(true);
	}
	
	return;
}

// **************************************************************************

ThreadStackItem *FramestackWidget::findThread(int threadNo)
{
    QListViewItem *sibling = firstChild();
    while (sibling != 0) {
        ThreadStackItem *thread = (ThreadStackItem*) sibling;
        if (thread->threadNo() == threadNo) {
            return thread;
        }
        sibling = sibling->nextSibling();
    }

    return 0;
}

// **************************************************************************

FrameStackItem *FramestackWidget::findFrame(int frameNo, int threadNo)
{
	ThreadStackItem * thread = findThread(threadNo);
	if (thread == 0) {
		kdDebug(9012) << "FramestackWidget::findFrame: no matching thread " << 
					frameNo << " thread: " << threadNo << endl;
		return 0;     // no matching thread?
	}

	QListViewItem * frameItem = thread->firstChild();

    while (frameItem != 0) {
        if (((FrameStackItem *) frameItem)->frameNo() == frameNo) {
            return (FrameStackItem *) frameItem;
		}

        frameItem = frameItem->nextSibling();
    }
	
    return 0;
}

// **************************************************************************
// **************************************************************************
// **************************************************************************

// **************************************************************************

FrameStackItem::FrameStackItem(ThreadStackItem *parent, int frameNo, const QString &frameDesc, const QString& frameName)
        : QListViewItem(parent),
        frameNo_(frameNo),
        threadNo_(parent->threadNo()),
		frameName_(frameName)		
{
	setText(0, frameDesc);
	key_.sprintf("%.6d", frameNo_);
}

// **************************************************************************

FrameStackItem::~FrameStackItem()
{
}

// **************************************************************************

QString FrameStackItem::key(int /*column*/, bool /*ascending*/) const 
{

	return key_;
}

// **************************************************************************
// **************************************************************************
// **************************************************************************

ThreadStackItem::ThreadStackItem(FramestackWidget *parent, int threadNo, const QString &threadDesc)
        : QListViewItem(parent),
        threadNo_(threadNo)
{
    setText(0, threadDesc);
    setExpandable(true);
}

// **************************************************************************

ThreadStackItem::~ThreadStackItem()
{
}

// **************************************************************************

void ThreadStackItem::setOpen(bool open)
{
    if (open)
        ((FramestackWidget*)listView())->slotSelectFrame(1, threadNo());

    QListViewItem::setOpen(open);
}

}

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

#include "framestackwidget.moc"