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 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
|
/***************************************************************************
begin : Sun Aug 8 1999
copyright : (C) 1999 by John Birch
email : jbb@kdevelop.org
***************************************************************************/
/***************************************************************************
* *
* 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 "gdbparser.h"
#include <klocale.h>
#include <qheader.h>
#include <qlistbox.h>
#include <qregexp.h>
#include <qstrlist.h>
#include <ctype.h>
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
namespace GDBDebugger
{
FramestackWidget::FramestackWidget(QWidget *parent, const char *name, WFlags f)
: QListView(parent, name, f),
viewedThread_(0)
{
setRootIsDecorated(true);
setSorting(-1);
setSelectionMode(Single);
addColumn(QString::null);
header()->hide();
connect( this, SIGNAL(clicked(QListViewItem*)),
this, SLOT(slotSelectionChanged(QListViewItem*)) );
}
/***************************************************************************/
FramestackWidget::~FramestackWidget()
{}
/***************************************************************************/
QListViewItem *FramestackWidget::lastChild() const
{
QListViewItem* child = firstChild();
if (child)
while (QListViewItem* nextChild = child->nextSibling())
child = nextChild;
return child;
}
// **************************************************************************
void FramestackWidget::clear()
{
viewedThread_ = 0;
QListView::clear();
}
/***************************************************************************/
void FramestackWidget::slotSelectionChanged(QListViewItem *thisItem)
{
ThreadStackItem *thread = dynamic_cast<ThreadStackItem*> (thisItem);
if (thread)
{
slotSelectFrame(0, thread->threadNo());
}
else
{
FrameStackItem *frame = dynamic_cast<FrameStackItem*> (thisItem);
if (frame)
slotSelectFrame(frame->frameNo(), frame->threadNo());
}
}
/***************************************************************************/
// someone (the vartree :-)) wants us to select this frame.
void FramestackWidget::slotSelectFrame(int frameNo, int threadNo)
{
FrameStackItem *frame = 0;
if (threadNo != -1)
{
viewedThread_ = findThread(threadNo);
if (!viewedThread_)
{
Q_ASSERT(!viewedThread_);
return; // fatal
}
}
frame = findFrame(frameNo, threadNo);
if (frame)
setSelected(frame, true);
emit selectFrame(frameNo, threadNo, !(frame));
}
void FramestackWidget::getBacktrace(int threadNo)
{
if (threadNo != -1)
{
viewedThread_ = findThread(threadNo);
if (!viewedThread_)
{
Q_ASSERT(!viewedThread_);
return; // fatal
}
}
emit produceBacktrace(threadNo);
}
/***************************************************************************/
void FramestackWidget::parseGDBThreadList(char *str)
{
// on receipt of a thread list we must always clear the list.
clear();
while (char *end = strchr(str, '\n'))
{
// make it a string and skip non-thread list strings
*end = 0;
if (*str == '*' || *str == ' ')
{
QString threadDesc = QString(str);
ThreadStackItem* thread = new ThreadStackItem(this, str);
// The thread with a '*' is always the viewedthread
if (*str == '*')
viewedThread_ = thread;
}
str = end+1;
}
}
/***************************************************************************/
void FramestackWidget::parseGDBBacktraceList(char *str)
{
// #0 Test::Test (this=0x8073b20, parent=0x0, name=0x0) at test.cpp:224
// #1 0x804bba9 in main (argc=1, argv=0xbffff9c4) at main.cpp:24
// If we don't have a thread program then clear the list.
// We don't have to clear the list in a threaded programe because that's
// already been done in the parseGDBThreadList() method.
if (!viewedThread_)
clear();
if(!strlen(str))
return;
if (strncmp(str, "No stack.", 9) == 0)
return;
while (char* end = strchr(str, '\n'))
{
// Don't bother with extra data
if (*str == '#')
{
// make it a string
*end = 0;
QString frameDesc = QString(str);
if (viewedThread_)
new FrameStackItem(viewedThread_, frameDesc);
else
new FrameStackItem(this, frameDesc);
}
str = end+1; // next string
}
// Make sure the first frame in the stopped backtrace is selected
// and open
if (viewedThread_)
viewedThread_->setOpen(true);
else
{
if (FrameStackItem* frame = (FrameStackItem*) firstChild())
frame->setOpen(true);
}
}
/***************************************************************************/
QString FramestackWidget::getFrameName(int frameNo, int threadNo)
{
FrameStackItem *frame = findFrame(frameNo, threadNo);
if (frame)
{
QString frameStr = frame->text(0);
const char *frameData = frameStr.latin1();
if (char *paramStart = strchr(frameData, '('))
{
char *fnstart = paramStart-2;
while (fnstart > frameData)
{
if (isspace(*fnstart))
break;
fnstart--;
}
if (threadNo != -1)
{
QString frameName("T%1#%2 %3(...)");
return frameName.arg(threadNo).arg(frameNo)
.arg(QCString(fnstart, paramStart-fnstart+1));
}
QString frameName("#%1 %2(...)");
return frameName.arg(frameNo).arg(
QCString(fnstart, paramStart-fnstart+1));
}
}
return i18n("No stack");
}
// **************************************************************************
ThreadStackItem *FramestackWidget::findThread(int threadNo)
{
QListViewItem *sibling = firstChild();
while (sibling)
{
ThreadStackItem *thread = dynamic_cast<ThreadStackItem*> (sibling);
if (thread && thread->threadNo() == threadNo)
{
return thread;
}
sibling = sibling->nextSibling();
}
return 0;
}
// **************************************************************************
FrameStackItem *FramestackWidget::findFrame(int frameNo, int threadNo)
{
QListViewItem* frameItem = 0;
if (threadNo != -1)
{
ThreadStackItem *thread = findThread(threadNo);
if (thread == 0)
return 0; // no matching thread?
frameItem = thread->firstChild();
}
else
frameItem = firstChild();
while (frameItem)
{
if (((FrameStackItem*)frameItem)->frameNo() == frameNo)
break;
frameItem = frameItem->nextSibling();
}
return (FrameStackItem*)frameItem;
}
// **************************************************************************
// **************************************************************************
// **************************************************************************
FrameStackItem::FrameStackItem(FramestackWidget *parent, const QString &frameDesc)
: QListViewItem(parent, parent->lastChild()),
frameNo_(-1),
threadNo_(-1)
{
setText(VarNameCol, frameDesc);
QRegExp num("[0-9]*");
int start;
if ((start=num.search(frameDesc,1))>=0)
frameNo_ = frameDesc.mid(start, num.matchedLength()).toInt();
}
// **************************************************************************
FrameStackItem::FrameStackItem(ThreadStackItem *parent, const QString &frameDesc)
: QListViewItem(parent, parent->lastChild()),
frameNo_(-1),
threadNo_(parent->threadNo())
{
setText(VarNameCol, frameDesc);
QRegExp num("[0-9]*");
int start;
if ((start=num.search(frameDesc,1))>=0)
frameNo_ = frameDesc.mid(start, num.matchedLength()).toInt();
}
// **************************************************************************
FrameStackItem::~FrameStackItem()
{}
// **************************************************************************
QListViewItem *FrameStackItem::lastChild() const
{
QListViewItem* child = firstChild();
if (child)
while (QListViewItem* nextChild = child->nextSibling())
child = nextChild;
return child;
}
// **************************************************************************
void FrameStackItem::setOpen(bool open)
{
if (open)
((FramestackWidget*)listView())->slotSelectFrame(0, threadNo());
QListViewItem::setOpen(open);
}
// **************************************************************************
// **************************************************************************
// **************************************************************************
ThreadStackItem::ThreadStackItem(FramestackWidget *parent, const QString &threadDesc)
: QListViewItem(parent, threadDesc),
threadNo_(-1)
{
setText(VarNameCol, threadDesc);
setExpandable(true);
QRegExp num("[0-9]*");
int start;
if ((start=num.search(threadDesc,2))>=0)
threadNo_ = threadDesc.mid(start, num.matchedLength()).toInt();
}
// **************************************************************************
ThreadStackItem::~ThreadStackItem()
{}
// **************************************************************************
QListViewItem *ThreadStackItem::lastChild() const
{
QListViewItem* child = firstChild();
if (child)
while (QListViewItem* nextChild = child->nextSibling())
child = nextChild;
return child;
}
// **************************************************************************
void ThreadStackItem::setOpen(bool open)
{
// If we're openining, and have no child yet, get backtrace from
// gdb.
if (open && !firstChild())
((FramestackWidget*)listView())->getBacktrace(threadNo());
QListViewItem::setOpen(open);
}
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
#include "framestackwidget.moc"
|