Deleted Added
full compact
stabs.c (178529) stabs.c (178546)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 33 unchanged lines hidden (view full) ---

42#include <sys/param.h>
43
44#include "ctftools.h"
45#include "list.h"
46#include "stack.h"
47#include "memory.h"
48#include "traverse.h"
49
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 33 unchanged lines hidden (view full) ---

42#include <sys/param.h>
43
44#include "ctftools.h"
45#include "list.h"
46#include "stack.h"
47#include "memory.h"
48#include "traverse.h"
49
50const char *curhdr;
50char *curhdr;
51
52/*
53 * The stabs generator will sometimes reference types before they've been
54 * defined. If this is the case, a TYPEDEF_UNRES tdesc will be generated.
55 * Note that this is different from a forward declaration, in which the
56 * stab is defined, but is defined as something that doesn't exist yet.
57 * When we have read all of the stabs from the file, we can go back and
58 * fix up all of the unresolved types. We should be able to fix all of them.
59 */
60/*ARGSUSED2*/
61static int
51
52/*
53 * The stabs generator will sometimes reference types before they've been
54 * defined. If this is the case, a TYPEDEF_UNRES tdesc will be generated.
55 * Note that this is different from a forward declaration, in which the
56 * stab is defined, but is defined as something that doesn't exist yet.
57 * When we have read all of the stabs from the file, we can go back and
58 * fix up all of the unresolved types. We should be able to fix all of them.
59 */
60/*ARGSUSED2*/
61static int
62resolve_tou_node(tdesc_t *node, tdesc_t **nodep, void *private)
62resolve_tou_node(tdesc_t *node, tdesc_t **nodep, void *private __unused)
63{
64 tdesc_t *new;
65
66 debug(3, "Trying to resolve %s (%d)\n", tdesc_name(node), node->t_id);
67 new = lookup(node->t_id);
68
69 if (new == NULL) {
70 terminate("Couldn't resolve type %d\n", node->t_id);
71 }
72
73 debug(3, " Resolving to %d\n", new->t_id);
74
75 *nodep = new;
76
77 return (1);
78}
79
80/*ARGSUSED*/
81static int
63{
64 tdesc_t *new;
65
66 debug(3, "Trying to resolve %s (%d)\n", tdesc_name(node), node->t_id);
67 new = lookup(node->t_id);
68
69 if (new == NULL) {
70 terminate("Couldn't resolve type %d\n", node->t_id);
71 }
72
73 debug(3, " Resolving to %d\n", new->t_id);
74
75 *nodep = new;
76
77 return (1);
78}
79
80/*ARGSUSED*/
81static int
82resolve_fwd_node(tdesc_t *node, tdesc_t **nodep, void *private)
82resolve_fwd_node(tdesc_t *node, tdesc_t **nodep, void *private __unused)
83{
84 tdesc_t *new = lookupname(node->t_name);
85
86 debug(3, "Trying to unforward %s (%d)\n", tdesc_name(node), node->t_id);
87
88 if (!new || (new->t_type != STRUCT && new->t_type != UNION))
89 return (0);
90

--- 78 unchanged lines hidden (view full) ---

169 ii->ii_args = NULL;
170}
171
172/*
173 * Read the stabs from the stab ELF section, and turn them into a tdesc tree,
174 * assembled under an iidesc list.
175 */
176int
83{
84 tdesc_t *new = lookupname(node->t_name);
85
86 debug(3, "Trying to unforward %s (%d)\n", tdesc_name(node), node->t_id);
87
88 if (!new || (new->t_type != STRUCT && new->t_type != UNION))
89 return (0);
90

--- 78 unchanged lines hidden (view full) ---

169 ii->ii_args = NULL;
170}
171
172/*
173 * Read the stabs from the stab ELF section, and turn them into a tdesc tree,
174 * assembled under an iidesc list.
175 */
176int
177stabs_read(tdata_t *td, Elf *elf, const char *file)
177stabs_read(tdata_t *td, Elf *elf, char *file)
178{
179 Elf_Scn *scn;
180 Elf_Data *data;
181 stab_t *stab;
182 stk_t *file_stack;
183 iidesc_t *iidescp;
184 iidesc_t *curfun = NULL;
185 char curpath[MAXPATHLEN];

--- 9 unchanged lines hidden (view full) ---

195 !((stabidx = findelfsecidx(elf, file, ".stab")) >= 0 &&
196 (stabstridx = findelfsecidx(elf, file, ".stabstr")) >= 0)) {
197 errno = ENOENT;
198 return (-1);
199 }
200
201 file_stack = stack_new(free);
202
178{
179 Elf_Scn *scn;
180 Elf_Data *data;
181 stab_t *stab;
182 stk_t *file_stack;
183 iidesc_t *iidescp;
184 iidesc_t *curfun = NULL;
185 char curpath[MAXPATHLEN];

--- 9 unchanged lines hidden (view full) ---

195 !((stabidx = findelfsecidx(elf, file, ".stab")) >= 0 &&
196 (stabstridx = findelfsecidx(elf, file, ".stabstr")) >= 0)) {
197 errno = ENOENT;
198 return (-1);
199 }
200
201 file_stack = stack_new(free);
202
203 stack_push(file_stack, (void *)file);
203 stack_push(file_stack, file);
204 curhdr = file;
205
206 debug(3, "Found stabs in %d, strings in %d\n", stabidx, stabstridx);
207
208 scn = elf_getscn(elf, stabidx);
209 data = elf_rawdata(scn, NULL);
210 nstabs = data->d_size / sizeof (stab_t);
211

--- 38 unchanged lines hidden (view full) ---

250 if ((str = elf_strptr(elf, stabstridx,
251 (size_t)stab->n_strx)) == NULL) {
252 terminate("%s: Can't find string at %u for stab %d\n",
253 file, stab->n_strx, i);
254 }
255
256 if (stab->n_type == N_BINCL) {
257 curhdr = xstrdup(str);
204 curhdr = file;
205
206 debug(3, "Found stabs in %d, strings in %d\n", stabidx, stabstridx);
207
208 scn = elf_getscn(elf, stabidx);
209 data = elf_rawdata(scn, NULL);
210 nstabs = data->d_size / sizeof (stab_t);
211

--- 38 unchanged lines hidden (view full) ---

250 if ((str = elf_strptr(elf, stabstridx,
251 (size_t)stab->n_strx)) == NULL) {
252 terminate("%s: Can't find string at %u for stab %d\n",
253 file, stab->n_strx, i);
254 }
255
256 if (stab->n_type == N_BINCL) {
257 curhdr = xstrdup(str);
258 stack_push(file_stack, (void *)curhdr);
258 stack_push(file_stack, curhdr);
259 continue;
260 } else if (stab->n_type == N_SO) {
261 if (str[strlen(str) - 1] != '/') {
262 strcpy(curpath, str);
263 curfile = basename(curpath);
264 }
265 continue;
266 } else if (stab->n_type == N_OPT) {

--- 115 unchanged lines hidden ---
259 continue;
260 } else if (stab->n_type == N_SO) {
261 if (str[strlen(str) - 1] != '/') {
262 strcpy(curpath, str);
263 curfile = basename(curpath);
264 }
265 continue;
266 } else if (stab->n_type == N_OPT) {

--- 115 unchanged lines hidden ---