public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH 02/10] gdb/python: make the gdb.unwinder.Unwinder class more robust
Date: Mon, 03 Apr 2023 11:02:44 +0100	[thread overview]
Message-ID: <875yade117.fsf@redhat.com> (raw)
In-Reply-To: <f6b2e3a6-ae4f-80ce-fdfc-c1a0e188047e@simark.ca>

Simon Marchi <simark@simark.ca> writes:

> On 3/10/23 09:55, Andrew Burgess via Gdb-patches wrote:
>> This commit makes a few related changes to the gdb.unwinder.Unwinder
>> class attributes:
>> 
>>   1. The 'name' attribute is now a read-only attribute.  This prevents
>>   user code from changing the name after registering the unwinder.  It
>>   seems very unlikely that any user is actually trying to do this in
>>   the wild, so I'm not very worried that this will upset anyone,
>> 
>>   2. We now validate that the name is a string in the
>>   Unwinder.__init__ method, and throw an error if this is not the
>>   case.  Hopefully nobody was doing this in the wild.  This should
>>   make it easier to ensure the 'info unwinder' command shows sane
>>   output (how to display a non-string name for an unwinder?),
>> 
>>   3. The 'enabled' attribute is now implemented with a getter and
>>   setter.  In the setter we ensure that the new value is a boolean,
>>   but the real important change is that we call
>>   'gdb.invalidate_cached_frames()'.  This means that the backtrace
>>   will be updated if a user manually disables an unwinder (rather than
>>   calling the 'disable unwinder' command).  It is not unreasonable to
>>   think that a user might register multiple unwinders (relating to
>>   some project) and have one command that disables/enables all the
>>   related unwinders.  This command might operate by poking the enabled
>>   attribute of each unwinder object directly, after this commit, this
>>   would now work correctly.
>> 
>> There's tests for all the changes, and lots of documentation updates
>> that both cover the new changes, but also further improve (I think)
>> the general documentation for GDB's Unwinder API.
>
> Hi Andrew,
>
> With this commit, I see:
>
>     python global_test_unwinder.name = "foo"^M
>     Traceback (most recent call last):^M
>       File "<string>", line 1, in <module>^M
>     AttributeError: can't set attribute 'name'^M
>     Error while executing Python code.^M
>     (gdb) FAIL: gdb.python/py-unwind.exp: python global_test_unwinder.name = "foo"

Sorry about that.  Turns out that older version of Python don't include
the attribute name in the error message, I was seeing this:

     (gdb) python global_test_unwinder.name = "foo"
     Traceback (most recent call last):
       File "<string>", line 1, in <module>
     AttributeError: can't set attribute
     Error while executing Python code.
     (gdb)

I've updated the test pattern so either is acceptable.  I went ahead and
pushed this fix.

Thanks,
Andrew

---

commit 4c148f65fc148918d0be15607938770ad8c46e36
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Mon Apr 3 10:56:10 2023 +0100

    gdb/testsuite: fix failure in gdb.python/py-unwind.exp
    
    A potential test failure was introduced with commit:
    
      commit 6bf5f25bb150c0fbcb125e3ee466ba8f9680310b
      Date:   Wed Mar 8 16:11:30 2023 +0000
    
          gdb/python: make the gdb.unwinder.Unwinder class more robust
    
    In this commit a new test was added, however the expected output
    pattern varies depending on which Python version GDB is linked
    against.
    
    Older versions of Python result in output like this:
    
        (gdb) python global_test_unwinder.name = "foo"
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
        AttributeError: can't set attribute
        Error while executing Python code.
        (gdb)
    
    While more recent versions of Python give a similar, but slightly more
    verbose error message, like this:
    
        (gdb) python global_test_unwinder.name = "foo"
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
        AttributeError: can't set attribute 'name'
        Error while executing Python code.
        (gdb)
    
    The test was only accepting the first version of the output.  This
    commit extends the test pattern so that either version will be
    accepted.

diff --git a/gdb/testsuite/gdb.python/py-unwind.exp b/gdb/testsuite/gdb.python/py-unwind.exp
index fddf4f15393..d0a1960058b 100644
--- a/gdb/testsuite/gdb.python/py-unwind.exp
+++ b/gdb/testsuite/gdb.python/py-unwind.exp
@@ -107,7 +107,7 @@ check_info_unwinder "info unwinder after failed disable" on
 # 'register_unwinder'.
 gdb_test "python global_test_unwinder.name = \"foo\"" \
     [multi_line \
-	 "AttributeError: can't set attribute" \
+	 "AttributeError: can't set attribute(?: 'name')?" \
 	 "Error while executing Python code\\."]
 check_info_unwinder "info unwinder after failed name change" on
 


  reply	other threads:[~2023-04-03 10:02 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 14:55 [PATCH 00/10] Improvements & Cleanup For Python Unwinder API Andrew Burgess
2023-03-10 14:55 ` [PATCH 01/10] gdb/doc: spring clean the Python unwinders documentation Andrew Burgess
2023-03-10 15:24   ` Eli Zaretskii
2023-03-14  9:27     ` Andrew Burgess
2023-03-14 12:56       ` Eli Zaretskii
2023-03-16 14:30         ` Andrew Burgess
2023-03-10 14:55 ` [PATCH 02/10] gdb/python: make the gdb.unwinder.Unwinder class more robust Andrew Burgess
2023-03-10 15:32   ` Eli Zaretskii
2023-03-14 10:06     ` Andrew Burgess
2023-03-14 12:57       ` Eli Zaretskii
2023-03-31  2:15   ` Simon Marchi
2023-04-03 10:02     ` Andrew Burgess [this message]
2023-03-10 14:55 ` [PATCH 03/10] gdb/python: remove unneeded nullptr check in frapy_block Andrew Burgess
2023-03-10 14:55 ` [PATCH 04/10] gdb/python: add PENDING_FRAMEPY_REQUIRE_VALID macro in py-unwind.c Andrew Burgess
2023-03-10 14:55 ` [PATCH 05/10] gdb/python: add some additional methods to gdb.PendingFrame Andrew Burgess
2023-03-10 15:42   ` Eli Zaretskii
2023-03-14 10:18     ` Andrew Burgess
2023-03-14 12:59       ` Eli Zaretskii
2023-03-16 14:28         ` Andrew Burgess
2023-03-16 14:46           ` Eli Zaretskii
2023-03-16 17:26             ` Andrew Burgess
2023-03-16 19:54               ` Eli Zaretskii
2023-03-10 14:55 ` [PATCH 06/10] gdb/python: add __repr__ for PendingFrame and UnwindInfo Andrew Burgess
2023-03-10 14:55 ` [PATCH 07/10] gdb/python: remove Py_TPFLAGS_BASETYPE from gdb.UnwindInfo Andrew Burgess
2023-03-10 14:55 ` [PATCH 08/10] gdb: have value_as_address call unpack_pointer Andrew Burgess
2023-03-10 15:28   ` Tom Tromey
2023-03-10 22:08     ` Andrew Burgess
2023-03-10 14:55 ` [PATCH 09/10] gdb/python: Allow gdb.UnwindInfo to be created with non gdb.Value args Andrew Burgess
2023-03-10 15:34   ` Tom Tromey
2023-03-10 22:16     ` Andrew Burgess
2023-03-11 14:47       ` Tom Tromey
2023-03-10 15:38   ` Eli Zaretskii
2023-03-10 14:55 ` [PATCH 10/10] gdb/python: Add new gdb.unwinder.FrameId class Andrew Burgess
2023-03-10 15:36   ` Eli Zaretskii
2023-03-14 10:58     ` Andrew Burgess
2023-03-14 13:00       ` Eli Zaretskii
2023-03-29 16:27 ` [PATCH 00/10] Improvements & Cleanup For Python Unwinder API Tom Tromey

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=875yade117.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).