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