1*12927SRod.Evans@Sun.COM /* 2*12927SRod.Evans@Sun.COM * CDDL HEADER START 3*12927SRod.Evans@Sun.COM * 4*12927SRod.Evans@Sun.COM * The contents of this file are subject to the terms of the 5*12927SRod.Evans@Sun.COM * Common Development and Distribution License (the "License"). 6*12927SRod.Evans@Sun.COM * You may not use this file except in compliance with the License. 7*12927SRod.Evans@Sun.COM * 8*12927SRod.Evans@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*12927SRod.Evans@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*12927SRod.Evans@Sun.COM * See the License for the specific language governing permissions 11*12927SRod.Evans@Sun.COM * and limitations under the License. 12*12927SRod.Evans@Sun.COM * 13*12927SRod.Evans@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*12927SRod.Evans@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*12927SRod.Evans@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*12927SRod.Evans@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*12927SRod.Evans@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*12927SRod.Evans@Sun.COM * 19*12927SRod.Evans@Sun.COM * CDDL HEADER END 20*12927SRod.Evans@Sun.COM */ 21*12927SRod.Evans@Sun.COM 22*12927SRod.Evans@Sun.COM /* 23*12927SRod.Evans@Sun.COM * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. 24*12927SRod.Evans@Sun.COM */ 25*12927SRod.Evans@Sun.COM #ifndef _RDB_H 26*12927SRod.Evans@Sun.COM #define _RDB_H 27*12927SRod.Evans@Sun.COM 28*12927SRod.Evans@Sun.COM #include <rtld_db.h> 29*12927SRod.Evans@Sun.COM #include <sys/types.h> 30*12927SRod.Evans@Sun.COM #include <procfs.h> 31*12927SRod.Evans@Sun.COM #include <proc_service.h> 32*12927SRod.Evans@Sun.COM #include <libelf.h> 33*12927SRod.Evans@Sun.COM #include <gelf.h> 34*12927SRod.Evans@Sun.COM 35*12927SRod.Evans@Sun.COM #include <rdb_mach.h> 36*12927SRod.Evans@Sun.COM 37*12927SRod.Evans@Sun.COM #ifdef __cplusplus 38*12927SRod.Evans@Sun.COM extern "C" { 39*12927SRod.Evans@Sun.COM #endif 40*12927SRod.Evans@Sun.COM 41*12927SRod.Evans@Sun.COM /* 42*12927SRod.Evans@Sun.COM * Definitions from 2.7 sys/procfs_isa.h. 43*12927SRod.Evans@Sun.COM */ 44*12927SRod.Evans@Sun.COM #ifndef PR_MODEL_LP64 45*12927SRod.Evans@Sun.COM #define PR_MODEL_UNKNOWN 0 46*12927SRod.Evans@Sun.COM #define PR_MODEL_ILP32 1 /* process data model is ILP32 */ 47*12927SRod.Evans@Sun.COM #define PR_MODEL_LP64 2 /* process data model is LP64 */ 48*12927SRod.Evans@Sun.COM #endif 49*12927SRod.Evans@Sun.COM 50*12927SRod.Evans@Sun.COM #define INTERPSECT ".interp" 51*12927SRod.Evans@Sun.COM #define PLTSECT ".plt" 52*12927SRod.Evans@Sun.COM 53*12927SRod.Evans@Sun.COM /* 54*12927SRod.Evans@Sun.COM * Flags for step_n routine 55*12927SRod.Evans@Sun.COM */ 56*12927SRod.Evans@Sun.COM typedef enum { 57*12927SRod.Evans@Sun.COM FLG_SN_NONE = 0, 58*12927SRod.Evans@Sun.COM FLG_SN_VERBOSE = (1 << 0), /* disassemble instructions */ 59*12927SRod.Evans@Sun.COM FLG_SN_PLTSKIP = (1 << 1) /* step *over* PLTS */ 60*12927SRod.Evans@Sun.COM } sn_flags_e; 61*12927SRod.Evans@Sun.COM 62*12927SRod.Evans@Sun.COM 63*12927SRod.Evans@Sun.COM typedef enum { 64*12927SRod.Evans@Sun.COM RET_FAILED = -1, 65*12927SRod.Evans@Sun.COM RET_OK = 0 66*12927SRod.Evans@Sun.COM } retc_t; 67*12927SRod.Evans@Sun.COM 68*12927SRod.Evans@Sun.COM /* 69*12927SRod.Evans@Sun.COM * sym_tbl_t contains a primary and an (optional) auxiliary symbol table, which 70*12927SRod.Evans@Sun.COM * we wish to treat as a single logical symbol table. In this logical table, 71*12927SRod.Evans@Sun.COM * the data from the auxiliary table precedes that from the primary. Symbol 72*12927SRod.Evans@Sun.COM * indices start at [0], which is the first item in the auxiliary table 73*12927SRod.Evans@Sun.COM * if there is one. The sole purpose for this is so that we can treat the 74*12927SRod.Evans@Sun.COM * combination of .SUNW_ldynsym and .dynsym sections as a logically single 75*12927SRod.Evans@Sun.COM * entity without having to violate the public interface to libelf. 76*12927SRod.Evans@Sun.COM * 77*12927SRod.Evans@Sun.COM * Both tables must share the same string table section. 78*12927SRod.Evans@Sun.COM * 79*12927SRod.Evans@Sun.COM * The symtab_getsym() function serves as a gelf_getsym() replacement 80*12927SRod.Evans@Sun.COM * that is aware of the two tables and makes them look like a single table 81*12927SRod.Evans@Sun.COM * to the caller. 82*12927SRod.Evans@Sun.COM * 83*12927SRod.Evans@Sun.COM */ 84*12927SRod.Evans@Sun.COM typedef struct sym_tbl { 85*12927SRod.Evans@Sun.COM Elf_Data *st_syms_pri; /* start of primary table */ 86*12927SRod.Evans@Sun.COM Elf_Data *st_syms_aux; /* start of auxiliary table */ 87*12927SRod.Evans@Sun.COM char *st_strs; /* ptr to strings */ 88*12927SRod.Evans@Sun.COM size_t st_symn; /* Total # of entries in both tables */ 89*12927SRod.Evans@Sun.COM size_t st_symn_aux; /* # of entries in auxiliary table */ 90*12927SRod.Evans@Sun.COM } sym_tbl_t; 91*12927SRod.Evans@Sun.COM 92*12927SRod.Evans@Sun.COM typedef struct map_info { 93*12927SRod.Evans@Sun.COM char *mi_name; /* file info */ 94*12927SRod.Evans@Sun.COM char *mi_refname; /* filter reference name */ 95*12927SRod.Evans@Sun.COM ulong_t mi_addr; /* start address */ 96*12927SRod.Evans@Sun.COM ulong_t mi_end; /* end address */ 97*12927SRod.Evans@Sun.COM int mi_mapfd; /* file desc. for mapping */ 98*12927SRod.Evans@Sun.COM size_t mi_pltentsz; /* size of PLT entries */ 99*12927SRod.Evans@Sun.COM Elf *mi_elf; /* elf handle so we can close */ 100*12927SRod.Evans@Sun.COM GElf_Ehdr mi_ehdr; 101*12927SRod.Evans@Sun.COM sym_tbl_t mi_symtab; /* symbol table */ 102*12927SRod.Evans@Sun.COM sym_tbl_t mi_dynsym; /* dynamic symbol table */ 103*12927SRod.Evans@Sun.COM Lmid_t mi_lmident; /* Link Map Ident */ 104*12927SRod.Evans@Sun.COM ulong_t mi_pltbase; /* PLT base address */ 105*12927SRod.Evans@Sun.COM ulong_t mi_pltsize; /* size of PLT table */ 106*12927SRod.Evans@Sun.COM struct map_info *mi_next; 107*12927SRod.Evans@Sun.COM ulong_t mi_flags; /* misc flags */ 108*12927SRod.Evans@Sun.COM rd_loadobj_t mi_loadobj; /* keep the old loadobj for */ 109*12927SRod.Evans@Sun.COM /* good luck */ 110*12927SRod.Evans@Sun.COM } map_info_t; 111*12927SRod.Evans@Sun.COM 112*12927SRod.Evans@Sun.COM #define FLG_MI_EXEC 0x0001 /* is object an EXEC */ 113*12927SRod.Evans@Sun.COM 114*12927SRod.Evans@Sun.COM #define FLG_PAP_SONAME 0x0001 /* embed SONAME in sym name */ 115*12927SRod.Evans@Sun.COM #define FLG_PAP_NOHEXNAME 0x0002 /* if no symbol return */ 116*12927SRod.Evans@Sun.COM /* null string */ 117*12927SRod.Evans@Sun.COM #define FLG_PAP_PLTDECOM 0x0004 /* decompe PLT name if */ 118*12927SRod.Evans@Sun.COM /* possible */ 119*12927SRod.Evans@Sun.COM typedef struct map_list { 120*12927SRod.Evans@Sun.COM map_info_t *ml_head; 121*12927SRod.Evans@Sun.COM map_info_t *ml_tail; 122*12927SRod.Evans@Sun.COM } map_list_t; 123*12927SRod.Evans@Sun.COM 124*12927SRod.Evans@Sun.COM /* 125*12927SRod.Evans@Sun.COM * Break point information 126*12927SRod.Evans@Sun.COM */ 127*12927SRod.Evans@Sun.COM typedef struct bpt_struct { 128*12927SRod.Evans@Sun.COM ulong_t bl_addr; /* address of breakpoint */ 129*12927SRod.Evans@Sun.COM bptinstr_t bl_instr; /* original instruction */ 130*12927SRod.Evans@Sun.COM unsigned bl_flags; /* break point flags */ 131*12927SRod.Evans@Sun.COM struct bpt_struct *bl_next; 132*12927SRod.Evans@Sun.COM } bptlist_t; 133*12927SRod.Evans@Sun.COM 134*12927SRod.Evans@Sun.COM #define FLG_BP_USERDEF 0x0001 /* user defined BP */ 135*12927SRod.Evans@Sun.COM #define FLG_BP_RDPREINIT 0x0002 /* PREINIT BreakPoint */ 136*12927SRod.Evans@Sun.COM #define FLG_BP_RDPOSTINIT 0x0004 /* POSTINIT BreakPoint */ 137*12927SRod.Evans@Sun.COM #define FLG_BP_RDDLACT 0x0008 /* DLACT BreakPoint */ 138*12927SRod.Evans@Sun.COM #define FLG_BP_PLTRES 0x0010 /* PLT Resolve BP */ 139*12927SRod.Evans@Sun.COM 140*12927SRod.Evans@Sun.COM #define MASK_BP_SPECIAL \ 141*12927SRod.Evans@Sun.COM (FLG_BP_RDPREINIT | FLG_BP_RDPOSTINIT | FLG_BP_RDDLACT) 142*12927SRod.Evans@Sun.COM #define MASK_BP_STOP \ 143*12927SRod.Evans@Sun.COM (FLG_BP_USERDEF | FLG_BP_PLTRES) 144*12927SRod.Evans@Sun.COM #define MASK_BP_ALL \ 145*12927SRod.Evans@Sun.COM (MASK_BP_SPECIAL | FLG_BP_USERDEF) 146*12927SRod.Evans@Sun.COM 147*12927SRod.Evans@Sun.COM /* 148*12927SRod.Evans@Sun.COM * Proc Services Structure 149*12927SRod.Evans@Sun.COM */ 150*12927SRod.Evans@Sun.COM struct ps_prochandle { 151*12927SRod.Evans@Sun.COM pid_t pp_pid; /* debug process pid */ 152*12927SRod.Evans@Sun.COM rd_agent_t *pp_rap; /* rtld_db handle */ 153*12927SRod.Evans@Sun.COM int pp_ctlfd; /* open ctl proc fd */ 154*12927SRod.Evans@Sun.COM int pp_statusfd; /* open status proc fd */ 155*12927SRod.Evans@Sun.COM int pp_asfd; /* open as proc fd */ 156*12927SRod.Evans@Sun.COM int pp_mapfd; /* open map proc fd */ 157*12927SRod.Evans@Sun.COM uintptr_t pp_ldsobase; /* ld.so.1 base address */ 158*12927SRod.Evans@Sun.COM uintptr_t pp_execphdr; /* a.out phdr address */ 159*12927SRod.Evans@Sun.COM map_info_t pp_ldsomap; /* ld.so.1 map info */ 160*12927SRod.Evans@Sun.COM map_info_t pp_execmap; /* exec map info */ 161*12927SRod.Evans@Sun.COM map_list_t pp_lmaplist; /* list of link map infos */ 162*12927SRod.Evans@Sun.COM bptlist_t *pp_breakpoints; /* break point list */ 163*12927SRod.Evans@Sun.COM void *pp_auxvp; /* pointer to AUX vectors */ 164*12927SRod.Evans@Sun.COM int pp_flags; /* misc flags */ 165*12927SRod.Evans@Sun.COM int pp_dmodel; /* data model */ 166*12927SRod.Evans@Sun.COM }; 167*12927SRod.Evans@Sun.COM 168*12927SRod.Evans@Sun.COM #define FLG_PP_PROMPT 0x0001 /* display debugger prompt */ 169*12927SRod.Evans@Sun.COM #define FLG_PP_LMAPS 0x0002 /* link maps available */ 170*12927SRod.Evans@Sun.COM #define FLG_PP_PACT 0x0004 /* active process being traced */ 171*12927SRod.Evans@Sun.COM #define FLG_PP_PLTSKIP 0x0008 /* PLT skipping is active */ 172*12927SRod.Evans@Sun.COM 173*12927SRod.Evans@Sun.COM /* 174*12927SRod.Evans@Sun.COM * Debugging Structure 175*12927SRod.Evans@Sun.COM */ 176*12927SRod.Evans@Sun.COM typedef struct rtld_debug { 177*12927SRod.Evans@Sun.COM int rd_vers; 178*12927SRod.Evans@Sun.COM caddr_t rd_preinit; 179*12927SRod.Evans@Sun.COM caddr_t rd_postinit; 180*12927SRod.Evans@Sun.COM } rtld_debug_t; 181*12927SRod.Evans@Sun.COM 182*12927SRod.Evans@Sun.COM #define TRAPBREAK 0x91d02001 /* ta ST_BREAKPOINT */ 183*12927SRod.Evans@Sun.COM 184*12927SRod.Evans@Sun.COM /* 185*12927SRod.Evans@Sun.COM * values for rdb_flags 186*12927SRod.Evans@Sun.COM */ 187*12927SRod.Evans@Sun.COM #define RDB_FL_EVENTS 0x0001 /* enable printing event information */ 188*12927SRod.Evans@Sun.COM 189*12927SRod.Evans@Sun.COM /* 190*12927SRod.Evans@Sun.COM * Globals 191*12927SRod.Evans@Sun.COM */ 192*12927SRod.Evans@Sun.COM 193*12927SRod.Evans@Sun.COM extern struct ps_prochandle proch; 194*12927SRod.Evans@Sun.COM extern unsigned long rdb_flags; 195*12927SRod.Evans@Sun.COM 196*12927SRod.Evans@Sun.COM /* 197*12927SRod.Evans@Sun.COM * Functions 198*12927SRod.Evans@Sun.COM */ 199*12927SRod.Evans@Sun.COM extern map_info_t *addr_to_map(struct ps_prochandle *, ulong_t); 200*12927SRod.Evans@Sun.COM extern retc_t addr_to_sym(struct ps_prochandle *, ulong_t, 201*12927SRod.Evans@Sun.COM GElf_Sym *, char **); 202*12927SRod.Evans@Sun.COM extern void CallStack(struct ps_prochandle *ph); 203*12927SRod.Evans@Sun.COM extern unsigned continue_to_break(struct ps_prochandle *); 204*12927SRod.Evans@Sun.COM extern retc_t delete_all_breakpoints(struct ps_prochandle *); 205*12927SRod.Evans@Sun.COM extern retc_t delete_breakpoint(struct ps_prochandle *, ulong_t, 206*12927SRod.Evans@Sun.COM unsigned); 207*12927SRod.Evans@Sun.COM extern void disasm(struct ps_prochandle *, int); 208*12927SRod.Evans@Sun.COM extern retc_t disasm_addr(struct ps_prochandle *, ulong_t, int); 209*12927SRod.Evans@Sun.COM extern retc_t display_all_regs(struct ps_prochandle *); 210*12927SRod.Evans@Sun.COM extern retc_t display_maps(struct ps_prochandle *); 211*12927SRod.Evans@Sun.COM extern retc_t display_linkmaps(struct ps_prochandle *); 212*12927SRod.Evans@Sun.COM extern void free_linkmaps(struct ps_prochandle *); 213*12927SRod.Evans@Sun.COM extern retc_t get_linkmaps(struct ps_prochandle *); 214*12927SRod.Evans@Sun.COM extern ulong_t hexstr_to_num(const char *); 215*12927SRod.Evans@Sun.COM extern ulong_t is_plt(struct ps_prochandle *, ulong_t); 216*12927SRod.Evans@Sun.COM extern void list_breakpoints(struct ps_prochandle *); 217*12927SRod.Evans@Sun.COM extern retc_t load_map(struct ps_prochandle *, caddr_t, 218*12927SRod.Evans@Sun.COM map_info_t *mp); 219*12927SRod.Evans@Sun.COM extern char *print_address(unsigned long); 220*12927SRod.Evans@Sun.COM extern char *print_address_ps(struct ps_prochandle *, 221*12927SRod.Evans@Sun.COM unsigned long, unsigned); 222*12927SRod.Evans@Sun.COM extern void print_mem(struct ps_prochandle *, ulong_t, int, 223*12927SRod.Evans@Sun.COM char *); 224*12927SRod.Evans@Sun.COM extern void print_varstring(struct ps_prochandle *, const char *); 225*12927SRod.Evans@Sun.COM extern void print_mach_varstring(struct ps_prochandle *, 226*12927SRod.Evans@Sun.COM const char *); 227*12927SRod.Evans@Sun.COM extern void rdb_help(const char *); 228*12927SRod.Evans@Sun.COM extern void rdb_prompt(); 229*12927SRod.Evans@Sun.COM extern void perr(char *); 230*12927SRod.Evans@Sun.COM extern retc_t proc_string_read(struct ps_prochandle *, 231*12927SRod.Evans@Sun.COM ulong_t, char *, int); 232*12927SRod.Evans@Sun.COM extern retc_t ps_close(struct ps_prochandle *); 233*12927SRod.Evans@Sun.COM extern retc_t ps_init(int, int, pid_t, struct ps_prochandle *); 234*12927SRod.Evans@Sun.COM extern retc_t set_breakpoint(struct ps_prochandle *, ulong_t, 235*12927SRod.Evans@Sun.COM unsigned); 236*12927SRod.Evans@Sun.COM extern retc_t set_objpad(struct ps_prochandle *, size_t); 237*12927SRod.Evans@Sun.COM extern retc_t step_n(struct ps_prochandle *, size_t, sn_flags_e); 238*12927SRod.Evans@Sun.COM extern void step_to_addr(struct ps_prochandle *, ulong_t); 239*12927SRod.Evans@Sun.COM extern retc_t str_map_sym(const char *, map_info_t *, GElf_Sym *, 240*12927SRod.Evans@Sun.COM char **); 241*12927SRod.Evans@Sun.COM extern map_info_t *str_to_map(struct ps_prochandle *, const char *); 242*12927SRod.Evans@Sun.COM extern retc_t str_to_sym(struct ps_prochandle *, const char *, 243*12927SRod.Evans@Sun.COM GElf_Sym *); 244*12927SRod.Evans@Sun.COM extern int yyparse(void); 245*12927SRod.Evans@Sun.COM extern int yyerror(char *); 246*12927SRod.Evans@Sun.COM extern int yylex(void); 247*12927SRod.Evans@Sun.COM 248*12927SRod.Evans@Sun.COM #ifdef __cplusplus 249*12927SRod.Evans@Sun.COM } 250*12927SRod.Evans@Sun.COM #endif 251*12927SRod.Evans@Sun.COM 252*12927SRod.Evans@Sun.COM #endif /* _RDB_H */ 253