1 /* 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. */
5 /* OBSOLETE This file is part of GDB. */
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. */
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. */
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. */ */
22 /* OBSOLETE /* Written 13-Mar-86 by David Bridgham. */ */
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> */
31 /* OBSOLETE main (argc, argv) */
32 /* OBSOLETE int argc; */
33 /* OBSOLETE char *argv[]; */
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] = */
46 /* OBSOLETE if (argc < 4) */
47 /* OBSOLETE err ("Not enough arguments\nUsage: %s -o kdb file1 file2 ...\n", */
48 /* OBSOLETE argv[0]); */
50 /* OBSOLETE outfile = 0; */
51 /* OBSOLETE for (i = 1; i < argc; i++) */
53 /* OBSOLETE if (STREQ (argv[i], "-o")) */
54 /* OBSOLETE outfile = argv[++i]; */
56 /* OBSOLETE if (outfile == 0) */
57 /* OBSOLETE err ("Output file not specified\n"); */
59 /* OBSOLETE offset = get_offset (outfile, "_heap"); */
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)); */
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++) */
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); */
89 /* OBSOLETE size = 0; */
90 /* OBSOLETE write (out_fd, &size, sizeof (int)); */
91 /* OBSOLETE close (out_fd); */
92 /* OBSOLETE return (0); */
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) */
100 /* OBSOLETE int f; */
101 /* OBSOLETE struct exec file_hdr; */
102 /* OBSOLETE struct nlist *symbol_table; */
103 /* OBSOLETE int size; */
104 /* OBSOLETE char *strings; */
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); */
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)); */
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)); */
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); */
141 /* OBSOLETE find_symbol (char *sym_name, struct nlist *symbol_table, int length, */
142 /* OBSOLETE char *strings) */
144 /* OBSOLETE register struct nlist *sym; */
146 /* OBSOLETE /* Find symbol in question */ */
147 /* OBSOLETE for (sym = symbol_table; */
148 /* OBSOLETE sym != (struct nlist *) ((char *) symbol_table + length); */
149 /* OBSOLETE sym++) */
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; */
158 /* OBSOLETE err ("Data symbol %s not found in %s\n", sym_name, file); */
161 /* OBSOLETE /* VARARGS */ */
163 /* OBSOLETE err (va_alist) */
164 /* OBSOLETE va_dcl */
166 /* OBSOLETE va_list args; */
167 /* OBSOLETE char *string; */
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); */
This page took 0.032822 seconds and 4 git commands to generate.