* callback.h: Deleted, moved to ../include.

* callback.c: Deleted, moved to ../sim/common.
	* Makefile.in (SFILES,COMMON_OBJS): Delete callback.[co].
	(callback.o): Delete rule.
	* remote-sim.h: No longer include callback.h
	(sim_callback_write_stdout): Delete prototype.
	* remote-sim.c (init_callbacks,end_callbacks): New functions.
	(gdb_os_write_stdout, gdb_os_printf_filtered): New functions.
	(gdb_callback, callbacks_initialized): New static globals.
	(gdbsim_open): Call init_callbacks.
	(gdbsim_close): Call end_callbacks.
	(simulator_command): Call init_callbacks.
This commit is contained in:
David Edelsohn 1996-11-20 08:55:42 +00:00
parent 9d10b92d2a
commit 4da8b2a5f4
6 changed files with 112 additions and 430 deletions

View File

@ -158,8 +158,6 @@ breakpoint.c
breakpoint.h breakpoint.h
buildsym.c buildsym.c
buildsym.h buildsym.h
callback.c
callback.h
c-exp.y c-exp.y
c-lang.c c-lang.c
c-lang.h c-lang.h

View File

@ -1,3 +1,18 @@
Wed Nov 20 00:43:09 1996 Doug Evans <dje@canuck.cygnus.com>
* callback.h: Deleted, moved to ../include.
* callback.c: Deleted, moved to ../sim/common.
* Makefile.in (SFILES,COMMON_OBJS): Delete callback.[co].
(callback.o): Delete rule.
* remote-sim.h: No longer include callback.h
(sim_callback_write_stdout): Delete prototype.
* remote-sim.c (init_callbacks,end_callbacks): New functions.
(gdb_os_write_stdout, gdb_os_printf_filtered): New functions.
(gdb_callback, callbacks_initialized): New static globals.
(gdbsim_open): Call init_callbacks.
(gdbsim_close): Call end_callbacks.
(simulator_command): Call init_callbacks.
start-sanitize-gdbtk start-sanitize-gdbtk
Tue Nov 19 09:26:14 1996 Tom Tromey <tromey@cygnus.com> Tue Nov 19 09:26:14 1996 Tom Tromey <tromey@cygnus.com>

View File

@ -1,368 +0,0 @@
/* Host callback routines for GDB.
Copyright 1995 Free Software Foundation, Inc.
Contributed by Cygnus Support.
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* This file provides a standard way for targets to talk to the host OS
level.
This interface will probably need a bit more banging to make it
smooth. Currently the simulator uses this file to provide the
callbacks for itself when it's built standalone, which is rather
ugly. */
#ifndef INSIDE_SIMULATOR
#include "defs.h"
#endif
#include "ansidecl.h"
#include "callback.h"
#ifdef ANSI_PROTOTYPES
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
static int os_init PARAMS ((host_callback *));
static int os_shutdown PARAMS ((host_callback *));
static int os_unlink PARAMS ((host_callback *, const char *));
static long os_time PARAMS ((host_callback *, long *));
static int os_system PARAMS ((host_callback *, const char *));
static int os_rename PARAMS ((host_callback *, const char *, const char *));
static int os_write_stdout PARAMS ((host_callback *, const char *, int));
static int os_write PARAMS ((host_callback *, int, const char *, int));
static int os_read_stdin PARAMS ((host_callback *, char *, int));
static int os_read PARAMS ((host_callback *, int, char *, int));
static int os_open PARAMS ((host_callback *, const char *, int));
static int os_lseek PARAMS ((host_callback *, int, long, int));
static int os_isatty PARAMS ((host_callback *, int));
static int os_get_errno PARAMS ((host_callback *));
static int os_close PARAMS ((host_callback *, int));
static int fdmap PARAMS ((host_callback *, int));
static int fdbad PARAMS ((host_callback *, int));
static int wrap PARAMS ((host_callback *, int));
/* Set the callback copy of errno from what we see now. */
static int
wrap (p, val)
host_callback *p;
int val;
{
p->last_errno = errno;
return val;
}
/* Make sure the FD provided is ok. If not, return non-zero
and set errno. */
static int
fdbad (p, fd)
host_callback *p;
int fd;
{
if (fd < 0 || fd > MAX_CALLBACK_FDS || !p->fdopen[fd])
{
p->last_errno = EINVAL;
return -1;
}
return 0;
}
static int
fdmap (p, fd)
host_callback *p;
int fd;
{
return p->fdmap[fd];
}
static int
os_close (p, fd)
host_callback *p;
int fd;
{
int result;
result = fdbad (p, fd);
if (result)
return result;
result = wrap (p, close (fdmap (p, fd)));
return result;
}
static int
os_get_errno (p)
host_callback *p;
{
/* !!! fixme, translate from host to taget errno value */
return p->last_errno;
}
static int
os_isatty (p, fd)
host_callback *p;
int fd;
{
int result;
result = fdbad (p, fd);
if (result)
return result;
result = wrap (p, isatty (fdmap (p, fd)));
return result;
}
static int
os_lseek (p, fd, off, way)
host_callback *p;
int fd;
long off;
int way;
{
int result;
result = fdbad (p, fd);
if (result)
return result;
result = lseek (fdmap (p, fd), off, way);
return result;
}
static int
os_open (p, name, flags)
host_callback *p;
const char *name;
int flags;
{
int i;
for (i = 0; i < MAX_CALLBACK_FDS; i++)
{
if (!p->fdopen[i])
{
int f = open (name, flags);
if (f < 0)
{
p->last_errno = errno;
return f;
}
p->fdopen[i] = 1;
p->fdmap[i] = f;
return i;
}
}
p->last_errno = EMFILE;
return -1;
}
static int
os_read (p, fd, buf, len)
host_callback *p;
int fd;
char *buf;
int len;
{
int result;
result = fdbad (p, fd);
if (result)
return result;
result = wrap (p, read (fdmap (p, fd), buf, len));
return result;
}
static int
os_read_stdin (p, buf, len)
host_callback *p;
char *buf;
int len;
{
return wrap (p, read (0, buf, len));
}
static int
os_write (p, fd, buf, len)
host_callback *p;
int fd;
const char *buf;
int len;
{
int result;
result = fdbad (p, fd);
if (result)
return result;
result = wrap (p, write (fdmap (p, fd), buf, len));
return result;
}
/* ignore the grossness of INSIDE_SIMULATOR, it will go away one day. */
static int
os_write_stdout (p, buf, len)
host_callback *p;
const char *buf;
int len;
{
#ifdef INSIDE_SIMULATOR
return os_write (p, 1, buf, len);
#else
int i;
char b[2];
for (i = 0; i< len; i++)
{
b[0] = buf[i];
b[1] = 0;
if (target_output_hook)
target_output_hook (b);
else
fputs_filtered (b, gdb_stdout);
}
return len;
#endif
}
static int
os_rename (p, f1, f2)
host_callback *p;
const char *f1;
const char *f2;
{
return wrap (p, rename (f1, f2));
}
static int
os_system (p, s)
host_callback *p;
const char *s;
{
return wrap (p, system (s));
}
static long
os_time (p, t)
host_callback *p;
long *t;
{
return wrap (p, time (t));
}
static int
os_unlink (p, f1)
host_callback *p;
const char *f1;
{
return wrap (p, unlink (f1));
}
static int
os_shutdown (p)
host_callback *p;
{
int i;
for (i = 0; i < MAX_CALLBACK_FDS; i++)
{
if (p->fdopen[i] && !p->alwaysopen[i]) {
close (p->fdmap[i]);
p->fdopen[i] = 0;
}
}
return 1;
}
static int
os_init(p)
host_callback *p;
{
int i;
os_shutdown (p);
for (i= 0; i < 3; i++)
{
p->fdmap[i] = i;
p->fdopen[i] = 1;
p->alwaysopen[i] = 1;
}
return 1;
}
/* !!fixme!!
This bit is ugly. When the interface has settled down I'll
move the whole file into sim/common and remove this bit. */
/* VARARGS */
static void
#ifdef ANSI_PROTOTYPES
os_printf_filtered (host_callback *p, const char *format, ...)
#else
os_printf_filtered (p, va_alist)
host_callback *p;
va_dcl
#endif
{
va_list args;
#ifdef ANSI_PROTOTYPES
va_start (args, format);
#else
char *format;
va_start (args);
format = va_arg (args, char *);
#endif
#ifdef INSIDE_SIMULATOR
vprintf (format, args);
#else
vfprintf_filtered (stdout, format, args);
#endif
va_end (args);
}
host_callback default_callback =
{
os_close,
os_get_errno,
os_isatty,
os_lseek,
os_open,
os_read,
os_read_stdin,
os_rename,
os_system,
os_time,
os_unlink,
os_write,
os_write_stdout,
os_shutdown,
os_init,
os_printf_filtered,
0, /* last errno */
};

View File

@ -1,41 +0,0 @@
#ifndef CALLBACK_H
#define CALLBACK_H
typedef struct host_callback_struct host_callback;
#define MAX_CALLBACK_FDS 10
struct host_callback_struct
{
int (*close) PARAMS ((host_callback *,int));
int (*get_errno) PARAMS ((host_callback *));
int (*isatty) PARAMS ((host_callback *, int));
int (*lseek) PARAMS ((host_callback *, int, long , int));
int (*open) PARAMS ((host_callback *, const char*, int mode));
int (*read) PARAMS ((host_callback *,int, char *, int));
int (*read_stdin) PARAMS (( host_callback *, char *, int));
int (*rename) PARAMS ((host_callback *, const char *, const char *));
int (*system) PARAMS ((host_callback *, const char *));
long (*time) PARAMS ((host_callback *, long *));
int (*unlink) PARAMS ((host_callback *, const char *));
int (*write) PARAMS ((host_callback *,int, const char *, int));
int (*write_stdout) PARAMS ((host_callback *, const char *, int));
/* Used when the target has gone away, so we can close open
handles and free memory etc etc. */
int (*shutdown) PARAMS ((host_callback *));
int (*init) PARAMS ((host_callback *));
/* Talk to the user on a console. */
void (*printf_filtered) PARAMS ((host_callback *, const char *, ...));
int last_errno; /* host format */
int fdmap[MAX_CALLBACK_FDS];
char fdopen[MAX_CALLBACK_FDS];
char alwaysopen[MAX_CALLBACK_FDS];
};
#endif
extern host_callback default_callback;

View File

@ -1,5 +1,5 @@
/* Generic remote debugging interface for simulators. /* Generic remote debugging interface for simulators.
Copyright 1993, 1994 Free Software Foundation, Inc. Copyright 1993, 1994, 1996 Free Software Foundation, Inc.
Contributed by Cygnus Support. Contributed by Cygnus Support.
Steve Chamberlain (sac@cygnus.com). Steve Chamberlain (sac@cygnus.com).
@ -32,14 +32,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "terminal.h" #include "terminal.h"
#include "target.h" #include "target.h"
#include "gdbcore.h" #include "gdbcore.h"
#include "callback.h"
#include "remote-sim.h" #include "remote-sim.h"
#include "remote-utils.h" #include "remote-utils.h"
#include "callback.h"
/* Prototypes */ /* Prototypes */
static void dump_mem PARAMS ((char *buf, int len)); static void dump_mem PARAMS ((char *buf, int len));
static void init_callbacks PARAMS ((void));
static void end_callbacks PARAMS ((void));
static int gdb_os_write_stdout PARAMS ((host_callback *, const char *, int));
static void gdb_os_printf_filtered PARAMS ((host_callback *, const char *, ...));
static void gdbsim_fetch_register PARAMS ((int regno)); static void gdbsim_fetch_register PARAMS ((int regno));
static void gdbsim_store_register PARAMS ((int regno)); static void gdbsim_store_register PARAMS ((int regno));
@ -76,7 +84,6 @@ static void simulator_command PARAMS ((char *args, int from_tty));
/* Naming convention: /* Naming convention:
sim_* are the interface to the simulator (see remote-sim.h). sim_* are the interface to the simulator (see remote-sim.h).
sim_callback_* are the stuff which the simulator can see inside GDB.
gdbsim_* are stuff which is internal to gdb. */ gdbsim_* are stuff which is internal to gdb. */
/* Forward data declarations */ /* Forward data declarations */
@ -109,6 +116,87 @@ dump_mem (buf, len)
} }
} }
static host_callback gdb_callback;
static int callbacks_initialized = 0;
/* Initialize gdb_callback. */
static void
init_callbacks ()
{
if (! callbacks_initialized)
{
gdb_callback = default_callback;
default_callback.init (&gdb_callback);
default_callback.write_stdout = gdb_os_write_stdout;
default_callback.printf_filtered = gdb_os_printf_filtered;
sim_set_callbacks (&gdb_callback);
callbacks_initialized = 1;
}
}
/* Release callbacks (free resources used by them). */
static void
end_callbacks ()
{
if (callbacks_initialized)
{
gdb_callback.shutdown (&gdb_callback);
callbacks_initialized = 0;
}
}
/* GDB version of os_write_stdout callback. */
static int
gdb_os_write_stdout (p, buf, len)
host_callback *p;
const char *buf;
int len;
{
int i;
char b[2];
for (i = 0; i < len; i++)
{
b[0] = buf[i];
b[1] = 0;
if (target_output_hook)
target_output_hook (b);
else
fputs_filtered (b, gdb_stdout);
}
return len;
}
/* GDB version of printf_filtered callback. */
/* VARARGS */
static void
#ifdef ANSI_PROTOTYPES
gdb_os_printf_filtered (host_callback *p, const char *format, ...)
#else
gdb_os_printf_filtered (p, va_alist)
host_callback *p;
va_dcl
#endif
{
va_list args;
#ifdef ANSI_PROTOTYPES
va_start (args, format);
#else
char *format;
va_start (args);
format = va_arg (args, char *);
#endif
vfprintf_filtered (stdout, format, args);
va_end (args);
}
static void static void
gdbsim_fetch_register (regno) gdbsim_fetch_register (regno)
int regno; int regno;
@ -255,8 +343,7 @@ gdbsim_open (args, from_tty)
if (sr_get_debug ()) if (sr_get_debug ())
printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)"); printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)");
sim_set_callbacks (&default_callback); init_callbacks ();
default_callback.init (&default_callback);
sim_open (args); sim_open (args);
@ -284,6 +371,8 @@ gdbsim_close (quitting)
program_loaded = 0; program_loaded = 0;
sim_close (quitting); sim_close (quitting);
end_callbacks ();
} }
/* Takes a program previously attached to and detaches it. /* Takes a program previously attached to and detaches it.
@ -451,8 +540,7 @@ simulator_command (args, from_tty)
{ {
/* The user may give a command before the simulator is opened, so /* The user may give a command before the simulator is opened, so
ensure that the callbacks have been set up. */ ensure that the callbacks have been set up. */
sim_set_callbacks (&default_callback); init_callbacks ();
default_callback.init (&default_callback);
sim_do_command (args); sim_do_command (args);
} }

View File

@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if !defined (REMOTE_SIM_H) #if !defined (REMOTE_SIM_H)
#define REMOTE_SIM_H 1 #define REMOTE_SIM_H 1
#include "callback.h"
/* This file is used when building stand-alone simulators, so isolate this /* This file is used when building stand-alone simulators, so isolate this
file from gdb. */ file from gdb. */
@ -37,14 +36,11 @@ typedef CORE_ADDR_TYPE SIM_ADDR;
The simulator may use the following callbacks (gdb routines) which the The simulator may use the following callbacks (gdb routines) which the
standalone program must provide. standalone program must provide.
void printf_filtered (char *msg, ...);
void error /-* noreturn *-/ (char *msg, ...); void error /-* noreturn *-/ (char *msg, ...);
void *xmalloc (long size); void *xmalloc (long size);
int sim_callback_write_stdout (char *, int len);
The new way of doing I/O is to use the pointer provided by GDB I/O is done by using a pointer provided by GDB via the sim_set_callbacks
via the sim_set_callbacks call, look in callbacks.c to see what call, look in callbacks.c to see what can be done.
can be done.
*/ */
/* Main simulator entry points ... /* Main simulator entry points ...
@ -129,14 +125,8 @@ void sim_resume PARAMS ((int step, int siggnal));
void sim_do_command PARAMS ((char *cmd)); void sim_do_command PARAMS ((char *cmd));
/* Callbacks for the simulator to use. */
int sim_callback_write_stdout PARAMS ((char *, int));
/* Provide simulator with a standard host_callback_struct. */ /* Provide simulator with a standard host_callback_struct. */
void sim_set_callbacks PARAMS ((struct host_callback_struct *)); void sim_set_callbacks PARAMS ((struct host_callback_struct *));
#endif /* !defined (REMOTE_SIM_H) */ #endif /* !defined (REMOTE_SIM_H) */