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