From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0A9543858CD1 for ; Tue, 19 Mar 2024 09:38:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A9543858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0A9543858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710841135; cv=none; b=MVDtdkzgdpKkIxBd58pmKP7YfSGn1JwV6HPCoV/Btx1sS1LQy+OdXUH7lBmgbhRR3xU5YzT/XKFLpZpPqYX0N5lFb9wZpy0xaLkoAf/hFLty39iRB6C9iLnGD/tNVkbYuy4YH+i9pYTMnAo7KyHTF80OBuyGyygt0bIS9dnTc5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710841135; c=relaxed/simple; bh=pRoZGj8P+28KPe+ZDGkxySHohZp9IJVLtDoR4zamgls=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nLWg3NmrIzjtAV5eQE/nFCrQInkHXPhCBgQNaAMBmidOQ44/EchgyLSa0j32upmPRZuDXkmynPJLEyjl5NGBv7XRP6Wf5X2i2CVjON+Jhw/of3MHr4bacigR1lpiS7/0y2JfaaGtPzlJBdIKLfSN91a+huTYkPzqraboCV5NHMU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710841132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D/muHQMl85cZ/MJippQ49ao3nQPvniFhKXhlMJGxwUw=; b=S3YdK3rh7V4RuZIZf17nWKYnGVuFnJQgdfyS9aWKWyb/tIa9DHqhtLf695+7eE5LslTwzM x82z1jKKmEkYvQSUsuC1kWbifzLrm5XdG+D2jyaZ887VYwSts5LJcwhLskRyqnclTkHnns xdOJKSVrvBicIFi5iP5pvKIrE/sxplo= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-264-88x2PexlMI2ImRs5djlDaw-1; Tue, 19 Mar 2024 05:38:51 -0400 X-MC-Unique: 88x2PexlMI2ImRs5djlDaw-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a46852c2239so253646566b.1 for ; Tue, 19 Mar 2024 02:38:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710841129; x=1711445929; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D/muHQMl85cZ/MJippQ49ao3nQPvniFhKXhlMJGxwUw=; b=wH3yJcLo4S7jTbr1tc4Q2ud6R/mvGW/ilTeyfBIXutLvCPgCfXk0Wgw0QTSXm6ij2G BpNOmSFh/9B+YRIwCxcuVkGNBb7feV0dxx6aGeNXAX0E7WKl4AAmBXfoCJqX8MWzDtrk zV1uezJl4YIACIZkNAb81N+XD0GfzPRhc3TaDW2LR1DSwvqEE8jAZ4utN6JwH9Q0jkdH sF5LE+e6eUFzcsxc3mbEgD1cTA3mLcvBkrSMoSgiIa2zpemEjvVDHnXji0ny7U4shX5l 8oEu4JfcxCYKpsmQ/KzUQuLg4/gAd4dvkmoSMFlI/ygSYLS+SGGpA+hH34g/X7DefZ51 fTaA== X-Gm-Message-State: AOJu0YyjAR91o098hxQeFmj/YhnhNsgQ1DFzC2NDPkHO6m8oaIeMcETo J+YvAKOu8rKkvi6HK/x473HvbeI1/uZ1QyHGwKXdnfQfRtKHVsho6yWuRWZCQVnZG3ynKrbmO6L xH2u/6FVt1QrpzQcae1/rBAd2DojaNnfNK1SYPDLcqUBhz1JoenMCYwG4o2Gua1LToDk= X-Received: by 2002:a17:906:7b8f:b0:a46:50ca:b318 with SMTP id s15-20020a1709067b8f00b00a4650cab318mr10687762ejo.16.1710841129219; Tue, 19 Mar 2024 02:38:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFety7OXB6gCS22ESR5pKOCVIKZG8hPwqMk1KMr+9lBGGDjMAsb5C48lvdHtGMYfcdpgDOSgw== X-Received: by 2002:a17:906:7b8f:b0:a46:50ca:b318 with SMTP id s15-20020a1709067b8f00b00a4650cab318mr10687746ejo.16.1710841128706; Tue, 19 Mar 2024 02:38:48 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id k13-20020a1709067acd00b00a46dd1f7dc1sm637774ejo.92.2024.03.19.02.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 02:38:48 -0700 (PDT) From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdb/python: test exception case for gdb.solib_name In-Reply-To: <87msqzk540.fsf@tromey.com> References: <856ee4315d2d615388efe8352b29379feefa4054.1710503245.git.aburgess@redhat.com> <87msqzk540.fsf@tromey.com> Date: Tue, 19 Mar 2024 09:38:47 +0000 Message-ID: <8734smv9w8.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tom Tromey writes: >>>>>> "Andrew" == Andrew Burgess 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 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 : 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 : 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 : invalid literal for int\\(\\) with base 10: 'string'" \ + "Error occurred in Python: invalid literal for int\\(\\) with base 10: 'string'"]