Pass GCC -W...

This commit is contained in:
Andrew Cagney 1997-03-21 03:56:07 +00:00
parent 011fa67124
commit fa21d299e6
4 changed files with 312 additions and 164 deletions

View file

@ -1,3 +1,30 @@
Fri Mar 21 13:36:20 1997 Andrew Cagney <cagney@kremvax.cygnus.com>
* run.c (string.h, strings.h, stdlib.h): Include.
* sim-events.c (sim_events_tick): Recent cleanup failed to return
0 when nothing pending.
* run.c (sim_size, sim_trace): Plicate GCC - these two functions
will soon be going away.
(getopt): Plicate GCC.
* sim-endian.c (sim-io.h): Plicate GCC.
* sim-bits.c (sim-io.h): Ditto.
* sim-n-bits.h (ROTn): Ditto.
* sim-io.c (sim_io_error): Correct check for NULL.
* sim-assert.h (SIM_FILTER_PATH): Separate out the code filtering
the __FILE__.
* sim-events.c: Use SIM_FILTER_PATH to filter out the filename
path.
Wed Mar 19 01:12:06 1997 Andrew Cagney <cagney@kremvax.cygnus.com>
* aclocal.m4 (SIM_AC_OPTION_*: Move so that they are outside of
SIM_AC_COMMON - SIM_AC_COMMON was gobling arguments.
Tue Mar 18 20:48:12 1997 Andrew Cagney <cagney@kremvax.cygnus.com>
* sim-alu.h: Include sim-xcat.h.

View file

@ -1,5 +1,5 @@
/* run front end support for all the simulators.
Copyright (C) 1992, 1993 1994, 1995 Free Software Foundation, Inc.
Copyright (C) 1992, 1993 1994, 1995, 1996 Free Software Foundation, Inc.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -15,21 +15,38 @@ 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. */
/* Steve Chamberlain sac@cygnus.com,
and others at Cygnus. */
/* Steve Chamberlain
sac@cygnus.com */
#include "config.h"
#include "tconfig.h"
#include <signal.h>
#include <stdio.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#include "bfd.h"
#include "remote-sim.h"
#include "callback.h"
#ifndef SIGQUIT
#define SIGQUIT SIGTERM
#endif
void usage();
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#endif
#include "libiberty.h"
#include "bfd.h"
#include "callback.h"
#include "remote-sim.h"
static void usage PARAMS ((void));
extern int optind;
extern char *optarg;
@ -38,6 +55,17 @@ bfd *exec_bfd;
int target_byte_order;
extern host_callback default_callback;
static char *myname;
/* NOTE: sim_size() and sim_trace() are going away */
extern void sim_size PARAMS ((int i));
extern int sim_trace PARAMS ((SIM_DESC sd));
extern int getopt ();
int
main (ac, av)
int ac;
@ -49,135 +77,211 @@ main (ac, av)
int i;
int verbose = 0;
int trace = 0;
char *name = "";
char *name;
static char *no_args[2];
char **sim_argv = &no_args[0];
char **prog_args;
enum sim_stop reason;
int sigrc;
SIM_DESC sd;
while ((i = getopt (ac, av, "m:p:s:tv")) != EOF)
myname = av[0] + strlen (av[0]);
while (myname > av[0] && myname[-1] != '/')
--myname;
/* The first element of sim_open's argv is the program name. */
no_args[0] = av[0];
/* FIXME: This is currently being rewritten to have each simulator
do all argv processing. */
#ifdef SIM_H8300 /* FIXME: quick hack */
while ((i = getopt (ac, av, "a:c:m:p:s:htv")) != EOF)
#else
while ((i = getopt (ac, av, "a:c:m:p:s:tv")) != EOF)
#endif
switch (i)
{
case 'a':
/* FIXME: Temporary hack. */
{
int len = strlen (av[0]) + strlen (optarg);
char *argbuf = (char *) alloca (len + 2);
sprintf (argbuf, "%s %s", av[0], optarg);
sim_argv = buildargv (argbuf);
}
break;
#ifdef SIM_HAVE_SIMCACHE
case 'c':
sim_set_simcache_size (atoi (optarg));
break;
#endif
case 'm':
/* FIXME: Rename to sim_set_mem_size. */
sim_size (atoi (optarg));
break;
#ifdef SIM_HAVE_PROFILE
case 'p':
sim_set_profile (atoi (optarg));
break;
case 's':
sim_set_profile_size (atoi (optarg));
break;
#endif
case 't':
trace = 1;
/* FIXME: need to allow specification of what to trace. */
/* sim_set_trace (1); */
break;
case 'v':
/* Things that are printed with -v are the kinds of things that
gcc -v prints. This is not meant to include detailed tracing
or debugging information, just summaries. */
verbose = 1;
/* sim_set_verbose (1); */
break;
/* FIXME: Quick hack, to be replaced by more general facility. */
#ifdef SIM_H8300
case 'h':
set_h8300h (1);
break;
#endif
default:
usage();
usage ();
}
ac -= optind;
av += optind;
if (ac != 1)
usage();
name = *av;
prog_args = av + 1;
if (verbose)
{
printf ("run %s\n", name);
printf ("%s %s\n", myname, name);
}
exec_bfd = abfd = bfd_openr (name, 0);
if (!abfd)
{
fprintf (stderr, "run: can't open %s: %s\n",
name, bfd_errmsg(bfd_get_error()));
fprintf (stderr, "%s: can't open %s: %s\n",
myname, name, bfd_errmsg (bfd_get_error ()));
exit (1);
}
if (!bfd_check_format (abfd, bfd_object))
{
fprintf (stderr, "run: can't load %s: %s\n",
name, bfd_errmsg(bfd_get_error()));
fprintf (stderr, "%s: can't load %s: %s\n",
myname, name, bfd_errmsg (bfd_get_error ()));
exit (1);
}
sim_set_callbacks (&default_callback);
/* This must be set before sim_open is called, because gdb assumes that
the simulator endianness is known immediately after the sim_open call. */
target_byte_order = bfd_big_endian (abfd) ? 4321 : 1234;
sim_set_callbacks (NULL, &default_callback);
default_callback.init (&default_callback);
/* Ensure that any run-time initialisation that needs to be
performed by the simulator can occur. */
sim_open(NULL);
sd = sim_open (sim_argv);
for (s = abfd->sections; s; s = s->next)
if (abfd && (s->flags & SEC_LOAD))
{
unsigned char *buffer = (unsigned char *)malloc ((size_t)(bfd_section_size (abfd, s)));
if (buffer != NULL)
{
bfd_get_section_contents (abfd,
s,
buffer,
0,
bfd_section_size (abfd, s));
sim_write (s->vma, buffer, bfd_section_size (abfd, s));
}
else
{
fprintf (stderr, "run: failed to allocate section buffer: %s\n",
bfd_errmsg(bfd_get_error()));
exit (1);
}
if (s->flags & SEC_LOAD)
{
unsigned char *buffer = (unsigned char *)malloc ((size_t)(bfd_section_size (abfd, s)));
if (buffer != NULL)
{
bfd_get_section_contents (abfd,
s,
buffer,
0,
bfd_section_size (abfd, s));
sim_write (sd, s->vma, buffer, bfd_section_size (abfd, s));
/* FIXME: How come we don't free buffer? */
}
else
{
fprintf (stderr, "%s: failed to allocate section buffer: %s\n",
myname, bfd_errmsg (bfd_get_error ()));
exit (1);
}
}
}
start_address = bfd_get_start_address (abfd);
sim_create_inferior (start_address, NULL, NULL);
target_byte_order = bfd_big_endian (abfd) ? 4321 : 1234;
sim_create_inferior (sd, start_address, prog_args, NULL);
if (trace)
{
int done = 0;
while (!done)
{
done = sim_trace ();
done = sim_trace (sd);
}
}
else
{
sim_resume (0, 0);
sim_resume (sd, 0, 0);
}
if (verbose)
sim_info (0);
sim_info (sd, 0);
sim_stop_reason (&reason, &sigrc);
sim_stop_reason (sd, &reason, &sigrc);
sim_close(0);
/* Why did we stop? */
switch (reason)
{
case sim_signalled:
case sim_stopped:
fprintf (stderr, "program stopped with signal %d.\n", sigrc);
break;
case sim_exited:
break;
}
sim_close (sd, 0);
/* If reason is sim_exited, then sigrc holds the exit code which we want
to return. If reason is sim_stopped or sim_signalled, then sigrc holds
the signal that the simulator received; we want to return that to
indicate failure. */
#ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */
if (sigrc == SIGILL)
abort ();
sigrc = 0;
#else
/* Why did we stop? */
switch (reason)
{
case sim_signalled:
case sim_stopped:
if (sigrc != 0)
fprintf (stderr, "program stopped with signal %d.\n", sigrc);
break;
case sim_exited:
break;
}
#endif
return sigrc;
}
void
usage()
static void
usage ()
{
fprintf (stderr, "usage: run [-tv][-m size] program\n");
fprintf (stderr, "Usage: %s [options] program [program args]\n", myname);
fprintf (stderr, "Options:\n");
fprintf (stderr, "-a args Pass `args' to simulator.\n");
#ifdef SIM_HAVE_SIMCACHE
fprintf (stderr, "-c size Set simulator cache size to `size'.\n");
#endif
#ifdef SIM_H8300
fprintf (stderr, "-h Executable is for h8/300h or h8/300s.\n");
#endif
fprintf (stderr, "-m size Set memory size of simulator, in bytes.\n");
#ifdef SIM_HAVE_PROFILE
fprintf (stderr, "-p freq Set profiling frequency.\n");
fprintf (stderr, "-s size Set profiling size.\n");
#endif
fprintf (stderr, "-t Perform instruction tracing.\n");
fprintf (stderr, " Note: Very few simulators support tracing.\n");
fprintf (stderr, "-v Verbose output.\n");
fprintf (stderr, "\n");
fprintf (stderr, "program args Arguments to pass to simulated program.\n");
fprintf (stderr, " Note: Very few simulators support this.\n");
exit (1);
}

View file

@ -22,48 +22,63 @@
#ifndef _SIM_ASSERT_H_
#define _SIM_ASSERT_H_
# if defined (WITH_ASSERT)
#define SIM_ASSERT(EXPRESSION) \
do { \
if (WITH_ASSERT) { \
if (!(EXPRESSION)) { \
/* strip leading path */ \
const char *file = __FILE__; \
const char *p = file; \
while (*p != '\0' && *p != ':') { \
if (*p == '/') \
file = p; \
p++; \
#define SIM_FILTER_PATH(FILE, PATH) \
do \
{ \
/* strip leading path */ \
const char *p = (PATH); \
(FILE) = p; \
while (*p != '\0' && *p != ':') \
{ \
if (*p == '/') \
(FILE) = p; \
p++; \
} \
/* report the failure */ \
sim_io_error (sd, "%s:%d: assertion failed - %s", \
file, __LINE__, #EXPRESSION); \
} \
} \
} while (0)
while (0)
/* The subtle difference between SIM_ASSERT and ASSERT is that
SIM_ASSERT passes `sd' to sim_io_error for the SIM_DESC,
ASSERT passes NULL. */
#if defined (WITH_ASSERT)
#define SIM_ASSERT(EXPRESSION) \
do \
{ \
if (WITH_ASSERT) \
{ \
if (!(EXPRESSION)) \
{ \
/* report the failure */ \
const char *file; \
SIM_FILTER_PATH(file, __FILE__); \
sim_io_error (sd, "%s:%d: assertion failed - %s", \
file, __LINE__, #EXPRESSION); \
} \
} \
} \
while (0)
#else
#define SIM_ASSERT(EXPRESSION) do { /*nothing*/; } while (0)
#endif
#if defined (WITH_ASSERT)
#define ASSERT(EXPRESSION) \
do { \
if (WITH_ASSERT) { \
if (!(EXPRESSION)) { \
/* strip leading path */ \
const char *file = __FILE__; \
const char *p = file; \
while (*p != '\0' && *p != ':') { \
if (*p == '/') \
file = p; \
p++; \
do \
{ \
if (WITH_ASSERT) \
{ \
if (!(EXPRESSION)) \
{ \
/* report the failure */ \
const char *file; \
SIM_FILTER_PATH(file, __FILE__); \
sim_io_error (NULL, "%s:%d: assertion failed - %s", \
file, __LINE__, #EXPRESSION); \
} \
} \
/* report the failure */ \
sim_io_error (NULL, "%s:%d: assertion failed - %s", \
file, __LINE__, #EXPRESSION); \
} \
} \
} while (0)
while (0)
#else
#define ASSERT(EXPRESSION) do { /*nothing*/; } while (0)
#endif

View file

@ -22,153 +22,153 @@
#ifndef _SIM_IO_C_
#define _SIM_IO_C_
#include "engine.h"
#include "sim-state.h"
/* See the file include/callbacks.h for a description */
INLINE_SIM_IO(int)
sim_io_init(engine *system)
sim_io_init(SIM_DESC sd)
{
return system->callback->init (system->callback);
return sd->callback->init (sd->callback);
}
INLINE_SIM_IO(int)
sim_io_shutdown(engine *system)
sim_io_shutdown(SIM_DESC sd)
{
return system->callback->shutdown (system->callback);
return sd->callback->shutdown (sd->callback);
}
INLINE_SIM_IO(int)
sim_io_unlink(engine *system,
sim_io_unlink(SIM_DESC sd,
const char *f1)
{
return system->callback->unlink (system->callback, f1);
return sd->callback->unlink (sd->callback, f1);
}
INLINE_SIM_IO(long)
sim_io_time(engine *system,
sim_io_time(SIM_DESC sd,
long *t)
{
return system->callback->time (system->callback, t);
return sd->callback->time (sd->callback, t);
}
INLINE_SIM_IO(int)
sim_io_system(engine *system, const char *s)
sim_io_system(SIM_DESC sd, const char *s)
{
return system->callback->system (system->callback, s);
return sd->callback->system (sd->callback, s);
}
INLINE_SIM_IO(int)
sim_io_rename(engine *system,
sim_io_rename(SIM_DESC sd,
const char *f1,
const char *f2)
{
return system->callback->rename (system->callback, f1, f2);
return sd->callback->rename (sd->callback, f1, f2);
}
INLINE_SIM_IO(int)
sim_io_write_stdout(engine *system,
sim_io_write_stdout(SIM_DESC sd,
const char *buf,
int len)
{
switch (CURRENT_STDIO) {
case DO_USE_STDIO:
return system->callback->write_stdout (system->callback, buf, len);
return sd->callback->write_stdout (sd->callback, buf, len);
break;
case DONT_USE_STDIO:
return system->callback->write (system->callback, 1, buf, len);
return sd->callback->write (sd->callback, 1, buf, len);
break;
default:
sim_io_error (system, "sim_io_write_stdout: unaccounted switch\n");
sim_io_error (sd, "sim_io_write_stdout: unaccounted switch\n");
break;
}
return 0;
}
INLINE_SIM_IO(int)
sim_io_flush_stdout(engine *system)
INLINE_SIM_IO(void)
sim_io_flush_stdout(SIM_DESC sd)
{
switch (CURRENT_STDIO) {
case DO_USE_STDIO:
return system->callback->flush_stdout (system->callback);
sd->callback->flush_stdout (sd->callback);
break;
case DONT_USE_STDIO:
break;
default:
sim_io_error (system, "sim_io_flush_stdout: unaccounted switch\n");
sim_io_error (sd, "sim_io_flush_stdout: unaccounted switch\n");
break;
}
}
INLINE_SIM_IO(int)
sim_io_write_stderr(engine *system,
sim_io_write_stderr(SIM_DESC sd,
const char *buf,
int len)
{
switch (CURRENT_STDIO) {
case DO_USE_STDIO:
return system->callback->write_stderr (system->callback, buf, len);
return sd->callback->write_stderr (sd->callback, buf, len);
break;
case DONT_USE_STDIO:
return system->callback->write (system->callback, 2, buf, len);
return sd->callback->write (sd->callback, 2, buf, len);
break;
default:
sim_io_error (system, "sim_io_write_stderr: unaccounted switch\n");
sim_io_error (sd, "sim_io_write_stderr: unaccounted switch\n");
break;
}
return 0;
}
INLINE_SIM_IO(int)
sim_io_flush_stderr(engine *system)
INLINE_SIM_IO(void)
sim_io_flush_stderr(SIM_DESC sd)
{
switch (CURRENT_STDIO) {
case DO_USE_STDIO:
return system->callback->flush_stderr (system->callback);
sd->callback->flush_stderr (sd->callback);
break;
case DONT_USE_STDIO:
break;
default:
sim_io_error (system, "sim_io_flush_stderr: unaccounted switch\n");
sim_io_error (sd, "sim_io_flush_stderr: unaccounted switch\n");
break;
}
}
INLINE_SIM_IO(int)
sim_io_write(engine *system,
sim_io_write(SIM_DESC sd,
int fd,
const char *buf,
int len)
{
return system->callback->write (system->callback, fd, buf, len);
return sd->callback->write (sd->callback, fd, buf, len);
}
INLINE_SIM_IO(int)
sim_io_read_stdin(engine *system,
sim_io_read_stdin(SIM_DESC sd,
char *buf,
int len)
{
switch (CURRENT_STDIO) {
case DO_USE_STDIO:
return system->callback->read_stdin (system->callback, buf, len);
return sd->callback->read_stdin (sd->callback, buf, len);
break;
case DONT_USE_STDIO:
return system->callback->read (system->callback, 0, buf, len);
return sd->callback->read (sd->callback, 0, buf, len);
break;
default:
sim_io_error (system, "sim_io_read_stdin: unaccounted switch\n");
sim_io_error (sd, "sim_io_read_stdin: unaccounted switch\n");
break;
}
return 0;
@ -176,115 +176,117 @@ sim_io_read_stdin(engine *system,
INLINE_SIM_IO(int)
sim_io_read(engine *system, int fd,
sim_io_read(SIM_DESC sd, int fd,
char *buf,
int len)
{
return system->callback->read(system->callback, fd, buf, len);
return sd->callback->read (sd->callback, fd, buf, len);
}
INLINE_SIM_IO(int)
sim_io_open(engine *system,
sim_io_open(SIM_DESC sd,
const char *name,
int flags)
{
return system->callback->open (system->callback, name, flags);
return sd->callback->open (sd->callback, name, flags);
}
INLINE_SIM_IO(int)
sim_io_lseek(engine *system,
sim_io_lseek(SIM_DESC sd,
int fd,
long off,
int way)
{
return system->callback->lseek (system->callback, fd, off, way);
return sd->callback->lseek (sd->callback, fd, off, way);
}
INLINE_SIM_IO(int)
sim_io_isatty(engine *system,
sim_io_isatty(SIM_DESC sd,
int fd)
{
return system->callback->isatty (system->callback, fd);
return sd->callback->isatty (sd->callback, fd);
}
INLINE_SIM_IO(int)
sim_io_get_errno(engine *system)
sim_io_get_errno(SIM_DESC sd)
{
return system->callback->get_errno (system->callback);
return sd->callback->get_errno (sd->callback);
}
INLINE_SIM_IO(int)
sim_io_close(engine *system,
sim_io_close(SIM_DESC sd,
int fd)
{
return system->callback->close (system->callback, fd);
return sd->callback->close (sd->callback, fd);
}
INLINE_SIM_IO(void)
sim_io_printf(engine *system,
sim_io_printf(SIM_DESC sd,
const char *fmt,
...)
{
va_list ap;
va_start(ap, fmt);
system->callback->vprintf_filtered (system->callback, fmt, ap);
sd->callback->vprintf_filtered (sd->callback, fmt, ap);
va_end(ap);
}
INLINE_SIM_IO(void)
sim_io_vprintf(engine *system,
sim_io_vprintf(SIM_DESC sd,
const char *fmt,
va_list ap)
{
system->callback->vprintf_filtered (system->callback, fmt, ap);
sd->callback->vprintf_filtered (sd->callback, fmt, ap);
}
INLINE_SIM_IO(void)
sim_io_eprintf(engine *system,
sim_io_eprintf(SIM_DESC sd,
const char *fmt,
...)
{
va_list ap;
va_start(ap, fmt);
system->callback->evprintf_filtered (system->callback, fmt, ap);
sd->callback->evprintf_filtered (sd->callback, fmt, ap);
va_end(ap);
}
INLINE_SIM_IO(void)
sim_io_evprintf(engine *system,
sim_io_evprintf(SIM_DESC sd,
const char *fmt,
va_list ap)
{
system->callback->evprintf_filtered (system->callback, fmt, ap);
sd->callback->evprintf_filtered (sd->callback, fmt, ap);
}
INLINE_SIM_IO(void)
sim_io_error(engine *system,
sim_io_error(SIM_DESC sd,
const char *fmt,
...)
{
char buf[1000];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
if (strlen(buf) >= sizeof(buf))
abort();
system->callback->error (system->callback, "%s", buf);
if (sd == NULL || sd->callback == NULL) {
va_list ap;
va_start(ap, fmt);
vfprintf (stderr, fmt, ap);
va_end(ap);
abort ();
}
else {
va_list ap;
va_start(ap, fmt);
sd->callback->evprintf_filtered (sd->callback, fmt, ap);
va_end(ap);
sd->callback->error (sd->callback, "");
}
}
#endif