sim: sim-close: unify sim_close logic

Other than the nice advantage of all sims having to declare one fewer
common function, this also fixes leakage in pretty much every sim.
Many were not freeing any resources, and a few were inconsistent as
to the ones they did.  Now we have a single module that takes care of
all the logic for us.

Most of the non-cgen based ones could be deleted outright.  The cgen
ones required adding a callback to the arch-specific cleanup func.
The few that still have close callbacks are to manage their internal
state.

We do not convert erc32, m32c, ppc, rl78, or rx as they do not use
the common sim core.
This commit is contained in:
Mike Frysinger 2015-03-22 23:10:09 -04:00
parent 1bd1b71421
commit 6e4f085c7f
50 changed files with 173 additions and 171 deletions

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* wrapper.c (sim_close): Delete.
2015-07-14 Nick Clifton <nickc@redhat.com>
* armcopro.c: Remove extraneous whitespace.

View File

@ -913,13 +913,6 @@ sim_open (SIM_OPEN_KIND kind,
return sd;
}
void
sim_close (SIM_DESC sd ATTRIBUTE_UNUSED,
int quitting ATTRIBUTE_UNUSED)
{
/* Nothing to do. */
}
void
sim_stop_reason (SIM_DESC sd ATTRIBUTE_UNUSED,
enum sim_stop *reason,

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -1758,12 +1758,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
{

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-10-11 Mike Frysinger <vapier@gentoo.org>
PR sim/18407

View File

@ -820,12 +820,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
sim_module_uninstall (sd);
}
/* Some utils don't like having a NULL environ. */
static const char * const simple_env[] = { "HOME=/", "PATH=/bin", NULL };

View File

@ -1,3 +1,8 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* Make-common.in (SIM_NEW_COMMON_OBJS): Add sim-close.o
* sim-close.c: New file.
2015-09-25 Andrew Bennett <andrew.bennett@imgtec.com>
Ali Lown <ali.lown@imgtec.com>

View File

@ -173,6 +173,7 @@ SIM_COMMON_HW_OBJS = \
SIM_NEW_COMMON_OBJS = \
sim-arange.o \
sim-bits.o \
sim-close.o \
sim-command.o \
sim-config.o \
sim-core.o \

57
sim/common/sim-close.c Normal file
View File

@ -0,0 +1,57 @@
/* Miscellaneous simulator utilities.
Copyright (C) 2005-2015 Free Software Foundation, Inc.
Contributed by Analog Devices, Inc. and Stephane Carrez.
This file is part of simulators.
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 "sim-main.h"
#include "sim-module.h"
#include "gdb/remote-sim.h"
/* Generic implementation of sim_close that works with simulators that use
sim-module for all custom runtime options. */
#ifndef SIM_CLOSE_HOOK
# define SIM_CLOSE_HOOK(sd, quitting)
#endif
void
sim_close (SIM_DESC sd, int quitting)
{
SIM_CLOSE_HOOK (sd, quitting);
/* If cgen is active, close it down. */
#ifdef CGEN_ARCH
# define __cgen_cpu_close(arch) arch##_cgen_cpu_close
# define _cgen_cpu_close(arch) __cgen_cpu_close (arch)
# define cgen_cpu_close _cgen_cpu_close (CGEN_ARCH)
cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
#endif
/* Shut down all registered/active modules. */
sim_module_uninstall (sd);
/* Ensure that any resources allocated through the callback
mechanism are released. */
sim_io_shutdown (sd);
/* Break down all of the cpus. */
sim_cpu_free_all (sd);
/* Finally break down the sim state itself. */
sim_state_free (sd);
}

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-11-10 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_cr16_translate_dmap_addr): Mark static.

View File

@ -945,13 +945,6 @@ sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *cb, struct bfd *abfd,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* Nothing to do. */
}
uint8 *
dmem_addr (uint32 offset)
{

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -1060,13 +1060,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting ATTRIBUTE_UNUSED)
{
cris_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd,

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-11-10 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_d10v_translate_dmap_addr): Mark static.

View File

@ -866,13 +866,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* Nothing to do. */
}
uint8 *
dmem_addr (uint16 offset)
{

View File

@ -1,3 +1,11 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Rename to ...
(frv_sim_close): ... this. Delete calls to frv_cgen_cpu_close and
sim_module_uninstall.
* sim-main.h (frv_sim_close): Declare.
(SIM_CLOSE_HOOK): Define.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure.ac (AC_ARG_ENABLE(sim-trapdump)): Call AS_HELP_STRING.

View File

@ -199,7 +199,7 @@ sim_open (kind, callback, abfd, argv)
}
void
sim_close (sd, quitting)
frv_sim_close (sd, quitting)
SIM_DESC sd;
int quitting;
{
@ -211,9 +211,6 @@ sim_close (sd, quitting)
frv_cache_term (CPU_INSN_CACHE (cpu));
frv_cache_term (CPU_DATA_CACHE (cpu));
}
frv_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
sim_module_uninstall (sd);
}
SIM_RC

View File

@ -43,6 +43,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "profile.h"
void frv_sim_engine_halt_hook (SIM_DESC, SIM_CPU *, sim_cia);
extern void frv_sim_close (SIM_DESC sd, int quitting);
#define SIM_CLOSE_HOOK(...) frv_sim_close (__VA_ARGS__)
/* The _sim_cpu struct. */

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-09-29 James Bowman <james.bowman@ftdichip.com>
* interp.c (step_once): Correct length for MEMSET and MEMCPY

View File

@ -862,12 +862,6 @@ sim_open (SIM_OPEN_KIND kind,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (SIM_DESC sd,
struct bfd *abfd,

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* compile.c (sim_close): Delete.
2015-11-09 Mike Frysinger <vapier@gentoo.org>
* compile.c (littleendian): Delete.

View File

@ -4966,12 +4966,6 @@ sim_open (SIM_OPEN_KIND kind,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* Nothing to do. */
}
/* Called by gdb to load a program into memory. */
SIM_RC

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -155,15 +155,6 @@ sim_open (kind, callback, abfd, argv)
return sd;
}
void
sim_close (sd, quitting)
SIM_DESC sd;
int quitting;
{
iq2000_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (sd, abfd, argv, envp)

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -246,15 +246,6 @@ sim_open (kind, callback, abfd, argv)
return sd;
}
void
sim_close (sd, quitting)
SIM_DESC sd;
int quitting;
{
lm32_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (sd, abfd, argv, envp)

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -179,15 +179,6 @@ sim_open (kind, callback, abfd, argv)
return sd;
}
void
sim_close (sd, quitting)
SIM_DESC sd;
int quitting;
{
m32r_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (sd, abfd, argv, envp)

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -499,22 +499,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* shut down modules */
sim_module_uninstall (sd);
/* Ensure that any resources allocated through the callback
mechanism are released: */
sim_io_shutdown (sd);
/* FIXME - free SD */
sim_state_free (sd);
return;
}
/* Generic implementation of sim_engine_run that works within the
sim_engine setjmp/longjmp framework. */

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -1452,12 +1452,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* nothing to do */
}
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
{

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -459,12 +459,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* Do nothing. */
}
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
{

View File

@ -1,3 +1,11 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Rename to ...
(mips_sim_close): ... this. Delete calls to sim_module_uninstall and
sim_io_shutdown.
* sim-main.h (mips_sim_close): Declare.
(SIM_CLOSE_HOOK): Define.
2015-09-25 Andrew Bennett <andrew.bennett@imgtec.com>
Ali Lown <ali.lown@imgtec.com>

View File

@ -834,34 +834,15 @@ get_insn_name (sim_cpu *cpu, int i)
}
void
sim_close (SIM_DESC sd, int quitting)
mips_sim_close (SIM_DESC sd, int quitting)
{
#ifdef DEBUG
printf("DBG: sim_close: entered (quitting = %d)\n",quitting);
#endif
/* "quitting" is non-zero if we cannot hang on errors */
/* shut down modules */
sim_module_uninstall (sd);
/* Ensure that any resources allocated through the callback
mechanism are released: */
sim_io_shutdown (sd);
#if WITH_TRACE_ANY_P
if (tracefh != NULL && tracefh != stderr)
fclose(tracefh);
tracefh = NULL;
#endif
/* FIXME - free SD */
return;
}
int
sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size)
{

View File

@ -474,6 +474,8 @@ struct _sim_cpu {
sim_cpu_base base;
};
extern void mips_sim_close (SIM_DESC sd, int quitting);
#define SIM_CLOSE_HOOK(...) mips_sim_close (__VA_ARGS__)
/* MIPS specific simulator watch config */

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -317,14 +317,6 @@ sim_open (SIM_OPEN_KIND kind,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (SIM_DESC sd,
struct bfd *prog_bfd,

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-10-11 Mike Frysinger <vapier@gentoo.org>
PR sim/18273

View File

@ -1246,13 +1246,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* nothing to do */
}
/* Load the device tree blob. */
static void

View File

@ -1,3 +1,10 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Rename to ...
(msp430_sim_close): ... this. Delete call to sim_state_free.
* sim-main.h (msp430_sim_close): Declare.
(SIM_CLOSE_HOOK): Define.
2015-06-24 Mike Frysinger <vapier@gentoo.org>
* msp430-sim.c (trace_reg_put): Change TRACE_VPU to TRACE_REGISTER.

View File

@ -239,11 +239,9 @@ sim_open (SIM_OPEN_KIND kind,
}
void
sim_close (SIM_DESC sd,
int quitting)
msp430_sim_close (SIM_DESC sd, int quitting)
{
free (STATE_SYMBOL_TABLE (sd));
sim_state_free (sd);
}
SIM_RC

View File

@ -54,4 +54,7 @@ struct sim_state
#include "sim-engine.h"
#include "sim-options.h"
extern void msp430_sim_close (SIM_DESC sd, int quitting);
#define SIM_CLOSE_HOOK(...) msp430_sim_close (__VA_ARGS__)
#endif /* _MSP430_MAIN_SIM_H_ */

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -2501,12 +2501,6 @@ parse_and_set_memory_size (const char *str)
callback->printf_filtered (callback, "Bad memory size %d; must be 1 to 24, inclusive\n", n);
}
void
sim_close (SIM_DESC sd, int quitting)
{
/* nothing to do */
}
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
{

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -161,15 +161,6 @@ sim_open (kind, callback, abfd, argv)
return sd;
}
void
sim_close (sd, quitting)
SIM_DESC sd;
int quitting;
{
sh_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (sd, abfd, argv, envp)

View File

@ -1,3 +1,7 @@
2015-11-14 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_close): Delete.
2015-06-23 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -303,13 +303,6 @@ sim_open (SIM_OPEN_KIND kind,
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
sim_module_uninstall (sd);
}
SIM_RC
sim_create_inferior (SIM_DESC sd,
struct bfd * prog_bfd,