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

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