Blame SOURCES/python-framefilter-invalidarg.patch

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