From: Philippe Waroquiers Date: Sat, 18 May 2019 10:10:40 +0000 (+0200) Subject: Add a test for the new gdbserver adddress[length] syntax. X-Git-Tag: VALGRIND_3_16_0~287 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc758374a25e5cfb1a7c11f3ac3b0e31217746a5;p=thirdparty%2Fvalgrind.git Add a test for the new gdbserver adddress[length] syntax. --- diff --git a/memcheck/tests/leak_cpp_interior.cpp b/memcheck/tests/leak_cpp_interior.cpp index a4b4824522..56c53709d1 100644 --- a/memcheck/tests/leak_cpp_interior.cpp +++ b/memcheck/tests/leak_cpp_interior.cpp @@ -11,65 +11,65 @@ // 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; diff --git a/memcheck/tests/leak_cpp_interior.stderr.exp-64bit b/memcheck/tests/leak_cpp_interior.stderr.exp-64bit index 4474b03439..5c85d99176 100644 --- a/memcheck/tests/leak_cpp_interior.stderr.exp-64bit +++ b/memcheck/tests/leak_cpp_interior.stderr.exp-64bit @@ -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"