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