ctftools.h revision 495021bdf7d49b2cc9a6e6981b5ec4110264741b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _CTFTOOLS_H
#define _CTFTOOLS_H
/*
* Functions and data structures used in the manipulation of stabs and CTF data
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <libelf.h>
#include <gelf.h>
#include <pthread.h>
#include <sys/ccompile.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "list.h"
#include "hash.h"
#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL 0
#endif
#ifndef DEBUG_PARSE
#define DEBUG_PARSE 0
#endif
#ifndef DEBUG_STREAM
#define DEBUG_STREAM stderr
#endif
#ifndef MAX
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#endif
#ifndef MIN
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#endif
#define TRUE 1
#define FALSE 0
#define CTF_ELF_SCN_NAME ".SUNW_ctf"
#define CTF_LABEL_LASTIDX -1
#define CTF_DEFAULT_LABEL "*** No Label Provided ***"
/*
* Default hash sizes
*/
/*
* The default function argument array size. We'll realloc the array larger
* if we need to, but we want a default value that will allow us to avoid
* reallocation in the common case.
*/
#define FUNCARG_DEF 5
extern const char *progname;
extern int debug_level;
extern int debug_parse;
extern const char *curhdr;
/*
* This is a partial copy of the stab.h that DevPro includes with their
* compiler.
*/
typedef struct stab {
} stab_t;
/*
* Nodes in the type tree
*
* Each node consists of a single tdesc_t, with one of several auxiliary
* structures linked in via the `data' union.
*/
/* The type of tdesc_t node */
typedef enum stabtype {
STABTYPE_FIRST, /* do not use */
ENUM,
STABTYPE_LAST /* do not use */
} stabtype_t;
/* Auxiliary structure for array tdesc_t */
typedef struct ardef {
} ardef_t;
typedef struct mlist {
int ml_offset; /* Offset from start of structure (in bits) */
int ml_size; /* Member size (in bits) */
char *ml_name; /* Member name */
} mlist_t;
/* Auxiliary structure for enum tdesc_t */
typedef struct elist {
char *el_name;
int el_number;
} elist_t;
/* Auxiliary structure for intrinsics (integers and reals) */
typedef enum {
} intrtype_t;
typedef struct intr {
int intr_signed;
union {
char _iformat;
int _fformat;
} _u;
int intr_offset;
int intr_nbits;
} intr_t;
typedef struct fnarg {
char *fna_name;
} fnarg_t;
#define FN_F_GLOBAL 0x1
#define FN_F_VARARGS 0x2
typedef struct fndef {
} fndef_t;
/*
* The tdesc_t (Type DESCription) is the basic node type used in the stabs data
* structure. Each data node gets a tdesc structure. Each node is linked into
* a directed graph (think of it as a tree with multiple roots and multiple
* leaves), with the root nodes at the top, and intrinsics at the bottom. The
* root nodes, which are pointed to by iidesc nodes, correspond to the types,
* globals, and statics defined by the stabs.
*/
struct tdesc {
char *t_name;
int t_size; /* Size in bytes of object represented by this node */
union {
} t_data;
int t_flags;
int t_vgen; /* Visitation generation (see traverse.c) */
};
#define TDESC_F_GLOBAL 0x2
#define TDESC_F_RESOLVED 0x4
/*
* iidesc_t (Interesting Item DESCription) nodes point to tdesc_t nodes that
* correspond to "interesting" stabs. A stab is interesting if it defines a
* global or static variable, a global or static function, or a data type.
*/
typedef enum iitype {
II_NOT = 0,
II_GFUN, /* Global function */
II_SFUN, /* Static function */
II_GVAR, /* Global variable */
II_SVAR, /* Static variable */
II_PSYM, /* Function argument */
II_SOU, /* Struct or union */
II_TYPE /* Type (typedef) */
} iitype_t;
typedef struct iidesc {
char *ii_name;
char *ii_owner; /* File that defined this node */
int ii_flags;
/* Function arguments (if any) */
int ii_nargs;
int ii_vargs; /* Function uses varargs */
} iidesc_t;
/*
* labelent_t nodes identify labels and corresponding type ranges associated
* with them. The label in a given labelent_t is associated with types with
* ids <= le_idx.
*/
typedef struct labelent {
char *le_name;
int le_idx;
} labelent_t;
/*
* The tdata_t (Type DATA) structure contains or references all type data for
* a given file or, during merging, several files.
*/
typedef struct tdata {
int td_curemark; /* Equality mark (see merge.c) */
int td_curvgen; /* Visitation generation (see traverse.c) */
int td_nextid; /* The ID for the next tdesc_t created */
char *td_parlabel; /* Top label uniq'd against in parent */
char *td_parname; /* Basename of parent */
int td_ref;
} tdata_t;
/*
* By design, the iidesc hash is heterogeneous. The CTF emitter, on the
* other hand, needs to be able to access the elements of the list by type,
* and in a specific sorted order. An iiburst holds these elements in that
* order. (A burster is a machine that separates carbon-copy forms)
*/
typedef struct iiburst {
int iib_nfuncs;
int iib_curfunc;
int iib_nobjts;
int iib_curobjt;
int iib_maxtypeid;
} iiburst_t;
typedef struct symit_data symit_data_t;
/* fixup_tdescs.c */
void cvt_fixstabs(tdata_t *);
/* ctf.c */
/* iidesc.c */
iidesc_t *iidesc_new(char *);
int iidesc_hash(int, void *);
void iter_iidescs_by_name(tdata_t *, const char *,
int (*)(iidesc_t *, void *), void *);
void iidesc_free(iidesc_t *, void *);
int iidesc_count_type(void *, void *);
void iidesc_stats(hash_t *);
int iidesc_dump(iidesc_t *);
/* input.c */
typedef enum source_types {
SOURCE_NONE = 0,
SOURCE_UNKNOWN = 1,
SOURCE_C = 2,
SOURCE_S = 4
int count_files(char **, int);
void *, int);
int read_ctf_save_cb(tdata_t *, char *, void *);
void symit_reset(symit_data_t *);
char *symit_curfile(symit_data_t *);
char *symit_name(symit_data_t *);
void symit_free(symit_data_t *);
/* merge.c */
/* output.c */
/* parse.c */
void parse_init(tdata_t *);
void parse_finish(tdata_t *);
tdesc_t *lookupname(const char *);
void check_hash(void);
void resolve_typed_bitfields(void);
/* stabs.c */
/* dwarf.c */
const char *dw_tag2str(uint_t);
/* tdata.c */
void tdata_free(tdata_t *);
const char *tdesc_name(tdesc_t *);
int tdesc_idhash(int, void *);
int tdesc_idcmp(void *, void *);
int tdesc_namehash(int, void *);
int tdesc_namecmp(void *, void *);
int tdesc_layouthash(int, void *);
int tdesc_layoutcmp(void *, void *);
void tdesc_free(tdesc_t *);
void tdata_label_add(tdata_t *, char *, int);
int tdata_label_find(tdata_t *, char *);
void tdata_label_free(tdata_t *);
void tdata_label_newmax(tdata_t *, int);
/* util.c */
int streq(const char *, const char *);
int findelfsecidx(Elf *, const char *, const char *);
char *mktmpname(const char *, const char *);
void terminate(char *, ...) __NORETURN;
void aborterr(char *, ...) __NORETURN;
void set_terminate_cleanup(void (*)());
void elfterminate(const char *, const char *, ...);
void warning(char *, ...);
void debug(int, char *, ...);
#ifdef __cplusplus
}
#endif
#endif /* _CTFTOOLS_H */