Debugger: Fix crash when trying to insert iname-less WatchItems

The actual problem here was a wrong use of the recursive
findItem() (instead of a check of the direct children).
That went unnoticed, as the recursive search happens
to find the right child *unless* the iname was empty,
which usually should not happen, but did here, since the
LLDB output was not as well-formed as expected.

Task-number: QTCREATORBUG-14660
Change-Id: I368d92c058354d829aab52c6cc37c7f350223dbe
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2015-07-03 13:48:00 +02:00
parent 997f6102b6
commit 24e25e92fa

View File

@@ -1159,16 +1159,23 @@ void WatchHandler::insertItem(WatchItem *item)
void WatchModel::insertItem(WatchItem *item)
{
QTC_ASSERT(!item->iname.isEmpty(), return);
WatchItem *parent = findItem(parentName(item->iname));
QTC_ASSERT(parent, return);
if (WatchItem *existing = parent->findItem(item->iname)) {
int row = parent->children().indexOf(existing);
delete takeItem(existing);
parent->insertChild(row, item);
} else {
parent->appendChild(item);
bool found = false;
const QVector<TreeItem *> siblings = parent->children();
for (int row = 0, n = siblings.size(); row < n; ++row) {
if (static_cast<WatchItem *>(siblings.at(row))->iname == item->iname) {
delete takeItem(parent->children().at(row));
parent->insertChild(row, item);
found = true;
break;
}
}
if (!found)
parent->appendChild(item);
item->walkTree([this](TreeItem *sub) { showEditValue(static_cast<WatchItem *>(sub)); });
}