Blame SOURCES/gdb-rhbz1281351-python-unreadable-arg.patch

01917d
commit c75bd3a23915c3122070a95e1974e323543ffbe4
01917d
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
01917d
Date:   Sun Sep 7 14:09:59 2014 +0200
01917d
01917d
    Fix crash on Python frame filters with unreadable arg
01917d
    
01917d
    https://bugzilla.redhat.com/show_bug.cgi?id=1126177
01917d
    
01917d
    ERROR: AddressSanitizer: SEGV on unknown address 0x000000000050 (pc 0x000000992bef sp 0x7ffff9039530 bp 0x7ffff9039540
01917d
    T0)
01917d
        #0 0x992bee in value_type .../gdb/value.c:925
01917d
        #1 0x87c951 in py_print_single_arg python/py-framefilter.c:445
01917d
        #2 0x87cfae in enumerate_args python/py-framefilter.c:596
01917d
        #3 0x87e0b0 in py_print_args python/py-framefilter.c:968
01917d
    
01917d
    It crashes because frame_arg::val is documented it may contain NULL
01917d
    (frame_arg::error is then non-NULL) but the code does not handle it.
01917d
    
01917d
    Another bug is that py_print_single_arg() calls goto out of its TRY_CATCH
01917d
    which messes up GDB cleanup chain crashing GDB later.
01917d
    
01917d
    It is probably 7.7 regression (I have not verified it) due to the introduction
01917d
    of Python frame filters.
01917d
    
01917d
    gdb/ChangeLog
01917d
    
01917d
    	PR python/17355
01917d
    	* python/py-framefilter.c (py_print_single_arg): Handle NULL FA->VAL.
01917d
    	Fix goto out of TRY_CATCH.
01917d
    
01917d
    gdb/testsuite/ChangeLog
01917d
    
01917d
    	PR python/17355
01917d
    	* gdb.python/amd64-py-framefilter-invalidarg.S: New file.
01917d
    	* gdb.python/py-framefilter-invalidarg-gdb.py.in: New file.
01917d
    	* gdb.python/py-framefilter-invalidarg.exp: New file.
01917d
    	* gdb.python/py-framefilter-invalidarg.py: New file.
01917d
01917d
### a/gdb/ChangeLog
01917d
### b/gdb/ChangeLog
01917d
## -1,3 +1,9 @@
01917d
+2014-09-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
01917d
+
01917d
+	PR python/17355
01917d
+	* python/py-framefilter.c (py_print_single_arg): Handle NULL FA->VAL.
01917d
+	Fix goto out of TRY_CATCH.
01917d
+
01917d
 2014-09-06  Doug Evans  <xdje42@gmail.com>
01917d
 	    Tom Tromey  <tromey@redhat.com>
01917d
 
01917d
### a/gdb/testsuite/ChangeLog
01917d
### b/gdb/testsuite/ChangeLog
01917d
## -1,3 +1,11 @@
01917d
+2014-09-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
01917d
+
01917d
+	PR python/17355
01917d
+	* gdb.python/amd64-py-framefilter-invalidarg.S: New file.
01917d
+	* gdb.python/py-framefilter-invalidarg-gdb.py.in: New file.
01917d
+	* gdb.python/py-framefilter-invalidarg.exp: New file.
01917d
+	* gdb.python/py-framefilter-invalidarg.py: New file.
01917d
+
01917d
 2014-09-06  Doug Evans  <xdje42@gmail.com>
01917d
 
01917d
 	PR 15276
01917d
Index: gdb-7.6.1/gdb/python/py-framefilter.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/python/py-framefilter.c	2015-11-27 18:06:21.901228682 +0100
01917d
+++ gdb-7.6.1/gdb/python/py-framefilter.c	2015-11-27 18:06:22.445231731 +0100
01917d
@@ -365,9 +365,12 @@
01917d
 {
01917d
   struct value *val;
01917d
   volatile struct gdb_exception except;
01917d
+  enum py_bt_status retval = PY_BT_OK;
01917d
 
01917d
   if (fa != NULL)
01917d
     {
01917d
+      if (fa->val == NULL && fa->error == NULL)
01917d
+	return PY_BT_OK;
01917d
       language = language_def (SYMBOL_LANGUAGE (fa->sym));
01917d
       val = fa->val;
01917d
     }
01917d
@@ -433,16 +436,18 @@
01917d
       /* For MI print the type, but only for simple values.  This seems
01917d
 	 weird, but this is how MI choose to format the various output
01917d
 	 types.  */
01917d
-      if (args_type == MI_PRINT_SIMPLE_VALUES)
01917d
+      if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
01917d
 	{
01917d
 	  if (py_print_type (out, val) == PY_BT_ERROR)
01917d
 	    {
01917d
+	      retval = PY_BT_ERROR;
01917d
 	      do_cleanups (cleanups);
01917d
-	      goto error;
01917d
+	      continue;
01917d
 	    }
01917d
 	}
01917d
 
01917d
-      annotate_arg_value (value_type (val));
01917d
+      if (val != NULL)
01917d
+	annotate_arg_value (value_type (val));
01917d
 
01917d
       /* If the output is to the CLI, and the user option "set print
01917d
 	 frame-arguments" is set to none, just output "...".  */
01917d
@@ -454,27 +459,25 @@
01917d
 	     for the case of MI_PRINT_NO_VALUES.  */
01917d
 	  if (args_type != NO_VALUES)
01917d
 	    {
01917d
-	      if (py_print_value (out, val, opts, 0, args_type, language)
01917d
-		  == PY_BT_ERROR)
01917d
+	      if (val == NULL)
01917d
 		{
01917d
-		  do_cleanups (cleanups);
01917d
-		  goto error;
01917d
+		  gdb_assert (fa != NULL && fa->error != NULL);
01917d
+		  ui_out_field_fmt (out, "value",
01917d
+				    _("<error reading variable: %s>"),
01917d
+				    fa->error);
01917d
 		}
01917d
+	      else if (py_print_value (out, val, opts, 0, args_type, language)
01917d
+		       == PY_BT_ERROR)
01917d
+		retval = PY_BT_ERROR;
01917d
 	    }
01917d
 	}
01917d
 
01917d
       do_cleanups (cleanups);
01917d
     }
01917d
   if (except.reason < 0)
01917d
-    {
01917d
-      gdbpy_convert_exception (except);
01917d
-      goto error;
01917d
-    }
01917d
-
01917d
-  return PY_BT_OK;
01917d
+    gdbpy_convert_exception (except);
01917d
 
01917d
- error:
01917d
-  return PY_BT_ERROR;
01917d
+  return retval;
01917d
 }
01917d
 
01917d
 /* Helper function to loop over frame arguments provided by the
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.python/amd64-py-framefilter-invalidarg.S
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.python/amd64-py-framefilter-invalidarg.S	2015-11-27 18:06:22.446231736 +0100
01917d
@@ -0,0 +1,261 @@
01917d
+/* This testcase is part of GDB, the GNU debugger.
01917d
+
01917d
+   Copyright 2014 Free Software Foundation, Inc.
01917d
+
01917d
+   This program is free software; you can redistribute it and/or modify
01917d
+   it under the terms of the GNU General Public License as published by
01917d
+   the Free Software Foundation; either version 3 of the License, or
01917d
+   (at your option) any later version.
01917d
+
01917d
+   This program is distributed in the hope that it will be useful,
01917d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+   GNU General Public License for more details.
01917d
+
01917d
+   You should have received a copy of the GNU General Public License
01917d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
01917d
+
01917d
+/* This file is compiled from a single line
01917d
+   int main (int argc, char **argv) { return 0; }
01917d
+   using -g -dA -S -O2 and patched as #if-ed below.  */
01917d
+
01917d
+	.file	"py-framefilter-invalidarg.c"
01917d
+	.text
01917d
+.Ltext0:
01917d
+	.globl	main
01917d
+	.type	main, @function
01917d
+main:
01917d
+.LFB0:
01917d
+	.file 1 "py-framefilter-invalidarg.c"
01917d
+	# py-framefilter-invalidarg.c:1
01917d
+	.loc 1 1 0
01917d
+	.cfi_startproc
01917d
+# BLOCK 2 seq:0
01917d
+# PRED: ENTRY (FALLTHRU)
01917d
+	pushq	%rbp
01917d
+	.cfi_def_cfa_offset 16
01917d
+	.cfi_offset 6, -16
01917d
+	movq	%rsp, %rbp
01917d
+	.cfi_def_cfa_register 6
01917d
+	movl	%edi, -4(%rbp)
01917d
+	movq	%rsi, -16(%rbp)
01917d
+	# py-framefilter-invalidarg.c:2
01917d
+	.loc 1 2 0
01917d
+	movl	$0, %eax
01917d
+	# py-framefilter-invalidarg.c:3
01917d
+	.loc 1 3 0
01917d
+	popq	%rbp
01917d
+	.cfi_def_cfa 7, 8
01917d
+# SUCC: EXIT [100.0%] 
01917d
+	ret
01917d
+	.cfi_endproc
01917d
+.LFE0:
01917d
+	.size	main, .-main
01917d
+.Letext0:
01917d
+	.section	.debug_info,"",@progbits
01917d
+.Ldebug_info0:
01917d
+	.long	.Le - .Ls	# Length of Compilation Unit Info
01917d
+.Ls:
01917d
+	.value	0x4	# DWARF version number
01917d
+	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
01917d
+	.byte	0x8	# Pointer Size (in bytes)
01917d
+	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
01917d
+	.long	.LASF3	# DW_AT_producer: "GNU C 4.9.1 20140813 (Red Hat 4.9.1-7) -mtune=generic -march=x86-64 -g"
01917d
+	.byte	0x1	# DW_AT_language
01917d
+	.long	.LASF4	# DW_AT_name: "py-framefilter-invalidarg.c"
01917d
+	.long	.LASF5	# DW_AT_comp_dir: ""
01917d
+	.quad	.Ltext0	# DW_AT_low_pc
01917d
+	.quad	.Letext0-.Ltext0	# DW_AT_high_pc
01917d
+	.long	.Ldebug_line0	# DW_AT_stmt_list
01917d
+die2d:
01917d
+	.uleb128 0x2	# (DIE (0x2d) DW_TAG_subprogram)
01917d
+			# DW_AT_external
01917d
+	.long	.LASF6	# DW_AT_name: "main"
01917d
+	.byte	0x1	# DW_AT_decl_file (py-framefilter-invalidarg.c)
01917d
+	.byte	0x1	# DW_AT_decl_line
01917d
+			# DW_AT_prototyped
01917d
+	.long	die6b-.Ldebug_info0	# DW_AT_type
01917d
+	.quad	.LFB0	# DW_AT_low_pc
01917d
+	.quad	.LFE0-.LFB0	# DW_AT_high_pc
01917d
+	.uleb128 0x1	# DW_AT_frame_base
01917d
+	.byte	0x9c	# DW_OP_call_frame_cfa
01917d
+			# DW_AT_GNU_all_call_sites
01917d
+die4e:
01917d
+	.uleb128 0x3	# (DIE (0x4e) DW_TAG_formal_parameter)
01917d
+	.long	.LASF0	# DW_AT_name: "argc"
01917d
+	.byte	0x1	# DW_AT_decl_file (py-framefilter-invalidarg.c)
01917d
+	.byte	0x1	# DW_AT_decl_line
01917d
+	.long	die6b-.Ldebug_info0	# DW_AT_type
01917d
+#if 0
01917d
+	.uleb128 0x2	# DW_AT_location
01917d
+	.byte	0x91	# DW_OP_fbreg
01917d
+	.sleb128 -20
01917d
+#endif
01917d
+#if 0
01917d
+	.uleb128 1f - 2f	# DW_AT_location
01917d
+2:
01917d
+	.byte	0x03	# DW_OP_addr
01917d
+	.quad 0
01917d
+1:
01917d
+#endif
01917d
+#if 1
01917d
+	.uleb128 1f - 2f	# DW_AT_location
01917d
+2:
01917d
+	.byte	0x13	# DW_OP_drop
01917d
+	.quad 0
01917d
+1:
01917d
+#endif
01917d
+die5c:
01917d
+	.uleb128 0x3	# (DIE (0x5c) DW_TAG_formal_parameter)
01917d
+	.long	.LASF1	# DW_AT_name: "argv"
01917d
+	.byte	0x1	# DW_AT_decl_file (py-framefilter-invalidarg.c)
01917d
+	.byte	0x1	# DW_AT_decl_line
01917d
+	.long	die72-.Ldebug_info0	# DW_AT_type
01917d
+	.uleb128 0x2	# DW_AT_location
01917d
+	.byte	0x91	# DW_OP_fbreg
01917d
+	.sleb128 -32
01917d
+	.byte	0	# end of children of DIE 0x2d
01917d
+die6b:
01917d
+	.uleb128 0x4	# (DIE (0x6b) DW_TAG_base_type)
01917d
+	.byte	0x4	# DW_AT_byte_size
01917d
+	.byte	0x5	# DW_AT_encoding
01917d
+	.ascii "int\0"	# DW_AT_name
01917d
+die72:
01917d
+	.uleb128 0x5	# (DIE (0x72) DW_TAG_pointer_type)
01917d
+	.byte	0x8	# DW_AT_byte_size
01917d
+	.long	die78-.Ldebug_info0	# DW_AT_type
01917d
+die78:
01917d
+	.uleb128 0x5	# (DIE (0x78) DW_TAG_pointer_type)
01917d
+	.byte	0x8	# DW_AT_byte_size
01917d
+	.long	die7e-.Ldebug_info0	# DW_AT_type
01917d
+die7e:
01917d
+	.uleb128 0x6	# (DIE (0x7e) DW_TAG_base_type)
01917d
+	.byte	0x1	# DW_AT_byte_size
01917d
+	.byte	0x6	# DW_AT_encoding
01917d
+	.long	.LASF2	# DW_AT_name: "char"
01917d
+	.byte	0	# end of children of DIE 0xb
01917d
+.Le:
01917d
+	.section	.debug_abbrev,"",@progbits
01917d
+.Ldebug_abbrev0:
01917d
+	.uleb128 0x1	# (abbrev code)
01917d
+	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
01917d
+	.byte	0x1	# DW_children_yes
01917d
+	.uleb128 0x25	# (DW_AT_producer)
01917d
+	.uleb128 0xe	# (DW_FORM_strp)
01917d
+	.uleb128 0x13	# (DW_AT_language)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x3	# (DW_AT_name)
01917d
+	.uleb128 0xe	# (DW_FORM_strp)
01917d
+	.uleb128 0x1b	# (DW_AT_comp_dir)
01917d
+	.uleb128 0xe	# (DW_FORM_strp)
01917d
+	.uleb128 0x11	# (DW_AT_low_pc)
01917d
+	.uleb128 0x1	# (DW_FORM_addr)
01917d
+	.uleb128 0x12	# (DW_AT_high_pc)
01917d
+	.uleb128 0x7	# (DW_FORM_data8)
01917d
+	.uleb128 0x10	# (DW_AT_stmt_list)
01917d
+	.uleb128 0x17	# (DW_FORM_sec_offset)
01917d
+	.byte	0
01917d
+	.byte	0
01917d
+	.uleb128 0x2	# (abbrev code)
01917d
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
01917d
+	.byte	0x1	# DW_children_yes
01917d
+	.uleb128 0x3f	# (DW_AT_external)
01917d
+	.uleb128 0x19	# (DW_FORM_flag_present)
01917d
+	.uleb128 0x3	# (DW_AT_name)
01917d
+	.uleb128 0xe	# (DW_FORM_strp)
01917d
+	.uleb128 0x3a	# (DW_AT_decl_file)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x3b	# (DW_AT_decl_line)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x27	# (DW_AT_prototyped)
01917d
+	.uleb128 0x19	# (DW_FORM_flag_present)
01917d
+	.uleb128 0x49	# (DW_AT_type)
01917d
+	.uleb128 0x13	# (DW_FORM_ref4)
01917d
+	.uleb128 0x11	# (DW_AT_low_pc)
01917d
+	.uleb128 0x1	# (DW_FORM_addr)
01917d
+	.uleb128 0x12	# (DW_AT_high_pc)
01917d
+	.uleb128 0x7	# (DW_FORM_data8)
01917d
+	.uleb128 0x40	# (DW_AT_frame_base)
01917d
+	.uleb128 0x18	# (DW_FORM_exprloc)
01917d
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
01917d
+	.uleb128 0x19	# (DW_FORM_flag_present)
01917d
+	.byte	0
01917d
+	.byte	0
01917d
+	.uleb128 0x3	# (abbrev code)
01917d
+	.uleb128 0x5	# (TAG: DW_TAG_formal_parameter)
01917d
+	.byte	0	# DW_children_no
01917d
+	.uleb128 0x3	# (DW_AT_name)
01917d
+	.uleb128 0xe	# (DW_FORM_strp)
01917d
+	.uleb128 0x3a	# (DW_AT_decl_file)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x3b	# (DW_AT_decl_line)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x49	# (DW_AT_type)
01917d
+	.uleb128 0x13	# (DW_FORM_ref4)
01917d
+	.uleb128 0x2	# (DW_AT_location)
01917d
+	.uleb128 0x18	# (DW_FORM_exprloc)
01917d
+	.byte	0
01917d
+	.byte	0
01917d
+	.uleb128 0x4	# (abbrev code)
01917d
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
01917d
+	.byte	0	# DW_children_no
01917d
+	.uleb128 0xb	# (DW_AT_byte_size)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x3e	# (DW_AT_encoding)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x3	# (DW_AT_name)
01917d
+	.uleb128 0x8	# (DW_FORM_string)
01917d
+	.byte	0
01917d
+	.byte	0
01917d
+	.uleb128 0x5	# (abbrev code)
01917d
+	.uleb128 0xf	# (TAG: DW_TAG_pointer_type)
01917d
+	.byte	0	# DW_children_no
01917d
+	.uleb128 0xb	# (DW_AT_byte_size)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x49	# (DW_AT_type)
01917d
+	.uleb128 0x13	# (DW_FORM_ref4)
01917d
+	.byte	0
01917d
+	.byte	0
01917d
+	.uleb128 0x6	# (abbrev code)
01917d
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
01917d
+	.byte	0	# DW_children_no
01917d
+	.uleb128 0xb	# (DW_AT_byte_size)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x3e	# (DW_AT_encoding)
01917d
+	.uleb128 0xb	# (DW_FORM_data1)
01917d
+	.uleb128 0x3	# (DW_AT_name)
01917d
+	.uleb128 0xe	# (DW_FORM_strp)
01917d
+	.byte	0
01917d
+	.byte	0
01917d
+	.byte	0
01917d
+	.section	.debug_aranges,"",@progbits
01917d
+	.long	0x2c	# Length of Address Ranges Info
01917d
+	.value	0x2	# DWARF Version
01917d
+	.long	.Ldebug_info0	# Offset of Compilation Unit Info
01917d
+	.byte	0x8	# Size of Address
01917d
+	.byte	0	# Size of Segment Descriptor
01917d
+	.value	0	# Pad to 16 byte boundary
01917d
+	.value	0
01917d
+	.quad	.Ltext0	# Address
01917d
+	.quad	.Letext0-.Ltext0	# Length
01917d
+	.quad	0
01917d
+	.quad	0
01917d
+	.section	.debug_line,"",@progbits
01917d
+.Ldebug_line0:
01917d
+	.section	.debug_str,"MS",@progbits,1
01917d
+.LASF1:
01917d
+	.string	"argv"
01917d
+.LASF4:
01917d
+	.string	"py-framefilter-invalidarg.c"
01917d
+.LASF5:
01917d
+	.string	""
01917d
+.LASF0:
01917d
+	.string	"argc"
01917d
+.LASF3:
01917d
+	.string	"GNU C 4.9.1 20140813 (Red Hat 4.9.1-7) -mtune=generic -march=x86-64 -g"
01917d
+.LASF6:
01917d
+	.string	"main"
01917d
+.LASF2:
01917d
+	.string	"char"
01917d
+	.ident	"GCC: (GNU) 4.9.1 20140813 (Red Hat 4.9.1-7)"
01917d
+	.section	.note.GNU-stack,"",@progbits
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-invalidarg-gdb.py.in
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-invalidarg-gdb.py.in	2015-11-27 18:06:22.446231736 +0100
01917d
@@ -0,0 +1,48 @@
01917d
+# Copyright (C) 2014 Free Software Foundation, Inc.
01917d
+
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+# This file is part of the GDB testsuite.  It tests Python-based
01917d
+# frame-filters.
01917d
+import gdb
01917d
+import itertools
01917d
+from gdb.FrameDecorator import FrameDecorator
01917d
+
01917d
+
01917d
+class FrameObjFile ():
01917d
+
01917d
+    def __init__ (self):
01917d
+        self.name = "Filter1"
01917d
+        self.priority = 1
01917d
+        self.enabled = False
01917d
+        gdb.current_progspace().frame_filters ["Progspace" + self.name] = self
01917d
+        gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self
01917d
+
01917d
+    def filter (self, frame_iter):
01917d
+        return frame_iter
01917d
+
01917d
+class FrameObjFile2 ():
01917d
+
01917d
+    def __init__ (self):
01917d
+        self.name = "Filter2"
01917d
+        self.priority = 100
01917d
+        self.enabled = True
01917d
+        gdb.current_progspace().frame_filters ["Progspace" + self.name] = self
01917d
+        gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self
01917d
+
01917d
+    def filter (self, frame_iter):
01917d
+        return frame_iter
01917d
+
01917d
+FrameObjFile()
01917d
+FrameObjFile2()
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp	2015-11-27 18:19:26.346625521 +0100
01917d
@@ -0,0 +1,86 @@
01917d
+# Copyright (C) 2014 Free Software Foundation, Inc.
01917d
+
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+load_lib gdb-python.exp
01917d
+
01917d
+standard_testfile amd64-py-framefilter-invalidarg.S
01917d
+
01917d
+if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
01917d
+    verbose "Skipping py-framefilter-invalidarg."
01917d
+    return
01917d
+}
01917d
+
01917d
+# We cannot use prepare_for_testing as we have to set the safe-patch
01917d
+# to check objfile and progspace printers.
01917d
+if {[build_executable $testfile.exp $testfile $srcfile {}] == -1} {
01917d
+    return -1
01917d
+}
01917d
+
01917d
+# Start with a fresh gdb.
01917d
+gdb_exit
01917d
+gdb_start
01917d
+
01917d
+# Skip all tests if Python scripting is not enabled.
01917d
+if { [skip_python_tests] } { continue }
01917d
+
01917d
+### IMPORT:
01917d
+# Like remote_download but provides a gdb-specific behavior.  If DEST
01917d
+# is "host", and the host is not remote, and TOFILE is not specified,
01917d
+# then the [file tail] of FROMFILE is passed through
01917d
+# standard_output_file to compute the destination.
01917d
+
01917d
+proc gdb_remote_download {dest fromfile {tofile {}}} {
01917d
+    if {$dest == "host" && ![is_remote host] && $tofile == ""} {
01917d
+	set tofile [standard_output_file [file tail $fromfile]]
01917d
+    }
01917d
+
01917d
+    if { $tofile == "" } {
01917d
+	return [remote_download $dest $fromfile]
01917d
+    } else {
01917d
+	return [remote_download $dest $fromfile $tofile]
01917d
+    }
01917d
+}
01917d
+### IMPORT^
01917d
+
01917d
+# Make the -gdb.py script available to gdb, it is automagically loaded by gdb.
01917d
+# Care is taken to put it in the same directory as the binary so that
01917d
+# gdb will find it.
01917d
+set remote_obj_python_file \
01917d
+    [remote_download \
01917d
+	 host ${srcdir}/${subdir}/${testfile}-gdb.py.in \
01917d
+	 [standard_output_file ${testfile}-gdb.py]]
01917d
+
01917d
+gdb_reinitialize_dir $srcdir/$subdir
01917d
+gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \
01917d
+    "set auto-load safe-path"
01917d
+gdb_load ${binfile}
01917d
+# Verify gdb loaded the script.
01917d
+gdb_test "info auto-load python-scripts" "Yes.*/${testfile}-gdb.py.*" \
01917d
+    "Test auto-load had loaded python scripts"
01917d
+
01917d
+if ![runto_main] then {
01917d
+    perror "couldn't run to breakpoint"
01917d
+    return
01917d
+}
01917d
+gdb_test_no_output "set python print-stack full" \
01917d
+    "Set python print-stack to full"
01917d
+
01917d
+# Load global frame-filters
01917d
+set remote_python_file [gdb_remote_download host \
01917d
+			    ${srcdir}/${subdir}/${testfile}.py]
01917d
+gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
01917d
+    "Load python file"
01917d
+
01917d
+gdb_test "bt" " in niam \\(argc=<error reading variable: dwarf expression stack underflow>, argv=0x\[0-9a-f\]+\\) at py-framefilter-invalidarg.c:\[0-9\]+" "bt full with filters"
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-invalidarg.py
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.python/py-framefilter-invalidarg.py	2015-11-27 18:06:22.447231742 +0100
01917d
@@ -0,0 +1,59 @@
01917d
+# Copyright (C) 2014 Free Software Foundation, Inc.
01917d
+
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+# This file is part of the GDB testsuite.  It tests Python-based
01917d
+# frame-filters.
01917d
+import gdb
01917d
+import itertools
01917d
+from gdb.FrameDecorator import FrameDecorator
01917d
+import copy
01917d
+
01917d
+class Reverse_Function (FrameDecorator):
01917d
+
01917d
+    def __init__(self, fobj):
01917d
+        super(Reverse_Function, self).__init__(fobj)
01917d
+        self.fobj = fobj
01917d
+
01917d
+    def function (self):
01917d
+        fname = str (self.fobj.function())
01917d
+        if (fname == None or fname == ""):
01917d
+            return None
01917d
+        if fname == 'end_func':
01917d
+            extra = self.fobj.inferior_frame().read_var('str').string()
01917d
+        else:
01917d
+            extra = ''
01917d
+        fname = fname[::-1] + extra
01917d
+        return fname
01917d
+
01917d
+class FrameFilter ():
01917d
+
01917d
+    def __init__ (self):
01917d
+        self.name = "Reverse"
01917d
+        self.priority = 100
01917d
+        self.enabled = True
01917d
+        gdb.frame_filters [self.name] = self
01917d
+
01917d
+    def filter (self, frame_iter):
01917d
+        # Python 3.x moved the itertools.imap functionality to map(),
01917d
+        # so check if it is available.
01917d
+        if hasattr(itertools, "imap"):
01917d
+            frame_iter = itertools.imap (Reverse_Function,
01917d
+                                         frame_iter)
01917d
+        else:
01917d
+            frame_iter = map(Reverse_Function, frame_iter)
01917d
+
01917d
+        return frame_iter
01917d
+
01917d
+FrameFilter()