public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/python: test exception case for gdb.solib_name
@ 2024-03-15 11:47 Andrew Burgess
  2024-03-15 12:39 ` Eli Zaretskii
  2024-03-15 13:16 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Burgess @ 2024-03-15 11:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

I noticed that gdb.solib_name() and Progspace.solib_name() were not
documented as being able to throw an exception, but in some cases it
is possible to get an exception from these functions.  An exception
can occur when the address argument can't be converted to an unsigned
integer.

This commit extends the documentation to mention the exception case,
and I've added a couple of tests to cover this case.

There's no changes to GDB itself in this commit.
---
 gdb/doc/python.texi                    | 10 ++++++++--
 gdb/testsuite/gdb.python/py-shared.exp | 15 +++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 4ca3ae4eca4..db681abfcd6 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -521,7 +521,11 @@
 
 @defun gdb.solib_name (address)
 Return the name of the shared library holding the given @var{address}
-as a string, or @code{None}.  This is identical to
+as a string, or @code{None} if there is no library containing
+@var{address}.  If @var{address} can't be converted to a unsigned
+integer address then an exception will be raised.
+
+This is identical to
 @code{gdb.current_progspace().solib_name(address)} and is included for
 historical compatibility.
 @end defun
@@ -5406,7 +5410,9 @@
 
 @defun Progspace.solib_name (address)
 Return the name of the shared library holding the given @var{address}
-as a string, or @code{None}.
+as a string, or @code{None} if there is no library containing
+@var{address}.  If @var{address} can't be converted to a unsigned
+integer address then an exception will be raised.
 @end defun
 
 @defun Progspace.objfile_for_address (address)
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'"]

base-commit: 9fe07b7f95fbfdaf34d5b69e6d73cae000b43eea
-- 
2.25.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-19 16:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15 11:47 [PATCH] gdb/python: test exception case for gdb.solib_name Andrew Burgess
2024-03-15 12:39 ` Eli Zaretskii
2024-03-15 13:16 ` Tom Tromey
2024-03-19  9:38   ` Andrew Burgess
2024-03-19 15:55     ` Tom Tromey
2024-03-19 16:04       ` Andrew Burgess

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).