mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2026-08-27 00:26:02 -04:00
gdb/amd-dbgapi-target: Move Linux code to amd-dbagapi-posix-hdep.c
The current amd-dbgapi-target.c file contains some code that is Linux specific. This patch extracts such code to host dependent files, so they can be replaced for other host platforms. The code in question is related to the event loop. The way dbgapi notifies GDB that there is a pending event is platform specific. For Linux (the only platform supported so far), this is done using a file descriptor GDB can use in its main event loop. This patch introduces an overall host-dependency infrastructure and moves the Linux-specific code to amd-dbgapi-posix-hdep.c. The "posix" naming is because even though only Linux is supported, the code is really plain POSIX code that would work on other POSIX platforms. This also follows the existing posix-hdep.c nomenclature. Co-Authored-By: Pedro Alves <pedro@palves.net> Change-Id: Id3d4b947176e5cfe91b0ab64376fca1a6a8c6fc9
This commit is contained in:
parent
8b752803cf
commit
c4aa08decd
6 changed files with 118 additions and 18 deletions
|
|
@ -1285,6 +1285,7 @@ HFILES_NO_SRCDIR = \
|
|||
amd64-nat.h \
|
||||
amd64-ravenscar-thread.h \
|
||||
amd64-tdep.h \
|
||||
amd-dbgapi-hdep.h \
|
||||
amd-dbgapi-target.h \
|
||||
amdgpu-tdep.h \
|
||||
annotate.h \
|
||||
|
|
@ -1792,6 +1793,7 @@ ALLDEPFILES = \
|
|||
alpha-netbsd-tdep.c \
|
||||
alpha-obsd-tdep.c \
|
||||
alpha-tdep.c \
|
||||
amd-dbgapi-posix-hdep.c \
|
||||
amd-dbgapi-target.c \
|
||||
amd64-bsd-nat.c \
|
||||
amd64-darwin-tdep.c \
|
||||
|
|
|
|||
34
gdb/amd-dbgapi-hdep.h
Normal file
34
gdb/amd-dbgapi-hdep.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* Host dependent utilities used by the amd-dbgapi target.
|
||||
|
||||
Copyright (C) 2024-2026 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GDB.
|
||||
|
||||
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/>. */
|
||||
|
||||
#ifndef GDB_AMD_DBGAPI_HDEP_H
|
||||
#define GDB_AMD_DBGAPI_HDEP_H
|
||||
|
||||
#include <amd-dbgapi/amd-dbgapi.h>
|
||||
|
||||
/* Null amd_dbgapi_notifier_t. */
|
||||
extern const amd_dbgapi_notifier_t null_amd_dbgapi_notifier;
|
||||
|
||||
/* Clear the notifier. */
|
||||
extern void amd_dbgapi_notifier_clear (amd_dbgapi_notifier_t notifier);
|
||||
|
||||
/* Get the file descriptor associated with the notifier. */
|
||||
extern int amd_dbgapi_notifier_get_fd (amd_dbgapi_notifier_t notifier);
|
||||
|
||||
#endif /* GDB_AMD_DBGAPI_HDEP_H */
|
||||
48
gdb/amd-dbgapi-posix-hdep.c
Normal file
48
gdb/amd-dbgapi-posix-hdep.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* Host dependent utilities for the amd-dbgapi target on POSIX.
|
||||
|
||||
Copyright (C) 2019-2026 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GDB.
|
||||
|
||||
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/>. */
|
||||
|
||||
#include "amd-dbgapi-hdep.h"
|
||||
#include <amd-dbgapi/amd-dbgapi.h>
|
||||
|
||||
/* See amd-dbgapi-hdep.h. */
|
||||
const amd_dbgapi_notifier_t null_amd_dbgapi_notifier = -1;
|
||||
|
||||
/* See amd-dbgapi-hdep.h. */
|
||||
|
||||
void
|
||||
amd_dbgapi_notifier_clear (amd_dbgapi_notifier_t notifier)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Drain the notifier pipe. */
|
||||
do
|
||||
{
|
||||
char buf;
|
||||
ret = read (notifier, &buf, 1);
|
||||
}
|
||||
while (ret >= 0 || (ret == -1 && errno == EINTR));
|
||||
}
|
||||
|
||||
/* See amd-dbgapi-hdep.h. */
|
||||
|
||||
int
|
||||
amd_dbgapi_notifier_get_fd (amd_dbgapi_notifier_t notifier)
|
||||
{
|
||||
return notifier;
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
|
||||
#include "amd-dbgapi-target.h"
|
||||
#include "amd-dbgapi-hdep.h"
|
||||
#include "amdgpu-tdep.h"
|
||||
#include "async-event.h"
|
||||
#include "breakpoint.h"
|
||||
|
|
@ -203,7 +204,7 @@ struct amd_dbgapi_inferior_info
|
|||
amd_dbgapi_process_id_t process_id = AMD_DBGAPI_PROCESS_NONE;
|
||||
|
||||
/* The amd_dbgapi_notifier_t for this inferior. */
|
||||
amd_dbgapi_notifier_t notifier = -1;
|
||||
amd_dbgapi_notifier_t notifier = null_amd_dbgapi_notifier;
|
||||
|
||||
/* The status of the inferior's runtime support. */
|
||||
amd_dbgapi_runtime_state_t runtime_state = AMD_DBGAPI_RUNTIME_STATE_UNLOADED;
|
||||
|
|
@ -1205,15 +1206,8 @@ dbgapi_notifier_handler (int err, gdb_client_data client_data)
|
|||
{
|
||||
amd_dbgapi_inferior_info &info
|
||||
= *static_cast<amd_dbgapi_inferior_info *> (client_data);
|
||||
int ret;
|
||||
|
||||
/* Drain the notifier pipe. */
|
||||
do
|
||||
{
|
||||
char buf;
|
||||
ret = read (info.notifier, &buf, 1);
|
||||
}
|
||||
while (ret >= 0 || (ret == -1 && errno == EINTR));
|
||||
amd_dbgapi_notifier_clear (info.notifier);
|
||||
|
||||
if (info.inf->target_is_pushed (&the_amd_dbgapi_target))
|
||||
{
|
||||
|
|
@ -1315,8 +1309,9 @@ amd_dbgapi_target::async (bool enable)
|
|||
{
|
||||
amd_dbgapi_inferior_info &info = get_amd_dbgapi_inferior_info (inf);
|
||||
|
||||
if (info.notifier != -1)
|
||||
add_file_handler (info.notifier, dbgapi_notifier_handler, &info,
|
||||
if (info.notifier != null_amd_dbgapi_notifier)
|
||||
add_file_handler (amd_dbgapi_notifier_get_fd (info.notifier),
|
||||
dbgapi_notifier_handler, &info,
|
||||
string_printf ("amd-dbgapi notifier for pid %d",
|
||||
inf->pid));
|
||||
}
|
||||
|
|
@ -1339,8 +1334,8 @@ amd_dbgapi_target::async (bool enable)
|
|||
const amd_dbgapi_inferior_info &info
|
||||
= get_amd_dbgapi_inferior_info (inf);
|
||||
|
||||
if (info.notifier != -1)
|
||||
delete_file_handler (info.notifier);
|
||||
if (info.notifier != null_amd_dbgapi_notifier)
|
||||
delete_file_handler (amd_dbgapi_notifier_get_fd (info.notifier));
|
||||
}
|
||||
|
||||
delete_async_event_handler (&amd_dbgapi_async_event_handler);
|
||||
|
|
@ -1879,7 +1874,8 @@ attach_amd_dbgapi (inferior *inf)
|
|||
}
|
||||
|
||||
amd_dbgapi_debug_printf ("process_id = %" PRIu64 ", notifier fd = %d",
|
||||
info.process_id.handle, info.notifier);
|
||||
info.process_id.handle,
|
||||
amd_dbgapi_notifier_get_fd (info.notifier));
|
||||
|
||||
set_process_memory_precision (info);
|
||||
|
||||
|
|
@ -1888,8 +1884,8 @@ attach_amd_dbgapi (inferior *inf)
|
|||
target. */
|
||||
dbgapi_notifier_handler (0, &info);
|
||||
|
||||
add_file_handler (info.notifier, dbgapi_notifier_handler, &info,
|
||||
"amd-dbgapi notifier");
|
||||
add_file_handler (amd_dbgapi_notifier_get_fd (info.notifier),
|
||||
dbgapi_notifier_handler, &info, "amd-dbgapi notifier");
|
||||
}
|
||||
|
||||
static void maybe_reset_amd_dbgapi ();
|
||||
|
|
@ -1917,8 +1913,8 @@ detach_amd_dbgapi (inferior *inf)
|
|||
warning (_("amd-dbgapi: could not detach from process %d (%s)"),
|
||||
inf->pid, get_status_string (status));
|
||||
|
||||
gdb_assert (info.notifier != -1);
|
||||
delete_file_handler (info.notifier);
|
||||
gdb_assert (info.notifier != null_amd_dbgapi_notifier);
|
||||
delete_file_handler (amd_dbgapi_notifier_get_fd (info.notifier));
|
||||
|
||||
/* This is a noop if the target is not pushed. */
|
||||
inf->unpush_target (&the_amd_dbgapi_target);
|
||||
|
|
|
|||
10
gdb/configure
vendored
10
gdb/configure
vendored
|
|
@ -25444,6 +25444,16 @@ $as_echo "#define HAVE_AMD_DBGAPI 1" >>confdefs.h
|
|||
if test "$all_targets" = true; then
|
||||
TARGET_OBS="$TARGET_OBS \$(ALL_AMD_DBGAPI_TARGET_OBS)"
|
||||
fi
|
||||
|
||||
# Add the host-specific objects.
|
||||
case ${gdb_host} in
|
||||
*linux*)
|
||||
gdb_host_obs="${gdb_host_obs} amd-dbgapi-posix-hdep.o"
|
||||
;;
|
||||
*)
|
||||
as_fn_error $? "amd-dbgapi not supported for host ${gdb_host}" "$LINENO" 5
|
||||
;;
|
||||
esac
|
||||
elif test "$gdb_require_amd_dbgapi" = true -o "$with_amd_dbgapi" = yes; then
|
||||
# amd-dbgapi was not found and...
|
||||
#
|
||||
|
|
|
|||
|
|
@ -341,6 +341,16 @@ if test "$gdb_require_amd_dbgapi" = true \
|
|||
if test "$all_targets" = true; then
|
||||
TARGET_OBS="$TARGET_OBS \$(ALL_AMD_DBGAPI_TARGET_OBS)"
|
||||
fi
|
||||
|
||||
# Add the host-specific objects.
|
||||
case ${gdb_host} in
|
||||
*linux*)
|
||||
gdb_host_obs="${gdb_host_obs} amd-dbgapi-posix-hdep.o"
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([amd-dbgapi not supported for host ${gdb_host}])
|
||||
;;
|
||||
esac
|
||||
elif test "$gdb_require_amd_dbgapi" = true -o "$with_amd_dbgapi" = yes; then
|
||||
# amd-dbgapi was not found and...
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue