From: Ilya Leoshkevich via Gdb-patches <gdb-patches@sourceware.org>
To: Tom Tromey <tromey@adacore.com>, Andrew Burgess <aburgess@redhat.com>
Cc: Ulrich Weigand <ulrich.weigand@de.ibm.com>,
Andreas Arnez <arnez@linux.ibm.com>,
gdb-patches@sourceware.org, Pedro Alves <pedro@palves.net>,
Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH v2 4/7] gdb.base/: Introduce jit-protocol-util.h
Date: Tue, 31 May 2022 00:11:44 +0200 [thread overview]
Message-ID: <20220530221147.1991835-5-iii@linux.ibm.com> (raw)
In-Reply-To: <20220530221147.1991835-1-iii@linux.ibm.com>
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 <sys/stat.h>
#include <unistd.h>
-#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 <sys/stat.h>
#include <unistd.h>
-#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 <http://www.gnu.org/licenses/>. */
+
+/* Frequently used functions for testing JITed objects. */
+
+#ifndef JIT_PROTOCOL_UTIL_H
+#define JIT_PROTOCOL_UTIL_H
+
+#include "jit-protocol.h"
+#include <stddef.h>
+
+/* 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 <sys/mman.h>
#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
next prev parent reply other threads:[~2022-05-30 22:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 22:11 [PATCH v2 0/7] gdb.perf/: Add JIT performance test Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 1/7] gdb.perf/: Fix tcl_string_list_to_python_list {x} Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 2/7] gdb.perf/: Add binary_link_with_shlibs setting to GenPerfTest Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 3/7] gdb.perf/: Allow adjusting GenPerfTest compile options Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` Ilya Leoshkevich via Gdb-patches [this message]
2022-05-30 22:11 ` [PATCH v2 5/7] gdb.base/: Introduce jit_compile_options Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 6/7] gdb.base/: Introduce n_jit_so_address Ilya Leoshkevich via Gdb-patches
2022-05-30 22:11 ` [PATCH v2 7/7] gdb.perf/: Add JIT performance test Ilya Leoshkevich via Gdb-patches
2022-06-22 8:48 ` [PING] [PATCH v2 0/7] " Ilya Leoshkevich via Gdb-patches
2022-08-03 10:52 ` [PING^2] " Ilya Leoshkevich via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220530221147.1991835-5-iii@linux.ibm.com \
--to=gdb-patches@sourceware.org \
--cc=aburgess@redhat.com \
--cc=arnez@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=pedro@palves.net \
--cc=tromey@adacore.com \
--cc=ulrich.weigand@de.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox