From patchwork Tue Apr 4 17:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67270 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 AFC133858C5E for ; Tue, 4 Apr 2023 17:09:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFC133858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680628159; bh=yW7MhkMzoyopTFxaiZZKdmkZc2n8BWw/VfkgX9d2rfE=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QzxhzaB8YdZWesOg2tax040HAVAx3G4ObHknOp7azkfsdFPy3Qc45GjbgesBj8GRs V+Vg3NjWw/x2wQLGPCMTDLYVlaeVQCCQmm4BAa/NBxDUgoJ/uimw2ntXKdDUEcsyGX y4dUyv6b3IAIrgXxQSfBwkZ5fUrKv6LyQn5tDmEQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id DD2563858C5F for ; Tue, 4 Apr 2023 17:08:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD2563858C5F Received: by mail-il1-x135.google.com with SMTP id t5so6117205ilu.5 for ; Tue, 04 Apr 2023 10:08:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680628132; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yW7MhkMzoyopTFxaiZZKdmkZc2n8BWw/VfkgX9d2rfE=; b=Hb4QQRpmbIPA8CpZJlIEpDktLnK+AJ1cSkyRe8wtPKNAVzpgzZFf9IteQWOSzHz7iU mDTPhDBRQezV2jXq35hhP58rHtyvx/f/SilIM9dmlfhzCMfe+AzkWDp8X1oIz/0v/kSH Shem65CCYwmM/5aH9q26G8EB2/j7mTldnz+5J8KDeBWT1yTjLCHp/dpAF4936jEpGFoG Nn19hlnkKWSnOnH7qyLd16cxbRJIC1PKiGgXmvUrL0ApiTItPeEkfhn4328M0ip+VtGu /RAWMLRUO1Vm46TYMmyx5yEUGF8+mnMgbLX67ce8YAqBwFpkUTc+CCgWq3hN1GAHqGMj vpKA== X-Gm-Message-State: AAQBX9dDVarA50ejR+6AGsm+IVdRGbPt0QQEKqtjNeFPxxhQtZh7v8J9 TMP5PmGZFwnnPb1Zmsj2iVx8G+1WuIcjoM5+pd9f+w== X-Google-Smtp-Source: AKy350agh8FY6rhX6TzGUd8vF00FpKji5dmsUJt6WtiMaVUjMDem+CAxon+4tGfFfqlJNiNgytfsNg== X-Received: by 2002:a92:d5c8:0:b0:322:fe6b:d779 with SMTP id d8-20020a92d5c8000000b00322fe6bd779mr2257896ilq.29.1680628131945; Tue, 04 Apr 2023 10:08:51 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id f4-20020a02a104000000b0040b4c29010fsm1188306jag.140.2023.04.04.10.08.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 10:08:51 -0700 (PDT) Date: Tue, 04 Apr 2023 11:08:49 -0600 Subject: [PATCH 1/9] Use field_signed from Python MI commands MIME-Version: 1.0 Message-Id: <20230404-dap-loaded-sources-v1-1-75c796bd644b@adacore.com> References: <20230404-dap-loaded-sources-v1-0-75c796bd644b@adacore.com> In-Reply-To: <20230404-dap-loaded-sources-v1-0-75c796bd644b@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" If an MI command written in Python includes a number in its output, currently that is simply emitted as a string. However, it's convenient for a later patch if these are emitted using field_signed. This does not make a difference to ordinary MI clients. --- gdb/python/py-micmd.c | 15 +++++++++++++++ gdb/python/python-internal.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c index c7c5a609f56..09dd88ca268 100644 --- a/gdb/python/py-micmd.c +++ b/gdb/python/py-micmd.c @@ -293,6 +293,21 @@ serialize_mi_result_1 (PyObject *result, const char *field_name) } else { + if (PyLong_Check (result)) + { + int overflow = 0; + gdb_py_longest val = gdb_py_long_as_long_and_overflow (result, + &overflow); + if (PyErr_Occurred () != nullptr) + gdbpy_handle_exception (); + if (overflow == 0) + { + uiout->field_signed (field_name, val); + return; + } + /* Fall through to the string case on overflow. */ + } + gdb::unique_xmalloc_ptr string (gdbpy_obj_to_string (result)); if (string == nullptr) gdbpy_handle_exception (); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 258f5c42537..617bdb23669 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -110,6 +110,7 @@ typedef PY_LONG_LONG gdb_py_longest; typedef unsigned PY_LONG_LONG gdb_py_ulongest; #define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong +#define gdb_py_long_as_long_and_overflow PyLong_AsLongLongAndOverflow #else /* HAVE_LONG_LONG */ @@ -118,6 +119,7 @@ typedef unsigned PY_LONG_LONG gdb_py_ulongest; typedef long gdb_py_longest; typedef unsigned long gdb_py_ulongest; #define gdb_py_long_as_ulongest PyLong_AsUnsignedLong +#define gdb_py_long_as_long_and_overflow PyLong_AsLongAndOverflow #endif /* HAVE_LONG_LONG */