From 7388034eef7d9a04318618b8597f4f52d31ebd3e Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 7 May 2012 13:15:48 +0200 Subject: [PATCH] debugger: recognize null references explicitly. Change-Id: Ie315997363d9f591526ea8c122759f59d808fae5 Reviewed-by: hjk --- share/qtcreator/dumper/dumper.py | 9 +++++++ .../debugger/simple/simple_test_app.cpp | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/share/qtcreator/dumper/dumper.py b/share/qtcreator/dumper/dumper.py index 9eb1b9dbd59..c5cc107fa4b 100644 --- a/share/qtcreator/dumper/dumper.py +++ b/share/qtcreator/dumper/dumper.py @@ -1408,6 +1408,15 @@ class Dumper: #warn("REAL VALUE: %s " % value) if type.code == ReferenceCode: + try: + # Try to recognize null references explicitly. + if long(value.address) == 0: + self.putValue("") + self.putType(typeName) + self.putNumChild(0) + return + except: + pass try: # FIXME: This throws "RuntimeError: Attempt to dereference a # generic pointer." with MinGW's gcc 4.5 when it "identifies" diff --git a/tests/manual/debugger/simple/simple_test_app.cpp b/tests/manual/debugger/simple/simple_test_app.cpp index 155424967ac..2d633f469c7 100644 --- a/tests/manual/debugger/simple/simple_test_app.cpp +++ b/tests/manual/debugger/simple/simple_test_app.cpp @@ -2100,6 +2100,31 @@ namespace final { dummyStatement(&app); } + void testNullReferenceHelper(int &i, int &j) + { + i += 1; + j += 1; + } + + void testNullReference() + { + int i = 21; + int *p = &i; + int *q = 0; + int &pp = *p; + int &qq = *q; + BREAK_HERE; + // Check i 21 int. + // CheckType p int. + // Check p 21 int. + // Check q 0x0 int *. + // Check qq int. + // Continue. + return; // Uncomment. + testNullReferenceHelper(pp, qq); + dummyStatement(p, q, &i); + } + void testFinal(QCoreApplication *app) { // This contains all "final" tests that do not allow proceeding @@ -2108,6 +2133,7 @@ namespace final { // Continue. testQSettings(); testNullPointerDeref(); + testNullReference(); testEndlessLoop(); testEndlessRecursion(); testUncaughtException();