Debugger: Prepend '*'s for autodereferenced pointers

If automatic dereferencing of pointers is enabled, the
"Value" and "Type" columns for pointers hold the values for
the dereferenced pointers.

In order to have a consistent behavior for the "Name" column
as well, prepend '*'s to indicate that the variable/expression
has actually been dereferenced.
Add parantheses around the original expression if it doesn't
match a simple regex for variable names, to avoid that the
leading '*' changes the meaning of the expression
(so e.g. a dereferenced 'somepointer + 1' is displayed
as  '*(somepointer + 1)' rather than '*somepointer + 1').

This introduces a new 'autoderefcount' field to propagate the
information how many levels of dereferencing have taken
place from the Python to the C++ side, which is then
used to add the leading '*'s for the display name.

Fixes: QTCREATORBUG-20907
Change-Id: Ia9a41cb42e25ba72a6d980a765dbe2b454deb8c8
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Michael Weghorn
2021-02-17 08:40:48 +01:00
parent c6493e170f
commit f4dc3fd5c5
4 changed files with 29 additions and 0 deletions

View File

@@ -869,6 +869,19 @@ static QString displayName(const WatchItem *item)
else
result = watchModel(item)->removeNamespaces(item->name);
// prepend '*'s to indicate where autodereferencing has taken place
if (item->autoDerefCount > 0) {
// add parentheses for everything except simple variable names (e.g. pointer arithmetics,...)
QRegularExpression variableNameRegex("^[a-zA-Z0-9_]+$");
bool addParanthesis = !variableNameRegex.match(result).hasMatch();
if (addParanthesis)
result = "(" + result;
for (uint i = 0; i < item->autoDerefCount; i++)
result = "*" + result;
if (addParanthesis)
result += ")";
}
// Simplify names that refer to base classes.
if (result.startsWith('[')) {
result = simplifyType(result);