ctfstabs.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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This program has two modes.
*
* In the first, or genassym, mode, it generates a header file containing
* #define'd values for offsets and other information about requested
* structures and arrays. This header file can then be used by assembly
* source files to access those structures without having to hard-code the
* offsets. The offsets and values in the header file are derived from the
* CTF data in a provided object file.
*
* The second mode creates forthdebug macros for specified structures and
* members from an object file. The macros are created using the CTF data in
* the object file.
*
* Forthdebug macros and offsets header files are generated using the same
* tool for historical reasons.
*
* The input and output files, and their interaction with the tool are
* shown below:
*
* --------------- ----------- cc -c -g ------------------
* |#includes | -----> |#includes| ------------> |object file with|
* |mode-specific| ----------- ctfconvert | CTF data |
* | directives| ------------------
* --------------- |
* | | obj_file
* | V
* | ------------ ----------
* \-------------> |directives| ---------------> |ctfstabs|
* ------------ input_template ----------
* |
* V
* ---------------
* Mode-specific input and output formats are |mode-specific|
* described in forth.c and genassym.c | output |
* ---------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <libgen.h>
#include <string.h>
#include <ctype.h>
#include "ctf_headers.h"
#include "utils.h"
#include "memory.h"
#include "ctfstabs.h"
#define WORD_LEN 256
static int lineno;
static void
usage(void)
{
"[-i input_template] [-o output] obj_file\n", getpname());
"[-i input_template] [-o output] obj_file\n", getpname());
exit(2);
}
/*PRINTFLIKE1*/
int
parse_warn(char *format, ...)
{
return (-1);
}
#define READLINE_BUF_INCR 2
/*
* Read a line of input into a statically-allocated buffer. If the line
* is larger than the buffer, the buffer will be dynamically resized.
* Subsequent calls will overwrite the buffer.
*/
static char *
{
static int buflen;
if (buflen == 0) {
}
for (;;) {
return (NULL);
return (buf);
}
}
/*
* We're only given a type name. Even if it's a struct or a union, we
* still only get the struct or union name. We therefore iterate through
* the possible prefixes, trying to find the right type.
*/
{
return (id);
return (id);
return (id);
return (id);
return (CTF_ERR);
}
static int
{
char *line;
int skipping;
int err = 0;
if (len == 0)
skipping = 0;
if (skipping == 1)
continue;
(void) parse_warn("Error found: skipping to the next "
"blank line");
err++;
skipping = 1;
continue;
}
}
return (err > 0 ? -1 : 0);
}
static char *
{
/* Neither of these should fail */
die("Couldn't get size of long in object file");
if (lsz == 8)
return ("lp64");
else if (lsz == 4)
return ("ilp32");
else
return (NULL);
}
int
{
int ctferr, c;
switch (c) {
case 'i':
break;
case 'm':
break;
case 't':
else
usage();
break;
case 'o':
break;
default:
usage();
}
}
usage();
/*
* this can fail if ENOENT or if there's no CTF data in the file.
*/
ctf_errmsg(ctferr));
}
return (1);
}
return (0);
}