aboutsummaryrefslogtreecommitdiff
path: root/sim/common/sim-utils.c
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-08-27 04:44:41 +0000
committerAndrew Cagney <cagney@redhat.com>1997-08-27 04:44:41 +0000
commitfafce69ab16b45fb1ac6bd2ec5afc8e8dbed0374 (patch)
treeeaab2b03e17f79cd61e73a0b510942da3f20dcc3 /sim/common/sim-utils.c
parent9f64f00adaa7fb89b13ed291a778a262260dc409 (diff)
downloadgdb-fafce69ab16b45fb1ac6bd2ec5afc8e8dbed0374.zip
gdb-fafce69ab16b45fb1ac6bd2ec5afc8e8dbed0374.tar.gz
gdb-fafce69ab16b45fb1ac6bd2ec5afc8e8dbed0374.tar.bz2
Add ABFD argument to sim_create_inferior. Document.
Add file sim-hload.c - generic load for hardware only simulators. Review each simulators sim_open, sim_load, sim_create_inferior so that they more closely match required behavour.
Diffstat (limited to 'sim/common/sim-utils.c')
-rw-r--r--sim/common/sim-utils.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c
index e0432f8..a0b582d 100644
--- a/sim/common/sim-utils.c
+++ b/sim/common/sim-utils.c
@@ -119,9 +119,7 @@ char **
sim_copy_argv (argv)
char **argv;
{
- int i;
int argc;
- int len;
char **copy;
if (argv == NULL)
@@ -149,16 +147,56 @@ sim_copy_argv (argv)
return copy;
}
-/* Analyze a bfd and set various fields in the state struct. */
+/* Analyze a prog_name/prog_bfd and set various fields in the state
+ struct. */
-void
-sim_analyze_program (sd, prog_bfd)
+SIM_RC
+sim_analyze_program (sd, prog_name, prog_bfd)
SIM_DESC sd;
+ char *prog_name;
bfd *prog_bfd;
{
asection *s;
-
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
+
+ if (prog_bfd != NULL)
+ {
+ if (prog_bfd == STATE_PROG_BFD (sd))
+ /* already analyzed */
+ return SIM_RC_OK;
+ else
+ /* duplicate needed, save the name of the file to be re-opened */
+ prog_name = bfd_get_filename (prog_bfd);
+ }
+
+ /* do we need to duplicate anything? */
+ if (prog_name == NULL)
+ return SIM_RC_OK;
+
+ /* open a new copy of the prog_bfd */
+ prog_bfd = bfd_openr (prog_name, 0);
+ if (prog_bfd == NULL)
+ {
+ sim_io_eprintf (sd, "%s: can't open \"%s\": %s\n",
+ STATE_MY_NAME (sd),
+ prog_name,
+ bfd_errmsg (bfd_get_error ()));
+ return SIM_RC_FAIL;
+ }
+ if (!bfd_check_format (prog_bfd, bfd_object))
+ {
+ sim_io_eprintf (sd, "%s: \"%s\" is not an object file: %s\n",
+ STATE_MY_NAME (sd),
+ prog_name,
+ bfd_errmsg (bfd_get_error ()));
+ bfd_close (prog_bfd);
+ return SIM_RC_FAIL;
+ }
+
+
+ /* update the sim structure */
+ if (STATE_PROG_BFD (sd) != NULL)
+ bfd_close (STATE_PROG_BFD (sd));
STATE_PROG_BFD (sd) = prog_bfd;
STATE_START_ADDR (sd) = bfd_get_start_address (prog_bfd);
@@ -170,6 +208,8 @@ sim_analyze_program (sd, prog_bfd)
STATE_TEXT_END (sd) = STATE_TEXT_START (sd) + bfd_section_size (prog_bfd, s);
break;
}
+
+ return SIM_RC_OK;
}
/* Simulator timing support. */