stabs.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Routines used to read stabs data from a file, and to build a tdata structure
* based on the interesting parts of that data.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <libgen.h>
#include <errno.h>
#include "ctftools.h"
#include "list.h"
#include "stack.h"
#include "memory.h"
#include "traverse.h"
const char *curhdr;
/*
* The stabs generator will sometimes reference types before they've been
* defined. If this is the case, a TYPEDEF_UNRES tdesc will be generated.
* Note that this is different from a forward declaration, in which the
* stab is defined, but is defined as something that doesn't exist yet.
* When we have read all of the stabs from the file, we can go back and
* fix up all of the unresolved types. We should be able to fix all of them.
*/
/*ARGSUSED2*/
static int
{
}
return (1);
}
/*ARGSUSED*/
static int
{
return (0);
return (1);
}
static tdtrav_cb_f resolve_cbs[] = {
NULL,
NULL, /* intrinsic */
NULL, /* pointer */
NULL, /* array */
NULL, /* function */
NULL, /* struct */
NULL, /* union */
NULL, /* enum */
resolve_fwd_node, /* forward */
NULL, /* typedef */
resolve_tou_node, /* typedef unres */
NULL, /* volatile */
NULL, /* const */
NULL, /* restrict */
};
static void
{
}
static char *
{
char *out;
if (s1)
else
return (out);
}
/*
* N_FUN stabs come with their arguments in promoted form. In order to get the
* actual arguments, we need to wait for the N_PSYM stabs that will come towards
* the end of the function. These routines free the arguments (fnarg_free) we
* got from the N_FUN stab and add (fnarg_add) the ones from the N_PSYM stabs.
*/
static void
{
}
}
static void
{
}
/*
* Read the stabs from the stab ELF section, and turn them into a tdesc tree,
* assembled under an iidesc list.
*/
int
{
char curpath[MAXPATHLEN];
char *str;
int stabidx, stabstridx;
int scope = 0;
return (-1);
}
parse_init(td);
for (i = 0; i < nstabs; i++) {
/* We don't want any local definitions */
scope++;
continue;
scope--;
continue;
/*
* There's a bug in the 5.2 (Taz) compilers that causes
* them to emit an extra N_EINCL if there's no actual
* text in the file being compiled. To work around this
* bug, we explicitly check to make sure we're not
* trying to pop a stack that only has the outer scope
* on it.
*/
}
}
/* We only care about a subset of the stabs */
continue;
terminate("Can't find string at %u for stab %d\n",
}
continue;
}
continue;
terminate("GCC-generated stabs are "
"unsupported. Use DWARF instead.\n");
}
continue;
}
int offset = 1;
/*
* There's a bug in the compilers that causes them to
* generate \ for continuations with just -g (this is
* ok), and \\ for continuations with -g -O (this is
* broken). This bug is "fixed" in the 6.2 compilers
* via the elimination of continuation stabs.
*/
offset = 2;
continue;
} else
if (debug_level >= 3)
check_hash();
/*
* Sometimes the compiler stutters, and emits the same stab
* twice. This is bad for the parser, which will attempt to
* redefine the type IDs indicated in the stabs. This is
* compiler bug 4433511.
*/
continue;
}
if (ofstr)
terminate("Couldn't parse stab \"%s\" (file %s)\n",
if (rc == 0)
goto parse_loop_end;
/* Make sure the scope tracking is working correctly */
/*
* The only things we care about that are in local scope are
* the N_PSYM stabs.
*/
if (iidescp)
goto parse_loop_end;
}
case II_SFUN:
/*FALLTHROUGH*/
case II_GFUN:
break;
case II_SVAR:
/*FALLTHROUGH*/
case II_GVAR:
case II_TYPE:
case II_SOU:
break;
case II_PSYM:
break;
default:
}
}
if (ofstr)
return (0);
}