4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
29 #include <sys/types.h>
31 #include <proc_service.h>
42 * Definitions from 2.7 sys/procfs_isa.h.
45 #define PR_MODEL_UNKNOWN 0
46 #define PR_MODEL_ILP32 1 /* process data model is ILP32 */
47 #define PR_MODEL_LP64 2 /* process data model is LP64 */
50 #define INTERPSECT ".interp"
51 #define PLTSECT ".plt"
54 * Flags for step_n routine
58 FLG_SN_VERBOSE
= (1 << 0), /* disassemble instructions */
59 FLG_SN_PLTSKIP
= (1 << 1) /* step *over* PLTS */
69 * sym_tbl_t contains a primary and an (optional) auxiliary symbol table, which
70 * we wish to treat as a single logical symbol table. In this logical table,
71 * the data from the auxiliary table precedes that from the primary. Symbol
72 * indices start at [0], which is the first item in the auxiliary table
73 * if there is one. The sole purpose for this is so that we can treat the
74 * combination of .SUNW_ldynsym and .dynsym sections as a logically single
75 * entity without having to violate the public interface to libelf.
77 * Both tables must share the same string table section.
79 * The symtab_getsym() function serves as a gelf_getsym() replacement
80 * that is aware of the two tables and makes them look like a single table
84 typedef struct sym_tbl
{
85 Elf_Data
*st_syms_pri
; /* start of primary table */
86 Elf_Data
*st_syms_aux
; /* start of auxiliary table */
87 char *st_strs
; /* ptr to strings */
88 size_t st_symn
; /* Total # of entries in both tables */
89 size_t st_symn_aux
; /* # of entries in auxiliary table */
92 typedef struct map_info
{
93 char *mi_name
; /* file info */
94 char *mi_refname
; /* filter reference name */
95 ulong_t mi_addr
; /* start address */
96 ulong_t mi_end
; /* end address */
97 int mi_mapfd
; /* file desc. for mapping */
98 size_t mi_pltentsz
; /* size of PLT entries */
99 Elf
*mi_elf
; /* elf handle so we can close */
101 sym_tbl_t mi_symtab
; /* symbol table */
102 sym_tbl_t mi_dynsym
; /* dynamic symbol table */
103 Lmid_t mi_lmident
; /* Link Map Ident */
104 ulong_t mi_pltbase
; /* PLT base address */
105 ulong_t mi_pltsize
; /* size of PLT table */
106 struct map_info
*mi_next
;
107 ulong_t mi_flags
; /* misc flags */
108 rd_loadobj_t mi_loadobj
; /* keep the old loadobj for */
112 #define FLG_MI_EXEC 0x0001 /* is object an EXEC */
114 #define FLG_PAP_SONAME 0x0001 /* embed SONAME in sym name */
115 #define FLG_PAP_NOHEXNAME 0x0002 /* if no symbol return */
117 #define FLG_PAP_PLTDECOM 0x0004 /* decompe PLT name if */
119 typedef struct map_list
{
125 * Break point information
127 typedef struct bpt_struct
{
128 ulong_t bl_addr
; /* address of breakpoint */
129 bptinstr_t bl_instr
; /* original instruction */
130 unsigned bl_flags
; /* break point flags */
131 struct bpt_struct
*bl_next
;
134 #define FLG_BP_USERDEF 0x0001 /* user defined BP */
135 #define FLG_BP_RDPREINIT 0x0002 /* PREINIT BreakPoint */
136 #define FLG_BP_RDPOSTINIT 0x0004 /* POSTINIT BreakPoint */
137 #define FLG_BP_RDDLACT 0x0008 /* DLACT BreakPoint */
138 #define FLG_BP_PLTRES 0x0010 /* PLT Resolve BP */
140 #define MASK_BP_SPECIAL \
141 (FLG_BP_RDPREINIT | FLG_BP_RDPOSTINIT | FLG_BP_RDDLACT)
142 #define MASK_BP_STOP \
143 (FLG_BP_USERDEF | FLG_BP_PLTRES)
144 #define MASK_BP_ALL \
145 (MASK_BP_SPECIAL | FLG_BP_USERDEF)
148 * Proc Services Structure
150 struct ps_prochandle
{
151 pid_t pp_pid
; /* debug process pid */
152 rd_agent_t
*pp_rap
; /* rtld_db handle */
153 int pp_ctlfd
; /* open ctl proc fd */
154 int pp_statusfd
; /* open status proc fd */
155 int pp_asfd
; /* open as proc fd */
156 int pp_mapfd
; /* open map proc fd */
157 uintptr_t pp_ldsobase
; /* ld.so.1 base address */
158 uintptr_t pp_execphdr
; /* a.out phdr address */
159 map_info_t pp_ldsomap
; /* ld.so.1 map info */
160 map_info_t pp_execmap
; /* exec map info */
161 map_list_t pp_lmaplist
; /* list of link map infos */
162 bptlist_t
*pp_breakpoints
; /* break point list */
163 void *pp_auxvp
; /* pointer to AUX vectors */
164 int pp_flags
; /* misc flags */
165 int pp_dmodel
; /* data model */
168 #define FLG_PP_PROMPT 0x0001 /* display debugger prompt */
169 #define FLG_PP_LMAPS 0x0002 /* link maps available */
170 #define FLG_PP_PACT 0x0004 /* active process being traced */
171 #define FLG_PP_PLTSKIP 0x0008 /* PLT skipping is active */
174 * Debugging Structure
176 typedef struct rtld_debug
{
182 #define TRAPBREAK 0x91d02001 /* ta ST_BREAKPOINT */
185 * values for rdb_flags
187 #define RDB_FL_EVENTS 0x0001 /* enable printing event information */
193 extern struct ps_prochandle proch
;
194 extern unsigned long rdb_flags
;
199 extern map_info_t
*addr_to_map(struct ps_prochandle
*, ulong_t
);
200 extern retc_t
addr_to_sym(struct ps_prochandle
*, ulong_t
,
201 GElf_Sym
*, char **);
202 extern void CallStack(struct ps_prochandle
*ph
);
203 extern unsigned continue_to_break(struct ps_prochandle
*);
204 extern retc_t
delete_all_breakpoints(struct ps_prochandle
*);
205 extern retc_t
delete_breakpoint(struct ps_prochandle
*, ulong_t
,
207 extern void disasm(struct ps_prochandle
*, int);
208 extern retc_t
disasm_addr(struct ps_prochandle
*, ulong_t
, int);
209 extern retc_t
display_all_regs(struct ps_prochandle
*);
210 extern retc_t
display_maps(struct ps_prochandle
*);
211 extern retc_t
display_linkmaps(struct ps_prochandle
*);
212 extern void free_linkmaps(struct ps_prochandle
*);
213 extern retc_t
get_linkmaps(struct ps_prochandle
*);
214 extern ulong_t
hexstr_to_num(const char *);
215 extern ulong_t
is_plt(struct ps_prochandle
*, ulong_t
);
216 extern void list_breakpoints(struct ps_prochandle
*);
217 extern retc_t
load_map(struct ps_prochandle
*, caddr_t
,
219 extern char *print_address(unsigned long);
220 extern char *print_address_ps(struct ps_prochandle
*,
221 unsigned long, unsigned);
222 extern void print_mem(struct ps_prochandle
*, ulong_t
, int,
224 extern void print_varstring(struct ps_prochandle
*, const char *);
225 extern void print_mach_varstring(struct ps_prochandle
*,
227 extern void rdb_help(const char *);
228 extern void rdb_prompt();
229 extern void perr(char *);
230 extern retc_t
proc_string_read(struct ps_prochandle
*,
231 ulong_t
, char *, int);
232 extern retc_t
ps_close(struct ps_prochandle
*);
233 extern retc_t
ps_init(int, int, pid_t
, struct ps_prochandle
*);
234 extern retc_t
set_breakpoint(struct ps_prochandle
*, ulong_t
,
236 extern retc_t
set_objpad(struct ps_prochandle
*, size_t);
237 extern retc_t
step_n(struct ps_prochandle
*, size_t, sn_flags_e
);
238 extern void step_to_addr(struct ps_prochandle
*, ulong_t
);
239 extern retc_t
str_map_sym(const char *, map_info_t
*, GElf_Sym
*,
241 extern map_info_t
*str_to_map(struct ps_prochandle
*, const char *);
242 extern retc_t
str_to_sym(struct ps_prochandle
*, const char *,
244 extern int yyparse(void);
245 extern int yyerror(char *);
246 extern int yylex(void);