Commit bdfd7166 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Replace int WatchData::childCount by bool ...hasChildren in Debugger.



...making engine implementations easier.
Acked-by: default avatarhjk <qtc-committer@nokia.com>
parent 75709964
......@@ -795,7 +795,7 @@ void CdbDebugEngine::evaluateWatcher(WatchData *wd)
wd->setValue(errorMessage);
wd->setTypeUnneeded();
}
wd->setChildCount(0);
wd->setHasChildren(false);
}
void CdbDebugEngine::updateWatchData(const WatchData &incomplete)
......
......@@ -340,25 +340,6 @@ void CdbSymbolGroupContext::clear()
m_inameIndexMap.clear();
}
int CdbSymbolGroupContext::getDisplayableChildCount(unsigned long index) const
{
if (!isExpanded(index))
return 0;
int rc = 0;
// Skip over expanded children, count displayable ones
const unsigned long childCount = m_symbolParameters.at(index).SubElements;
unsigned long seenChildren = 0;
for (unsigned long c = index + 1; seenChildren < childCount; c++) {
const DEBUG_SYMBOL_PARAMETERS &params = m_symbolParameters.at(c);
if (params.ParentSymbol == index) {
seenChildren++;
if (isSymbolDisplayable(params))
rc++;
}
}
return rc;
}
QString CdbSymbolGroupContext::symbolINameAt(unsigned long index) const
{
return m_inameIndexMap.key(index);
......@@ -383,18 +364,11 @@ WatchData CdbSymbolGroupContext::symbolAt(unsigned long index) const
wd.setType(getSymbolString(m_symbolGroup, &IDebugSymbolGroup2::GetSymbolTypeNameWide, index));
wd.setValue(getSymbolString(m_symbolGroup, &IDebugSymbolGroup2::GetSymbolValueTextWide, index).toUtf8());
wd.setChildrenNeeded(); // compensate side effects of above setters
wd.setChildCountNeeded();
// Figure out children. The SubElement is only a guess unless the symbol,
// is expanded, so, we leave this as a guess for later updates.
// If the symbol has children (expanded or not), we leave the 'Children' flag
// in 'needed' state.
const DEBUG_SYMBOL_PARAMETERS &params = m_symbolParameters.at(index);
if (params.SubElements) {
if (getSymbolState(params) == ExpandedSymbol)
wd.setChildCount(getDisplayableChildCount(index));
} else {
wd.setChildCount(0);
}
wd.setHasChildren(m_symbolParameters.at(index).SubElements);
if (debug > 1)
qDebug() << Q_FUNC_INFO << index << '\n' << wd.toString();
return wd;
......
......@@ -121,7 +121,6 @@ private:
bool expandSymbol(const QString &prefix, unsigned long index, QString *errorMessage);
void populateINameIndexMap(const QString &prefix, unsigned long parentId, unsigned long start, unsigned long count);
QString symbolINameAt(unsigned long index) const;
int getDisplayableChildCount(unsigned long index) const;
inline DEBUG_SYMBOL_PARAMETERS *symbolParameters() { return &(*m_symbolParameters.begin()); }
inline const DEBUG_SYMBOL_PARAMETERS *symbolParameters() const { return &(*m_symbolParameters.constBegin()); }
......
......@@ -87,22 +87,23 @@ bool insertSymbolRecursion(WatchData wd,
// Find out whether to recurse (has children or at least knows it has children)
// Open next level if specified by recursion depth or child is already expanded
// (Sometimes, some root children are already expanded after creating the context).
const bool hasChildren = wd.childCount > 0 || wd.isChildrenNeeded();
const bool hasChildren = wd.hasChildren || wd.isChildrenNeeded();
const bool recurse = hasChildren && (level < maxRecursionLevel || sg->isExpanded(wd.iname));
if (debugSgRecursion)
qDebug() << Q_FUNC_INFO << '\n' << wd.iname << "level=" << level << "recurse=" << recurse;
qDebug() << "insertSymbolRecursion" << '\n' << wd.iname << "level=" << level << "recurse=" << recurse;
bool rc = true;
if (recurse) { // Determine number of children and indicate in model
int childCount;
rc = insertChildrenRecursion(wd.iname, sg, it, maxRecursionLevel, level, errorMessage, &childCount);
if (rc) {
wd.setChildCount(childCount);
wd.setHasChildren(childCount > 0);
wd.setChildrenUnneeded();
}
} else {
// No further recursion at this level, pretend entry is complete
// to the watchmodel
if (wd.isChildrenNeeded()) {
wd.setChildCount(1);
wd.setHasChildren(true);
wd.setChildrenUnneeded();
}
}
......@@ -124,7 +125,7 @@ template <class OutputIterator>
int *childCountPtr)
{
if (debugSgRecursion > 1)
qDebug() << Q_FUNC_INFO << '\n' << iname << level;
qDebug() << "insertChildrenRecursion" << '\n' << iname << level;
QList<WatchData> watchList;
// This implicitly enforces expansion
......@@ -159,7 +160,7 @@ bool CdbSymbolGroupContext::populateModelInitially(CdbSymbolGroupContext *sg,
QString *errorMessage)
{
if (debugSgRecursion)
qDebug() << "###" << Q_FUNC_INFO;
qDebug() << "### CdbSymbolGroupContext::populateModelInitially";
// Insert root items
QList<WatchData> watchList;
......@@ -198,7 +199,7 @@ bool CdbSymbolGroupContext::completeData(CdbSymbolGroupContext *sg,
QString *errorMessage)
{
if (debugSgRecursion)
qDebug().nospace() << "###>" << Q_FUNC_INFO << ' ' << incompleteLocal.iname << '\n';
qDebug().nospace() << "###>CdbSymbolGroupContext::completeData" << ' ' << incompleteLocal.iname << '\n';
const bool contextExpanded = sg->isExpanded(incompleteLocal.iname);
if (debugSgRecursion)
qDebug() << " " << incompleteLocal.iname << "CE=" << contextExpanded;
......
......@@ -2763,14 +2763,8 @@ static void setWatchDataValueToolTip(WatchData &data, const GdbMi &mi,
static void setWatchDataChildCount(WatchData &data, const GdbMi &mi)
{
if (mi.isValid()) {
data.childCount = mi.data().toInt();
data.setChildCountUnneeded();
if (data.childCount == 0)
data.setChildrenUnneeded();
} else {
data.childCount = -1;
}
if (mi.isValid())
data.setHasChildren(mi.data().toInt() > 0);
}
static void setWatchDataValueDisabled(WatchData &data, const GdbMi &mi)
......@@ -2932,7 +2926,7 @@ void GdbEngine::updateSubItem(const WatchData &data0)
#else
data.setType(strNotInScope);
data.setValue(strNotInScope);
data.setChildCount(0);
data.setHasChildren(false);
insertData(data);
return;
#endif
......@@ -3033,7 +3027,7 @@ void GdbEngine::updateSubItem(const WatchData &data0)
return;
}
if (data.isChildCountNeeded() && hasDebuggingHelperForType(data.type)) {
if (data.isHasChildrenNeeded() && hasDebuggingHelperForType(data.type)) {
#if DEBUG_SUBITEM
qDebug() << "UPDATE SUBITEM: CUSTOMVALUE WITH CHILDREN";
#endif
......@@ -3041,7 +3035,7 @@ void GdbEngine::updateSubItem(const WatchData &data0)
return;
}
if (data.isChildCountNeeded() && data.variable.isEmpty()) {
if (data.isHasChildrenNeeded() && data.variable.isEmpty()) {
#if DEBUG_SUBITEM
qDebug() << "UPDATE SUBITEM: VARIABLE NEEDED FOR CHILDCOUNT";
#endif
......@@ -3051,7 +3045,7 @@ void GdbEngine::updateSubItem(const WatchData &data0)
return;
}
if (data.isChildCountNeeded()) {
if (data.isHasChildrenNeeded()) {
QTC_ASSERT(!data.variable.isEmpty(), return); // tested above
QString cmd = _("-var-list-children --all-values \"") + data.variable + _c('"');
postCommand(cmd, Discardable, CB(handleVarListChildren), QVariant::fromValue(data));
......@@ -3231,7 +3225,7 @@ void GdbEngine::handleVarCreate(const GdbResultRecord &record,
data.value = strNotInScope;
data.type = _(" ");
data.setAllUnneeded();
data.setChildCount(0);
data.setHasChildren(false);
data.valuedisabled = true;
insertData(data);
}
......@@ -3424,21 +3418,21 @@ void GdbEngine::handleDebuggingHelperValue3(const GdbResultRecord &record,
for (int i = 0; i < l; ++i)
str.append(list.at(i).toInt());
data.setValue(_c('"') + str + _c('"'));
data.setChildCount(0);
data.setHasChildren(false);
data.setAllUnneeded();
insertData(data);
} else if (data.type == __("QStringList")
|| data.type.endsWith(__("::QStringList"))) {
if (out.isEmpty()) {
data.setValue(tr("<0 items>"));
data.setChildCount(0);
data.setHasChildren(false);
data.setAllUnneeded();
insertData(data);
} else {
int l = list.size();
//: In string list
data.setValue(tr("<%n items>", 0, l));
data.setChildCount(list.size());
data.setHasChildren(!list.empty());
data.setAllUnneeded();
insertData(data);
for (int i = 0; i < l; ++i) {
......@@ -3448,7 +3442,7 @@ void GdbEngine::handleDebuggingHelperValue3(const GdbResultRecord &record,
data1.iname = data.iname + _(".%1").arg(i);
data1.addr = _(list.at(i));
data1.exp = _("((") + gdbQuoteTypes(data1.type) + _("*)") + data1.addr + _c(')');
data1.setChildCount(0);
data1.setHasChildren(false);
data1.setValueNeeded();
QString cmd = _("qdumpqstring (") + data1.exp + _c(')');
QVariant var;
......@@ -3572,7 +3566,7 @@ void GdbEngine::setLocals(const QList<GdbMi> &locals)
setWatchDataValue(data, item.findChild("value"));
//: Type of variable <FIXME: what? bug Andre about it>
data.setType(tr("<shadowed>"));
data.setChildCount(0);
data.setHasChildren(false);
insertData(data);
} else {
seen[name] = 1;
......@@ -3590,7 +3584,7 @@ void GdbEngine::setLocals(const QList<GdbMi> &locals)
if (!qq->watchHandler()->isExpandedIName(data.iname))
data.setChildrenUnneeded();
if (isPointerType(data.type) || data.name == __("this"))
data.setChildCount(1);
data.setHasChildren(true);
if (0 && m_varToType.contains(data.framekey)) {
qDebug() << "RE-USING" << m_varToType.value(data.framekey);
data.setType(m_varToType.value(data.framekey));
......@@ -3665,7 +3659,7 @@ void GdbEngine::handleVarListChildrenHelper(const GdbMi &item,
data.exp = parent.exp;
data.setTypeUnneeded();
data.setValueUnneeded();
data.setChildCountUnneeded();
data.setHasChildrenUnneeded();
data.setChildrenUnneeded();
//qDebug() << "DATA" << data.toString();
QString cmd = _("-var-list-children --all-values \"") + data.variable + _c('"');
......@@ -3681,7 +3675,7 @@ void GdbEngine::handleVarListChildrenHelper(const GdbMi &item,
setWatchDataValue(data, item.findChild("value"));
setWatchDataAddress(data, item.findChild("addr"));
setWatchDataSAddress(data, item.findChild("saddr"));
data.setChildCount(0);
data.setHasChildren(false);
insertData(data);
} else if (parent.iname.endsWith(_c('.'))) {
// Happens with anonymous unions
......@@ -3741,7 +3735,7 @@ void GdbEngine::handleVarListChildrenHelper(const GdbMi &item,
if (hasDebuggingHelperForType(data.type)) {
// we do not trust gdb if we have a custom dumper
data.setValueNeeded();
data.setChildCountNeeded();
data.setHasChildrenNeeded();
}
//qDebug() << "VAR_LIST_CHILDREN: PARENT 3" << parent.toString();
......@@ -3771,7 +3765,7 @@ void GdbEngine::handleVarListChildren(const GdbResultRecord &record,
data1.iname = data.iname + _(".child");
//: About variable's value
data1.value = tr("<no information>");
data1.childCount = 0;
data1.hasChildren = false;
data1.setAllUnneeded();
insertData(data1);
data.setAllUnneeded();
......@@ -3835,7 +3829,7 @@ void GdbEngine::handleToolTip(const GdbResultRecord &record,
m_toolTip.iname = tooltipIName;
m_toolTip.setChildrenUnneeded();
m_toolTip.setChildCountUnneeded();
m_toolTip.setHasChildrenUnneeded();
insertData(m_toolTip);
qDebug() << "DATA INSERTED";
QTimer::singleShot(0, this, SLOT(updateWatchModel2()));
......
......@@ -636,11 +636,11 @@ void ScriptEngine::updateSubItem(const WatchData &data0)
} else if (ob.isBool()) {
data.setType("Bool");
data.setValue(ob.toBool() ? "true" : "false");
data.setChildCount(0);
data.setHasChildren(false);
} else if (ob.isDate()) {
data.setType("Date");
data.setValue(ob.toDateTime().toString().toUtf8());
data.setChildCount(0);
data.setHasChildren(false);
} else if (ob.isError()) {
data.setType("Error");
data.setValue(" ");
......@@ -653,7 +653,7 @@ void ScriptEngine::updateSubItem(const WatchData &data0)
} else if (ob.isNumber()) {
data.setType("Number");
data.setValue(QString::number(ob.toNumber()).toUtf8());
data.setChildCount(0);
data.setHasChildren(false);
} else if (ob.isObject()) {
data.setType("Object");
data.setValue(" ");
......@@ -701,20 +701,20 @@ void ScriptEngine::updateSubItem(const WatchData &data0)
++numChild;
}
//SDEBUG(" ... CHILDREN: " << numChild);
data.setChildCount(numChild);
data.setHasChildren(numChild > 0);
data.setChildrenUnneeded();
qq->watchHandler()->insertData(data);
return;
}
if (data.isChildCountNeeded()) {
if (data.isHasChildrenNeeded()) {
int numChild = 0;
QScriptValueIterator it(data.scriptValue);
while (it.hasNext()) {
it.next();
++numChild;
}
data.setChildCount(numChild);
data.setHasChildren(numChild > 0);
//SDEBUG(" ... CHILDCOUNT: " << numChild);
qq->watchHandler()->insertData(data);
return;
......
......@@ -95,28 +95,27 @@ public:
QList<WatchItem *> children; // fetched children
};
////////////////////////////////////////////////////////////////////
//
// WatchData
//
////////////////////////////////////////////////////////////////////
WatchData::WatchData()
WatchData::WatchData() :
hasChildren(false),
generation(-1),
valuedisabled(false),
source(0),
state(InitialState),
changed(false)
{
childCount = -1;
valuedisabled = false;
source = 0;
state = InitialState;
changed = false;
generation = -1;
}
void WatchData::setError(const QString &msg)
{
setAllUnneeded();
value = msg;
setChildCount(0);
setHasChildren(false);
valuedisabled = true;
}
......@@ -125,7 +124,7 @@ void WatchData::setValue(const QString &value0)
value = value0;
if (value == "{...}") {
value.clear();
childCount = 1; // at least one...
hasChildren = true; // at least one...
}
// avoid duplicated information
......@@ -137,13 +136,13 @@ void WatchData::setValue(const QString &value0)
if (/*isIntOrFloatType(type) && */ value.startsWith("@0x")
&& value.contains(':')) {
value = value.mid(value.indexOf(':') + 2);
setChildCount(0);
setHasChildren(false);
}
// "numchild" is sometimes lying
//MODEL_DEBUG("\n\n\nPOINTER: " << type << value);
if (isPointerType(type))
setChildCount(value != "0x0" && value != "<null>");
setHasChildren(value != "0x0" && value != "<null>");
// pointer type information is available in the 'type'
// column. No need to duplicate it here.
......@@ -184,7 +183,7 @@ void WatchData::setType(const QString &str)
}
setTypeUnneeded();
if (isIntOrFloatType(type))
setChildCount(0);
setHasChildren(false);
}
void WatchData::setAddress(const QString & str)
......@@ -197,7 +196,8 @@ WatchData WatchData::pointerChildPlaceHolder() const
WatchData data1;
data1.iname = iname + QLatin1String(".*");
data1.name = QLatin1Char('*') + name;
data1.exp = QLatin1String("(*(") + exp + QLatin1String("))");
data1
.exp = QLatin1String("(*(") + exp + QLatin1String("))");
data1.type = stripPointerType(type);
data1.setValueNeeded();
return data1;
......@@ -208,9 +208,6 @@ QString WatchData::toString() const
const char *doubleQuoteComma = "\",";
QString res;
QTextStream str(&res);
if (childCount)
str << "childCount=\"" << childCount << doubleQuoteComma;
if (!iname.isEmpty())
str << "iname=\"" << iname << doubleQuoteComma;
if (!exp.isEmpty())
......@@ -232,10 +229,10 @@ QString WatchData::toString() const
if (isTypeKnown() && !type.isEmpty())
str << "type=\"" << type << doubleQuoteComma;
if (isChildCountNeeded())
str << "numchild=<needed>,";
if (isChildCountKnown() && childCount == -1)
str << "numchild=\"" << childCount << doubleQuoteComma;
if (isHasChildrenNeeded())
str << "hasChildren=<needed>,";
if (isHasChildrenKnown())
str << "hasChildren=\"" << (hasChildren ? "true" : "false") << doubleQuoteComma;
if (isChildrenNeeded())
str << "children=<needed>,";
......@@ -284,7 +281,7 @@ WatchModel::WatchModel(WatchHandler *handler, WatchType type)
: QAbstractItemModel(handler), m_handler(handler), m_type(type)
{
m_root = new WatchItem;
m_root->childCount = 1;
m_root->hasChildren = 1;
m_root->state = 0;
m_root->name = WatchHandler::tr("Root");
......@@ -304,7 +301,7 @@ WatchModel::WatchModel(WatchHandler *handler, WatchType type)
item->name = WatchHandler::tr("Tooltip");
break;
}
item->childCount = 1;
item->hasChildren = true;
item->state = 0;
item->parent = m_root;
item->fetchedTriggered = true;
......@@ -542,7 +539,7 @@ int WatchModel::columnCount(const QModelIndex &idx) const
bool WatchModel::hasChildren(const QModelIndex &parent) const
{
WatchItem *item = watchItem(parent);
return !item || item->childCount > 0;
return !item || item->hasChildren;
}
WatchItem *WatchModel::watchItem(const QModelIndex &idx) const
......
......@@ -54,7 +54,7 @@ public:
enum State
{
Complete = 0,
ChildCountNeeded = 1,
HasChildrenNeeded = 1,
ValueNeeded = 2,
TypeNeeded = 4,
ChildrenNeeded = 8,
......@@ -62,12 +62,12 @@ public:
NeededMask = ValueNeeded
| TypeNeeded
| ChildrenNeeded
| ChildCountNeeded,
| HasChildrenNeeded,
InitialState = ValueNeeded
| TypeNeeded
| ChildrenNeeded
| ChildCountNeeded
| HasChildrenNeeded
};
void setValue(const QString &);
......@@ -95,12 +95,12 @@ public:
void setChildrenNeeded() { state = State(state | ChildrenNeeded); }
void setChildrenUnneeded() { state = State(state & ~ChildrenNeeded); }
bool isChildCountNeeded() const { return state & ChildCountNeeded; }
bool isChildCountKnown() const { return !(state & ChildCountNeeded); }
void setChildCountNeeded() { state = State(state | ChildCountNeeded); }
void setChildCountUnneeded() { state = State(state & ~ChildCountNeeded); }
void setChildCount(int n) { childCount = n; setChildCountUnneeded();
if (n == 0) setChildrenUnneeded(); }
bool isHasChildrenNeeded() const { return state & HasChildrenNeeded; }
bool isHasChildrenKnown() const { return !(state & HasChildrenNeeded); }
void setHasChildrenNeeded() { state = State(state | HasChildrenNeeded); }
void setHasChildrenUnneeded() { state = State(state & ~HasChildrenNeeded); }
void setHasChildren(bool c) { hasChildren = c; setHasChildrenUnneeded();
if (!c) setChildrenUnneeded(); }
WatchData pointerChildPlaceHolder() const;
......@@ -123,7 +123,7 @@ public:
QString saddr; // stored address (pointer in container)
QString framekey; // key for type cache
QScriptValue scriptValue; // if needed...
int childCount;
bool hasChildren;
int generation; // when updated?
bool valuedisabled; // value will be greyed out
......
......@@ -488,7 +488,7 @@ QList<WatchData> QtDumperResult::toWatchData(int source) const
root.valuedisabled = valuedisabled;
root.setAddress(address);
root.source = source;
root.setChildCount(childCount);
root.setHasChildren(childCount > 0);
// Children
if (childCount > 0) {
if (children.size() == childCount) {
......@@ -506,7 +506,7 @@ QList<WatchData> QtDumperResult::toWatchData(int source) const
wchild.setType(dchild.type.isEmpty() ? childType : dchild.type);
wchild.setAddress(dchild.address);
wchild.setValue(decodeData(dchild.value, dchild.valueEncoded));
wchild.setChildCount(0);
wchild.setHasChildren(false);
}
root.setChildrenUnneeded();
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment