Debugger[CDB]: Fix handling of shadowed variables.

Fix name formatting and algorithm to find uninitialized
variables to use reverse order in case locals of the same
name occur in a scope.

Reviewed-by: hjk
Task-number: QTCREATORBUG-4475
This commit is contained in:
Friedemann Kleint
2011-04-12 11:57:57 +02:00
parent ff58d9960b
commit 28d5526459
3 changed files with 8 additions and 5 deletions

View File

@@ -1432,19 +1432,21 @@ void CdbEngine::updateLocals(bool forNewStackFrame)
} }
} }
addLocalsOptions(str); addLocalsOptions(str);
// Uninitialized variables if desired // Uninitialized variables if desired. Quote as safeguard against shadowed
// variables in case of errors in uninitializedVariables().
if (debuggerCore()->boolSetting(UseCodeModel)) { if (debuggerCore()->boolSetting(UseCodeModel)) {
QStringList uninitializedVariables; QStringList uninitializedVariables;
getUninitializedVariables(debuggerCore()->cppCodeModelSnapshot(), getUninitializedVariables(debuggerCore()->cppCodeModelSnapshot(),
frame.function, frame.file, frame.line, &uninitializedVariables); frame.function, frame.file, frame.line, &uninitializedVariables);
if (!uninitializedVariables.isEmpty()) { if (!uninitializedVariables.isEmpty()) {
str << blankSeparator << "-u "; str << blankSeparator << "-u \"";
int i = 0; int i = 0;
foreach(const QString &u, uninitializedVariables) { foreach(const QString &u, uninitializedVariables) {
if (i++) if (i++)
str << ','; str << ',';
str << localsPrefixC << u; str << localsPrefixC << u;
} }
str << '"';
} }
} }
// Perform watches synchronization // Perform watches synchronization

View File

@@ -397,7 +397,7 @@ QString WatchData::shadowedName(const QString &name, int seen)
{ {
if (seen <= 0) if (seen <= 0)
return name; return name;
return shadowedNameFormat().arg(name, seen); return shadowedNameFormat().arg(name).arg(seen);
} }
quint64 WatchData::coreAddress() const quint64 WatchData::coreAddress() const

View File

@@ -338,8 +338,9 @@ static void blockRecursion(const CPlusPlus::Overview &overview,
SeenHash *seenHash, SeenHash *seenHash,
int level = 0) int level = 0)
{ {
const int size = scope->memberCount(); // Go backwards in case someone has identical variables in the same scope.
for (int s = 0; s < size; s++){ // Fixme: loop variables or similar are currently seen in the outer scope
for (int s = scope->memberCount() - 1; s >= 0; --s){
const CPlusPlus::Symbol *symbol = scope->memberAt(s); const CPlusPlus::Symbol *symbol = scope->memberAt(s);
if (symbol->isDeclaration()) { if (symbol->isDeclaration()) {
// Find out about shadowed symbols by bookkeeping // Find out about shadowed symbols by bookkeeping