29a059c2efb96af9e7f9ebe8c2c5bf2adf3f399b
1 /* Miscellaneous simulator utilities.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "sim-assert.h"
26 #include "libiberty.h"
29 /* Global pointer to all state data.
31 struct sim_state
*current_state
;
33 /* Allocate zero filled memory with xmalloc. */
36 zalloc (unsigned long size
)
38 void *memory
= (void *) xmalloc (size
);
39 memset (memory
, 0, size
);
49 /* Allocate a sim_state struct. */
52 sim_state_alloc (void)
54 SIM_DESC sd
= zalloc (sizeof (struct sim_state
));
55 sd
->base
.magic
= SIM_MAGIC_NUMBER
;
59 /* Free a sim_state struct. */
62 sim_state_free (SIM_DESC sd
)
64 ASSERT (sd
->base
.magic
== SIM_MAGIC_NUMBER
);
68 /* Make a copy of ARGV.
69 This can also be used to copy the environment vector.
70 The result is a pointer to the malloc'd copy or NULL if insufficient
83 for ( ; argv
[argc
]; ++argc
)
84 len
+= strlen (argv
[argc
]) + 1;
87 copy
= (char **) malloc ((argc
+ 1) * sizeof (char *) + len
);
91 p
= (char *) copy
+ (argc
+ 1) * sizeof (char *);
92 for (i
= 0; i
< argc
; ++i
)
96 p
+= strlen (argv
[i
]) + 1;
103 /* Analyze a bfd and set various fields in the state struct. */
106 sim_analyze_program (sd
, prog_bfd
)
112 STATE_PROG_BFD (sd
) = prog_bfd
;
113 STATE_START_ADDR (sd
) = bfd_get_start_address (prog_bfd
);
115 for (s
= prog_bfd
->sections
; s
; s
= s
->next
)
116 if (strcmp (bfd_get_section_name (prog_bfd
, s
), ".text") == 0)
118 STATE_TEXT_SECTION (sd
) = s
;
119 STATE_TEXT_START (sd
) = bfd_get_section_vma (prog_bfd
, s
);
120 STATE_TEXT_END (sd
) = STATE_TEXT_START (sd
) + bfd_section_size (prog_bfd
, s
);
This page took 0.039328 seconds and 4 git commands to generate.