1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <msg.h> 30 #include <_rtld.h> 31 #include <conv.h> 32 #include <sys/mdb_modapi.h> 33 #include <sys/param.h> 34 #include <stdlib.h> 35 36 /* 37 * Data structure for walkers. 38 */ 39 typedef struct { 40 uint_t w_flags; 41 } W_desc; 42 43 44 /* 45 * Flags values for dcmds 46 */ 47 48 #define RTLD_FLG_VERBOSE 0x0001 /* verbose output */ 49 50 static const mdb_bitmask_t rtflags_bits[] = { 51 { MSG_ORIG(MSG_FLG_ISMAIN), FLG_RT_ISMAIN, FLG_RT_ISMAIN}, 52 { MSG_ORIG(MSG_FLG_IMGALLOC), FLG_RT_IMGALLOC, FLG_RT_IMGALLOC}, 53 { MSG_ORIG(MSG_FLG_RELOCED), FLG_RT_RELOCED, FLG_RT_RELOCED}, 54 { MSG_ORIG(MSG_FLG_SETGROUP), FLG_RT_SETGROUP, FLG_RT_SETGROUP}, 55 { MSG_ORIG(MSG_FLG_HWCAP), FLG_RT_HWCAP, FLG_RT_HWCAP}, 56 { MSG_ORIG(MSG_FLG_OBJECT), FLG_RT_OBJECT, FLG_RT_OBJECT}, 57 { MSG_ORIG(MSG_FLG_NODUMP), FLG_RT_NODUMP, FLG_RT_NODUMP}, 58 { MSG_ORIG(MSG_FLG_DELETE), FLG_RT_DELETE, FLG_RT_DELETE}, 59 { MSG_ORIG(MSG_FLG_ANALYZED), FLG_RT_ANALYZED, FLG_RT_ANALYZED}, 60 { MSG_ORIG(MSG_FLG_INITDONE), FLG_RT_INITDONE, FLG_RT_INITDONE}, 61 { MSG_ORIG(MSG_FLG_TRANS), FLG_RT_TRANS, FLG_RT_TRANS}, 62 { MSG_ORIG(MSG_FLG_FIXED), FLG_RT_FIXED, FLG_RT_FIXED}, 63 { MSG_ORIG(MSG_FLG_PRELOAD), FLG_RT_PRELOAD, FLG_RT_PRELOAD}, 64 { MSG_ORIG(MSG_FLG_ALTER), FLG_RT_ALTER, FLG_RT_ALTER}, 65 { MSG_ORIG(MSG_FLG_LOADFLTR), FLG_RT_LOADFLTR, FLG_RT_LOADFLTR}, 66 { MSG_ORIG(MSG_FLG_AUDIT), FLG_RT_AUDIT, FLG_RT_AUDIT}, 67 { MSG_ORIG(MSG_FLG_MODESET), FLG_RT_MODESET, FLG_RT_MODESET}, 68 { MSG_ORIG(MSG_FLG_ANALZING), FLG_RT_ANALZING, FLG_RT_ANALZING}, 69 { MSG_ORIG(MSG_FLG_INITFRST), FLG_RT_INITFRST, FLG_RT_INITFRST}, 70 { MSG_ORIG(MSG_FLG_NOOPEN), FLG_RT_NOOPEN, FLG_RT_NOOPEN}, 71 { MSG_ORIG(MSG_FLG_FINICLCT), FLG_RT_FINICLCT, FLG_RT_FINICLCT}, 72 { MSG_ORIG(MSG_FLG_INITCALL), FLG_RT_INITCALL, FLG_RT_INITCALL}, 73 { MSG_ORIG(MSG_FLG_INTRPOSE), FLG_RT_INTRPOSE, FLG_RT_INTRPOSE}, 74 { MSG_ORIG(MSG_FLG_DIRECT), FLG_RT_DIRECT, FLG_RT_DIRECT}, 75 { MSG_ORIG(MSG_FLG_SUNWBSS), FLG_RT_SUNWBSS, FLG_RT_SUNWBSS}, 76 { MSG_ORIG(MSG_FLG_MOVE), FLG_RT_MOVE, FLG_RT_MOVE}, 77 { MSG_ORIG(MSG_FLG_DLSYM), FLG_RT_DLSYM, FLG_RT_DLSYM}, 78 { MSG_ORIG(MSG_FLG_REGSYMS), FLG_RT_REGSYMS, FLG_RT_REGSYMS}, 79 { MSG_ORIG(MSG_FLG_INITCLCT), FLG_RT_INITCLCT, FLG_RT_INITCLCT}, 80 { MSG_ORIG(MSG_FLG_HANDLE), FLG_RT_HANDLE, FLG_RT_HANDLE}, 81 { MSG_ORIG(MSG_FLG_RELOCING), FLG_RT_RELOCING, FLG_RT_RELOCING}, 82 { NULL, 0, 0} 83 }; 84 85 static const mdb_bitmask_t rtflags1_bits[] = { 86 { MSG_ORIG(MSG_FL1_COPYTOOK), FL1_RT_COPYTOOK, FL1_RT_COPYTOOK}, 87 { MSG_ORIG(MSG_FL1_RELATIVE), FL1_RT_RELATIVE, FL1_RT_RELATIVE }, 88 { MSG_ORIG(MSG_FL1_CONFSET), FL1_RT_CONFSET, FL1_RT_CONFSET }, 89 { MSG_ORIG(MSG_FL1_NODEFLIB), FL1_RT_NODEFLIB, FL1_RT_NODEFLIB }, 90 { MSG_ORIG(MSG_FL1_ENDFILTE), FL1_RT_ENDFILTE, FL1_RT_ENDFILTE }, 91 { MSG_ORIG(MSG_FL1_DISPREL), FL1_RT_DISPREL, FL1_RT_DISPREL }, 92 { MSG_ORIG(MSG_FL1_TEXTREL), FL1_RT_TEXTREL, FL1_RT_TEXTREL }, 93 { MSG_ORIG(MSG_FL1_INITWAIT), FL1_RT_INITWAIT, FL1_RT_INITWAIT }, 94 { MSG_ORIG(MSG_FL1_LDDSTUB), FL1_RT_LDDSTUB, FL1_RT_LDDSTUB}, 95 { MSG_ORIG(MSG_FL1_NOINIFIN), FL1_RT_NOINIFIN, FL1_RT_NOINIFIN }, 96 { MSG_ORIG(MSG_FL1_USED), FL1_RT_USED, FL1_RT_USED }, 97 { MSG_ORIG(MSG_FL1_SYMBOLIC), FL1_RT_SYMBOLIC, FL1_RT_SYMBOLIC }, 98 { MSG_ORIG(MSG_FL1_OBJSFLTR), FL1_RT_OBJSFLTR, FL1_RT_OBJSFLTR }, 99 { MSG_ORIG(MSG_FL1_OBJAFLTR), FL1_RT_OBJAFLTR, FL1_RT_OBJAFLTR }, 100 { MSG_ORIG(MSG_FL1_SYMSFLTR), FL1_RT_SYMSFLTR, FL1_RT_SYMSFLTR }, 101 { MSG_ORIG(MSG_FL1_SYMAFLTR), FL1_RT_SYMAFLTR, FL1_RT_SYMAFLTR }, 102 103 { MSG_ORIG(MSG_LTFL_AUD_PREINIT), LML_TFLG_AUD_PREINIT, 104 LML_TFLG_AUD_PREINIT }, 105 { MSG_ORIG(MSG_LTFL_AUD_OBJSEARCH), LML_TFLG_AUD_OBJSEARCH, 106 LML_TFLG_AUD_OBJSEARCH }, 107 { MSG_ORIG(MSG_LTFL_AUD_OBJOPEN), LML_TFLG_AUD_OBJOPEN, 108 LML_TFLG_AUD_OBJOPEN }, 109 { MSG_ORIG(MSG_LTFL_AUD_OBJFILTER), LML_TFLG_AUD_OBJFILTER, 110 LML_TFLG_AUD_OBJFILTER }, 111 { MSG_ORIG(MSG_LTFL_AUD_OBJCLOSE), LML_TFLG_AUD_OBJCLOSE, 112 LML_TFLG_AUD_OBJCLOSE }, 113 { MSG_ORIG(MSG_LTFL_AUD_SYMBIND), LML_TFLG_AUD_SYMBIND, 114 LML_TFLG_AUD_SYMBIND }, 115 { MSG_ORIG(MSG_LTFL_AUD_PLTENTER), LML_TFLG_AUD_PLTENTER, 116 LML_TFLG_AUD_PLTENTER }, 117 { MSG_ORIG(MSG_LTFL_AUD_PLTEXIT), LML_TFLG_AUD_PLTEXIT, 118 LML_TFLG_AUD_PLTEXIT }, 119 { MSG_ORIG(MSG_LTFL_AUD_ACTIVITY), LML_TFLG_AUD_ACTIVITY, 120 LML_TFLG_AUD_ACTIVITY }, 121 { NULL, 0, 0} 122 }; 123 124 static const mdb_bitmask_t rtmode_bits[] = { 125 { MSG_ORIG(MSG_MODE_LAZY), RTLD_LAZY, RTLD_LAZY }, 126 { MSG_ORIG(MSG_MODE_NOW), RTLD_NOW, RTLD_NOW }, 127 { MSG_ORIG(MSG_MODE_NOLOAD), RTLD_NOLOAD, RTLD_NOLOAD }, 128 { MSG_ORIG(MSG_MODE_GLOBAL), RTLD_GLOBAL, RTLD_GLOBAL }, 129 { MSG_ORIG(MSG_MODE_PARENT), RTLD_PARENT, RTLD_PARENT }, 130 { MSG_ORIG(MSG_MODE_GROUP), RTLD_GROUP, RTLD_GROUP }, 131 { MSG_ORIG(MSG_MODE_WORLD), RTLD_WORLD, RTLD_WORLD }, 132 { MSG_ORIG(MSG_MODE_NODELETE), RTLD_NODELETE, RTLD_NODELETE }, 133 { MSG_ORIG(MSG_MODE_FIRST), RTLD_FIRST, RTLD_FIRST }, 134 { MSG_ORIG(MSG_MODE_CONFGEN), RTLD_CONFGEN, RTLD_CONFGEN }, 135 { NULL, 0, 0} 136 }; 137 138 static const mdb_bitmask_t bndflags_bits[] = { 139 { MSG_ORIG(MSG_BFL_NEEDED), BND_NEEDED, BND_NEEDED }, 140 { MSG_ORIG(MSG_BFL_REFER), BND_REFER, BND_REFER }, 141 { NULL, 0, 0} 142 }; 143 144 static const mdb_bitmask_t grhflags_bits[] = { 145 { MSG_ORIG(MSG_GPH_ZERO), GPH_ZERO, GPH_ZERO }, 146 { MSG_ORIG(MSG_GPH_LDSO), GPH_LDSO, GPH_LDSO }, 147 { MSG_ORIG(MSG_GPH_FIRST), GPH_FIRST, GPH_FIRST }, 148 { MSG_ORIG(MSG_GPH_PARENT), GPH_PARENT, GPH_PARENT }, 149 { MSG_ORIG(MSG_GPH_FILTEE), GPH_FILTEE, GPH_FILTEE }, 150 { MSG_ORIG(MSG_GPH_INITIAL), GPH_INITIAL, GPH_INITIAL }, 151 { MSG_ORIG(MSG_GPH_STICKY), GPH_STICKY, GPH_STICKY }, 152 { NULL, 0, 0} 153 }; 154 155 static const mdb_bitmask_t grdflags_bits[] = { 156 { MSG_ORIG(MSG_GPD_AVAIL), GPD_AVAIL, GPD_AVAIL }, 157 { MSG_ORIG(MSG_GPD_ADDEPS), GPD_ADDEPS, GPD_ADDEPS }, 158 { MSG_ORIG(MSG_GPD_PARENT), GPD_PARENT, GPD_PARENT }, 159 { MSG_ORIG(MSG_GPD_FILTER), GPD_FILTER, GPD_FILTER }, 160 { MSG_ORIG(MSG_GPD_REMOVE), GPD_REMOVE, GPD_REMOVE }, 161 { NULL, 0, 0} 162 }; 163 164 static const mdb_bitmask_t lmc_bits[] = { 165 { MSG_ORIG(MSG_LMC_ANALYZING), LMC_FLG_ANALYZING, LMC_FLG_ANALYZING}, 166 { MSG_ORIG(MSG_LMC_RELOCATING), LMC_FLG_RELOCATING, LMC_FLG_RELOCATING}, 167 { MSG_ORIG(MSG_LMC_REANALYZE), LMC_FLG_REANALYZE, LMC_FLG_REANALYZE}, 168 { NULL, 0, 0} 169 }; 170 171 /* 172 * Obtain a string - typically a link-map name. 173 */ 174 static char * 175 String(uintptr_t addr, const char *name) 176 { 177 static char str[MAXPATHLEN]; 178 179 if (addr) { 180 if (mdb_readstr(str, MAXPATHLEN, addr) == -1) { 181 mdb_warn(MSG_ORIG(MSG_ERR_READ), name, addr); 182 return (0); 183 } 184 return (str); 185 } 186 return ((char *)MSG_ORIG(MSG_STR_EMPTY)); 187 } 188 189 /* 190 * Obtain a link-map name. 191 */ 192 static char * 193 Rtmap_Name(uintptr_t addr) 194 { 195 Rt_map rtmap; 196 197 if (addr) { 198 if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) { 199 mdb_warn(MSG_ORIG(MSG_ERR_READ), 200 MSG_ORIG(MSG_RTMAP_STR), addr); 201 return (0); 202 } 203 return (String((uintptr_t)NAME(&rtmap), 204 MSG_ORIG(MSG_STR_NAME))); 205 } 206 return ((char *)MSG_ORIG(MSG_STR_EMPTY)); 207 } 208 209 void 210 dcmd_Bind_help(void) 211 { 212 mdb_printf(MSG_ORIG(MSG_BND_HELP)); 213 } 214 215 static int 216 /* ARGSUSED2 */ 217 dcmd_Bind(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 218 { 219 Bnd_desc bnd; 220 char *str; 221 222 /* 223 * Insure we have a valid address. 224 */ 225 if ((flags & DCMD_ADDRSPEC) == 0) { 226 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_BND_STR)); 227 return (DCMD_USAGE); 228 } 229 230 /* 231 * Obtain the binding descriptor. 232 */ 233 if (mdb_vread(&bnd, sizeof (Bnd_desc), addr) == -1) { 234 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_BND_STR), addr); 235 return (DCMD_ERR); 236 } 237 mdb_printf(MSG_ORIG(MSG_BND_TITLE), addr); 238 239 /* 240 * Establish the identity of the caller. 241 */ 242 if ((str = Rtmap_Name((uintptr_t)bnd.b_caller)) == 0) 243 return (DCMD_ERR); 244 mdb_printf(MSG_ORIG(MSG_BND_LINE1), bnd.b_caller, str); 245 246 /* 247 * Establish the identity of the dependency. 248 */ 249 if ((str = Rtmap_Name((uintptr_t)bnd.b_depend)) == 0) 250 return (DCMD_ERR); 251 mdb_printf(MSG_ORIG(MSG_BND_LINE2), bnd.b_depend, str); 252 253 /* 254 * Display any flags. 255 */ 256 mdb_printf(MSG_ORIG(MSG_BND_LINE3), bnd.b_flags, bnd.b_flags, 257 bndflags_bits); 258 259 return (DCMD_OK); 260 } 261 262 static void 263 dcmd_Depends_help(void) 264 { 265 mdb_printf(MSG_ORIG(MSG_DEPENDS_HELP)); 266 } 267 268 static int 269 Depends(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv, 270 uint_t flg, const char *msg) 271 { 272 Alist al; 273 uintptr_t listcalc, listnext; 274 size_t ucnt, tcnt; 275 Bnd_desc * bdp; 276 277 /* 278 * Obtain the Alist and determine its number of elements and those 279 * that are in use. 280 */ 281 if (mdb_vread(&al, sizeof (Alist), addr) == -1) { 282 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr); 283 return (DCMD_ERR); 284 } 285 286 ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size; 287 tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size; 288 mdb_printf(msg, addr, ucnt, tcnt); 289 290 if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0)) 291 return (DCMD_OK); 292 293 /* 294 * Under verbose mode print the name of each dependency. An Alist can 295 * have a variable number of data items, so read each individual entry. 296 */ 297 listcalc = (uintptr_t)(&(al.al_data[0])); 298 listcalc -= (uintptr_t)(&al); 299 listcalc += addr; 300 if (mdb_vread(&bdp, sizeof (Bnd_desc *), listcalc) == -1) { 301 mdb_warn(MSG_ORIG(MSG_ERR_READ), 302 MSG_ORIG(MSG_BNDDESC_STR), listcalc); 303 return (DCMD_ERR); 304 } 305 306 mdb_inc_indent(4); 307 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 308 309 if (dcmd_Bind((uintptr_t)bdp, flags, argc, argv) == DCMD_ERR) { 310 mdb_dec_indent(4); 311 return (DCMD_ERR); 312 } 313 314 listnext = (uintptr_t)(al.al_next + addr); 315 for (listcalc += al.al_size; listcalc < listnext; 316 listcalc += al.al_size) { 317 if (mdb_vread(&bdp, sizeof (Bnd_desc *), listcalc) == -1) { 318 mdb_warn(MSG_ORIG(MSG_ERR_READ), 319 MSG_ORIG(MSG_BNDDESC_STR), listcalc); 320 return (DCMD_ERR); 321 } 322 323 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 324 if (dcmd_Bind((uintptr_t)bdp, flags, argc, argv) == DCMD_ERR) { 325 mdb_dec_indent(4); 326 return (DCMD_ERR); 327 } 328 } 329 mdb_dec_indent(4); 330 return (DCMD_OK); 331 } 332 333 static int 334 dcmd_Depends(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 335 { 336 Rt_map rtmap; 337 char *str; 338 uint_t flg = 0; 339 340 /* 341 * Insure we have a valid address, and provide for a -v option. 342 */ 343 if ((flags & DCMD_ADDRSPEC) == 0) { 344 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_DEPENDS_STR)); 345 return (DCMD_USAGE); 346 } 347 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE, 348 &flg, NULL) != argc) 349 return (DCMD_USAGE); 350 351 /* 352 * Read the Rt_map contents. 353 */ 354 if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) { 355 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr); 356 return (DCMD_ERR); 357 } 358 if ((str = String((uintptr_t)NAME(&rtmap), 359 MSG_ORIG(MSG_STR_NAME))) == 0) 360 return (DCMD_ERR); 361 362 mdb_printf(MSG_ORIG(MSG_DEPENDS_LINE1), str); 363 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 364 365 if (DEPENDS(&rtmap) == 0) 366 return (DCMD_OK); 367 368 return (Depends((uintptr_t)DEPENDS(&rtmap), flags, argc, argv, flg, 369 MSG_ORIG(MSG_DEPENDS_LINE2))); 370 } 371 372 static void 373 dcmd_Callers_help(void) 374 { 375 mdb_printf(MSG_ORIG(MSG_CALLERS_HELP)); 376 } 377 378 static int 379 dcmd_Callers(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 380 { 381 Rt_map rtmap; 382 char *str; 383 uint_t flg = 0; 384 385 /* 386 * Insure we have a valid address, and provide for a -v option. 387 */ 388 if ((flags & DCMD_ADDRSPEC) == 0) { 389 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_DEPENDS_STR)); 390 return (DCMD_USAGE); 391 } 392 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE, 393 &flg, NULL) != argc) 394 return (DCMD_USAGE); 395 396 /* 397 * Read the Rt_map contents. 398 */ 399 if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) { 400 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr); 401 return (DCMD_ERR); 402 } 403 if ((str = String((uintptr_t)NAME(&rtmap), 404 MSG_ORIG(MSG_STR_NAME))) == 0) 405 return (DCMD_ERR); 406 407 mdb_printf(MSG_ORIG(MSG_CALLERS_LINE1), str); 408 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 409 410 if (CALLERS(&rtmap) == 0) 411 return (DCMD_OK); 412 413 return (Depends((uintptr_t)CALLERS(&rtmap), flags, argc, argv, flg, 414 MSG_ORIG(MSG_CALLERS_LINE2))); 415 } 416 417 void 418 dcmd_rtmap_help(void) 419 { 420 mdb_printf(MSG_ORIG(MSG_RTMAP_HELP)); 421 } 422 423 static int 424 /* ARGSUSED2 */ 425 dcmd_rtmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 426 { 427 Rt_map rtmap; 428 char *str; 429 430 if ((flags & DCMD_ADDRSPEC) == 0) { 431 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_RTMAP_STR)); 432 return (DCMD_USAGE); 433 } 434 435 if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) { 436 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr); 437 return (DCMD_ERR); 438 } 439 440 mdb_printf(MSG_ORIG(MSG_RTMAP_TITLE), addr); 441 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 442 443 /* 444 * Determine the objects name. NAME() is the name by which the object 445 * has been opened, typically from adding a search path to a file name. 446 * PATHNAME() is the fully resolve name, which is displayed by the proc 447 * tools and debuggers. If the two names differ, print the PATHNAME(). 448 */ 449 if ((str = String((uintptr_t)NAME(&rtmap), 450 MSG_ORIG(MSG_STR_NAME))) == 0) 451 return (DCMD_ERR); 452 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE1), str); 453 if (NAME(&rtmap) != PATHNAME(&rtmap)) { 454 if ((str = String((uintptr_t)PATHNAME(&rtmap), 455 MSG_ORIG(MSG_STR_PATHNAME))) == 0) 456 return (DCMD_ERR); 457 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE2), str); 458 } 459 460 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE3), ADDR(&rtmap), DYN(&rtmap)); 461 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE4), NEXT(&rtmap), PREV(&rtmap)); 462 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE5), rtmap.rt_fct, TLSMODID(&rtmap)); 463 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE6), INIT(&rtmap), FINI(&rtmap)); 464 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE7), GROUPS(&rtmap), HANDLES(&rtmap)); 465 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE8), DEPENDS(&rtmap), CALLERS(&rtmap)); 466 467 if ((str = String((uintptr_t)REFNAME(&rtmap), 468 MSG_ORIG(MSG_STR_REFNAME))) == 0) 469 return (DCMD_ERR); 470 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE9), DYNINFO(&rtmap), str); 471 472 if ((str = String((uintptr_t)RPATH(&rtmap), 473 MSG_ORIG(MSG_STR_RPATH))) == 0) 474 return (DCMD_ERR); 475 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE10), RLIST(&rtmap), str); 476 477 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE11), LIST(&rtmap), LIST(&rtmap)); 478 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE12), FLAGS(&rtmap)); 479 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), FLAGS(&rtmap), rtflags_bits); 480 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE13), FLAGS1(&rtmap)); 481 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), FLAGS1(&rtmap), rtflags1_bits); 482 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE14), MODE(&rtmap)); 483 mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), MODE(&rtmap), rtmode_bits); 484 485 return (DCMD_OK); 486 } 487 488 489 static int 490 rtmap_format(uintptr_t addr, const void * data, void * private) 491 { 492 const Rt_map *lmp = (const Rt_map *)data; 493 W_desc *wdp = (W_desc *)private; 494 char *str; 495 496 if (wdp && (wdp->w_flags & RTLD_FLG_VERBOSE)) { 497 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 498 mdb_call_dcmd(MSG_ORIG(MSG_RTMAP_STR), addr, DCMD_ADDRSPEC, 499 NULL, NULL); 500 return (0); 501 } 502 503 if ((str = String((uintptr_t)NAME(lmp), 504 MSG_ORIG(MSG_STR_NAME))) == 0) 505 return (DCMD_ERR); 506 507 mdb_printf(MSG_ORIG(MSG_FMT_RT), CNTL(lmp), addr, ADDR(lmp), str); 508 return (0); 509 } 510 511 void 512 dcmd_Rtmaps_help(void) 513 { 514 mdb_printf(MSG_ORIG(MSG_RTMAPS_HELP)); 515 } 516 517 static int 518 dcmd_Rtmaps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 519 { 520 uint_t flg = 0; 521 GElf_Sym gsym; 522 List l; 523 Listnode ln; 524 uintptr_t naddr; 525 const char *str; 526 W_desc wdesc; 527 528 /* 529 * '-v' - Verbose output of rtmap 530 */ 531 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE, 532 &flg, NULL) != argc) 533 return (DCMD_USAGE); 534 535 /* 536 * If an address was provided use it. 537 */ 538 if (flags & DCMD_ADDRSPEC) { 539 if (((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) && 540 !(flg & RTLD_FLG_VERBOSE)) { 541 mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0)); 542 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 543 } 544 545 wdesc.w_flags = flg; 546 if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), rtmap_format, 547 (void *)&wdesc, addr) == -1) 548 return (DCMD_ERR); 549 return (DCMD_OK); 550 } 551 552 /* 553 * Otherwise traverse the dynlm_list and display each link-map. 554 */ 555 if (mdb_lookup_by_obj(MSG_ORIG(MSG_STR_LDSO1), 556 MSG_ORIG(MSG_STR_DYNLMLIST), &gsym) == -1) { 557 mdb_warn(MSG_ORIG(MSG_ERR_SYMFAILED), MSG_ORIG(MSG_STR_LDSO1), 558 MSG_ORIG(MSG_STR_DYNLMLIST)); 559 return (DCMD_ERR); 560 } 561 if (mdb_vread((void *)&l, sizeof (l), (uintptr_t)gsym.st_value) == -1) { 562 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_LIST_STR), 563 gsym.st_value); 564 return (DCMD_ERR); 565 } 566 567 mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE1), MSG_ORIG(MSG_STR_DYNLMLIST), 568 &gsym); 569 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 570 571 flags |= (DCMD_LOOP | DCMD_LOOPFIRST); 572 for (naddr = (uintptr_t)l.head; naddr; naddr = (uintptr_t)ln.next) { 573 Lm_list lml; 574 575 if (mdb_vread(&ln, sizeof (ln), naddr) == -1) { 576 mdb_warn(MSG_ORIG(MSG_ERR_READ), 577 MSG_ORIG(MSG_STR_LISTNODE), naddr); 578 return (DCMD_ERR); 579 } 580 if (mdb_vread(&lml, sizeof (lml), (uintptr_t)ln.data) == -1) { 581 mdb_warn(MSG_ORIG(MSG_ERR_READ), 582 MSG_ORIG(MSG_LMLIST_STR), ln.data); 583 return (DCMD_ERR); 584 } 585 586 mdb_inc_indent(2); 587 if (lml.lm_flags & LML_FLG_BASELM) 588 str = MSG_ORIG(MSG_LMLIST_BASE); 589 else if (lml.lm_flags & LML_FLG_RTLDLM) 590 str = MSG_ORIG(MSG_LMLIST_LDSO); 591 else 592 str = MSG_ORIG(MSG_LMLIST_NEWLM); 593 594 if ((flags & DCMD_LOOP) && ((flags & DCMD_LOOPFIRST) == 0)) 595 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 596 597 mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE2), ln.data, str); 598 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 599 600 mdb_inc_indent(2); 601 602 if (((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) && 603 !(flg & RTLD_FLG_VERBOSE)) { 604 mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0)); 605 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 606 } 607 608 wdesc.w_flags = flg; 609 if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), rtmap_format, 610 (void *)&wdesc, (uintptr_t)lml.lm_head) == -1) { 611 mdb_dec_indent(4); 612 return (DCMD_ERR); 613 } 614 mdb_dec_indent(4); 615 flags &= ~DCMD_LOOPFIRST; 616 } 617 return (DCMD_OK); 618 } 619 620 static int 621 /* ARGSUSED2 */ 622 format_listnode(uintptr_t addr, const void * data, void * private) 623 { 624 Listnode * lnp = (Listnode *)data; 625 626 mdb_printf(MSG_ORIG(MSG_FMT_LN), addr, lnp->data, lnp->next); 627 return (0); 628 } 629 630 void 631 dcmd_List_help(void) 632 { 633 mdb_printf(MSG_ORIG(MSG_LIST_HELP)); 634 } 635 636 static int 637 /* ARGSUSED2 */ 638 dcmd_List(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 639 { 640 if ((flags & DCMD_ADDRSPEC) == 0) 641 return (DCMD_USAGE); 642 if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) { 643 mdb_printf(MSG_ORIG(MSG_LIST_TITLE)); 644 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 645 } 646 if (mdb_pwalk(MSG_ORIG(MSG_LIST_STR), format_listnode, 647 (void *)0, addr) == -1) 648 return (DCMD_ERR); 649 return (DCMD_OK); 650 } 651 652 void 653 dcmd_Setenv_help(void) 654 { 655 mdb_printf(MSG_ORIG(MSG_SETENV_HELP)); 656 } 657 658 /* 659 * As of s10, mdb provides its own setenv command. This command allows the 660 * environment of the process being controlled to be changed at any time. 661 * Prior to this, ld.so.1 provided it's own, more primitive implementation. 662 * This allowed for changing mdb's environment only, which if it was changed 663 * before the application ws executed, would be copied to the applications 664 * environment. Thus, we could start mdb, set an LD_ variable within its 665 * environment (which it's own ld.so.1 had already finished processing), and 666 * have this setting be inherited by the application. 667 */ 668 static int 669 /* ARGSUSED */ 670 dcmd_Setenv(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 671 { 672 char *str; 673 674 if (mdb_call_dcmd(MSG_ORIG(MSG_STR_SETENV), addr, flags, argc, 675 argv) == 0) 676 return (DCMD_OK); 677 678 if (((flags & DCMD_ADDRSPEC) != 0) || (argc == 0) || (argc > 1) || 679 (argv->a_type != MDB_TYPE_STRING)) 680 return (DCMD_USAGE); 681 682 str = mdb_alloc((strlen(argv->a_un.a_str) + 1), UM_NOSLEEP); 683 if (str == NULL) 684 return (DCMD_ERR); 685 686 (void) strcpy(str, argv->a_un.a_str); 687 (void) putenv(str); 688 return (DCMD_OK); 689 } 690 691 int 692 walk_List_init(mdb_walk_state_t *wsp) 693 { 694 List lst; 695 696 if (wsp->walk_addr == NULL) { 697 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_LIST_STR)); 698 return (WALK_ERR); 699 } 700 701 if (mdb_vread(&lst, sizeof (List), wsp->walk_addr) == -1) { 702 mdb_warn(MSG_ORIG(MSG_ERR_READ), 703 MSG_ORIG(MSG_LIST_STR), wsp->walk_addr); 704 return (WALK_DONE); 705 } 706 707 wsp->walk_addr = (uintptr_t)lst.head; 708 return (WALK_NEXT); 709 } 710 711 712 static int 713 walk_List_step(mdb_walk_state_t *wsp) 714 { 715 Listnode lnp; 716 int status; 717 718 if (wsp->walk_addr == NULL) 719 return (WALK_DONE); 720 721 if (mdb_vread(&lnp, sizeof (Listnode), wsp->walk_addr) == -1) { 722 mdb_warn(MSG_ORIG(MSG_ERR_READ), 723 MSG_ORIG(MSG_STR_LISTNODE), wsp->walk_addr); 724 return (WALK_DONE); 725 } 726 727 status = wsp->walk_callback(wsp->walk_addr, &lnp, wsp->walk_cbdata); 728 wsp->walk_addr = (uintptr_t)lnp.next; 729 return (status); 730 } 731 732 /* 733 * Walk Rt_map lists 734 */ 735 static int 736 walk_rtmap_init(mdb_walk_state_t *wsp) 737 { 738 if (wsp->walk_addr == NULL) { 739 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_RTMAP_STR)); 740 return (WALK_ERR); 741 } 742 return (WALK_NEXT); 743 } 744 745 static int 746 walk_rtmap_step(mdb_walk_state_t *wsp) 747 { 748 int status; 749 Rt_map lmp; 750 751 if (wsp->walk_addr == NULL) 752 return (WALK_DONE); 753 if (mdb_vread(&lmp, sizeof (Rt_map), wsp->walk_addr) == -1) { 754 mdb_warn(MSG_ORIG(MSG_ERR_READ), 755 MSG_ORIG(MSG_RTMAP_STR), wsp->walk_addr); 756 return (WALK_DONE); 757 } 758 759 status = wsp->walk_callback(wsp->walk_addr, &lmp, wsp->walk_cbdata); 760 wsp->walk_addr = (uintptr_t)(NEXT(&lmp)); 761 return (status); 762 } 763 764 static const mdb_bitmask_t lml_flags_bit[] = { 765 { MSG_ORIG(MSG_LFL_BASELM), LML_FLG_BASELM, LML_FLG_BASELM }, 766 { MSG_ORIG(MSG_LFL_RTLDLM), LML_FLG_RTLDLM, LML_FLG_RTLDLM }, 767 { MSG_ORIG(MSG_LFL_NOAUDIT), LML_FLG_NOAUDIT, LML_FLG_NOAUDIT }, 768 { MSG_ORIG(MSG_LFL_PLTREL), LML_FLG_PLTREL, LML_FLG_PLTREL }, 769 { MSG_ORIG(MSG_LFL_HOLDLOCK), LML_FLG_HOLDLOCK, LML_FLG_HOLDLOCK }, 770 { MSG_ORIG(MSG_LFL_ENVIRON), LML_FLG_ENVIRON, LML_FLG_ENVIRON }, 771 { MSG_ORIG(MSG_LFL_INTRPOSE), LML_FLG_INTRPOSE, LML_FLG_INTRPOSE }, 772 { MSG_ORIG(MSG_LFL_LOCAUDIT), LML_FLG_LOCAUDIT, LML_FLG_LOCAUDIT }, 773 { MSG_ORIG(MSG_LFL_LOADAVAIL), LML_FLG_LOADAVAIL, LML_FLG_LOADAVAIL }, 774 { MSG_ORIG(MSG_LFL_IGNRELERR), LML_FLG_IGNRELERR, LML_FLG_IGNRELERR }, 775 { MSG_ORIG(MSG_LFL_DBNOTIF), LML_FLG_DBNOTIF, LML_FLG_DBNOTIF }, 776 { MSG_ORIG(MSG_LFL_BNDUNINIT), LML_FLG_BNDUNINIT, LML_FLG_BNDUNINIT }, 777 { MSG_ORIG(MSG_LFL_STARTREL), LML_FLG_STARTREL, LML_FLG_STARTREL }, 778 779 { MSG_ORIG(MSG_LFL_TRC_LDDSTUB), LML_FLG_TRC_LDDSTUB, 780 LML_FLG_TRC_LDDSTUB }, 781 { MSG_ORIG(MSG_LFL_TRC_ENABLE), LML_FLG_TRC_ENABLE, 782 LML_FLG_TRC_ENABLE }, 783 { MSG_ORIG(MSG_LFL_TRC_WARN), LML_FLG_TRC_WARN, LML_FLG_TRC_WARN }, 784 { MSG_ORIG(MSG_LFL_TRC_VERBOSE), LML_FLG_TRC_VERBOSE, 785 LML_FLG_TRC_VERBOSE }, 786 { MSG_ORIG(MSG_LFL_TRC_SEARCH), LML_FLG_TRC_SEARCH, 787 LML_FLG_TRC_SEARCH }, 788 { MSG_ORIG(MSG_LFL_TRC_UNREF), LML_FLG_TRC_UNREF, LML_FLG_TRC_UNREF }, 789 { MSG_ORIG(MSG_LFL_TRC_UNUSED), LML_FLG_TRC_UNUSED, 790 LML_FLG_TRC_UNUSED }, 791 { MSG_ORIG(MSG_LFL_TRC_INIT), LML_FLG_TRC_INIT, LML_FLG_TRC_INIT }, 792 { NULL, 0, 0} 793 }; 794 795 static const mdb_bitmask_t lml_tflags_bit[] = { 796 { MSG_ORIG(MSG_LTFL_NOLAZYLD), LML_TFLG_NOLAZYLD, LML_TFLG_NOLAZYLD }, 797 { MSG_ORIG(MSG_LTFL_NODIRECT), LML_TFLG_NODIRECT, LML_TFLG_NODIRECT }, 798 { MSG_ORIG(MSG_LTFL_LOADFLTR), LML_TFLG_LOADFLTR, LML_TFLG_LOADFLTR }, 799 800 { MSG_ORIG(MSG_LTFL_AUD_PREINIT), LML_TFLG_AUD_PREINIT, 801 LML_TFLG_AUD_PREINIT }, 802 { MSG_ORIG(MSG_LTFL_AUD_OBJSEARCH), LML_TFLG_AUD_OBJSEARCH, 803 LML_TFLG_AUD_OBJSEARCH }, 804 { MSG_ORIG(MSG_LTFL_AUD_OBJOPEN), LML_TFLG_AUD_OBJOPEN, 805 LML_TFLG_AUD_OBJOPEN }, 806 { MSG_ORIG(MSG_LTFL_AUD_OBJFILTER), LML_TFLG_AUD_OBJFILTER, 807 LML_TFLG_AUD_OBJFILTER }, 808 { MSG_ORIG(MSG_LTFL_AUD_OBJCLOSE), LML_TFLG_AUD_OBJCLOSE, 809 LML_TFLG_AUD_OBJCLOSE }, 810 { MSG_ORIG(MSG_LTFL_AUD_SYMBIND), LML_TFLG_AUD_SYMBIND, 811 LML_TFLG_AUD_SYMBIND }, 812 { MSG_ORIG(MSG_LTFL_AUD_PLTENTER), LML_TFLG_AUD_PLTENTER, 813 LML_TFLG_AUD_PLTENTER }, 814 { MSG_ORIG(MSG_LTFL_AUD_PLTEXIT), LML_TFLG_AUD_PLTEXIT, 815 LML_TFLG_AUD_PLTEXIT }, 816 { MSG_ORIG(MSG_LTFL_AUD_ACTIVITY), LML_TFLG_AUD_ACTIVITY, 817 LML_TFLG_AUD_ACTIVITY }, 818 { NULL, 0, 0} 819 }; 820 821 void 822 dcmd_Lm_list_help(void) 823 { 824 mdb_printf(MSG_ORIG(MSG_LMLIST_HELP)); 825 } 826 827 static int 828 /* ARGSUSED1 */ 829 _dcmd_Lm_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 830 { 831 Lm_list lml; 832 const char *str; 833 uint_t flg = 0; 834 835 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE, 836 &flg, NULL) != argc) 837 return (DCMD_USAGE); 838 839 if (mdb_vread(&lml, sizeof (lml), addr) == -1) { 840 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_LMLIST_STR), 841 addr); 842 return (DCMD_ERR); 843 } 844 845 if (lml.lm_flags & LML_FLG_BASELM) 846 str = MSG_ORIG(MSG_LMLIST_BASE); 847 else if (lml.lm_flags & LML_FLG_RTLDLM) 848 str = MSG_ORIG(MSG_LMLIST_LDSO); 849 else 850 str = MSG_ORIG(MSG_LMLIST_NEWLM); 851 852 if ((flags & DCMD_LOOP) && ((flags & DCMD_LOOPFIRST) == 0)) 853 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 854 855 mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE2), addr, str); 856 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 857 858 if (lml.lm_lists) { 859 Alist al; 860 size_t ucnt, tcnt; 861 Lm_cntl lmc; 862 uintptr_t listcalc; 863 864 addr = (uintptr_t)lml.lm_lists; 865 if (mdb_vread(&al, sizeof (Alist), addr) == -1) { 866 mdb_warn(MSG_ORIG(MSG_ERR_READ), 867 MSG_ORIG(MSG_STR_ALIST), addr); 868 return (DCMD_ERR); 869 } 870 871 /* 872 * Determine whether the Alist has been populated. Note, the 873 * implementation first reserves an alist entry, and initializes 874 * this element when the first link-map is processed. Thus, 875 * there's a window when ucnt is updated, but before the next 876 * element has been initialized. 877 */ 878 ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / 879 al.al_size; 880 tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / 881 al.al_size; 882 883 if (ucnt && (flg & RTLD_FLG_VERBOSE)) { 884 listcalc = (uintptr_t)(&(al.al_data[0])); 885 listcalc -= (uintptr_t)(&al); 886 listcalc += addr; 887 888 if (mdb_vread(&lmc, sizeof (Lm_cntl), 889 listcalc) == -1) { 890 mdb_warn(MSG_ORIG(MSG_ERR_READ), 891 MSG_ORIG(MSG_LMLIST_STR), listcalc); 892 return (DCMD_ERR); 893 } 894 } 895 896 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE0), addr, ucnt, tcnt); 897 mdb_inc_indent(2); 898 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 899 900 if (ucnt && (flg & RTLD_FLG_VERBOSE)) { 901 uintptr_t listnext; 902 903 mdb_inc_indent(2); 904 mdb_printf(MSG_ORIG(MSG_LMC_LINE1), listcalc); 905 mdb_printf(MSG_ORIG(MSG_LMC_LINE2), lmc.lc_head, 906 lmc.lc_tail); 907 mdb_printf(MSG_ORIG(MSG_LMC_LINE3), lmc.lc_flags, 908 lmc.lc_now); 909 mdb_printf(MSG_ORIG(MSG_LMC_LINE4), lmc.lc_flags, 910 lmc_bits); 911 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 912 mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0)); 913 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 914 915 if (lmc.lc_head) { 916 if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), 917 rtmap_format, (void *)0, 918 (uintptr_t)lmc.lc_head) == -1) { 919 mdb_dec_indent(4); 920 return (DCMD_ERR); 921 } 922 } else 923 mdb_printf(MSG_ORIG(MSG_FMT_RT), 0, 0, 0, 924 MSG_ORIG(MSG_STR_EMPTY)); 925 926 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 927 928 listnext = (uintptr_t)(al.al_next + addr); 929 for (listcalc += al.al_size; listcalc < listnext; 930 listcalc += al.al_size) { 931 if (mdb_vread(&lmc, sizeof (Lm_cntl), 932 listcalc) == -1) { 933 mdb_warn(MSG_ORIG(MSG_ERR_READ), 934 MSG_ORIG(MSG_LMLIST_STR), listcalc); 935 mdb_dec_indent(4); 936 return (DCMD_ERR); 937 } 938 939 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 940 mdb_printf(MSG_ORIG(MSG_LMC_LINE1), listcalc); 941 mdb_printf(MSG_ORIG(MSG_LMC_LINE2), 942 lmc.lc_head, lmc.lc_tail); 943 mdb_printf(MSG_ORIG(MSG_LMC_LINE3), 944 lmc.lc_flags, lmc.lc_now); 945 mdb_printf(MSG_ORIG(MSG_LMC_LINE4), 946 lmc.lc_flags, lmc_bits); 947 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 948 mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0)); 949 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 950 951 if (lmc.lc_head) { 952 if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), 953 rtmap_format, (void *)0, 954 (uintptr_t)lmc.lc_head) == -1) { 955 mdb_dec_indent(4); 956 return (DCMD_ERR); 957 } 958 } else 959 mdb_printf(MSG_ORIG(MSG_FMT_RT), 0, 0, 960 0, MSG_ORIG(MSG_STR_EMPTY)); 961 962 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 963 } 964 mdb_dec_indent(2); 965 } 966 mdb_dec_indent(2); 967 } 968 969 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE1), lml.lm_head, lml.lm_tail); 970 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE2), lml.lm_alp, lml.lm_peh_lmp); 971 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE3), lml.lm_handle, lml.lm_obj, 972 lml.lm_init, lml.lm_lazy); 973 974 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE4), lml.lm_flags); 975 if (lml.lm_flags) 976 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE6), lml.lm_flags, 977 lml_flags_bit); 978 979 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE5), lml.lm_tflags); 980 if (lml.lm_tflags) 981 mdb_printf(MSG_ORIG(MSG_LMLIST_LINE6), lml.lm_tflags, 982 lml_tflags_bit); 983 984 return (DCMD_OK); 985 } 986 987 static int 988 /* ARGSUSED2 */ 989 dcmd_Lm_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 990 { 991 GElf_Sym gsym; 992 List l; 993 Listnode ln; 994 uintptr_t naddr; 995 996 /* 997 * If an address was provided us it. 998 */ 999 if (flags & DCMD_ADDRSPEC) 1000 return (_dcmd_Lm_list(addr, flags, argc, argv)); 1001 1002 /* 1003 * Otherwise traverse the dynlm_list and display each link-map list. 1004 */ 1005 if (mdb_lookup_by_obj(MSG_ORIG(MSG_STR_LDSO1), 1006 MSG_ORIG(MSG_STR_DYNLMLIST), &gsym) == -1) { 1007 mdb_warn(MSG_ORIG(MSG_ERR_SYMFAILED), MSG_ORIG(MSG_STR_LDSO1), 1008 MSG_ORIG(MSG_STR_DYNLMLIST)); 1009 return (DCMD_ERR); 1010 } 1011 if (mdb_vread((void *)&l, sizeof (l), (uintptr_t)gsym.st_value) == -1) { 1012 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_LIST_STR), 1013 gsym.st_value); 1014 return (DCMD_ERR); 1015 } 1016 1017 mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE1), MSG_ORIG(MSG_STR_DYNLMLIST), 1018 &gsym); 1019 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1020 1021 flags |= (DCMD_LOOP | DCMD_LOOPFIRST); 1022 for (naddr = (uintptr_t)l.head; naddr; naddr = (uintptr_t)ln.next) { 1023 if (mdb_vread(&ln, sizeof (ln), naddr) == -1) { 1024 mdb_warn(MSG_ORIG(MSG_ERR_READ), 1025 MSG_ORIG(MSG_STR_LISTNODE), naddr); 1026 return (DCMD_ERR); 1027 } 1028 1029 mdb_inc_indent(2); 1030 if (_dcmd_Lm_list((uintptr_t)ln.data, flags, 1031 argc, argv) == DCMD_ERR) { 1032 mdb_dec_indent(2); 1033 return (DCMD_ERR); 1034 } 1035 mdb_dec_indent(2); 1036 flags &= ~DCMD_LOOPFIRST; 1037 } 1038 return (DCMD_OK); 1039 } 1040 1041 void 1042 dcmd_GrpDesc_help(void) 1043 { 1044 mdb_printf(MSG_ORIG(MSG_GRPDESC_HELP)); 1045 } 1046 1047 static int 1048 /* ARGSUSED2 */ 1049 dcmd_GrpDesc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1050 { 1051 Grp_desc gd; 1052 char *str; 1053 1054 /* 1055 * Insure we have a valid address. 1056 */ 1057 if ((flags & DCMD_ADDRSPEC) == 0) { 1058 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GRPDESC_STR)); 1059 return (DCMD_USAGE); 1060 } 1061 1062 mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE1), addr); 1063 if (mdb_vread(&gd, sizeof (Grp_desc), addr) == -1) { 1064 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_GRPDESC_STR), 1065 addr); 1066 return (DCMD_ERR); 1067 } 1068 1069 if ((str = Rtmap_Name((uintptr_t)gd.gd_depend)) == 0) 1070 return (DCMD_ERR); 1071 1072 mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE2), gd.gd_depend, str); 1073 mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE3), gd.gd_flags, gd.gd_flags, 1074 grdflags_bits); 1075 1076 return (DCMD_OK); 1077 } 1078 1079 void 1080 dcmd_GrpHdl_help(void) 1081 { 1082 mdb_printf(MSG_ORIG(MSG_GRPHDL_HELP)); 1083 } 1084 1085 static int 1086 /* ARGSUSED2 */ 1087 dcmd_GrpHdl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1088 { 1089 Grp_hdl gh; 1090 Alist al; 1091 uintptr_t listcalc, listnext; 1092 char *str; 1093 uint_t flg = 0; 1094 size_t ucnt, tcnt; 1095 1096 /* 1097 * Insure we have a valid address, and provide for a -v option. 1098 */ 1099 if ((flags & DCMD_ADDRSPEC) == 0) { 1100 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GRPHDL_STR)); 1101 return (DCMD_USAGE); 1102 } 1103 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE, 1104 &flg, NULL) != argc) 1105 return (DCMD_USAGE); 1106 1107 mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE1), addr); 1108 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1109 1110 if (mdb_vread(&gh, sizeof (Grp_hdl), addr) == -1) { 1111 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_GRPHDL_STR), 1112 addr); 1113 return (DCMD_ERR); 1114 } 1115 1116 /* 1117 * Determine the handles owner. Note that an orphaned handle may no 1118 * longer contain its originating owner. 1119 */ 1120 if (gh.gh_owner) { 1121 if ((str = Rtmap_Name((uintptr_t)gh.gh_owner)) == 0) 1122 return (DCMD_ERR); 1123 } else 1124 str = (char *)MSG_ORIG(MSG_STR_ORPHANED); 1125 1126 mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE2), str); 1127 mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE3), gh.gh_flags, gh.gh_flags, 1128 grhflags_bits); 1129 1130 if (gh.gh_depends == 0) { 1131 mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE4), gh.gh_refcnt); 1132 return (DCMD_OK); 1133 } 1134 1135 addr = (uintptr_t)gh.gh_depends; 1136 if (mdb_vread(&al, sizeof (Alist), addr) == -1) { 1137 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr); 1138 return (DCMD_ERR); 1139 } 1140 1141 ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size; 1142 tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size; 1143 mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE5), gh.gh_refcnt, addr, ucnt, tcnt); 1144 1145 if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0)) 1146 return (DCMD_OK); 1147 1148 mdb_inc_indent(4); 1149 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1150 1151 /* 1152 * Under verbose mode print the name of each dependency. An Alist can 1153 * have a variable number of data items, so read each individual entry. 1154 */ 1155 listcalc = (uintptr_t)(&(al.al_data[0])); 1156 listcalc -= (uintptr_t)(&al); 1157 listcalc += addr; 1158 if (dcmd_GrpDesc(listcalc, flags, argc, argv) == DCMD_ERR) { 1159 mdb_dec_indent(4); 1160 return (DCMD_ERR); 1161 } 1162 1163 listnext = (uintptr_t)(al.al_next + addr); 1164 for (listcalc += al.al_size; listcalc < listnext; 1165 listcalc += al.al_size) { 1166 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1167 if (dcmd_GrpDesc(listcalc, flags, argc, argv) == DCMD_ERR) { 1168 mdb_dec_indent(4); 1169 return (DCMD_ERR); 1170 } 1171 } 1172 1173 mdb_dec_indent(4); 1174 return (DCMD_OK); 1175 } 1176 1177 static void 1178 dcmd_Handles_help(void) 1179 { 1180 mdb_printf(MSG_ORIG(MSG_HANDLES_HELP)); 1181 } 1182 1183 static int 1184 dcmd_Handles(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1185 { 1186 Rt_map rtmap; 1187 char *str; 1188 uint_t flg = 0; 1189 Alist al; 1190 uintptr_t listcalc, listnext; 1191 size_t ucnt, tcnt; 1192 Grp_hdl * ghp; 1193 1194 /* 1195 * Insure we have a valid address, and provide for a -v option. 1196 */ 1197 if ((flags & DCMD_ADDRSPEC) == 0) { 1198 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_HANDLES_STR)); 1199 return (DCMD_USAGE); 1200 } 1201 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE, 1202 &flg, NULL) != argc) 1203 return (DCMD_USAGE); 1204 1205 /* 1206 * Read the Rt_map contents. 1207 */ 1208 if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) { 1209 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr); 1210 return (DCMD_ERR); 1211 } 1212 if ((str = String((uintptr_t)NAME(&rtmap), 1213 MSG_ORIG(MSG_STR_NAME))) == 0) 1214 return (DCMD_ERR); 1215 1216 mdb_printf(MSG_ORIG(MSG_HANDLES_LINE1), str); 1217 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1218 1219 if (HANDLES(&rtmap) == 0) 1220 return (DCMD_OK); 1221 1222 addr = (uintptr_t)HANDLES(&rtmap); 1223 if (mdb_vread(&al, sizeof (Alist), addr) == -1) { 1224 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr); 1225 return (DCMD_ERR); 1226 } 1227 1228 ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size; 1229 tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size; 1230 mdb_printf(MSG_ORIG(MSG_HANDLES_LINE2), addr, ucnt, tcnt); 1231 1232 if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0)) 1233 return (DCMD_OK); 1234 1235 /* 1236 * Under verbose mode print the name of each dependency. An Alist can 1237 * have a variable number of data items, so read each individual entry. 1238 */ 1239 listcalc = (uintptr_t)(&(al.al_data[0])); 1240 listcalc -= (uintptr_t)(&al); 1241 listcalc += addr; 1242 if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) { 1243 mdb_warn(MSG_ORIG(MSG_ERR_READ), 1244 MSG_ORIG(MSG_GRPHDL_STR), listcalc); 1245 return (DCMD_ERR); 1246 } 1247 1248 mdb_inc_indent(4); 1249 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1250 1251 if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, argv) == DCMD_ERR) { 1252 mdb_dec_indent(4); 1253 return (DCMD_ERR); 1254 } 1255 1256 listnext = (uintptr_t)(al.al_next + addr); 1257 for (listcalc += al.al_size; listcalc < listnext; 1258 listcalc += al.al_size) { 1259 if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) { 1260 mdb_warn(MSG_ORIG(MSG_ERR_READ), 1261 MSG_ORIG(MSG_GRPHDL_STR), listcalc); 1262 return (DCMD_ERR); 1263 } 1264 1265 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1266 if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, 1267 argv) == DCMD_ERR) { 1268 mdb_dec_indent(4); 1269 return (DCMD_ERR); 1270 } 1271 } 1272 mdb_dec_indent(4); 1273 return (DCMD_OK); 1274 } 1275 1276 static void 1277 dcmd_Groups_help(void) 1278 { 1279 mdb_printf(MSG_ORIG(MSG_GROUPS_HELP)); 1280 } 1281 1282 1283 static int 1284 dcmd_Groups(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1285 { 1286 Rt_map rtmap; 1287 char *str; 1288 Alist al; 1289 uint_t flg = 0; 1290 uintptr_t listcalc, listnext; 1291 size_t ucnt, tcnt; 1292 Grp_hdl * ghp; 1293 1294 /* 1295 * Insure we have a valid address, and provide for a -v option. 1296 */ 1297 if ((flags & DCMD_ADDRSPEC) == 0) { 1298 mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GROUPS_STR)); 1299 return (DCMD_USAGE); 1300 } 1301 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE, 1302 &flg, NULL) != argc) 1303 return (DCMD_USAGE); 1304 1305 /* 1306 * Read the Rt_map contents. 1307 */ 1308 if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) { 1309 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr); 1310 return (DCMD_ERR); 1311 } 1312 if ((str = String((uintptr_t)NAME(&rtmap), 1313 MSG_ORIG(MSG_STR_NAME))) == 0) 1314 return (DCMD_ERR); 1315 1316 mdb_printf(MSG_ORIG(MSG_GROUPS_LINE1), str); 1317 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1318 1319 if (GROUPS(&rtmap) == 0) 1320 return (DCMD_OK); 1321 1322 addr = (uintptr_t)GROUPS(&rtmap); 1323 if (mdb_vread(&al, sizeof (Alist), addr) == -1) { 1324 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr); 1325 return (DCMD_ERR); 1326 } 1327 1328 ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size; 1329 tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size; 1330 mdb_printf(MSG_ORIG(MSG_GROUPS_LINE2), addr, ucnt, tcnt); 1331 1332 if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0)) 1333 return (DCMD_OK); 1334 1335 /* 1336 * Under verbose mode print the name of each dependency. An Alist can 1337 * have a variable number of data items, so read each individual entry. 1338 */ 1339 listcalc = (uintptr_t)(&(al.al_data[0])); 1340 listcalc -= (uintptr_t)(&al); 1341 listcalc += addr; 1342 if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) { 1343 mdb_warn(MSG_ORIG(MSG_ERR_READ), 1344 MSG_ORIG(MSG_GRPHDL_STR), listcalc); 1345 return (DCMD_ERR); 1346 } 1347 1348 mdb_inc_indent(4); 1349 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1350 1351 if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, argv) == DCMD_ERR) { 1352 mdb_dec_indent(4); 1353 return (DCMD_ERR); 1354 } 1355 1356 listnext = (uintptr_t)(al.al_next + addr); 1357 for (listcalc += al.al_size; listcalc < listnext; 1358 listcalc += al.al_size) { 1359 if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) { 1360 mdb_warn(MSG_ORIG(MSG_ERR_READ), 1361 MSG_ORIG(MSG_GRPHDL_STR), listcalc); 1362 return (DCMD_ERR); 1363 } 1364 1365 mdb_printf(MSG_ORIG(MSG_STR_DASHES)); 1366 if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, 1367 argv) == DCMD_ERR) { 1368 mdb_dec_indent(4); 1369 return (DCMD_ERR); 1370 } 1371 } 1372 mdb_dec_indent(4); 1373 return (DCMD_OK); 1374 } 1375 static void 1376 dcmd_ElfDyn_help(void) 1377 { 1378 mdb_printf(MSG_ORIG(MSG_ELFDYN_HELP)); 1379 } 1380 1381 static int 1382 /* ARGSUSED2 */ 1383 dcmd_ElfDyn(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1384 { 1385 Dyn dyn; 1386 const char *dynstr; 1387 1388 if ((flags & DCMD_ADDRSPEC) == 0) 1389 return (DCMD_USAGE); 1390 if (mdb_vread(&dyn, sizeof (dyn), addr) == -1) { 1391 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_ELFDYN_STR), 1392 addr); 1393 return (DCMD_ERR); 1394 } 1395 1396 mdb_printf(MSG_ORIG(MSG_ELFDYN_TITLE), addr); 1397 dynstr = conv_dyntag_str(dyn.d_tag, M_MACH); 1398 mdb_printf(MSG_ORIG(MSG_ELFDYN_LINE1), addr, dynstr, dyn.d_un.d_ptr); 1399 1400 mdb_set_dot(addr + sizeof (Dyn)); 1401 1402 return (DCMD_OK); 1403 } 1404 1405 static void 1406 dcmd_ElfEhdr_help(void) 1407 { 1408 mdb_printf(MSG_ORIG(MSG_EHDR_HELP)); 1409 } 1410 1411 static int 1412 /* ARGSUSED2 */ 1413 dcmd_ElfEhdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1414 { 1415 Ehdr ehdr; 1416 Byte *byte; 1417 const char *flgs; 1418 1419 if ((flags & DCMD_ADDRSPEC) == 0) 1420 return (DCMD_USAGE); 1421 1422 if (mdb_vread(&ehdr, sizeof (ehdr), addr) == -1) { 1423 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_EHDR_STR), 1424 addr); 1425 return (DCMD_ERR); 1426 } 1427 1428 mdb_printf(MSG_ORIG(MSG_EHDR_TITLE), addr); 1429 byte = &ehdr.e_ident[0]; 1430 mdb_printf(MSG_ORIG(MSG_EHDR_LINE1), byte[EI_MAG0], 1431 (byte[EI_MAG1] ? byte[EI_MAG1] : '0'), 1432 (byte[EI_MAG2] ? byte[EI_MAG2] : '0'), 1433 (byte[EI_MAG3] ? byte[EI_MAG3] : '0')); 1434 mdb_printf(MSG_ORIG(MSG_EHDR_LINE2), 1435 conv_eclass_str(ehdr.e_ident[EI_CLASS]), 1436 conv_edata_str(ehdr.e_ident[EI_DATA])); 1437 1438 mdb_printf(MSG_ORIG(MSG_EHDR_LINE3), 1439 conv_emach_str(ehdr.e_machine), conv_ever_str(ehdr.e_version)); 1440 mdb_printf(MSG_ORIG(MSG_EHDR_LINE4), conv_etype_str(ehdr.e_type)); 1441 1442 /* 1443 * Line up the flags differently depending on wether we 1444 * received a numeric (e.g. "0x200") or text represent- 1445 * ation (e.g. "[ EF_SPARC_SUN_US1 ]"). 1446 */ 1447 flgs = conv_eflags_str(ehdr.e_machine, ehdr.e_flags); 1448 if (flgs[0] == '[') 1449 mdb_printf(MSG_ORIG(MSG_EHDR_LINE5), flgs); 1450 else 1451 mdb_printf(MSG_ORIG(MSG_EHDR_LINE6), flgs); 1452 1453 mdb_printf(MSG_ORIG(MSG_EHDR_LINE7), ehdr.e_entry, ehdr.e_ehsize, 1454 ehdr.e_shstrndx); 1455 mdb_printf(MSG_ORIG(MSG_EHDR_LINE8), ehdr.e_shoff, ehdr.e_shentsize, 1456 ehdr.e_shnum); 1457 mdb_printf(MSG_ORIG(MSG_EHDR_LINE9), ehdr.e_phoff, ehdr.e_phentsize, 1458 ehdr.e_phnum); 1459 1460 mdb_set_dot(addr + sizeof (Ehdr)); 1461 1462 return (DCMD_OK); 1463 } 1464 1465 static void 1466 dcmd_ElfPhdr_help(void) 1467 { 1468 mdb_printf(MSG_ORIG(MSG_EPHDR_HELP)); 1469 } 1470 1471 static int 1472 /* ARGSUSED2 */ 1473 dcmd_ElfPhdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1474 { 1475 Phdr phdr; 1476 1477 if ((flags & DCMD_ADDRSPEC) == 0) 1478 return (DCMD_USAGE); 1479 1480 if (mdb_vread(&phdr, sizeof (phdr), addr) == -1) { 1481 mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_EPHDR_STR), 1482 addr); 1483 return (DCMD_ERR); 1484 } 1485 1486 mdb_printf(MSG_ORIG(MSG_EPHDR_TITLE), addr); 1487 mdb_printf(MSG_ORIG(MSG_EPHDR_LINE1), phdr.p_vaddr, 1488 conv_phdrflg_str(phdr.p_flags)); 1489 mdb_printf(MSG_ORIG(MSG_EPHDR_LINE2), phdr.p_paddr, 1490 conv_phdrtyp_str(M_MACH, phdr.p_type)); 1491 mdb_printf(MSG_ORIG(MSG_EPHDR_LINE3), phdr.p_filesz, 1492 phdr.p_memsz); 1493 mdb_printf(MSG_ORIG(MSG_EPHDR_LINE4), phdr.p_offset, 1494 phdr.p_align); 1495 1496 mdb_set_dot(addr + sizeof (Phdr)); 1497 1498 return (DCMD_OK); 1499 } 1500 1501 1502 static const mdb_dcmd_t dcmds[] = { 1503 { MSG_ORIG(MSG_BND_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1504 MSG_ORIG(MSG_BND_DCD), 1505 dcmd_Bind, dcmd_Bind_help}, 1506 { MSG_ORIG(MSG_DEPENDS_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1507 MSG_ORIG(MSG_DEPENDS_DCD), 1508 dcmd_Depends, dcmd_Depends_help}, 1509 { MSG_ORIG(MSG_CALLERS_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1510 MSG_ORIG(MSG_CALLERS_DCD), 1511 dcmd_Callers, dcmd_Callers_help}, 1512 { MSG_ORIG(MSG_GRPHDL_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1513 MSG_ORIG(MSG_GRPHDL_DCD), 1514 dcmd_GrpHdl, dcmd_GrpHdl_help}, 1515 { MSG_ORIG(MSG_GRPDESC_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1516 MSG_ORIG(MSG_GRPDESC_DCD), 1517 dcmd_GrpDesc, dcmd_GrpDesc_help}, 1518 { MSG_ORIG(MSG_HANDLES_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1519 MSG_ORIG(MSG_HANDLES_DCD), 1520 dcmd_Handles, dcmd_Handles_help}, 1521 { MSG_ORIG(MSG_GROUPS_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1522 MSG_ORIG(MSG_GROUPS_DCD), 1523 dcmd_Groups, dcmd_Groups_help}, 1524 { MSG_ORIG(MSG_ELFDYN_STR), MSG_ORIG(MSG_USG_ADDREQ), 1525 MSG_ORIG(MSG_ELFDYN_DCD), 1526 dcmd_ElfDyn, dcmd_ElfDyn_help}, 1527 { MSG_ORIG(MSG_EHDR_STR), MSG_ORIG(MSG_USG_ADDREQ), 1528 MSG_ORIG(MSG_EHDR_DCD), 1529 dcmd_ElfEhdr, dcmd_ElfEhdr_help}, 1530 { MSG_ORIG(MSG_EPHDR_STR), MSG_ORIG(MSG_USG_ADDREQ), 1531 MSG_ORIG(MSG_EPHDR_DCD), 1532 dcmd_ElfPhdr, dcmd_ElfPhdr_help}, 1533 { MSG_ORIG(MSG_LIST_STR), MSG_ORIG(MSG_USG_ADDREQ), 1534 MSG_ORIG(MSG_LIST_DCD), 1535 dcmd_List, dcmd_List_help}, 1536 { MSG_ORIG(MSG_LMLIST_STR), MSG_ORIG(MSG_USG_ADDREQ_V), 1537 MSG_ORIG(MSG_LMLIST_DCD), 1538 dcmd_Lm_list, dcmd_Lm_list_help}, 1539 { MSG_ORIG(MSG_RTMAPS_STR), MSG_ORIG(MSG_USG_ADDOPT_V), 1540 MSG_ORIG(MSG_RTMAPS_DCD), 1541 dcmd_Rtmaps, dcmd_Rtmaps_help}, 1542 { MSG_ORIG(MSG_RTMAP_STR), MSG_ORIG(MSG_USG_ADDREQ), 1543 MSG_ORIG(MSG_RTMAP_DCD), 1544 dcmd_rtmap, dcmd_rtmap_help}, 1545 { MSG_ORIG(MSG_SETENV_STR), MSG_ORIG(MSG_USG_SETENV), 1546 MSG_ORIG(MSG_SETENV_DCD), 1547 dcmd_Setenv, dcmd_Setenv_help}, 1548 { NULL } 1549 }; 1550 1551 static const mdb_walker_t walkers[] = { 1552 { MSG_ORIG(MSG_RTMAPS_STR), MSG_ORIG(MSG_WWD_RTMAP), 1553 walk_rtmap_init, walk_rtmap_step, NULL, NULL }, 1554 { MSG_ORIG(MSG_LIST_STR), MSG_ORIG(MSG_WWD_LIST), 1555 walk_List_init, walk_List_step, NULL, NULL }, 1556 { NULL } 1557 }; 1558 1559 static const mdb_modinfo_t modinfo = { 1560 MDB_API_VERSION, dcmds, walkers 1561 }; 1562 1563 const mdb_modinfo_t * 1564 _mdb_init(void) 1565 { 1566 return (&modinfo); 1567 } 1568