From: Kevin Buettner <kevin@buettner.to>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 1/5] Extend test gdb.python/py-recurse-unwind.exp
Date: Wed, 02 Nov 2016 22:14:00 -0000 [thread overview]
Message-ID: <20161102151428.11d1d20e@pinnacle.lan> (raw)
In-Reply-To: <20161102151111.2462c806@pinnacle.lan>
This patch modifies the unwinder (sniffer) defined in
py-recurse-unwind.py so that, depending upon the value of one of its
class variables, it will take different paths through the code,
testing different functionality.
The original test attempted to obtain the value of an undefined
symbol.
This somewhat expanded test checks to see if 'pc' can be read via
gdb.PendingFrame.read_register() and also via gdb.parse_and_eval().
gdb/testsuite/ChangeLog:
* gdb.python/py-recurse-unwind.c (ccc): Delete.
(ccc0, ccc1, ccc2): New functions.
(bbb): Call ccc0, ccc1, and ccc2.
* gdb.python/py-recurse-unwind.py (TestUnwinder): Add calls
to read_register() and gdb.parse_and_eval(). Make each code
call a separate case that can be individually tested.
* gdb.python/py-recurse-unwind.exp (cont_and_backtrace): New
proc. Call cont_and_backtrace for each of the code paths that
we want to test in the unwinder.
---
gdb/testsuite/gdb.python/py-recurse-unwind.c | 16 ++++++-
gdb/testsuite/gdb.python/py-recurse-unwind.exp | 61 ++++++++++++++++----------
gdb/testsuite/gdb.python/py-recurse-unwind.py | 29 +++++++++---
3 files changed, 76 insertions(+), 30 deletions(-)
diff --git a/gdb/testsuite/gdb.python/py-recurse-unwind.c b/gdb/testsuite/gdb.python/py-recurse-unwind.c
index 02a835a..bd0330a 100644
--- a/gdb/testsuite/gdb.python/py-recurse-unwind.c
+++ b/gdb/testsuite/gdb.python/py-recurse-unwind.c
@@ -18,14 +18,26 @@
/* This is the test program loaded into GDB by the py-recurse-unwind test. */
void
-ccc (int arg)
+ccc0 (int arg)
+{
+}
+
+void
+ccc1 (int arg)
+{
+}
+
+void
+ccc2 (int arg)
{
}
void
bbb (int arg)
{
- ccc (789);
+ ccc0 (789);
+ ccc1 (789);
+ ccc2 (789);
}
void
diff --git a/gdb/testsuite/gdb.python/py-recurse-unwind.exp b/gdb/testsuite/gdb.python/py-recurse-unwind.exp
index 9629a97..ed5e600 100644
--- a/gdb/testsuite/gdb.python/py-recurse-unwind.exp
+++ b/gdb/testsuite/gdb.python/py-recurse-unwind.exp
@@ -45,29 +45,44 @@ if ![runto_main] then {
return 0
}
-gdb_breakpoint "ccc"
-gdb_continue_to_breakpoint "ccc"
-
-# If the unwinder is active, the usage count will increment while
-# running to the breakpoint. Reset it prior to doing the backtrace.
-gdb_test_no_output "python TestUnwinder.reset_count()"
-
-# The python based unwinder should be called a number of times while
-# generating the backtrace, but its sniffer always returns None. So
-# it doesn't really contribute to generating any of the frames below.
-#
-# But that's okay. Our goal here is to make sure that GDB doesn't
-# get hung up in potentially infinite recursion when invoking the
-# Python-based unwinder.
-
-gdb_test_sequence "bt" "backtrace" {
- "\\r\\n#0 .* ccc \\(arg=789\\) at "
- "\\r\\n#1 .* bbb \\(arg=456\\) at "
- "\\r\\n#2 .* aaa \\(arg=123\\) at "
- "\\r\\n#3 .* main \\(.*\\) at"
+proc cont_and_backtrace { tst func } {
+
+ gdb_breakpoint "$func"
+
+ # We're testing different code paths within the unwinder's sniffer.
+ # Set the current path to be tested here.
+ gdb_test_no_output "python TestUnwinder.set_test(\"$tst\")" \
+ "set code path within python unwinder to $tst"
+
+ # If the unwinder is active, the usage count will increment while
+ # running to the breakpoint. Reset it prior to doing the backtrace.
+ gdb_test_no_output "python TestUnwinder.reset_count()" \
+ "reset count for $tst"
+
+ gdb_continue_to_breakpoint "$func"
+
+ # The python based unwinder should be called a number of times while
+ # generating the backtrace, but its sniffer always returns None. So
+ # it doesn't really contribute to generating any of the frames below.
+ #
+ # But that's okay. Our goal here is to make sure that GDB doesn't
+ # get hung up in potentially infinite recursion when invoking the
+ # Python-based unwinder.
+
+ gdb_test_sequence "bt" "backtrace for $tst" {
+ "\\r\\n#0 .* ccc. \\(arg=789\\) at "
+ "\\r\\n#1 .* bbb \\(arg=456\\) at "
+ "\\r\\n#2 .* aaa \\(arg=123\\) at "
+ "\\r\\n#3 .* main \\(.*\\) at"
+ }
+
+ # Test that the python-based unwinder / sniffer was actually called
+ # during generation of the backtrace.
+ gdb_test "python print(TestUnwinder.count > 0)" "True" \
+ "python unwinder called for $tst"
}
-# Test that the python-based unwinder / sniffer was actually called
-# during generation of the backtrace.
-gdb_test "python print(TestUnwinder.count > 0)" "True"
+cont_and_backtrace "check_undefined_symbol" "ccc0"
+cont_and_backtrace "check_user_reg_pc" "ccc1"
+cont_and_backtrace "check_pae_pc" "ccc2"
diff --git a/gdb/testsuite/gdb.python/py-recurse-unwind.py b/gdb/testsuite/gdb.python/py-recurse-unwind.py
index 1da7aca..5eb87bb 100644
--- a/gdb/testsuite/gdb.python/py-recurse-unwind.py
+++ b/gdb/testsuite/gdb.python/py-recurse-unwind.py
@@ -40,13 +40,18 @@ class TestUnwinder(Unwinder):
def inc_count (cls):
cls.count += 1
+ test = 'check_undefined_symbol'
+
+ @classmethod
+ def set_test (cls, test) :
+ cls.test = test
+
def __init__(self):
Unwinder.__init__(self, "test unwinder")
self.recurse_level = 0
def __call__(self, pending_frame):
-
if self.recurse_level > 0:
gdb.write("TestUnwinder: Recursion detected - returning early.\n")
return None
@@ -54,11 +59,25 @@ class TestUnwinder(Unwinder):
self.recurse_level += 1
TestUnwinder.inc_count()
- try:
- val = gdb.parse_and_eval("undefined_symbol")
+ if TestUnwinder.test == 'check_user_reg_pc' :
+
+ pc = pending_frame.read_register('pc')
+ pc_as_int = int(pc.cast(gdb.lookup_type('int')))
+ # gdb.write("In unwinder: pc=%x\n" % pc_as_int)
+
+ elif TestUnwinder.test == 'check_pae_pc' :
+
+ pc = gdb.parse_and_eval('$pc')
+ pc_as_int = int(pc.cast(gdb.lookup_type('int')))
+ # gdb.write("In unwinder: pc=%x\n" % pc_as_int)
+
+ elif TestUnwinder.test == 'check_undefined_symbol' :
+
+ try:
+ val = gdb.parse_and_eval("undefined_symbol")
- except Exception as arg:
- pass
+ except Exception as arg:
+ pass
self.recurse_level -= 1
next prev parent reply other threads:[~2016-11-02 22:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-02 22:11 [PATCH v2 0/5] Prevent more recursion in python based unwinders Kevin Buettner
2016-11-02 22:14 ` Kevin Buettner [this message]
2016-11-09 13:59 ` [PATCH v2 1/5] Extend test gdb.python/py-recurse-unwind.exp Pedro Alves
2016-11-16 18:52 ` Kevin Buettner
2016-11-16 22:46 ` Sergio Durigan Junior
2016-11-17 15:27 ` Kevin Buettner
2016-11-02 22:16 ` [PATCH v2 3/5] Distinguish sentinel frame from null frame Kevin Buettner
2016-11-02 22:20 ` Kevin Buettner
2016-11-09 14:48 ` Pedro Alves
2016-11-16 18:54 ` Kevin Buettner
2016-11-02 22:19 ` [PATCH v2 3/5] Change meaning of VALUE_FRAME_ID; rename to VALUE_NEXT_FRAME_ID Kevin Buettner
2016-11-09 14:48 ` Pedro Alves
2016-11-16 19:08 ` Kevin Buettner
2016-11-02 22:23 ` [PATCH v2 4/5] Make gdb.PendingFrame.read_register handle "user" registers Kevin Buettner
2016-11-16 19:08 ` Kevin Buettner
2016-11-02 22:26 ` [PATCH v2 5/5] Stash frame id of current frame before stashing frame id for previous frame Kevin Buettner
2016-11-09 14:48 ` Pedro Alves
2016-11-16 19:07 ` Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161102151428.11d1d20e@pinnacle.lan \
--to=kevin@buettner.to \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox