From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kEjpFbpBlWIQVAkAWB0awg (envelope-from ) for ; Mon, 30 May 2022 18:14:18 -0400 Received: by simark.ca (Postfix, from userid 112) id 555011E221; Mon, 30 May 2022 18:14:18 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Vje7b6Jx; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 90B0B1E01D for ; Mon, 30 May 2022 18:14:17 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 40BE5384B12C for ; Mon, 30 May 2022 22:14:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40BE5384B12C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1653948857; bh=rdoRmyZNYKHGDcuWzgRAToRKD+GgEwcy/axS3+tThlk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Vje7b6JxZzspNZrDZmSKxTxWvGovBUozkBuIgek7h+AcWP+Cr5nOnuOpJpjkkDQ8U wY+xvHfOh6k99KBlTvUIS2nuQsPApTBRsaFWDGZIBJyoHX24a9RFEvQKPHZZmxwUiR GOWKvKVEf7lxVVoRqXIdiqA+PwqAPEsm1I7m1BLk= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 4BE8E3857BB1 for ; Mon, 30 May 2022 22:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4BE8E3857BB1 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24UMC0Iu020557; Mon, 30 May 2022 22:12:30 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gd6gpg051-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 22:12:30 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24UMCUvS022229; Mon, 30 May 2022 22:12:30 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gd6gpg04r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 22:12:29 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24UM7jrB019635; Mon, 30 May 2022 22:12:27 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 3gbc97tdfp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 22:12:27 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24UMCNLv19202312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 May 2022 22:12:23 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1DA204C046; Mon, 30 May 2022 22:12:23 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B27534C044; Mon, 30 May 2022 22:12:22 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.0.196]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 30 May 2022 22:12:22 +0000 (GMT) To: Tom Tromey , Andrew Burgess Subject: [PATCH v2 4/7] gdb.base/: Introduce jit-protocol-util.h Date: Tue, 31 May 2022 00:11:44 +0200 Message-Id: <20220530221147.1991835-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220530221147.1991835-1-iii@linux.ibm.com> References: <20220530221147.1991835-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Z8Chb9DiDv6FFz_0mX3aOIAAxE4AHhs_ X-Proofpoint-GUID: UXLVXjCR_nwJd1cZTOjUmGul5tfnzC0Q Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-05-30_10,2022-05-30_03,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2205300117 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: , From: Ilya Leoshkevich via Gdb-patches Reply-To: Ilya Leoshkevich Cc: Ulrich Weigand , Andreas Arnez , gdb-patches@sourceware.org, Pedro Alves , Ilya Leoshkevich Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" jit-elf-fork-main, jit-elf-main and jit-reader-host use the same boilerplate to register and unregister JITed code. Move it to a new header that can be shared with performance tests. --- gdb/testsuite/gdb.base/jit-elf-fork-main.c | 37 ++--------- gdb/testsuite/gdb.base/jit-elf-main.c | 37 ++--------- gdb/testsuite/gdb.base/jit-protocol-util.h | 74 ++++++++++++++++++++++ gdb/testsuite/gdb.base/jit-reader-host.c | 8 +-- 4 files changed, 84 insertions(+), 72 deletions(-) create mode 100644 gdb/testsuite/gdb.base/jit-protocol-util.h diff --git a/gdb/testsuite/gdb.base/jit-elf-fork-main.c b/gdb/testsuite/gdb.base/jit-elf-fork-main.c index 45792622548..96fadaa57b7 100644 --- a/gdb/testsuite/gdb.base/jit-elf-fork-main.c +++ b/gdb/testsuite/gdb.base/jit-elf-fork-main.c @@ -29,8 +29,8 @@ #include #include -#include "jit-protocol.h" #include "jit-elf-util.h" +#include "jit-protocol-util.h" static void usage (void) @@ -77,17 +77,7 @@ main (int argc, char *argv[]) struct jit_code_entry *const entry = calloc (1, sizeof (*entry)); entry->symfile_addr = (const char *)addr; entry->symfile_size = obj_size; - entry->prev_entry = __jit_debug_descriptor.relevant_entry; - __jit_debug_descriptor.relevant_entry = entry; - - if (entry->prev_entry != NULL) - entry->prev_entry->next_entry = entry; - else - __jit_debug_descriptor.first_entry = entry; - - /* Notify GDB. */ - __jit_debug_descriptor.action_flag = JIT_REGISTER; - __jit_debug_register_code (); + jit_push_back (entry); if (jit_function () != 42) { @@ -103,27 +93,8 @@ main (int argc, char *argv[]) i = 0; /* break after fork */ /* Now unregister them all in reverse order. */ - while (__jit_debug_descriptor.relevant_entry != NULL) - { - struct jit_code_entry *const entry = - __jit_debug_descriptor.relevant_entry; - struct jit_code_entry *const prev_entry = entry->prev_entry; - - if (prev_entry != NULL) - { - prev_entry->next_entry = NULL; - entry->prev_entry = NULL; - } - else - __jit_debug_descriptor.first_entry = NULL; - - /* Notify GDB. */ - __jit_debug_descriptor.action_flag = JIT_UNREGISTER; - __jit_debug_register_code (); - - __jit_debug_descriptor.relevant_entry = prev_entry; - free (entry); - } + while (!jit_empty ()) + free (jit_pop_back ()); return 0; /* break before return */ } diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c index 948530f3197..8f482748ee5 100644 --- a/gdb/testsuite/gdb.base/jit-elf-main.c +++ b/gdb/testsuite/gdb.base/jit-elf-main.c @@ -29,8 +29,8 @@ #include #include -#include "jit-protocol.h" #include "jit-elf-util.h" +#include "jit-protocol-util.h" static void usage (void) @@ -96,17 +96,7 @@ MAIN (int argc, char *argv[]) struct jit_code_entry *const entry = calloc (1, sizeof (*entry)); entry->symfile_addr = (const char *)addr; entry->symfile_size = obj_size; - entry->prev_entry = __jit_debug_descriptor.relevant_entry; - __jit_debug_descriptor.relevant_entry = entry; - - if (entry->prev_entry != NULL) - entry->prev_entry->next_entry = entry; - else - __jit_debug_descriptor.first_entry = entry; - - /* Notify GDB. */ - __jit_debug_descriptor.action_flag = JIT_REGISTER; - __jit_debug_register_code (); + jit_push_back (entry); if (jit_function () != 42) { @@ -118,27 +108,8 @@ MAIN (int argc, char *argv[]) WAIT_FOR_GDB; i = 0; /* gdb break here 1 */ /* Now unregister them all in reverse order. */ - while (__jit_debug_descriptor.relevant_entry != NULL) - { - struct jit_code_entry *const entry = - __jit_debug_descriptor.relevant_entry; - struct jit_code_entry *const prev_entry = entry->prev_entry; - - if (prev_entry != NULL) - { - prev_entry->next_entry = NULL; - entry->prev_entry = NULL; - } - else - __jit_debug_descriptor.first_entry = NULL; - - /* Notify GDB. */ - __jit_debug_descriptor.action_flag = JIT_UNREGISTER; - __jit_debug_register_code (); - - __jit_debug_descriptor.relevant_entry = prev_entry; - free (entry); - } + while (!jit_empty ()) + free (jit_pop_back ()); WAIT_FOR_GDB; return 0; /* gdb break here 2 */ } diff --git a/gdb/testsuite/gdb.base/jit-protocol-util.h b/gdb/testsuite/gdb.base/jit-protocol-util.h new file mode 100644 index 00000000000..d0a59518429 --- /dev/null +++ b/gdb/testsuite/gdb.base/jit-protocol-util.h @@ -0,0 +1,74 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright (C) 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Frequently used functions for testing JITed objects. */ + +#ifndef JIT_PROTOCOL_UTIL_H +#define JIT_PROTOCOL_UTIL_H + +#include "jit-protocol.h" +#include + +/* Return whether there are no registered JITed objects. */ +static int +jit_empty (void) +{ + return __jit_debug_descriptor.relevant_entry == NULL; +} + +/* Register JITed object. symfile_addr and symfile_size must be set. */ +static void +jit_push_back (struct jit_code_entry *entry) +{ + entry->prev_entry = __jit_debug_descriptor.relevant_entry; + __jit_debug_descriptor.relevant_entry = entry; + + if (entry->prev_entry != NULL) + entry->prev_entry->next_entry = entry; + else + __jit_debug_descriptor.first_entry = entry; + + /* Notify GDB. */ + __jit_debug_descriptor.action_flag = JIT_REGISTER; + __jit_debug_register_code (); +} + +/* Unregister the last registered JITed object. */ +static struct jit_code_entry * +jit_pop_back (void) +{ + struct jit_code_entry *const entry = __jit_debug_descriptor.relevant_entry; + struct jit_code_entry *const prev_entry = entry->prev_entry; + + if (prev_entry != NULL) + { + prev_entry->next_entry = NULL; + entry->prev_entry = NULL; + } + else + __jit_debug_descriptor.first_entry = NULL; + + /* Notify GDB. */ + __jit_debug_descriptor.action_flag = JIT_UNREGISTER; + __jit_debug_register_code (); + + __jit_debug_descriptor.relevant_entry = prev_entry; + + return entry; +} + +#endif /* JIT_PROTOCOL_UTIL_H */ diff --git a/gdb/testsuite/gdb.base/jit-reader-host.c b/gdb/testsuite/gdb.base/jit-reader-host.c index 0cca894a3a5..65f77b981d6 100644 --- a/gdb/testsuite/gdb.base/jit-reader-host.c +++ b/gdb/testsuite/gdb.base/jit-reader-host.c @@ -24,8 +24,8 @@ #include #include JIT_READER_H /* Please see jit-reader.exp for an explanation. */ +#include "jit-protocol-util.h" #include "jit-reader-host.h" -#include "jit-protocol.h" struct jit_code_entry only_entry; @@ -85,11 +85,7 @@ main (int argc, char **argv) only_entry.symfile_addr = symfile; only_entry.symfile_size = sizeof (struct jithost_abi); - __jit_debug_descriptor.first_entry = &only_entry; - __jit_debug_descriptor.relevant_entry = &only_entry; - __jit_debug_descriptor.action_flag = JIT_REGISTER; - __jit_debug_descriptor.version = 1; - __jit_debug_register_code (); + jit_push_back (&only_entry); function_stack_mangle (); function_add (5, 6); -- 2.35.3