[binutils-gdb] gdb/python: test exception case for gdb.solib_name

Andrew Burgess aburgess@sourceware.org
Tue Mar 19 16:04:02 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=52ca06e807be411af8cdfeafbe36a86e26c628af

commit 52ca06e807be411af8cdfeafbe36a86e26c628af
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.
    
    Approved-By: Tom Tromey <tom@tromey.com>

Diff:
---
 gdb/testsuite/gdb.python/py-shared.exp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

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'"]


More information about the Gdb-cvs mailing list