OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [stuff.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* OBSOLETE /* Program to stuff files into a specially prepared space in kdb. */
2
/* OBSOLETE    Copyright 1986, 1989, 1991, 1992, 1995, 2000 */
3
/* OBSOLETE    Free Software Foundation, Inc. */
4
/* OBSOLETE  */
5
/* OBSOLETE    This file is part of GDB. */
6
/* OBSOLETE  */
7
/* OBSOLETE    This program is free software; you can redistribute it and/or modify */
8
/* OBSOLETE    it under the terms of the GNU General Public License as published by */
9
/* OBSOLETE    the Free Software Foundation; either version 2 of the License, or */
10
/* OBSOLETE    (at your option) any later version. */
11
/* OBSOLETE  */
12
/* OBSOLETE    This program is distributed in the hope that it will be useful, */
13
/* OBSOLETE    but WITHOUT ANY WARRANTY; without even the implied warranty of */
14
/* OBSOLETE    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
15
/* OBSOLETE    GNU General Public License for more details. */
16
/* OBSOLETE  */
17
/* OBSOLETE    You should have received a copy of the GNU General Public License */
18
/* OBSOLETE    along with this program; if not, write to the Free Software */
19
/* OBSOLETE    Foundation, Inc., 59 Temple Place - Suite 330, */
20
/* OBSOLETE    Boston, MA 02111-1307, USA.  */ */
21
/* OBSOLETE  */
22
/* OBSOLETE /* Written 13-Mar-86 by David Bridgham. */ */
23
/* OBSOLETE  */
24
/* OBSOLETE #include <stdio.h> */
25
/* OBSOLETE #include <a.out.h> */
26
/* OBSOLETE #include <sys/types.h> */
27
/* OBSOLETE #include "gdb_stat.h" */
28
/* OBSOLETE #include <sys/file.h> */
29
/* OBSOLETE #include <varargs.h> */
30
/* OBSOLETE  */
31
/* OBSOLETE main (argc, argv) */
32
/* OBSOLETE      int argc; */
33
/* OBSOLETE      char *argv[]; */
34
/* OBSOLETE { */
35
/* OBSOLETE   register char *cp; */
36
/* OBSOLETE   char *outfile; */
37
/* OBSOLETE   register int i; */
38
/* OBSOLETE   int offset; */
39
/* OBSOLETE   int out_fd, in_fd; */
40
/* OBSOLETE   struct stat stat_buf; */
41
/* OBSOLETE   int size, pad; */
42
/* OBSOLETE   char buf[1024]; */
43
/* OBSOLETE   static char zeros[4] = */
44
/* OBSOLETE   {0}; */
45
/* OBSOLETE  */
46
/* OBSOLETE   if (argc < 4) */
47
/* OBSOLETE     err ("Not enough arguments\nUsage: %s -o kdb file1 file2 ...\n", */
48
/* OBSOLETE      argv[0]); */
49
/* OBSOLETE  */
50
/* OBSOLETE   outfile = 0; */
51
/* OBSOLETE   for (i = 1; i < argc; i++) */
52
/* OBSOLETE     { */
53
/* OBSOLETE       if (STREQ (argv[i], "-o")) */
54
/* OBSOLETE     outfile = argv[++i]; */
55
/* OBSOLETE     } */
56
/* OBSOLETE   if (outfile == 0) */
57
/* OBSOLETE     err ("Output file not specified\n"); */
58
/* OBSOLETE  */
59
/* OBSOLETE   offset = get_offset (outfile, "_heap"); */
60
/* OBSOLETE  */
61
/* OBSOLETE   out_fd = open (outfile, O_WRONLY); */
62
/* OBSOLETE   if (out_fd < 0) */
63
/* OBSOLETE     err ("Error opening %s for write: %s\n", outfile, strerror (errno)); */
64
/* OBSOLETE   if (lseek (out_fd, offset, 0) < 0) */
65
/* OBSOLETE     err ("Error seeking to heap in %s: %s\n", outfile, strerror (errno)); */
66
/* OBSOLETE  */
67
/* OBSOLETE   /* For each file listed on the command line, write it into the */
68
/* OBSOLETE    * 'heap' of the output file.  Make sure to skip the arguments */
69
/* OBSOLETE    * that name the output file. */ */
70
/* OBSOLETE   for (i = 1; i < argc; i++) */
71
/* OBSOLETE     { */
72
/* OBSOLETE       if (STREQ (argv[i], "-o")) */
73
/* OBSOLETE     continue; */
74
/* OBSOLETE       if ((in_fd = open (argv[i], O_RDONLY)) < 0) */
75
/* OBSOLETE     err ("Error opening %s for read: %s\n", argv[i], */
76
/* OBSOLETE          strerror (errno)); */
77
/* OBSOLETE       if (fstat (in_fd, &stat_buf) < 0) */
78
/* OBSOLETE     err ("Error stat'ing %s: %s\n", argv[i], strerror (errno)); */
79
/* OBSOLETE       size = strlen (argv[i]); */
80
/* OBSOLETE       pad = 4 - (size & 3); */
81
/* OBSOLETE       size += pad + stat_buf.st_size + sizeof (int); */
82
/* OBSOLETE       write (out_fd, &size, sizeof (int)); */
83
/* OBSOLETE       write (out_fd, argv[i], strlen (argv[i])); */
84
/* OBSOLETE       write (out_fd, zeros, pad); */
85
/* OBSOLETE       while ((size = read (in_fd, buf, sizeof (buf))) > 0) */
86
/* OBSOLETE     write (out_fd, buf, size); */
87
/* OBSOLETE       close (in_fd); */
88
/* OBSOLETE     } */
89
/* OBSOLETE   size = 0; */
90
/* OBSOLETE   write (out_fd, &size, sizeof (int)); */
91
/* OBSOLETE   close (out_fd); */
92
/* OBSOLETE   return (0); */
93
/* OBSOLETE } */
94
/* OBSOLETE  */
95
/* OBSOLETE /* Read symbol table from file and returns the offset into the file */
96
/* OBSOLETE  * where symbol sym_name is located.  If error, print message and */
97
/* OBSOLETE  * exit. */ */
98
/* OBSOLETE get_offset (char *file, char *sym_name) */
99
/* OBSOLETE { */
100
/* OBSOLETE   int f; */
101
/* OBSOLETE   struct exec file_hdr; */
102
/* OBSOLETE   struct nlist *symbol_table; */
103
/* OBSOLETE   int size; */
104
/* OBSOLETE   char *strings; */
105
/* OBSOLETE  */
106
/* OBSOLETE   f = open (file, O_RDONLY); */
107
/* OBSOLETE   if (f < 0) */
108
/* OBSOLETE     err ("Error opening %s: %s\n", file, strerror (errno)); */
109
/* OBSOLETE   if (read (f, &file_hdr, sizeof (file_hdr)) < 0) */
110
/* OBSOLETE     err ("Error reading exec structure: %s\n", strerror (errno)); */
111
/* OBSOLETE   if (N_BADMAG (file_hdr)) */
112
/* OBSOLETE     err ("File %s not an a.out file\n", file); */
113
/* OBSOLETE  */
114
/* OBSOLETE   /* read in symbol table */ */
115
/* OBSOLETE   if ((symbol_table = (struct nlist *) malloc (file_hdr.a_syms)) == 0) */
116
/* OBSOLETE     err ("Couldn't allocate space for symbol table\n"); */
117
/* OBSOLETE   if (lseek (f, N_SYMOFF (file_hdr), 0) == -1) */
118
/* OBSOLETE     err ("lseek error: %s\n", strerror (errno)); */
119
/* OBSOLETE   if (read (f, symbol_table, file_hdr.a_syms) == -1) */
120
/* OBSOLETE     err ("Error reading symbol table from %s: %s\n", file, */
121
/* OBSOLETE      strerror (errno)); */
122
/* OBSOLETE  */
123
/* OBSOLETE   /* read in string table */ */
124
/* OBSOLETE   if (read (f, &size, 4) == -1) */
125
/* OBSOLETE     err ("reading string table size: %s\n", strerror (errno)); */
126
/* OBSOLETE   if ((strings = (char *) malloc (size)) == 0) */
127
/* OBSOLETE     err ("Couldn't allocate memory for string table\n"); */
128
/* OBSOLETE   if (read (f, strings, size - 4) == -1) */
129
/* OBSOLETE     err ("reading string table: %s\n", strerror (errno)); */
130
/* OBSOLETE  */
131
/* OBSOLETE   /* Find the core address at which the first byte of kdb text segment */
132
/* OBSOLETE      should be loaded into core when kdb is run.  */ */
133
/* OBSOLETE   origin = find_symbol ("_etext", symbol_table, file_hdr.a_syms, strings) */
134
/* OBSOLETE     - file_hdr.a_text; */
135
/* OBSOLETE   /* Find the core address at which the heap will appear.  */ */
136
/* OBSOLETE   coreaddr = find_symbol (sym_name, symbol_table, file_hdr.a_syms, strings); */
137
/* OBSOLETE   /* Return address in file of the heap data space.  */ */
138
/* OBSOLETE   return (N_TXTOFF (file_hdr) + core_addr - origin); */
139
/* OBSOLETE } */
140
/* OBSOLETE  */
141
/* OBSOLETE find_symbol (char *sym_name, struct nlist *symbol_table, int length, */
142
/* OBSOLETE          char *strings) */
143
/* OBSOLETE { */
144
/* OBSOLETE   register struct nlist *sym; */
145
/* OBSOLETE  */
146
/* OBSOLETE   /* Find symbol in question */ */
147
/* OBSOLETE   for (sym = symbol_table; */
148
/* OBSOLETE        sym != (struct nlist *) ((char *) symbol_table + length); */
149
/* OBSOLETE        sym++) */
150
/* OBSOLETE     { */
151
/* OBSOLETE       if ((sym->n_type & N_TYPE) != N_DATA) */
152
/* OBSOLETE     continue; */
153
/* OBSOLETE       if (sym->n_un.n_strx == 0) */
154
/* OBSOLETE     continue; */
155
/* OBSOLETE       if (STREQ (sym_name, strings + sym->n_un.n_strx - 4)) */
156
/* OBSOLETE     return sym->n_value; */
157
/* OBSOLETE     } */
158
/* OBSOLETE   err ("Data symbol %s not found in %s\n", sym_name, file); */
159
/* OBSOLETE } */
160
/* OBSOLETE  */
161
/* OBSOLETE /* VARARGS */ */
162
/* OBSOLETE void */
163
/* OBSOLETE err (va_alist) */
164
/* OBSOLETE      va_dcl */
165
/* OBSOLETE { */
166
/* OBSOLETE   va_list args; */
167
/* OBSOLETE   char *string; */
168
/* OBSOLETE  */
169
/* OBSOLETE   va_start (args); */
170
/* OBSOLETE   string = va_arg (args, char *); */
171
/* OBSOLETE   vfprintf (gdb_stderr, string, args); */
172
/* OBSOLETE   va_end (args); */
173
/* OBSOLETE   exit (-1); */
174
/* OBSOLETE } */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.