17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7a5d89c4Sab196087 * Common Development and Distribution License (the "License"). 6*7a5d89c4Sab196087 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 227c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 237c478bd9Sstevel@tonic-gate 2492ed1782Smike_s /* 25*7a5d89c4Sab196087 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 2692ed1782Smike_s * Use is subject to license terms. 2792ed1782Smike_s */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate 3292ed1782Smike_s /* 337c478bd9Sstevel@tonic-gate * symintHdr.h -- symbol information interface, Header file. 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * these headers are the definitions used by the set of 367c478bd9Sstevel@tonic-gate * routines which provide an interface to access symbol 377c478bd9Sstevel@tonic-gate * information stored in the object file. 387c478bd9Sstevel@tonic-gate * 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate /* protect against multiple inclusion */ 4192ed1782Smike_s #ifndef _SYMINTHDR_H 4292ed1782Smike_s #define _SYMINTHDR_H 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate 4692ed1782Smike_s #include <libelf.h> 4792ed1782Smike_s #include <sys/elf.h> 487c478bd9Sstevel@tonic-gate #include "dwarf.h" 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate 5192ed1782Smike_s /* 527c478bd9Sstevel@tonic-gate * PROF_DEBUG - compilation-time debug flag 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * if this is defined, we include debugging code. 557c478bd9Sstevel@tonic-gate * 567c478bd9Sstevel@tonic-gate * there are three levels: none, 1, and 2. 577c478bd9Sstevel@tonic-gate * 587c478bd9Sstevel@tonic-gate * none -- (PROF_DEBUG is undefined.) 597c478bd9Sstevel@tonic-gate * no debugging code is generated. 607c478bd9Sstevel@tonic-gate * 617c478bd9Sstevel@tonic-gate * 1 -- (PROF_DEBUG == 1.) 627c478bd9Sstevel@tonic-gate * assertion code is generated, only. 637c478bd9Sstevel@tonic-gate * 647c478bd9Sstevel@tonic-gate * 2 -- (PROF_DEBUG == anything else.) 657c478bd9Sstevel@tonic-gate * both assertion code and debug() code 667c478bd9Sstevel@tonic-gate * are generated. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #ifndef PROF_DEBUG 707c478bd9Sstevel@tonic-gate #define NDEBUG 717c478bd9Sstevel@tonic-gate #elif PROF_DEBUG == 1 727c478bd9Sstevel@tonic-gate #undef NDEBUG 737c478bd9Sstevel@tonic-gate #else /* == 2, anything else */ 747c478bd9Sstevel@tonic-gate #undef NDEBUG 757c478bd9Sstevel@tonic-gate #endif 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #include "assert.h" 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * Types 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * - caCOVWORD is used for all entries in the coverage structure. This 837c478bd9Sstevel@tonic-gate * includes the number of basic blocks, each line number in the line 847c478bd9Sstevel@tonic-gate * number array, and each execution count in the count array. The size 857c478bd9Sstevel@tonic-gate * (number of bytes) of the coverage structure may be found in the symbol 867c478bd9Sstevel@tonic-gate * table. 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate typedef unsigned char BYTES_1; 897c478bd9Sstevel@tonic-gate typedef unsigned short BYTES_2; 907c478bd9Sstevel@tonic-gate typedef unsigned int BYTES_4; 917c478bd9Sstevel@tonic-gate typedef unsigned long BYTES_LONG; /* ``long'' is 4 bytes, too */ 927c478bd9Sstevel@tonic-gate typedef BYTES_LONG caCOVWORD; 937c478bd9Sstevel@tonic-gate typedef unsigned char BOOLEAN; 9492ed1782Smike_s 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * Type of base address - used in dump.c and soqueue.c. 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate typedef unsigned long TYPE_BASEAD; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * Macros 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate #define SYMBOL_IS_FUNC(sym_p) \ 10492ed1782Smike_s (((sym_p)->ps_dbg.pd_symtag == TAG_subroutine) || \ 10592ed1782Smike_s ((sym_p)->ps_dbg.pd_symtag == TAG_global_subroutine)) 1067c478bd9Sstevel@tonic-gate #define SYMBOL_NAME(sym_p) (sym_p)->ps_dbg.pd_name 1077c478bd9Sstevel@tonic-gate #define SYMBOL_LINES_P(sym_p) (sym_p)->ps_dbg.pd_line_p 1087c478bd9Sstevel@tonic-gate #define SYMBOL_LASTLN_P(sym_p) (sym_p)->ps_dbg.pd_lali_p 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define ISYMBOL_IS_FUNC(sym_p, index) SYMBOL_IS_FUNC(&((sym_p)[(index)])) 1117c478bd9Sstevel@tonic-gate #define ISYMBOL_NAME(sym_p, index) SYMBOL_NAME(&((sym_p)[(index)])) 1127c478bd9Sstevel@tonic-gate #define ISYMBOL_LINES(sym_p, index) SYMBOL_LINES(&((sym_p)[(index)])) 1137c478bd9Sstevel@tonic-gate #define ISYMBOL_LASTLN(sym_p, index) SYMBOL_LASTLN(&((sym_p)[(index)])) 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate typedef struct { 1167c478bd9Sstevel@tonic-gate unsigned char pe_ident[EI_NIDENT]; 1177c478bd9Sstevel@tonic-gate Elf32_Half pe_type; 1187c478bd9Sstevel@tonic-gate } PROF_MAGIC; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #define PROF_MAGIC_FAKE_STRING "fake prof magic" 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #define COV_PREFIX "__coverage." 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate 12692ed1782Smike_s /* 1277c478bd9Sstevel@tonic-gate * ``primitive'' definitions used in 1287c478bd9Sstevel@tonic-gate * subsequent structures. 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate typedef unsigned char LEN1; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate typedef unsigned short LEN2; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate typedef unsigned long int LEN4; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate typedef unsigned long int ADDR; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate typedef LEN2 DBG_TAG; 1407c478bd9Sstevel@tonic-gate 14192ed1782Smike_s /* 1427c478bd9Sstevel@tonic-gate * object ``replacing'' a symbol table entry - PROF_SYMBOL. 1437c478bd9Sstevel@tonic-gate * 1447c478bd9Sstevel@tonic-gate * a PROF_SYMBOL will contain or direct us to all the information 1457c478bd9Sstevel@tonic-gate * needed by the profilers, for a given symbol. 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate typedef struct symint_prof_symbol 1487c478bd9Sstevel@tonic-gate PROF_SYMBOL; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate struct symint_prof_symbol { 1517c478bd9Sstevel@tonic-gate Elf32_Sym ps_sym; /* normal symbol entry */ 1527c478bd9Sstevel@tonic-gate }; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate 15592ed1782Smike_s /* 1567c478bd9Sstevel@tonic-gate * structure to replace LDFILE - PROF_FILE. 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate typedef struct symint_prof_file 1597c478bd9Sstevel@tonic-gate PROF_FILE; 1607c478bd9Sstevel@tonic-gate 161*7a5d89c4Sab196087 162*7a5d89c4Sab196087 /* 163*7a5d89c4Sab196087 * symint_prof_file contains a primary and an (optional) auxiliary 164*7a5d89c4Sab196087 * symbol table, which we wish to treat as a single logical symbol table. 165*7a5d89c4Sab196087 * In this logical table, the data from the auxiliary table preceeds that 166*7a5d89c4Sab196087 * from the primary. Symbol indices start at [0], which is the first item 167*7a5d89c4Sab196087 * in the auxiliary table if there is one. The sole purpose for this is so 168*7a5d89c4Sab196087 * that we can treat the combination of .SUNW_ldynsym and .dynsym sections 169*7a5d89c4Sab196087 * as a logically single entity. 170*7a5d89c4Sab196087 * 171*7a5d89c4Sab196087 * Both tables must share the same string table section. 172*7a5d89c4Sab196087 */ 1737c478bd9Sstevel@tonic-gate struct symint_prof_file { 1747c478bd9Sstevel@tonic-gate int pf_fildes; /* file descriptor */ 1757c478bd9Sstevel@tonic-gate Elf *pf_elf_p; /* elf descriptor */ 1767c478bd9Sstevel@tonic-gate Elf32_Ehdr *pf_elfhd_p; /* elf header */ 1777c478bd9Sstevel@tonic-gate Elf_Data *pf_snmdat_p; /* section names data */ 178*7a5d89c4Sab196087 Elf_Data *pf_symdat_pri_p; /* primary symbol table data */ 179*7a5d89c4Sab196087 Elf_Data *pf_symdat_aux_p; /* auxiliary symbol table data */ 180*7a5d89c4Sab196087 Elf32_Word pf_symstr_ndx; /* Section index of string table */ 181*7a5d89c4Sab196087 int pf_nstsyms; /* total # symbols in both tables */ 182*7a5d89c4Sab196087 int pf_nstsyms_aux; /* # symbols in auxiliary table */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate Elf32_Shdr *pf_shdarr_p; /* complete array of section hdrs */ 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate PROF_SYMBOL *pf_symarr_p; /* P_S array w/symbols of interest */ 1877c478bd9Sstevel@tonic-gate int pf_nsyms; /* number of symbols of interest */ 1887c478bd9Sstevel@tonic-gate }; 1897c478bd9Sstevel@tonic-gate 19092ed1782Smike_s #endif /* _SYMINTHDR_H */ 191