From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13281 invoked by alias); 25 Jul 2012 14:09:11 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 13240 invoked by uid 9514); 25 Jul 2012 14:09:10 -0000 Date: Wed, 25 Jul 2012 14:09:00 -0000 Message-ID: <20120725140910.13225.qmail@sourceware.org> From: pmuldoon@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-pmuldoon-python-backtrace: Fix some reference counting bugs. Remove FrameIterator and frame.locals, frame.args test (not longer provided in gdb.Frame) X-Git-Refname: refs/heads/archer-pmuldoon-python-backtrace X-Git-Reftype: branch X-Git-Oldrev: ba8c5e70fec3ee279735a4552039d044b36e000e X-Git-Newrev: 69d61b34b067f3be63fe01f99c6904d1b2e38200 X-SW-Source: 2012-q3/txt/msg00017.txt.bz2 List-Id: The branch, archer-pmuldoon-python-backtrace has been updated via 69d61b34b067f3be63fe01f99c6904d1b2e38200 (commit) from ba8c5e70fec3ee279735a4552039d044b36e000e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 69d61b34b067f3be63fe01f99c6904d1b2e38200 Author: Phil Muldoon Date: Wed Jul 25 15:08:27 2012 +0100 Fix some reference counting bugs. Remove FrameIterator and frame.locals, frame.args test (not longer provided in gdb.Frame) ----------------------------------------------------------------------- Summary of changes: gdb/python/py-framefilter.c | 90 +++++++++++++++++--------------- gdb/testsuite/gdb.python/py-frame.exp | 66 +----------------------- 2 files changed, 50 insertions(+), 106 deletions(-) First 500 lines of diff: diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index f6143bf..7dd7aaa 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -41,6 +41,7 @@ extract_sym_and_value (PyObject *obj, char **name, if (PyObject_HasAttrString (obj, "symbol")) { PyObject *result = PyObject_CallMethod (obj, "symbol", NULL); + if (! result) return 0; @@ -51,8 +52,8 @@ extract_sym_and_value (PyObject *obj, char **name, *name = python_string_to_host_string (result); Py_DECREF (result); - if (! name) - return 0; + if (! *name) + return 0; *language = current_language; } else @@ -146,6 +147,7 @@ py_print_locals (PyObject *filter, if (! iterator) goto locals_error; + make_cleanup_py_decref (iterator); while ((item = PyIter_Next (iterator))) { const struct language_defn *language; @@ -157,17 +159,14 @@ py_print_locals (PyObject *filter, if (! item) goto locals_error; - value_success = extract_sym_and_value (item, &sym_name, &val, &language); Py_DECREF (item); + item = NULL; if (! value_success) - { - Py_DECREF (iterator); - goto locals_error; - } + goto locals_error; fprintf_filtered (gdb_stdout, "%s%s = ", n_spaces (2 * indent), @@ -186,12 +185,14 @@ py_print_locals (PyObject *filter, { PyErr_SetString (PyExc_RuntimeError, except.message); - Py_DECREF (iterator); goto locals_error; } fprintf_filtered (gdb_stdout, "\n"); gdb_flush (gdb_stdout); } + + if (! item && PyErr_Occurred()) + goto locals_error; } } } @@ -215,7 +216,6 @@ py_print_args (PyObject *filter, { struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); PyObject *result = NULL; - struct ui_file *stb; /* Frame arguments. */ annotate_frame_args (); @@ -231,8 +231,6 @@ py_print_args (PyObject *filter, if (result) { make_cleanup_py_decref (result); - stb = mem_fileopen (); - make_cleanup_ui_file_delete (stb); if (result != Py_None) { @@ -248,9 +246,12 @@ py_print_args (PyObject *filter, PyObject *iterator = PyObject_GetIter (result); PyObject *item; int first = 0; + if (! iterator) goto args_error; + make_cleanup_py_decref (iterator); + item = PyIter_Next (iterator); if (! item && PyErr_Occurred ()) goto args_error; @@ -262,18 +263,17 @@ py_print_args (PyObject *filter, struct value *val; int value_success = 0; volatile struct gdb_exception except; + struct ui_file *stb; value_success = extract_sym_and_value (item, &sym_name, &val, &language); Py_DECREF (item); + item = NULL; if (! value_success) - { - Py_DECREF (iterator); - goto args_error; - } + goto args_error; annotate_arg_begin (); ui_out_field_string (out, "name", sym_name); @@ -284,6 +284,9 @@ py_print_args (PyObject *filter, /* True in "summary" mode, false otherwise. */ opts.summary = !strcmp (print_args_type, "scalars"); + stb = mem_fileopen (); + make_cleanup_ui_file_delete (stb); + TRY_CATCH (except, RETURN_MASK_ALL) { common_val_print (val, stb, 2, &opts, language); @@ -292,7 +295,6 @@ py_print_args (PyObject *filter, { PyErr_SetString (PyExc_RuntimeError, except.message); - Py_DECREF (iterator); goto args_error; } @@ -306,10 +308,7 @@ py_print_args (PyObject *filter, ui_out_text (out, ", "); else if (PyErr_Occurred ()) - { - Py_DECREF (iterator); - goto args_error; - } + goto args_error; annotate_arg_end (); } @@ -407,8 +406,8 @@ py_print_frame (PyObject *filter, { if (paddr != Py_None) { - has_addr = 1; address = PyLong_AsLong (paddr); + has_addr = 1; } Py_DECREF (paddr); } @@ -447,9 +446,9 @@ py_print_frame (PyObject *filter, } } - /* Print address to the address field. If no is provided address, - printing nothing. */ - if (opts.addressprint && has_addr) + /* Print address to the address field. If an address is not provided, + print nothing. */ + if (opts.addressprint && has_addr) { annotate_frame_address (); ui_out_field_core_addr (out, "addr", gdbarch, address); @@ -548,12 +547,11 @@ py_print_frame (PyObject *filter, goto error; } - /* For MI we need to deal with the children population of elided - frames, so if MI output detected do not send newline. */ + /* For MI we need to deal with the "children" list population of + elided frames, so if MI output detected do not send newline. */ if (! ui_out_is_mi_like_p (out)) { - if (has_addr) - annotate_frame_end (); + annotate_frame_end (); ui_out_text (out, "\n"); } @@ -586,6 +584,8 @@ py_print_frame (PyObject *filter, PyObject *item; struct cleanup *cleanup_stack; + Py_DECREF (result); + if (iterator == NULL) goto error; @@ -607,16 +607,28 @@ py_print_frame (PyObject *filter, opts, indent, levels_printed); if (success == 0 && PyErr_Occurred ()) { + Py_DECREF (iterator); + Py_DECREF (item); do_cleanups (cleanup_stack); goto error; } + + Py_DECREF (item); } + Py_DECREF (iterator); do_cleanups (cleanup_stack); } } } + /* In MI now we can signal the end. */ + if (ui_out_is_mi_like_p (out)) + { + annotate_frame_end (); + ui_out_text (out, "\n"); + } + return PY_BT_COMPLETED; error: @@ -666,16 +678,14 @@ apply_frame_filter (struct frame_info *frame, int print_level, if (!iterable) goto done; + make_cleanup_py_decref (iterable); if (iterable == Py_None) { - Py_DECREF (iterable); - return 2; + do_cleanups (cleanups); + return PY_BT_NO_FILTERS; } - get_user_print_options (&opts); - make_cleanup_py_decref (iterable); - /* Is it an iterator */ if PyIter_Check (iterable) { @@ -683,9 +693,10 @@ apply_frame_filter (struct frame_info *frame, int print_level, PyObject *item; htab_t levels_printed; - if (iterator == NULL) + if (! iterator) goto done; + make_cleanup_py_decref (iterator); levels_printed = htab_create (20, hash_printed_frame_entry, eq_printed_frame_entry, @@ -698,17 +709,12 @@ apply_frame_filter (struct frame_info *frame, int print_level, print_locals, out, opts, 0, levels_printed); if (success == PY_BT_ERROR && PyErr_Occurred ()) - { - gdbpy_print_stack (); - /* FIXME: Should we try to continue to print other - frames when we encounter an error? */ - break; - } + gdbpy_print_stack (); + Py_DECREF (item); } htab_delete (levels_printed); - Py_DECREF (iterator); } else { @@ -731,7 +737,7 @@ apply_frame_filter (struct frame_info *frame, int print_level, struct ui_out *out, int print_frame, int print_locals) { - return 2; + return 2; /* PY_BT_NO_FILTERS */ } #endif /* HAVE_PYTHON */ diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp index 20761e9..83ff8fe 100644 --- a/gdb/testsuite/gdb.python/py-frame.exp +++ b/gdb/testsuite/gdb.python/py-frame.exp @@ -18,8 +18,8 @@ load_lib gdb-python.exp -standard_testfile - +set testfile "py-frame" +set srcfile ${testfile}.c if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { return -1 } @@ -58,29 +58,6 @@ gdb_py_test_silent_cmd "python sb = sb.superblock" "get superblock" 0 gdb_test "python print bf1.read_var(\"i\", sb)" "99" "test i = 99" gdb_test "python print bf1.read_var(\"i\", sb).type" "int" "test int i" -# Test frame.locals and frame.arg -gdb_py_test_multiple "simple frame print" \ - "python" "" \ - "def print_var (iterator, frame):" "" \ - " for i in iterator:" "" \ - " print str(i),\"=\", frame.read_var (i)" "" \ - "end" "" -gdb_py_test_silent_cmd "python fframe = gdb.selected_frame ()" "get frame" 0 -gdb_py_test_silent_cmd "python flocals = fframe.locals()" "get locals" 0 -gdb_test "python print_var(flocals,fframe)" \ - "i =.*\"stuff\".*f =.*\"foo\".*b =.*\"bar\".*i = 1.1.*f = 2.2.*i = 99.*" \ - "test locals output" -gdb_py_test_silent_cmd "python fargs = fframe.arguments()" "get arguments" 0 -gdb_test "python print fargs" "None" "Test arguments, with no arguments" -gdb_test "up" ".*" "" -gdb_py_test_silent_cmd "python fframe = gdb.selected_frame ()" "get frame" 0 -gdb_py_test_silent_cmd "python flocals = fframe.locals()" "get locals" 0 -gdb_test "python print flocals" "None" "Test locals(), with mo locals" -gdb_py_test_silent_cmd "python fargs = fframe.arguments()" "get arguments" 0 -gdb_test "python print_var(fargs,fframe)" \ - "argc = .*argv = .*" \ - "test arguments() output" - gdb_breakpoint "f2" gdb_continue_to_breakpoint "breakpoint at f2" gdb_py_test_silent_cmd "python bframe = gdb.selected_frame()" \ @@ -113,42 +90,3 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success" gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame" - -# Test FrameIterator. This tests both the inbuilt iterator, and the -# seperate class. -gdb_breakpoint "f3" -gdb_continue_to_breakpoint "breakpoint at f3" -gdb_py_test_silent_cmd "python it = gdb.FrameIterator (gdb.newest_frame())" \ - "get iterator from newest frame" 0 -gdb_py_test_multiple "simple frame print" \ - "python" "" \ - "def print_function (iterator):" "" \ - " for i in iterator:" "" \ - " print str(i.function())" "" \ - "end" "" -gdb_test "python print_function(it)" \ - "f3.*f2.*f1.*main.*" "test vanilla frame iterator" -gdb_test "python print_function(gdb.newest_frame())" \ - "f3.*f2.*f1.*main.*" "test vanilla inbuilt frame iterator" -gdb_test "select 3" ".*" "" -gdb_py_test_silent_cmd "python it = gdb.FrameIterator (gdb.selected_frame(), reverse=True)" \ - "get iterator from selected frame" 0 -gdb_test "python print_function(it)" \ - "main.*f1.*f2.*f3.*" "test reverse traversal vanilla frame iterator" -gdb_py_test_silent_cmd "python it = gdb.FrameIterator(gdb.newest_frame(), regex=\"f\[0-9\]\")" \ - "get iterator from newest frame" 0 -gdb_test "python print_function(it)" \ - "f3.*f2.*f1.*" "test traversal with a regex filtered iterator" -gdb_py_test_silent_cmd "python it = gdb.FrameIterator(gdb.selected_frame(), regex=\"f\[0-9\]\", reverse=True)" \ - "get iterator from newest frame" 0 -gdb_test "python print_function(it)" \ - "f1.*f2.*f3.*" "test reverse traversal with a regex filtered iterator" -gdb_py_test_silent_cmd "python it = gdb.FrameIterator(gdb.selected_frame(), regex=\"nothing\")" \ - "get iterator from newest frame" 0 -gdb_test "python print_function(it)" \ - "" "test regex iterator that returns nothing" -gdb_test "python ite = gdb.FrameIterator(gdb.selected_frame(), regex=\"\[\")" \ - "Traceback.*Invalid regex.*Invalid regular expression.*" "test invalid regex" -gdb_test "python print ite" \ - ".*NameError.*name.*ite.*is not defined.*" \ - "test invalid iterator did not return an iterator" hooks/post-receive -- Repository for Project Archer.