public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/python: test exception case for gdb.solib_name
Date: Tue, 19 Mar 2024 09:38:47 +0000	[thread overview]
Message-ID: <8734smv9w8.fsf@redhat.com> (raw)
In-Reply-To: <87msqzk540.fsf@tromey.com>

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> I noticed that gdb.solib_name() and Progspace.solib_name() were not
> Andrew> documented as being able to throw an exception, but in some cases it
> Andrew> is possible to get an exception from these functions.  An exception
> Andrew> can occur when the address argument can't be converted to an unsigned
> Andrew> integer.
>
> Andrew> This commit extends the documentation to mention the exception case,
> Andrew> and I've added a couple of tests to cover this case.
>
> Maybe the Basic Python node should have a note explaining that there's a
> general rule allowing for type errors and the like.

I think you are right, such general exception cases probably don't need
documenting.

I still think it's worth testing these cases though.

How about the patch below, there's no documentation changes, just adding
a couple of additional tests.

Thanks,
Andrew

---

commit cb695b43ec06bf5b222272f76066b8f546f6ab1e
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Fri Mar 15 11:14:05 2024 +0000

    gdb/python: test exception case for gdb.solib_name
    
    The gdb.solib_name() and Progspace.solib_name() functions can throw an
    exception if the address argument is not a valid address, but this is
    not currently tested.
    
    This commit adds a couple of tests to check that exceptions are thrown
    correctly.
    
    An early version of this commit updated the documentation, but it was
    pointed out that lots of functions throw an exception if passed an
    argument of the wrong type, and we don't document all of these, it's
    kind-of assumed that passing an object of the incorrect type might
    result in an exception, so this updated version leaves the docs alone,
    but I do think adding the extra tests has value.
    
    There's no changes to GDB itself in this commit.

diff --git a/gdb/testsuite/gdb.python/py-shared.exp b/gdb/testsuite/gdb.python/py-shared.exp
index 6faa6cde521..9be5aa467e2 100644
--- a/gdb/testsuite/gdb.python/py-shared.exp
+++ b/gdb/testsuite/gdb.python/py-shared.exp
@@ -64,3 +64,18 @@ gdb_test "python print (gdb.solib_name(int(main)))" "None" "test main solib loca
 if {[is_lp64_target]} {
     gdb_test "python print (len(\[gdb.solib_name(0xffffffffffffffff)\]))" "1"
 }
+
+gdb_test "python print(gdb.solib_name(-1))" \
+    [multi_line \
+	 "Python Exception <class 'OverflowError'>: can't convert negative int to unsigned" \
+	 "Error occurred in Python: can't convert negative int to unsigned"]
+
+gdb_test "python print(gdb.current_progspace().solib_name(-1))" \
+    [multi_line \
+	 "Python Exception <class 'OverflowError'>: can't convert negative int to unsigned" \
+	 "Error occurred in Python: can't convert negative int to unsigned"]
+
+gdb_test "python print(gdb.current_progspace().solib_name(\"string\"))" \
+    [multi_line \
+	 "Python Exception <class 'ValueError'>: invalid literal for int\\(\\) with base 10: 'string'" \
+	 "Error occurred in Python: invalid literal for int\\(\\) with base 10: 'string'"]


  reply	other threads:[~2024-03-19  9:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15 11:47 Andrew Burgess
2024-03-15 12:39 ` Eli Zaretskii
2024-03-15 13:16 ` Tom Tromey
2024-03-19  9:38   ` Andrew Burgess [this message]
2024-03-19 15:55     ` Tom Tromey
2024-03-19 16:04       ` Andrew Burgess

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=8734smv9w8.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).