Re: Re-evaluate floating varobj as part of varobj_invalidate.

Andrew Burgess
2012-07-27T08:21:19Z

On 26/07/2012 9:35 AM, Jan Kratochvil wrote:
> On Wed, 25 Jul 2012 19:52:22 +0200, Tom Tromey wrote:
>>>>>>> "Andrew" == Andrew Burgess <aburgess@broadcom.com> writes:
>>
>> Andrew> I have a bug & patch, but no great way to reproduce the issue as
>> Andrew> it's a use of pointer after free issue,
>>
>> I suspect the recent-ish change to use -lmcheck by default will cause us
>> to catch this bug in the test suite, at least on glibc-using systems.
>
> Yes, FSF GDB HEAD crashes for me with the posted reproducer. Could you write
> this simple testcase?

There's a patch below that tests this issue, it does indeed fail for me running on x86-linux before my fix patch, and works afterwards.

If this test is ok I'll commit the fix and the test patches together.

Thanks
Andrew

gdb/testsuite/ChangeLog

2012-07-27 Andrew Burgess <aburgess@broadcom.com>

* gdb.mi/mi-var-invalidate.exp: Create a floating variable and
change its format immediately after reloading the binary.

diff --git a/gdb/testsuite/gdb.mi/mi-var-invalidate.exp b/gdb/testsuite/gdb.mi/mi-var-invalidate.exp
index 3ecbbdf..98dd3f1 100644
--- a/gdb/testsuite/gdb.mi/mi-var-invalidate.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-invalidate.exp
@@ -61,6 +61,9 @@ mi_runto do_locals_tests
# Desc: create local variables
mi_create_varobj linteger linteger "create local variable linteger"

+# Desc: create floating variable
+mi_create_floating_varobj float_simple array "create floating variable"
+
#
# Reload the same binary.
# Global variable should remain, local should be invalidated.
@@ -69,6 +72,12 @@ mi_delete_breakpoints
mi_gdb_load ${binfile_bis}
mi_runto main

+# Change format of floating variable immediately after reload reveals a
+# bug where gdb still uses a free'd pointer.
+mi_gdb_test "-var-set-format float_simple hexadecimal" \
+ "\\^done,format=\"hexadecimal\",value=\"\\\[-1\\\]\"" \
+ "set format variable float_simple"
+
# Check local variable is "invalid".
mi_gdb_test "-var-update linteger" \
"\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \