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 D9CC33856DCD for ; Thu, 26 May 2022 15:56:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D9CC33856DCD Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-404-bHHeDjBoNC6bIg77i1l7uw-1; Thu, 26 May 2022 11:55:59 -0400 X-MC-Unique: bHHeDjBoNC6bIg77i1l7uw-1 Received: by mail-wr1-f70.google.com with SMTP id e24-20020a5d5958000000b0020ffd1d62b2so392393wri.17 for ; Thu, 26 May 2022 08:55:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=wAt8oGryxwpwDtwFzuowrR/qiOJ145EHBhO6tvNp29s=; b=w97na9DIobYYs8Rl84bJvHDuwFoGc/Yx5p3VZdYutQfFWj1oFfGo6kBa718Ke80oB8 W1VqDhlQ174MvaOpUu6MVJBL5NyM+9vwgAmviEcYBg+ic97A2RFup9PR1bz2FoDe+JgT xEaIC+GJjRosJQB61zv+N3oOC+wyxR6f6US1kFKOP42s9DL0DL/zC6TlyzJFkdCx5Q3W 2Swv2uBdVVi4eJAOtQa9csQM4WEbi2lddpVY/WvSKpJ4HJ3avOIiMrF822RttXnRZLwL xUzsw7ZFV/T8y3d41kbJz4CchTqgwtlGiXcRsINSrg1OED+ceBm4fQwSQpD+NoybmulT zJOA== X-Gm-Message-State: AOAM530QLcGjsGSlltGi82zMkJ4pw4CAhpfomRackxejB8wZ89jlNRu/ RArsBVOTWpDfy7RDCeuPlrPND07jMCJv8/X8syEkksVka7/NGBbYS05QLEmMdoh5hRBaqP1xPqG EC/cUqK8lcyAfzdEuZKZcew== X-Received: by 2002:a1c:4342:0:b0:397:5c97:7138 with SMTP id q63-20020a1c4342000000b003975c977138mr2932762wma.164.1653580557893; Thu, 26 May 2022 08:55:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2S5YEl6LGOgQ4KPjdPoU9oiy7Up6Tp+STLcUQXAXUWQoHXSrpCjy2Krjk+/6blSqEhhWBuw== X-Received: by 2002:a1c:4342:0:b0:397:5c97:7138 with SMTP id q63-20020a1c4342000000b003975c977138mr2932742wma.164.1653580557552; Thu, 26 May 2022 08:55:57 -0700 (PDT) Received: from localhost (host109-152-215-36.range109-152.btcentralplus.com. [109.152.215.36]) by smtp.gmail.com with ESMTPSA id a11-20020a056000188b00b0020fcaba73bcsm2440438wri.104.2022.05.26.08.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 08:55:56 -0700 (PDT) From: Andrew Burgess To: Ilya Leoshkevich , Tom Tromey Cc: Ulrich Weigand , Andreas Arnez , Pedro Alves , gdb-patches@sourceware.org, Ilya Leoshkevich Subject: Re: [PATCH 4/5] gdb.base/: Introduce jit-protocol-util.h In-Reply-To: <20220525223711.845475-5-iii@linux.ibm.com> References: <20220525223711.845475-1-iii@linux.ibm.com> <20220525223711.845475-5-iii@linux.ibm.com> Date: Thu, 26 May 2022 16:55:55 +0100 Message-ID: <87sfowgues.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=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 15:56:02 -0000 Ilya Leoshkevich writes: > 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. LGTM. Thanks, Andrew > --- > 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