2002-04-20 Daniel Jacobowitz <drow@mvista.com>

* gdbserver/inferiors.c (struct inferior_info): Add regcache_data.
        (add_inferior): Call create_register_cache.
        (clear_inferiors): Call free_register_cache.
        (inferior_regcache_data, set_inferior_regcache_data): New functions.
        * gdbserver/regcache.c (struct inferior_regcache_data): New.
        (registers): Remove.
        (get_regcache): New function.
        (create_register_cache, free_register_cache): New functions.
        (set_register_cache): Don't initialize the register cache here.
        (registers_to_string, registers_from_string, register_data): Call
        get_regcache.
        * gdbserver/regcache.h: Add prototypes.
        * gdbserver/server.h: Likewise.
This commit is contained in:
Daniel Jacobowitz 2002-04-20 17:22:48 +00:00
parent 611cb4a542
commit c04a1aa88f
5 changed files with 91 additions and 6 deletions

View File

@ -1,3 +1,19 @@
2002-04-20 Daniel Jacobowitz <drow@mvista.com>
* gdbserver/inferiors.c (struct inferior_info): Add regcache_data.
(add_inferior): Call create_register_cache.
(clear_inferiors): Call free_register_cache.
(inferior_regcache_data, set_inferior_regcache_data): New functions.
* gdbserver/regcache.c (struct inferior_regcache_data): New.
(registers): Remove.
(get_regcache): New function.
(create_register_cache, free_register_cache): New functions.
(set_register_cache): Don't initialize the register cache here.
(registers_to_string, registers_from_string, register_data): Call
get_regcache.
* gdbserver/regcache.h: Add prototypes.
* gdbserver/server.h: Likewise.
2002-04-20 Daniel Jacobowitz <drow@mvista.com> 2002-04-20 Daniel Jacobowitz <drow@mvista.com>
* gdbserver/mem-break.c: New file. * gdbserver/mem-break.c: New file.

View File

@ -29,6 +29,7 @@ struct inferior_info
{ {
int pid; int pid;
void *target_data; void *target_data;
void *regcache_data;
struct inferior_info *next; struct inferior_info *next;
}; };
@ -52,6 +53,8 @@ add_inferior (int pid)
if (current_inferior == NULL) if (current_inferior == NULL)
current_inferior = inferiors; current_inferior = inferiors;
create_register_cache (new_inferior);
if (signal_pid == 0) if (signal_pid == 0)
signal_pid = pid; signal_pid = pid;
} }
@ -67,6 +70,8 @@ clear_inferiors (void)
if (inf->target_data) if (inf->target_data)
free (inf->target_data); free (inf->target_data);
if (inf->regcache_data)
free_register_cache (inf);
free (inf); free (inf);
inf = next_inf; inf = next_inf;
@ -86,3 +91,15 @@ set_inferior_target_data (struct inferior_info *inferior, void *data)
{ {
inferior->target_data = data; inferior->target_data = data;
} }
void *
inferior_regcache_data (struct inferior_info *inferior)
{
return inferior->regcache_data;
}
void
set_inferior_regcache_data (struct inferior_info *inferior, void *data)
{
inferior->regcache_data = data;
}

View File

@ -25,7 +25,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
static char *registers; struct inferior_regcache_data
{
char *registers;
};
static int register_bytes; static int register_bytes;
static struct reg *reg_defs; static struct reg *reg_defs;
@ -33,12 +37,47 @@ static int num_registers;
const char **gdbserver_expedite_regs; const char **gdbserver_expedite_regs;
static struct inferior_regcache_data *
get_regcache (struct inferior_info *inf)
{
struct inferior_regcache_data *regcache;
regcache = (struct inferior_regcache_data *) inferior_regcache_data (inf);
if (regcache == NULL)
fatal ("no register cache");
return regcache;
}
int int
registers_length (void) registers_length (void)
{ {
return 2 * register_bytes; return 2 * register_bytes;
} }
void
create_register_cache (struct inferior_info *inferior)
{
struct inferior_regcache_data *regcache;
regcache = malloc (sizeof (*regcache));
regcache->registers = malloc (register_bytes);
if (regcache->registers == NULL)
fatal ("Could not allocate register cache.");
set_inferior_regcache_data (inferior, regcache);
}
void
free_register_cache (struct inferior_info *inferior)
{
free (get_regcache (current_inferior)->registers);
free (get_regcache (current_inferior));
set_inferior_regcache_data (inferior, NULL);
}
void void
set_register_cache (struct reg *regs, int n) set_register_cache (struct reg *regs, int n)
{ {
@ -55,14 +94,13 @@ set_register_cache (struct reg *regs, int n)
} }
register_bytes = offset / 8; register_bytes = offset / 8;
registers = malloc (offset / 8);
if (!registers)
fatal ("Could not allocate register cache.");
} }
void void
registers_to_string (char *buf) registers_to_string (char *buf)
{ {
char *registers = get_regcache (current_inferior)->registers;
convert_int_to_ascii (registers, buf, register_bytes); convert_int_to_ascii (registers, buf, register_bytes);
} }
@ -70,6 +108,7 @@ void
registers_from_string (char *buf) registers_from_string (char *buf)
{ {
int len = strlen (buf); int len = strlen (buf);
char *registers = get_regcache (current_inferior)->registers;
if (len != register_bytes * 2) if (len != register_bytes * 2)
{ {
@ -119,6 +158,8 @@ register_size (int n)
char * char *
register_data (int n) register_data (int n)
{ {
char *registers = get_regcache (current_inferior)->registers;
return registers + (reg_defs[n].offset / 8); return registers + (reg_defs[n].offset / 8);
} }

View File

@ -21,6 +21,14 @@
#ifndef REGCACHE_H #ifndef REGCACHE_H
#define REGCACHE_H #define REGCACHE_H
/* Create a new register cache for INFERIOR. */
void create_register_cache (struct inferior_info *inferior);
/* Release all memory associated with the register cache for INFERIOR. */
void free_register_cache (struct inferior_info *inferior);
/* Convert all registers to a string in the currently specified remote /* Convert all registers to a string in the currently specified remote
format. */ format. */

View File

@ -54,6 +54,9 @@
least the size of a (void *). */ least the size of a (void *). */
typedef long long CORE_ADDR; typedef long long CORE_ADDR;
/* Opaque inferior process information. */
struct inferior_info;
#include "regcache.h" #include "regcache.h"
#include "gdb/signals.h" #include "gdb/signals.h"
@ -70,14 +73,14 @@ extern char *registers;
/* From inferiors.c. */ /* From inferiors.c. */
struct inferior_info;
extern struct inferior_info *current_inferior; extern struct inferior_info *current_inferior;
extern int signal_pid; extern int signal_pid;
void add_inferior (int pid); void add_inferior (int pid);
void clear_inferiors (void); void clear_inferiors (void);
void *inferior_target_data (struct inferior_info *); void *inferior_target_data (struct inferior_info *);
void set_inferior_target_data (struct inferior_info *, void *); void set_inferior_target_data (struct inferior_info *, void *);
void *inferior_regcache_data (struct inferior_info *);
void set_inferior_regcache_data (struct inferior_info *, void *);
/* Public variables in server.c */ /* Public variables in server.c */