From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 54F7E3858CDB for ; Thu, 18 May 2023 20:18:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54F7E3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-33818ccd411so19372365ab.1 for ; Thu, 18 May 2023 13:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684441089; x=1687033089; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Gk+BALlw0ifxM8gxs1OA3S00f5IfYDlxLuF/J/2edVI=; b=j5zBj3shjRUB1u5DRkol3a6nxAHYHjxvjUsu7KX2WygCIyI7clPP4xS8ZKSnuHCO8C n6UNvRzj5dOW/sm1LIvQT3DAK0mO/a/1LLUKGOp8gsKDKLY2zBOYTBU3ovJEHWMFGoxL 0mvVTDLd5Eun/h9wnK8JsWU1HEriCSqBiC21OIgT8cJBAW6cP/QSqmEppd48YLlauIzz JLBHHkcsw7i5zwQ944WfbVesUA6dN12eKlbFujBbQalexx3EpUOF33LLtG2ZIeimeK6A xOfso70B7xw3StYhYpJP7ZzfEHEeao4I3/Euql0axKNJjL4KSJBcC8Gvio19V3DlOC+m Vrng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684441089; x=1687033089; 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=Gk+BALlw0ifxM8gxs1OA3S00f5IfYDlxLuF/J/2edVI=; b=AU1Nw8nPyR/bnlZEeX8M6EcszavH+U/q1100pHSgQNBM+6a0mTUsjKh8s5/V0V5cxv ThqfjS1Pz0JcYONGQ8rwNTbSEAxSS6H6ypbON3vRuXNzjlKvUUnDYCU8ogZjrK8p3Sjv lDV1+apf1o3wjZjWGii4V6N6dgegCIFJlKw+mk2Atk0hfKkEkXXWbjomrHg3J7L/755O D2SwanNSTGBT4IGdRSYlgW8PmK0EZeeKaKkgWgjk2YyycdoF6xcLLagzl1Y1U28bqDeY k/1jZ4yrl+CNpmTx5hyxIHhntzW4j5mGSAHQu5+rfOqUMb9GU7haHOfpXlZyCtcbpVNC 5DdQ== X-Gm-Message-State: AC+VfDywZgDGByhyP+wCG+yvpC/sD9BW+Wz9154m0bW/PkTKYxkmZywG S0uhdoDyZpU8/TCyYJRLNCP+wkpAuvRJsafjm1lDWg== X-Google-Smtp-Source: ACHHUZ4liVEf4XQG0dItGQ29RPYnHj0RKUruNlPOuFQjgrOekEzh1zz2TxMjdVo21HOI5UdwILGHbA== X-Received: by 2002:a92:db03:0:b0:331:a2f5:b50d with SMTP id b3-20020a92db03000000b00331a2f5b50dmr5681076iln.30.1684441089593; Thu, 18 May 2023 13:18:09 -0700 (PDT) Received: from localhost.localdomain (75-166-157-55.hlrn.qwest.net. [75.166.157.55]) by smtp.gmail.com with ESMTPSA id i9-20020a05663813c900b00418ba399842sm703087jaj.13.2023.05.18.13.18.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 13:18:09 -0700 (PDT) From: Tom Tromey Date: Thu, 18 May 2023 14:18:07 -0600 Subject: [PATCH v2 1/9] Use field_signed from Python MI commands MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230404-dap-loaded-sources-v2-1-93f229095e03@adacore.com> References: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com> In-Reply-To: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.0 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,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: 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 e86807d049f..d7d95918cb4 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 dbd33570a78..1142e0e739d 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 */ -- 2.40.0