From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27565 invoked by alias); 22 Jun 2012 14:27:45 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 27532 invoked by uid 9514); 22 Jun 2012 14:27:42 -0000 Date: Fri, 22 Jun 2012 14:27:00 -0000 Message-ID: <20120622142742.27516.qmail@sourceware.org> From: pmuldoon@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-pmuldoon-python-backtrace: Add auto-loading tests. Fix RAW option to backtrace. Add error checks for a lot of invocation/module loading code. X-Git-Refname: refs/heads/archer-pmuldoon-python-backtrace X-Git-Reftype: branch X-Git-Oldrev: 94426f022d3e5a4e9c7b7d0a25c57a334ab6497d X-Git-Newrev: 01ab5c800ea2fc5ae1720880879c33a5ee2aef97 X-SW-Source: 2012-q2/txt/msg00063.txt.bz2 List-Id: The branch, archer-pmuldoon-python-backtrace has been updated via 01ab5c800ea2fc5ae1720880879c33a5ee2aef97 (commit) from 94426f022d3e5a4e9c7b7d0a25c57a334ab6497d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 01ab5c800ea2fc5ae1720880879c33a5ee2aef97 Author: Phil Muldoon Date: Fri Jun 22 15:26:46 2012 +0100 Add auto-loading tests. Fix RAW option to backtrace. Add error checks for a lot of invocation/module loading code. ----------------------------------------------------------------------- Summary of changes: gdb/python/py-framefilter.c | 15 ++++-- gdb/stack.c | 47 +++++++++++++-------- gdb/testsuite/gdb.python/py-framefilter-gdb.py.in | 47 +++++++++++++++++++++ gdb/testsuite/gdb.python/py-framefilter.exp | 34 +++++++++++++-- 4 files changed, 116 insertions(+), 27 deletions(-) create mode 100644 gdb/testsuite/gdb.python/py-framefilter-gdb.py.in First 500 lines of diff: diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index 96a41a5..5f729f8 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -564,25 +564,30 @@ apply_frame_filter (struct frame_info *frame, int print_level, cleanups = ensure_python_env (gdbarch, current_language); + module = PyImport_ImportModule ("gdb.command.frame_filters"); + if (! module) + goto done; + frame_obj = frame_info_to_frame_object (frame); if (! frame_obj) goto done; - module = PyImport_AddModule ("gdb.command.frame_filters"); - sort_func = PyObject_GetAttrString (module, "invoke"); if (!sort_func) { Py_DECREF (module); + Py_DECREF (frame_obj); goto done; } + iterable = PyObject_CallFunctionObjArgs (sort_func, frame_obj, NULL); + Py_DECREF (module); Py_DECREF (sort_func); Py_DECREF (frame_obj); - Py_DECREF (module); - if (!iterable || PyErr_Occurred()) + + if (!iterable) goto done; - + get_user_print_options (&opts); make_cleanup_py_decref (iterable); diff --git a/gdb/stack.c b/gdb/stack.c index 5055e99..78c2390 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1651,7 +1651,9 @@ frame_info (char *addr_exp, int from_tty) frames. */ static void -backtrace_command_1 (char *count_exp, int show_locals, int from_tty) +backtrace_command_1 (char *count_exp, int show_locals, int raw, + int from_tty) + { struct frame_info *fi; int count; @@ -1719,11 +1721,12 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty) find_pc_sect_symtab_via_partial (pc, find_pc_mapped_section (pc)); } } - - result = apply_frame_filter (trailing, 1, LOCATION, 1, - print_frame_arguments, current_uiout, - show_locals, count); - + + if (! raw) + result = apply_frame_filter (trailing, 1, LOCATION, 1, + print_frame_arguments, current_uiout, + show_locals, count); + if (! result) { for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi)) @@ -1765,7 +1768,8 @@ static void backtrace_command (char *arg, int from_tty) { struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); - int fulltrace_arg = -1, arglen = 0, argc = 0; + int fulltrace_arg = -1, arglen = 0, argc = 0, raw_arg = -1; + int user_arg = 0; if (arg) { @@ -1781,26 +1785,32 @@ backtrace_command (char *arg, int from_tty) for (j = 0; j < strlen (argv[i]); j++) argv[i][j] = tolower (argv[i][j]); - - if (fulltrace_arg < 0 && subset_compare (argv[i], "full")) - fulltrace_arg = argc; + + if (raw_arg < 0 && subset_compare (argv[i], "raw")) + raw_arg = argc; else { - arglen += strlen (argv[i]); - argc++; + if (fulltrace_arg < 0 && subset_compare (argv[i], "full")) + fulltrace_arg = argc; + else + { + user_arg++; + arglen += strlen (argv[i]); + } } + argc++; } - arglen += argc; - if (fulltrace_arg >= 0) + arglen += user_arg; + if (fulltrace_arg >= 0 || raw_arg >= 0) { if (arglen > 0) { arg = xmalloc (arglen + 1); make_cleanup (xfree, arg); arg[0] = 0; - for (i = 0; i < (argc + 1); i++) + for (i = 0; i < argc; i++) { - if (i != fulltrace_arg) + if (i != fulltrace_arg && i != raw_arg) { strcat (arg, argv[i]); strcat (arg, " "); @@ -1812,7 +1822,8 @@ backtrace_command (char *arg, int from_tty) } } - backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, from_tty); + backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, + raw_arg >= 0 /* no frame-filters */, from_tty); do_cleanups (old_chain); } @@ -1820,7 +1831,7 @@ backtrace_command (char *arg, int from_tty) static void backtrace_full_command (char *arg, int from_tty) { - backtrace_command_1 (arg, 1 /* show_locals */, from_tty); + backtrace_command_1 (arg, 1 /* show_locals */, 0, from_tty); } diff --git a/gdb/testsuite/gdb.python/py-framefilter-gdb.py.in b/gdb/testsuite/gdb.python/py-framefilter-gdb.py.in new file mode 100644 index 0000000..dc3d2f9 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-framefilter-gdb.py.in @@ -0,0 +1,47 @@ +# Copyright (C) 2012 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is part of the GDB testsuite. It tests Python-based +# frame-filters. +import gdb +import itertools +from gdb.FrameWrapper import FrameWrapper + + +class FrameObjFile (): + + def __init__ (self): + self.name = "Object File Filter 1" + self.priority = 1 + self.enabled = False + gdb.current_progspace().frame_filters [self.name] = self + + def filter (self, frame_iter): + return frame_iter + +class FrameObjFile2 (): + + def __init__ (self): + self.name = "Object File Filter 2" + self.priority = 100 + self.enabled = True + gdb.current_progspace().frame_filters [self.name] = self + + def filter (self, frame_iter): + return frame_iter + +FrameObjFile() +FrameObjFile2() + diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp index 7fd44d7..44b7de2 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.exp +++ b/gdb/testsuite/gdb.python/py-framefilter.exp @@ -22,26 +22,52 @@ set testfile "py-framefilter" set srcfile ${testfile}.c set binfile ${objdir}/${subdir}/${testfile} -if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { +# We cannot use prepare_for_testing as we have to set the safe-patch +# to check objfile and progspace printers. +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile ${srcfile}" return -1 } +# Start with a fresh gdb. +gdb_exit +gdb_start + # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } -set nl "\[\r\n\]+" +# Make the -gdb.py script available to gdb, it is automagically loaded by gdb. +# Care is taken to put it in the same directory as the binary so that +# gdb will find it. +set remote_obj_python_file [remote_download host ${srcdir}/${subdir}/${testfile}-gdb.py.in ${subdir}/${testfile}-gdb.py] + +gdb_reinitialize_dir $srcdir/$subdir +gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" "set auto-load safe-path" +gdb_load ${binfile} + +# Verify gdb loaded the script. +gdb_test "info auto-load python-scripts" "Yes.*/${testfile}-gdb.py.*" if ![runto_main ] then { perror "couldn't run to breakpoint" return } +# Load global frame-filters set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] gdb_test_no_output "python execfile ('${remote_python_file}')" gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"] gdb_continue_to_breakpoint "Backtrace end breakpoint" -gdb_test "bt" "#-1.*in Dummy function.*#22.*in 1cnuf.*#27.*in niam ().*" -gdb_test "bt" "#-1.*in Dummy function.*#22.*in 1cnuf.*#27.*in niam ().*" +gdb_test "info frame-filter" \ + {.*100.*Yes.*Reverse.*10.*Yes.*Add.*1.*No.*Object.*1.*} +# Test raw +gdb_test "bt raw" \ + {.*#0.*end_func.*#22.*in func1.*#27.*in main ().*} +gdb_test "bt" \ + {.*in Dummy function.*#22.*in 1cnuf.*#27.*in niam ().*} +gdb_test "bt" \ + {.*in Dummy function.*#22.*in 1cnuf.*#27.*in niam ().*} + remote_file host delete ${remote_python_file} hooks/post-receive -- Repository for Project Archer.