Compare commits

...

2 Commits

Author SHA1 Message Date
Christophe Lyon
68b4faa22a FDPIC WIP 2019-07-11 16:54:41 +02:00
Christophe Lyon
548c794021 ARM FDPIC: initial commit 2018-12-14 09:33:53 +00:00
18 changed files with 1465 additions and 8 deletions

View File

@@ -768,6 +768,7 @@ ALL_TARGET_OBS = \
solib-aix.o \
solib-darwin.o \
solib-dsbt.o \
solib-fdpic.o \
solib-frv.o \
solib-spu.o \
solib-svr4.o \

View File

@@ -25,6 +25,7 @@
#include "frame.h"
#include "regcache.h"
#include "solib-svr4.h"
#include "solib.h"
#include "osabi.h"
#include "regset.h"
#include "trad-frame.h"
@@ -1777,8 +1778,14 @@ arm_linux_init_abi (struct gdbarch_info info,
}
tdep->jb_elt_size = ARM_LINUX_JB_ELEMENT_SIZE;
#if 0
if (tdep->is_fdpic) {
set_solib_ops (gdbarch, &fdpic_so_ops);
} else {
#endif
set_solib_svr4_fetch_link_map_offsets
(gdbarch, svr4_ilp32_fetch_link_map_offsets);
// }
/* Single stepping. */
set_gdbarch_software_single_step (gdbarch, arm_linux_software_single_step);
@@ -1788,8 +1795,15 @@ arm_linux_init_abi (struct gdbarch_info info,
set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
/* Enable TLS support. */
#if 0
if (tdep->is_fdpic) {
set_gdbarch_fetch_tls_load_module_address (gdbarch,
fdpic_fetch_objfile_link_map);
} else {
#endif
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
// }
tramp_frame_prepend_unwinder (gdbarch,
&arm_linux_sigreturn_tramp_frame);

View File

@@ -8925,6 +8925,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
enum arm_float_model fp_model = arm_fp_model;
struct tdesc_arch_data *tdesc_data = NULL;
int i, is_m = 0;
int is_fdpic = 0;
int vfp_register_count = 0, have_vfp_pseudos = 0, have_neon_pseudos = 0;
int have_wmmx_registers = 0;
int have_neon = 0;
@@ -8957,10 +8958,13 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
anyway, so assume APCS. */
arm_abi = ARM_ABI_APCS;
}
else if (ei_osabi == ELFOSABI_NONE || ei_osabi == ELFOSABI_GNU)
else if (ei_osabi == ELFOSABI_NONE || ei_osabi == ELFOSABI_GNU || ei_osabi == ELFOSABI_ARM_FDPIC)
{
int eabi_ver = EF_ARM_EABI_VERSION (e_flags);
if (ei_osabi == ELFOSABI_ARM_FDPIC)
is_fdpic = 1;
switch (eabi_ver)
{
case EF_ARM_EABI_UNKNOWN:
@@ -9296,6 +9300,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
tdep->arm_abi = arm_abi;
tdep->fp_model = fp_model;
tdep->is_m = is_m;
tdep->is_fdpic = is_fdpic;
tdep->have_fpa_registers = have_fpa_registers;
tdep->have_wmmx_registers = have_wmmx_registers;
gdb_assert (vfp_register_count == 0

View File

@@ -113,6 +113,7 @@ struct gdbarch_tdep
int have_neon; /* Do we have a NEON unit? */
int is_m; /* Does the target follow the "M" profile. */
int is_fdpic; /* Is the loaded binary a fdpic one. */
CORE_ADDR lowest_pc; /* Lowest address at which instructions
will appear. */
@@ -297,4 +298,9 @@ extern struct target_desc *tdesc_arm_with_vfpv2;
extern struct target_desc *tdesc_arm_with_vfpv3;
extern struct target_desc *tdesc_arm_with_neon;
/* FDPIC structure and API. */
extern struct target_so_ops fdpic_so_ops;
extern CORE_ADDR fdpic_fetch_objfile_link_map (struct objfile *objfile);
extern CORE_ADDR fdpic_find_global_pointer (CORE_ADDR addr);
#endif /* arm-tdep.h */

View File

@@ -166,6 +166,12 @@ arm*-*-linux*)
solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
build_gdbserver=yes
;;
arm*-*-uclinuxfdpiceabi)
# Target: ARM based machine running GNU/Linux
gdb_target_obs="arch/arm-linux.o arm-linux-tdep.o glibc-tdep.o \
solib-svr4.o solib-fdpic.o symfile-mem.o linux-tdep.o linux-record.o"
# NO YET build_gdbserver=yes
;;
arm*-*-freebsd*)
# Target: FreeBSD/arm
gdb_target_obs="arm-fbsd-tdep.o"

View File

@@ -62,7 +62,7 @@ case "${target}" in
ipa_obj="${ipa_obj} linux-aarch64-tdesc-ipa.o"
ipa_obj="${ipa_obj} arch/aarch64-ipa.o"
;;
arm*-*-linux*) srv_regobj="reg-arm.o arm-with-iwmmxt.o"
arm*-*-linux*|arm*-*uclinuxfdpiceabi) srv_regobj="reg-arm.o arm-with-iwmmxt.o"
srv_regobj="${srv_regobj} arm-with-vfpv2.o"
srv_regobj="${srv_regobj} arm-with-vfpv3.o"
srv_regobj="${srv_regobj} arm-with-neon.o"

View File

@@ -94,6 +94,8 @@ gdb_flush_out_err ()
/* See server.h. */
void my_read_loadmap(const char*);
void my_hack_loadmap(const char*);
void
post_fork_inferior (int pid, const char *program)
{
@@ -107,12 +109,19 @@ post_fork_inferior (int pid, const char *program)
atexit (restore_old_foreground_pgrp);
#endif
fprintf(stderr, "GDBSERVER: %s before startup_inferior %s PID %d\n", __FUNCTION__, program, pid);
my_read_loadmap(__FUNCTION__);
my_hack_loadmap(__FUNCTION__);
startup_inferior (pid, START_INFERIOR_TRAPS_EXPECTED,
&cs.last_status, &cs.last_ptid);
fprintf(stderr, "GDBSERVER: %s after startup_inferior\n", __FUNCTION__);
my_read_loadmap(__FUNCTION__);
current_thread->last_resume_kind = resume_stop;
current_thread->last_status = cs.last_status;
signal_pid = pid;
target_post_create_inferior ();
fprintf(stderr, "GDBSERVER: %s after post_create_inferior\n", __FUNCTION__);
my_read_loadmap(__FUNCTION__);
fprintf (stderr, "Process %s created; pid = %d\n", program, pid);
fflush (stderr);
}

View File

@@ -120,11 +120,13 @@ struct arch_lwp_info
};
/* These are in <asm/elf.h> in current kernels. */
#ifndef __FDPIC__
#define HWCAP_VFP 64
#define HWCAP_IWMMXT 512
#define HWCAP_NEON 4096
#define HWCAP_VFPv3 8192
#define HWCAP_VFPv3D16 16384
#endif
#ifdef HAVE_SYS_REG_H
#include <sys/reg.h>

View File

@@ -995,6 +995,7 @@ linux_ptrace_fun ()
PROGRAM is the name of the program to be started, and PROGRAM_ARGS
are its arguments. */
void my_read_loadmap(const char* fnname);
static int
linux_create_inferior (const char *program,
const std::vector<char *> &program_args)
@@ -1004,6 +1005,8 @@ linux_create_inferior (const char *program,
int pid;
ptid_t ptid;
fprintf(stderr, "GDBSERVER: %s before fork_inferior\n", __FUNCTION__);
my_read_loadmap(__FUNCTION__);
{
maybe_disable_address_space_randomization restore_personality
(cs.disable_randomization);
@@ -1015,6 +1018,8 @@ linux_create_inferior (const char *program,
NULL, NULL, NULL, NULL);
}
fprintf(stderr, "GDBSERVER: %s after fork_inferior\n", __FUNCTION__);
my_read_loadmap(__FUNCTION__);
linux_add_process (pid, 0);
ptid = ptid_t (pid, pid, 0);
@@ -6517,6 +6522,30 @@ struct target_loadmap
# define LINUX_LOADMAP_INTERP PTRACE_GETFDPIC_INTERP
# endif
void my_read_loadmap(const char* fnname)
{
#if 0
struct target_loadmap *data = (struct target_loadmap *)0x7dffff38;
#ifdef __FDPIC__
fprintf(stderr, "GDBSERVER: %s from %s data forced %p version %d, nsegs=%d\n", __FUNCTION__, fnname, data, data->version, data->nsegs);
#else
fprintf(stderr, "GDBSERVER: %s from %s data forced %p, version/nsegs disabled\n", __FUNCTION__, fnname, data);
#endif
#endif
}
void my_hack_loadmap(const char* fnname)
{
#if 0
struct target_loadmap *data = (struct target_loadmap *)0x7dffff38;
#ifdef __FDPIC__
data->version = 1;
data->nsegs = 1;
fprintf(stderr, "GDBSERVER: %s from %s data forced %p version %d, nsegs=%d\n", __FUNCTION__, fnname, data, data->version, data->nsegs);
#else
fprintf(stderr, "GDBSERVER: %s from %s data forced %p disabled\n", __FUNCTION__, fnname, data);
#endif
#endif
}
static int
linux_read_loadmap (const char *annex, CORE_ADDR offset,
unsigned char *myaddr, unsigned int len)
@@ -6533,20 +6562,25 @@ linux_read_loadmap (const char *annex, CORE_ADDR offset,
else
return -1;
fprintf(stderr, "GDBSERVER: %s before ptrace %s\n", __FUNCTION__, annex);
if (ptrace (LINUX_LOADMAP, pid, addr, &data) != 0)
return -1;
fprintf(stderr, "GDBSERVER: %s ptrace OK data %p\n", __FUNCTION__, data);
if (data == NULL)
return -1;
fprintf(stderr, "GDBSERVER: %s data OK, data %p version %d, nsegs=%d\n", __FUNCTION__, data, data->version, data->nsegs);
actual_length = sizeof (struct target_loadmap)
+ sizeof (struct target_loadseg) * data->nsegs;
if (offset < 0 || offset > actual_length)
return -1;
fprintf(stderr, "GDBSERVER: %s actual_length %d\n", __FUNCTION__, actual_length);
copy_length = actual_length - offset < len ? actual_length - offset : len;
memcpy (myaddr, (char *) data + offset, copy_length);
fprintf(stderr, "GDBSERVER: %s copy_length=%d\n", __FUNCTION__, copy_length);
return copy_length;
}
#else

View File

@@ -221,6 +221,7 @@ handle_accept_event (int err, gdb_client_data client_data)
threads' status ('?'). */
target_async (0);
// fprintf(stderr, "GDBSERVER: %s returns 0\n", __FUNCTION__);
return 0;
}
@@ -325,6 +326,7 @@ remote_prepare (const char *name)
cs.transport_is_reliable = 1;
}
void my_read_loadmap(const char*);
/* Open a connection to a remote debugger.
NAME is the filename used for communication. */
@@ -334,6 +336,7 @@ remote_open (const char *name)
const char *port_str;
port_str = strchr (name, ':');
fprintf(stderr, "GDBSERVER: %s name |%s| port_str %s\n", __FUNCTION__, name, port_str);
#ifdef USE_WIN32API
if (port_str == NULL)
error ("Only HOST:PORT is supported on this platform.");
@@ -413,12 +416,14 @@ remote_open (const char *name)
gai_strerror (r));
else
fprintf (stderr, _("Listening on port %s\n"), listen_port);
my_read_loadmap(__FUNCTION__);
fflush (stderr);
/* Register the event loop handler. */
add_file_handler (listen_desc, handle_accept_event, NULL);
}
// fprintf(stderr, "GDBSERVER: %s returns\n", __FUNCTION__);
}
void
@@ -957,6 +962,7 @@ process_remaining (void *context)
else
res = 0;
// fprintf(stderr, "GDBSERVER: %s returns %d\n", __FUNCTION__, res);
return res;
}

View File

@@ -2057,6 +2057,7 @@ handle_qxfer (char *own_buf, int packet_len, int *new_packet_len_p)
*new_packet_len_p = write_qxfer_response (own_buf, data, n, 0);
free (data);
// fprintf(stderr, "GDBSERVER: %s packet size n %d\n", __FUNCTION__, n);
return 1;
}
else if (strcmp (rw, "write") == 0)
@@ -3577,7 +3578,9 @@ captured_main (int argc, char *argv[])
const char *selftest_filter = NULL;
#endif
// printf("GDBSERVER HELLO\n");
current_directory = getcwd (NULL, 0);
// printf("GDBSERVER HELLO2 CWD=%s\n", current_directory);
client_state &cs = get_client_state ();
if (current_directory == NULL)
@@ -3588,6 +3591,7 @@ captured_main (int argc, char *argv[])
while (*next_arg != NULL && **next_arg == '-')
{
fprintf(stderr, "GDBSERVER: %s next_arg %s\n", __FUNCTION__, *next_arg);
if (strcmp (*next_arg, "--version") == 0)
{
gdbserver_version ();
@@ -3725,6 +3729,7 @@ captured_main (int argc, char *argv[])
if (port == NULL)
{
port = *next_arg;
fprintf(stderr, "GDBSERVER: %s port %s\n", __FUNCTION__, port);
next_arg++;
}
if ((port == NULL || (!attach && !multi_mode && *next_arg == NULL))
@@ -3746,6 +3751,7 @@ captured_main (int argc, char *argv[])
start_inferior. */
if (port != NULL)
remote_prepare (port);
fprintf(stderr, "GDBSERVER: %s port after remote_prepare %s\n", __FUNCTION__, port);
bad_attach = 0;
pid = 0;
@@ -3805,6 +3811,7 @@ captured_main (int argc, char *argv[])
program_args.push_back (xstrdup (next_arg[i]));
program_args.push_back (NULL);
fprintf(stderr, "GDBSERVER: %s port before create_inferior %s\n", __FUNCTION__, port);
/* Wait till we are at first instruction in program. */
create_inferior (program_path.get (), program_args);
@@ -3841,6 +3848,7 @@ captured_main (int argc, char *argv[])
if (!was_running && !multi_mode)
error ("No program to debug");
fprintf(stderr, "GDBSERVER: %s port before remote_open %s\n", __FUNCTION__, port);
while (1)
{
cs.noack_mode = 0;
@@ -4378,6 +4386,7 @@ process_serial_event (void)
if (exit_requested)
return -1;
// fprintf(stderr, "GDBSERVER: %s returns 0\n", __FUNCTION__);
return 0;
}

View File

@@ -66,6 +66,7 @@
#endif
#include "pathmax.h"
#include <stdio.h>
/* In this file, PATH_MAX only serves as a threshold for choosing among two
algorithms. */
@@ -212,6 +213,8 @@ __getcwd (char *buf, size_t size)
rootdev = st.st_dev;
rootino = st.st_ino;
// printf("TOTO GDB: thisdev %d thisino %d\n", thisdev, thisino);
// printf("TOTO GDB: rootdev %d rootino %d\n", rootdev, rootino);
while (!(thisdev == rootdev && thisino == rootino))
{
struct dirent *d;
@@ -223,6 +226,7 @@ __getcwd (char *buf, size_t size)
size_t namlen;
bool use_d_ino = true;
// printf("TOTO GDB: going up\n");
/* Look at the parent directory. */
#if HAVE_OPENAT_SUPPORT
fd = openat (fd, "..", O_RDONLY);
@@ -249,6 +253,7 @@ __getcwd (char *buf, size_t size)
dotdev = st.st_dev;
dotino = st.st_ino;
mount_point = dotdev != thisdev;
// printf("TOTO GDB: mount_point: %d dotdev %d dotino %d\n", mount_point, dotdev, dotino);
/* Search for the last directory. */
#if HAVE_OPENAT_SUPPORT
@@ -267,6 +272,7 @@ __getcwd (char *buf, size_t size)
/* Clear errno to distinguish EOF from error if readdir returns
NULL. */
__set_errno (0);
// printf("TOTO GDB before readdir\n");
d = __readdir (dirstream);
/* When we've iterated through all directory entries without finding
@@ -278,11 +284,13 @@ __getcwd (char *buf, size_t size)
via lstat. */
if (d == NULL && errno == 0 && use_d_ino)
{
// printf("TOTO GDB weird: d=%p errno=%d\n", d, errno);
use_d_ino = false;
rewinddir (dirstream);
d = __readdir (dirstream);
}
// printf("TOTO GDB: d=%p errno=%d name %s\n", d, errno, d != NULL ? d->d_name : "null");
if (d == NULL)
{
if (errno == 0)

View File

@@ -28,6 +28,7 @@
#include "signals-state-save-restore.h"
#include "gdb_tilde_expand.h"
#include <vector>
#include "nat/linux-ptrace.h"
extern char **environ;

View File

@@ -24,7 +24,7 @@ struct buffer;
#include "gdb_wait.h"
#ifdef __UCLIBC__
#if !(defined(__UCLIBC_HAS_MMU__) || defined(__ARCH_HAS_MMU__))
#if !(defined(__UCLIBC_HAS_MMU__) || defined(__ARCH_USE_MMU__))
/* PTRACE_TEXT_ADDR and friends. */
#include <asm/ptrace.h>
#define HAS_NOMMU
@@ -83,7 +83,8 @@ struct buffer;
#define PTRACE_O_EXITKILL 0x00100000
#endif
#if (defined __bfin__ || defined __frv__ || defined __sh__) \
#if (defined __bfin__ || defined __frv__ || defined __sh__ \
|| defined __arm__ ) \
&& !defined PTRACE_GETFDPIC
#define PTRACE_GETFDPIC 31
#define PTRACE_GETFDPIC_EXEC 0

View File

@@ -1920,6 +1920,9 @@ packet_ok (const char *buf, struct packet_config *config)
{
enum packet_result result;
fprintf (stderr,
"GDB: %s Packet %s (%s)\n", __FUNCTION__,
config->name, config->title);
if (config->detect != AUTO_BOOLEAN_TRUE
&& config->support == PACKET_DISABLE)
internal_error (__FILE__, __LINE__,
@@ -4570,6 +4573,7 @@ remote_target::start_remote (int from_tty, int extended_p)
{
const char v_mustreplyempty[] = "vMustReplyEmpty";
fprintf(stderr, "GDB: %s 'v' must-reply-empty\n", __FUNCTION__);
putpkt (v_mustreplyempty);
getpkt (&rs->buf, &rs->buf_size, 0);
if (strcmp (rs->buf, "OK") == 0)
@@ -5374,6 +5378,8 @@ remote_target::remote_query_supported ()
}
for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
{
// fprintf(stderr, "GDB: %s comparing %s with %s\n", __FUNCTION__, remote_protocol_features[i].name, p);
if (strcmp (remote_protocol_features[i].name, p) == 0)
{
const struct protocol_feature *feature;
@@ -5383,6 +5389,7 @@ remote_target::remote_query_supported ()
feature->func (this, feature, is_supported, value);
break;
}
}
}
/* If we increased the packet size, make sure to increase the global
@@ -10798,6 +10805,10 @@ remote_target::remote_read_qxfer (const char *object_name,
struct remote_state *rs = get_remote_state ();
LONGEST i, n, packet_len;
if (!strcmp(object_name, "fdpic")) {
if (packet_config_support (packet) == PACKET_DISABLE)
fprintf(stderr, "GDB: %s DISABLED\n", __FUNCTION__);
}
if (packet_config_support (packet) == PACKET_DISABLE)
return TARGET_XFER_E_IO;
@@ -10837,6 +10848,9 @@ remote_target::remote_read_qxfer (const char *object_name,
if (packet_len < 0 || packet_ok (rs->buf, packet) != PACKET_OK)
return TARGET_XFER_E_IO;
if (!strcmp(object_name, "fdpic")) {
fprintf(stderr, "GDB: %s apres getpkt fdpic packet_len %ld\n", __FUNCTION__, packet_len);
}
if (rs->buf[0] != 'l' && rs->buf[0] != 'm')
error (_("Unknown remote qXfer reply: %s"), rs->buf);

1339
gdb/solib-fdpic.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -22,13 +22,15 @@
#include "gdbcore.h"
#include "solib.h"
#include "solist.h"
#include "frv-tdep.h"
//#include "frv-tdep.h" /* For frv_fdpic_loadmap_addresses() */
int frv_fdpic_loadmap_addresses (struct gdbarch *gdbarch,
CORE_ADDR *interp_addr, CORE_ADDR *exec_addr);
#include "objfiles.h"
#include "symtab.h"
#include "language.h"
#include "command.h"
#include "gdbcmd.h"
#include "elf/frv.h"
//#include "elf/frv.h" /* Used in find_canonical_descriptor_in_load_object() */
#include "gdb_bfd.h"
/* Flag which indicates whether internal debug messages should be printed. */
@@ -1083,7 +1085,7 @@ find_canonical_descriptor_in_load_object
this address (which is a GOT entry) to obtain a descriptor
address. */
if ((name == 0 || strcmp (name, (*rel->sym_ptr_ptr)->name) == 0)
&& rel->howto->type == R_FRV_FUNCDESC)
/*&& rel->howto->type == R_FRV_FUNCDESC*/)
{
gdb_byte buf [FRV_PTR_SIZE];

View File

@@ -168,7 +168,7 @@ int remote_timeout = 2;
/* Non-zero tells remote* modules to output debugging info. */
int remote_debug = 0;
int remote_debug = 0/*1*/;
/* Sbrk location on entry to main. Used for statistics only. */
#ifdef HAVE_USEFUL_SBRK