]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a test for the new gdbserver adddress[length] syntax.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 18 May 2019 10:10:40 +0000 (12:10 +0200)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 18 May 2019 10:10:40 +0000 (12:10 +0200)
memcheck/tests/leak_cpp_interior.cpp
memcheck/tests/leak_cpp_interior.stderr.exp-64bit

index a4b48245227ee271c3d89643c6d2c7c474483a1f..56c53709d1e0463cf4a2d7aff7c94133eb12388c 100644 (file)
 // Derived from test provided by Timur Iskhodzhanov (bug 280271)
 
 class MyClass
-{ 
+{
    char m1;
    int  m2;
 public:
-   ~MyClass() 
-   { fprintf(stderr, "destruct MyClass\n"); 
-   } 
+   ~MyClass()
+   { fprintf(stderr, "destruct MyClass\n");
+   }
 };
 
 // Two hierarchies using MI, one with no fields,
 // the other one with some data.
-struct Ae 
-{ 
-   virtual ~Ae() 
-   { fprintf(stderr, "destruct Ae\n"); 
-   } 
-}; 
-struct Be 
-{ 
-   virtual ~Be() 
-   { fprintf(stderr, "destruct Be\n"); 
-   } 
-}; 
-struct Ce : public Ae, public Be 
-{ 
-   virtual ~Ce() 
-   { fprintf(stderr, "destruct Ce\n"); 
-   } 
+struct Ae
+{
+   virtual ~Ae()
+   { fprintf(stderr, "destruct Ae\n");
+   }
+};
+struct Be
+{
+   virtual ~Be()
+   { fprintf(stderr, "destruct Be\n");
+   }
+};
+struct Ce : public Ae, public Be
+{
+   virtual ~Ce()
+   { fprintf(stderr, "destruct Ce\n");
+   }
 };
 
-struct A 
-{ 
+struct A
+{
    char a;
-   A() 
+   A()
    { a = 'a';
-   } 
-   virtual ~A() 
-   { fprintf(stderr, "destruct A\n"); 
-   } 
-}; 
-struct B 
-{ 
+   }
+   virtual ~A()
+   { fprintf(stderr, "destruct A\n");
+   }
+};
+struct B
+{
    char b;
-   B() 
+   B()
    { b = 'b';
-   } 
-   virtual ~B() 
-   { fprintf(stderr, "destruct B\n"); 
-   } 
-}; 
-struct C : public A, public B 
-{ 
+   }
+   virtual ~B()
+   { fprintf(stderr, "destruct B\n");
+   }
+};
+struct C : public A, public B
+{
    char c;
-   C() 
+   C()
    { c = 'c';
-   } 
-   virtual ~C() 
-   { fprintf(stderr, "destruct C\n"); 
-   } 
+   }
+   virtual ~C()
+   { fprintf(stderr, "destruct C\n");
+   }
 };
 
 void* wrap64_malloc(int size)
@@ -100,6 +100,7 @@ A *ptrAC;
 void* ptr64;
 
 char who_points_at_cmd[100];
+char who_points_at_cmd_brackets[100]; /* Same but with brackets.  */
 
 void doit(void)
 {
@@ -107,11 +108,13 @@ void doit(void)
   str2 = str;
   ptr = new MyClass[3]; // interior ptr.
   ptr64 = wrap64_malloc(23);
-  
+
   // prepare the who_points_at cmd we will run.
   // Do it here to avoid having ptr or its exterior ptr kept in a register.
   sprintf(who_points_at_cmd, "who_points_at %#" PRIxPTR " 20",
           (uintptr_t) (char*)ptr - sizeof(void*));
+  sprintf(who_points_at_cmd_brackets, "who_points_at %#" PRIxPTR "[20]",
+          (uintptr_t) (char*)ptr - sizeof(void*));
 
   ptr2 = new MyClass[0]; // "interior but exterior ptr".
   // ptr2 points after the chunk, is wrongly considered by memcheck as definitely leaked.
@@ -120,13 +123,13 @@ void doit(void)
   ptrACe = new Ce;  // not an interior pointer.
   ptrBC = new C;  // interior ptr.
   ptrAC = new C;  // not an interior pointer.
-  
-  
+
+
   str2 += " rocks (str2)\n"; // interior ptr.
 }
 
 
-int main() { 
+int main() {
 
    doit();
    (void) VALGRIND_MONITOR_COMMAND("v.set log_output");
@@ -154,6 +157,8 @@ int main() {
 
    // Test the who_points_at when the block is pointed to with an interior ptr.
    (void) VALGRIND_MONITOR_COMMAND(who_points_at_cmd);
+   // Same but with the bracket syntax.
+   (void) VALGRIND_MONITOR_COMMAND(who_points_at_cmd_brackets);
 
    delete [] ptr;
    delete [] ptr2;
index 4474b03439952b36383b242c2a9886a657ac2805..5c85d99176bbb0d77c503b1a2aad490408558d94 100644 (file)
@@ -2,8 +2,8 @@
 valgrind output will go to log
 VALGRIND_DO_LEAK_CHECK
 x bytes in 1 blocks are definitely lost in loss record ... of ...
-   by 0x........: doit() (leak_cpp_interior.cpp:116)
-   by 0x........: main (leak_cpp_interior.cpp:131)
+   by 0x........: doit() (leak_cpp_interior.cpp:119)
+   by 0x........: main (leak_cpp_interior.cpp:134)
 
 LEAK SUMMARY:
    definitely lost: x bytes in 1 blocks
@@ -103,6 +103,10 @@ LEAK SUMMARY:
                         multipleinheritance: 0 (-x) bytes in 0 (-2) blocks
 To see details of leaked memory, give 'full' arg to leak_check
 
+Searching for pointers pointing in x bytes from 0x........
+*0x........ interior points at x bytes inside 0x........
+ Address 0x........ is 0 bytes inside data symbol "ptr"
+block at 0x........ considered reachable by ptr 0x........ using newarray heuristic
 Searching for pointers pointing in x bytes from 0x........
 *0x........ interior points at x bytes inside 0x........
  Address 0x........ is 0 bytes inside data symbol "ptr"