aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2013-08-29 10:06:18 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2013-08-29 10:06:18 +0000
commit8f28f5226e56f018d5dec05522124f868ec86081 (patch)
treecd08845b151e258a1cf6dc08330cd547918e80e4 /gdb
parentca422daf34ee4bbf46d281ebaff362ce3c780483 (diff)
downloadgdb-8f28f5226e56f018d5dec05522124f868ec86081.zip
gdb-8f28f5226e56f018d5dec05522124f868ec86081.tar.gz
gdb-8f28f5226e56f018d5dec05522124f868ec86081.tar.bz2
2013-08-29 Phil Muldoon <pmuldoon@redhat.com>
* python/py-framefilter.c (py_print_frame): Remove usage of PyString_AsString. Use python_string_to_host_string instead. Refactor function to work with a string as a new allocation instead of a pointer. (py_print_frame): Ditto. * python/lib/gdb/frames.py (return_list): Cain iterators together instead of adding them as a list. (_sort_list): Call return_list, and remove duplicate code. (execute_frame_filters): Convert iterator to a list with list(). * python/lib/gdb/command/frame_filters.py (SetFrameFilterPriority._set_filter_priority): Convert priority attribute to an integer. * python/lib/gdb/FrameIterator.py (FrameIterator.next): Define wrapper function __next__. * python/lib/gdb/FrameDecorator.py: If basestring not defined, define as "str". 2013-08-29 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-framefilter.py (FrameFilter.filter): Check itertools for imap attribute. Otherwise use map(). (ElidingIterator): Define wrapper function __next__. * gdb.python/py-framefilter-mi.exp: Do not use execfile, use exec (open (read ())) instead. * gdb.python/py-framefilter.exp: Ditto. * gdb.python/py-arch.exp: Update print based test to Python 3.x compliance. * gdb.python/py-frame.exp: Ditto. * gdb.python/py-type.exp: Ditto.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog19
-rw-r--r--gdb/python/lib/gdb/FrameDecorator.py9
-rw-r--r--gdb/python/lib/gdb/FrameIterator.py6
-rw-r--r--gdb/python/lib/gdb/command/frame_filters.py5
-rw-r--r--gdb/python/lib/gdb/frames.py33
-rw-r--r--gdb/python/py-framefilter.c10
-rw-r--r--gdb/testsuite/ChangeLog13
-rw-r--r--gdb/testsuite/gdb.python/py-arch.exp14
-rw-r--r--gdb/testsuite/gdb.python/py-frame.exp2
-rw-r--r--gdb/testsuite/gdb.python/py-framefilter-mi.exp2
-rw-r--r--gdb/testsuite/gdb.python/py-framefilter.exp4
-rw-r--r--gdb/testsuite/gdb.python/py-framefilter.py16
-rw-r--r--gdb/testsuite/gdb.python/py-type.exp32
13 files changed, 116 insertions, 49 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 38ca053..23ca768 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,24 @@
2013-08-29 Phil Muldoon <pmuldoon@redhat.com>
+ * python/py-framefilter.c (py_print_frame): Remove usage of
+ PyString_AsString. Use python_string_to_host_string instead.
+ Refactor function to work with a string as a new allocation
+ instead of a pointer.
+ (py_print_frame): Ditto.
+ * python/lib/gdb/frames.py (return_list): Cain iterators together
+ instead of adding them as a list.
+ (_sort_list): Call return_list, and remove duplicate code.
+ (execute_frame_filters): Convert iterator to a list with list().
+ * python/lib/gdb/command/frame_filters.py
+ (SetFrameFilterPriority._set_filter_priority): Convert priority
+ attribute to an integer.
+ * python/lib/gdb/FrameIterator.py (FrameIterator.next): Define
+ wrapper function __next__.
+ * python/lib/gdb/FrameDecorator.py: If basestring not defined,
+ define as "str".
+
+2013-08-29 Phil Muldoon <pmuldoon@redhat.com>
+
PR python/15752
* python/py-framefilter.c (apply_frame_filter): Check
gdb_python_initialized. Exit if the Python frame-filter code
diff --git a/gdb/python/lib/gdb/FrameDecorator.py b/gdb/python/lib/gdb/FrameDecorator.py
index cacab4d..4e9cd7a 100644
--- a/gdb/python/lib/gdb/FrameDecorator.py
+++ b/gdb/python/lib/gdb/FrameDecorator.py
@@ -15,6 +15,15 @@
import gdb
+# This small code snippet deals with problem of strings in Python 2.x
+# and Python 3.x. Python 2.x has str and unicode classes which are
+# sub-classes of basestring. In Python 3.x all strings are encoded
+# and basestring has been removed.
+try:
+ basestring
+except NameError:
+ basestring = str
+
class FrameDecorator(object):
"""Basic implementation of a Frame Decorator"""
diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
index b3af94b..3f33bbb 100644
--- a/gdb/python/lib/gdb/FrameIterator.py
+++ b/gdb/python/lib/gdb/FrameIterator.py
@@ -43,3 +43,9 @@ class FrameIterator(object):
raise StopIteration
self.frame = result.older()
return result
+
+ # Python 3.x requires __next__(self) while Python 2.x requires
+ # next(self). Define next(self), and for Python 3.x create this
+ # wrapper.
+ def __next__(self):
+ return self.next()
diff --git a/gdb/python/lib/gdb/command/frame_filters.py b/gdb/python/lib/gdb/command/frame_filters.py
index 1b73059..b5d34ad 100644
--- a/gdb/python/lib/gdb/command/frame_filters.py
+++ b/gdb/python/lib/gdb/command/frame_filters.py
@@ -335,7 +335,10 @@ class SetFrameFilterPriority(gdb.Command):
list_op = command_tuple[0]
frame_filter = command_tuple[1]
- priority = command_tuple[2]
+
+ # GDB returns arguments as a string, so convert priority to
+ # a number.
+ priority = int(command_tuple[2])
op_list = gdb.frames.return_list(list_op)
diff --git a/gdb/python/lib/gdb/frames.py b/gdb/python/lib/gdb/frames.py
index 10dce8e..c148b98 100644
--- a/gdb/python/lib/gdb/frames.py
+++ b/gdb/python/lib/gdb/frames.py
@@ -108,13 +108,15 @@ def return_list(name):
# cannot return a combined dictionary as keys() may clash in
# between different dictionaries. As we just want all the frame
# filters to enable/disable them all, just return the combined
- # items() as a list.
+ # items() as a chained iterator of dictionary values.
if name == "all":
- all_dicts = gdb.frame_filters.values()
- all_dicts = all_dicts + gdb.current_progspace().frame_filters.values()
+ glob = gdb.frame_filters.values()
+ prog = gdb.current_progspace().frame_filters.values()
+ return_iter = itertools.chain(glob, prog)
for objfile in gdb.objfiles():
- all_dicts = all_dicts + objfile.frame_filters.values()
- return all_dicts
+ return_iter = itertools.chain(return_iter, objfile.frame_filters.values())
+
+ return return_iter
if name == "global":
return gdb.frame_filters
@@ -140,14 +142,7 @@ def _sort_list():
execute.
"""
- all_filters = []
- for objfile in gdb.objfiles():
- all_filters = all_filters + objfile.frame_filters.values()
- cp = gdb.current_progspace()
-
- all_filters = all_filters + cp.frame_filters.values()
- all_filters = all_filters + gdb.frame_filters.values()
-
+ all_filters = return_list("all")
sorted_frame_filters = sorted(all_filters, key = get_priority,
reverse = True)
@@ -180,7 +175,7 @@ def execute_frame_filters(frame, frame_low, frame_high):
"""
# Get a sorted list of frame filters.
- sorted_list = _sort_list()
+ sorted_list = list(_sort_list())
# Check to see if there are any frame-filters. If not, just
# return None and let default backtrace printing occur.
@@ -189,9 +184,13 @@ def execute_frame_filters(frame, frame_low, frame_high):
frame_iterator = FrameIterator(frame)
- # Apply a basic frame decorator to all gdb.Frames. This unifies the
- # interface.
- frame_iterator = itertools.imap(FrameDecorator, frame_iterator)
+ # Apply a basic frame decorator to all gdb.Frames. This unifies
+ # the interface. Python 3.x moved the itertools.imap
+ # functionality to map(), so check if it is available.
+ if hasattr(itertools,"imap"):
+ frame_iterator = itertools.imap(FrameDecorator, frame_iterator)
+ else:
+ frame_iterator = map(FrameDecorator, frame_iterator)
for ff in sorted_list:
frame_iterator = ff.filter(frame_iterator)
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 5ac8e47..871c245 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1170,13 +1170,17 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
if (gdbpy_is_string (py_func))
{
- function = PyString_AsString (py_func);
+ char *function_to_free = NULL;
+
+ function = function_to_free =
+ python_string_to_host_string (py_func);
if (function == NULL)
{
Py_DECREF (py_func);
goto error;
}
+ make_cleanup (xfree, function_to_free);
}
else if (PyLong_Check (py_func))
{
@@ -1251,13 +1255,15 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
{
if (py_fn != Py_None)
{
- char *filename = PyString_AsString (py_fn);
+ char *filename = python_string_to_host_string (py_fn);
if (filename == NULL)
{
Py_DECREF (py_fn);
goto error;
}
+
+ make_cleanup (xfree, filename);
TRY_CATCH (except, RETURN_MASK_ALL)
{
ui_out_wrap_hint (out, " ");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index f4aa317..1fe01f4 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,16 @@
+2013-08-29 Phil Muldoon <pmuldoon@redhat.com>
+
+ * gdb.python/py-framefilter.py (FrameFilter.filter): Check
+ itertools for imap attribute. Otherwise use map().
+ (ElidingIterator): Define wrapper function __next__.
+ * gdb.python/py-framefilter-mi.exp: Do not use execfile,
+ use exec (open (read ())) instead.
+ * gdb.python/py-framefilter.exp: Ditto.
+ * gdb.python/py-arch.exp: Update print based test to Python 3.x
+ compliance.
+ * gdb.python/py-frame.exp: Ditto.
+ * gdb.python/py-type.exp: Ditto.
+
2013-08-28 Jan Kratochvil <jan.kratochvil@redhat.com>
PR gdb/15415
diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp
index 4e736b8..c0cada4 100644
--- a/gdb/testsuite/gdb.python/py-arch.exp
+++ b/gdb/testsuite/gdb.python/py-arch.exp
@@ -38,16 +38,16 @@ gdb_py_test_silent_cmd "python insn_list3 = arch.disassemble(pc, count=1)" \
gdb_py_test_silent_cmd "python insn_list4 = arch.disassemble(pc)" \
"disassemble no end no count" 0
-gdb_test "python print len(insn_list1)" "1" "test number of instructions 1"
-gdb_test "python print len(insn_list2)" "1" "test number of instructions 2"
-gdb_test "python print len(insn_list3)" "1" "test number of instructions 3"
-gdb_test "python print len(insn_list4)" "1" "test number of instructions 4"
+gdb_test "python print (len(insn_list1))" "1" "test number of instructions 1"
+gdb_test "python print (len(insn_list2))" "1" "test number of instructions 2"
+gdb_test "python print (len(insn_list3))" "1" "test number of instructions 3"
+gdb_test "python print (len(insn_list4))" "1" "test number of instructions 4"
gdb_py_test_silent_cmd "python insn = insn_list1\[0\]" "get instruction" 0
-gdb_test "python print \"addr\" in insn" "True" "test key addr"
-gdb_test "python print \"asm\" in insn" "True" "test key asm"
-gdb_test "python print \"length\" in insn" "True" "test key length"
+gdb_test "python print (\"addr\" in insn)" "True" "test key addr"
+gdb_test "python print (\"asm\" in insn)" "True" "test key asm"
+gdb_test "python print (\"length\" in insn)" "True" "test key length"
# Negative test
gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" \
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
index 806da94..63e4afb 100644
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
@@ -40,7 +40,7 @@ gdb_py_test_silent_cmd "python bf1 = gdb.selected_frame ()" "get frame" 0
# Test Frame.architecture() method.
gdb_py_test_silent_cmd "python show_arch_str = gdb.execute(\"show architecture\", to_string=True)" "show arch" 0
-gdb_test "python print bf1.architecture().name() in show_arch_str" "True" "test Frame.architecture()"
+gdb_test "python print (bf1.architecture().name() in show_arch_str)" "True" "test Frame.architecture()"
# First test that read_var is unaffected by PR 11036 changes.
gdb_test "python print (bf1.read_var(\"i\"))" "\"stuff\"" "test i"
diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
index 8228a91..68f3dd7 100644
--- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
+++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
@@ -46,7 +46,7 @@ mi_runto main
set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${pyfile}]
-mi_gdb_test "python execfile ('${remote_python_file}')" ".*\\^done." \
+mi_gdb_test "python exec (open ('${remote_python_file}').read ())" ".*\\^done." \
"Load python file"
# Multiple blocks test
diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp
index be5a479..0bf108b 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.exp
+++ b/gdb/testsuite/gdb.python/py-framefilter.exp
@@ -59,7 +59,7 @@ gdb_test_no_output "set python print-stack full" \
# Load global frame-filters
set remote_python_file [gdb_remote_download host \
${srcdir}/${subdir}/${testfile}.py]
-gdb_test_no_output "python execfile ('${remote_python_file}')" \
+gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
"Load python file"
gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"]
@@ -221,7 +221,7 @@ gdb_test_no_output "set python print-stack full" \
# Load global frame-filters
set remote_python_file [gdb_remote_download host \
${srcdir}/${subdir}/${testfile}.py]
-gdb_test_no_output "python execfile ('${remote_python_file}')" \
+gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
"Load python file for no debuginfo tests"
# Disable Reverse
diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py
index d31bbbe..e70db11 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.py
+++ b/gdb/testsuite/gdb.python/py-framefilter.py
@@ -70,8 +70,14 @@ class FrameFilter ():
gdb.frame_filters [self.name] = self
def filter (self, frame_iter):
- frame_iter = itertools.imap (Reverse_Function,
- frame_iter)
+ # Python 3.x moved the itertools.imap functionality to map(),
+ # so check if it is available.
+ if hasattr(itertools, "imap"):
+ frame_iter = itertools.imap (Reverse_Function,
+ frame_iter)
+ else:
+ frame_iter = map(Reverse_Function, frame_iter)
+
return frame_iter
class ElidingFrameDecorator(FrameDecorator):
@@ -102,6 +108,12 @@ class ElidingIterator:
elided = next(self.input_iterator)
return ElidingFrameDecorator(frame, [elided])
+ # Python 3.x requires __next__(self) while Python 2.x requires
+ # next(self). Define next(self), and for Python 3.x create this
+ # wrapper.
+ def __next__(self):
+ return self.next()
+
class FrameElider ():
def __init__ (self):
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
index 8e1f9ed..f6b1d96 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -65,7 +65,7 @@ proc test_fields {lang} {
if {$lang == "c++"} {
# Test usage with a class
- gdb_py_test_silent_cmd "print c" "print value (c)" 1
+ gdb_py_test_silent_cmd "print (c)" "print value (c)" 1
gdb_py_test_silent_cmd "python c = gdb.history (0)" "get value (c) from history" 1
gdb_py_test_silent_cmd "python fields = c.type.fields()" "get fields from c.type" 1
gdb_test "python print (len(fields))" "2" "Check number of fields (c)"
@@ -78,7 +78,7 @@ proc test_fields {lang} {
}
# Test normal fields usage in structs.
- gdb_py_test_silent_cmd "print st" "print value (st)" 1
+ gdb_py_test_silent_cmd "print (st)" "print value (st)" 1
gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1
gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields from st.type" 1
gdb_test "python print (len(fields))" "2" "Check number of fields (st)"
@@ -109,7 +109,7 @@ proc test_fields {lang} {
gdb_test "python print (not not st.type\['a'\].type)" "True"
# Test regression PR python/10805
- gdb_py_test_silent_cmd "print ar" "print value (ar)" 1
+ gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1
gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1
gdb_test "python fields = ar.type.fields()"
gdb_test "python print (len(fields))" "1" "Check the number of fields"
@@ -118,7 +118,7 @@ proc test_fields {lang} {
# Test gdb.Type.array.
gdb_test "python print (ar\[0\].cast(ar\[0\].type.array(1)))" \
".1, 2." "cast to array with one argument"
- gdb_test "python print ar\[0\].cast(ar\[0\].type.array(0, 1))" \
+ gdb_test "python print (ar\[0\].cast(ar\[0\].type.array(0, 1)))" \
".1, 2." "cast to array with two arguments"
gdb_test "python print (ar\[0\].type == ar\[0\].type)" "True"
@@ -126,26 +126,26 @@ proc test_fields {lang} {
# Test gdb.Type.vector.
# Note: vectors cast differently than arrays. Here ar[0] is replicated
# for the size of the vector.
- gdb_py_test_silent_cmd "print vec_data_1" "print value (vec_data_1)" 1
+ gdb_py_test_silent_cmd "print (vec_data_1)" "print value (vec_data_1)" 1
gdb_py_test_silent_cmd "python vec_data_1 = gdb.history (0)" "get value (vec_data_1) from history" 1
- gdb_py_test_silent_cmd "print vec_data_2" "print value (vec_data_2)" 1
+ gdb_py_test_silent_cmd "print (vec_data_2)" "print value (vec_data_2)" 1
gdb_py_test_silent_cmd "python vec_data_2 = gdb.history (0)" "get value (vec_data_2) from history" 1
gdb_py_test_silent_cmd "python vec1 = vec_data_1.cast(ar\[0\].type.vector(1))" "set vec1" 1
- gdb_test "python print vec1" ".1, 1." "cast to vector with one argument"
+ gdb_test "python print (vec1)" ".1, 1." "cast to vector with one argument"
gdb_py_test_silent_cmd "python vec2 = vec_data_1.cast(ar\[0\].type.vector(0, 1))" "set vec2" 1
- gdb_test "python print vec2" ".1, 1." "cast to vector with two arguments"
- gdb_test "python print vec1 == vec2" "True"
+ gdb_test "python print (vec2)" ".1, 1." "cast to vector with two arguments"
+ gdb_test "python print (vec1 == vec2)" "True"
gdb_py_test_silent_cmd "python vec3 = vec_data_2.cast(ar\[0\].type.vector(1))" "set vec3" 1
- gdb_test "python print vec1 == vec3" "False"
+ gdb_test "python print (vec1 == vec3)" "False"
}
}
proc test_enums {} {
with_test_prefix "test_enum" {
- gdb_py_test_silent_cmd "print e" "print value (e)" 1
- gdb_py_test_silent_cmd "python e = gdb.history (0)" "get value (e) from history" 1
+ gdb_py_test_silent_cmd "print (e)" "print value (e)" 1
+ gdb_py_test_silent_cmd "python (e) = gdb.history (0)" "get value (e) from history" 1
gdb_py_test_silent_cmd "python fields = e.type.fields()" "extract type fields from e" 1
gdb_test "python print (len(fields))" "3" "Check the number of enum fields"
gdb_test "python print (fields\[0\].name)" "v1" "Check enum field\[0\] name"
@@ -161,7 +161,7 @@ proc test_enums {} {
}
proc test_base_class {} {
with_test_prefix "test_base_class" {
- gdb_py_test_silent_cmd "print d" "print value (d)" 1
+ gdb_py_test_silent_cmd "print (d)" "print value (d)" 1
gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value (d) from history" 1
gdb_py_test_silent_cmd "python fields = d.type.fields()" "extract type fields from d" 1
gdb_test "python print (len(fields))" "3" "Check the number of fields"
@@ -174,7 +174,7 @@ proc test_range {} {
with_test_prefix "test_range" {
with_test_prefix "on ranged value" {
# Test a valid range request.
- gdb_py_test_silent_cmd "print ar" "print value (ar)" 1
+ gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1
gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1
gdb_test "python print (len(ar.type.range()))" "2" "Check correct tuple length"
gdb_test "python print (ar.type.range()\[0\])" "0" "Check range low bound"
@@ -183,7 +183,7 @@ proc test_range {} {
with_test_prefix "on ranged type" {
# Test a range request on a ranged type.
- gdb_py_test_silent_cmd "print ar" "print value (ar)" 1
+ gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1
gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1
gdb_py_test_silent_cmd "python fields = ar.type.fields()" "get fields" 1
gdb_test "python print (fields\[0\].type.range()\[0\])" "0" "Check range low bound"
@@ -192,7 +192,7 @@ proc test_range {} {
with_test_prefix "on unranged value" {
# Test where a range does not exist.
- gdb_py_test_silent_cmd "print st" "print value (st)" 1
+ gdb_py_test_silent_cmd "print (st)" "print value (st)" 1
gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1
gdb_test "python print (st.type.range())" "RuntimeError: This type does not have a range.*" "Check range for non ranged type."
}