From patchwork Fri Mar 15 11:47:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 87236 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F1543857BA3 for ; Fri, 15 Mar 2024 11:48:24 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9D8383858D28 for ; Fri, 15 Mar 2024 11:47:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D8383858D28 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 9D8383858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710503283; cv=none; b=rIghfN3fgmPfLDfOX9NXsP+V7jrnWE6vuwbybs+eikMkoTc7RvlGu+A5DHhpn1U0gf3Xd4XVpmIfrUUspNGEnvRsjb4QQyMsOMJqMxp7ACUmYFqyJc+N9Guew+uU2L2lSmLvEtYMNkeZR05LWSIq+kaZmSrznH1LyeNUmHg5WJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710503283; c=relaxed/simple; bh=TS0xarPgFKHSph2iahZHhF8AVYIfgu6fa0vVUeFYdxI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EIlJP/PnJMWmnPdad31zNyimylnw3wtwXoTVH9OMN+yYcFyb/RDu1K6MfdGGas46T6D4MDz1ZyJIpeqIeGCNpmGrC5Bg/zoKMyB9PWSQZtV16iIxrXAXnT2nlIUrQI6xWDIyW/aKWNx7YiUJ3bRCCp24t5lyyVSEuh9F+Ev2/Oc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710503272; 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: content-transfer-encoding:content-transfer-encoding; bh=HzYUKifCC9ENSEa1LCpnRm19yeBoYSgJ1CNKxSqGArU=; b=itwsZVLie8NJiR0Oew1XHyxWYiTscUiL7RMqrwxTBUPN4vmK6/Ll1INIxLqXf1hntYLyP0 NxVeZO0lyL5zcrL3CQUCnsnz0v3BzoYW9AjR4ISoanBMTO0Fdrnu39Ol9BXUwDEY4DC4+W D0JWVhODkhdn36PCI6TP9NrSUfZpwrk= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-pqkvxSzSMECihRCxi83EGg-1; Fri, 15 Mar 2024 07:47:50 -0400 X-MC-Unique: pqkvxSzSMECihRCxi83EGg-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4131b4161dcso10710245e9.2 for ; Fri, 15 Mar 2024 04:47:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710503268; x=1711108068; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HzYUKifCC9ENSEa1LCpnRm19yeBoYSgJ1CNKxSqGArU=; b=hxymh9i/4zhWsz4Yl/BcuKeYc8xfxBtUlmeso2eNS2St5QrLrjJCLm09/NY12cItrX cVbF9UEaBy3mXJCV2XTsIVI3Yv4ZlWLo9TuiSFcSBzNx8cI8EvnMSuBCjmUBwL3rMqep ceAAy01gm2wzF7ll8bMGNm7sB+g7k0OSRuaPAQUJoH6GSSnBz9UcsuMB1E39/gPEvQlE RPjXe92cBTRmSJtDD6MtxehyfxRA626IfXa18rG0+0twzN/HHyEfiZhwHzKa3ZZjYp70 e0B2iyloUNoLaF9SlvwCuej5u1Et94gePlb3hNLVKzOKF57XOenCCWdLsglvB7+eoBCN /0zw== X-Gm-Message-State: AOJu0Yzt+3Vuy37rhKUrAhlyF+1memaOGXR7oWT/gESwFkSNjLTnslTN +eWtDtHs/IKuyVtKm9EJoBAjeXH0UYCtWxnc7reuhxExZgU8gx7gxqwH4b1fNi9v2E+yN4YsIZm P3uuBIUTOrqth2Z3B9X2/khhh/UzdBXJTdPXuwrzC2+NraSanqYRmdvAvPMCOT9wGKd3niZ1OMt vDXjm34CwkUEH1YB4W3jNHN7slPohzqR8QUmqPlFc/5do= X-Received: by 2002:a05:600c:1c14:b0:412:e50f:acaf with SMTP id j20-20020a05600c1c1400b00412e50facafmr2118985wms.24.1710503268198; Fri, 15 Mar 2024 04:47:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgS3wZ6VT12zeuDpUdafV7I7lGFwTXCG1Qv4uzgTCfh6Q+sh0xEerAF6PV1ANF/ratOfCxhQ== X-Received: by 2002:a05:600c:1c14:b0:412:e50f:acaf with SMTP id j20-20020a05600c1c1400b00412e50facafmr2118967wms.24.1710503267548; Fri, 15 Mar 2024 04:47:47 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id i9-20020a05600c354900b00413ef6826desm5559345wmq.4.2024.03.15.04.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 04:47:47 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb/python: test exception case for gdb.solib_name Date: Fri, 15 Mar 2024 11:47:45 +0000 Message-Id: <856ee4315d2d615388efe8352b29379feefa4054.1710503245.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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. Reviewed-By: Eli Zaretskii --- gdb/doc/python.texi | 10 ++++++++-- gdb/testsuite/gdb.python/py-shared.exp | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) base-commit: 9fe07b7f95fbfdaf34d5b69e6d73cae000b43eea 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 : 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'"]