Changeset 87605 in vbox for trunk/src/VBox/Runtime/tools
- Timestamp:
- Feb 4, 2021 1:24:43 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 142640
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTLdrFlt.cpp
r82968 r87605 43 43 44 44 45 /** Worker for ProduceKAllSyms. */ 46 static void PrintSymbolForKAllSyms(const char *pszModule, PCRTDBGSYMBOL pSymInfo, PCRTDBGSEGMENT pSegInfo, 47 RTUINTPTR uBaseAddr, bool fOneSeg) 48 { 49 RTUINTPTR uAddr; 50 char chType = 't'; 51 if (pSymInfo->iSeg < RTDBGSEGIDX_SPECIAL_FIRST) 52 { 53 uAddr = uBaseAddr + pSymInfo->offSeg; 54 if (!fOneSeg) 55 uAddr += pSegInfo->uRva; 56 if (pSegInfo->szName[0]) 57 { 58 if (strstr(pSegInfo->szName, "rodata") != NULL) 59 chType = 'r'; 60 else if (strstr(pSegInfo->szName, "bss") != NULL) 61 chType = 'b'; 62 else if (strstr(pSegInfo->szName, "data") != NULL) 63 chType = 'd'; 64 } 65 } 66 else if (pSymInfo->iSeg == RTDBGSEGIDX_ABS) 67 { 68 chType = 'a'; 69 uAddr = pSymInfo->offSeg; 70 } 71 else if (pSymInfo->iSeg == RTDBGSEGIDX_RVA) 72 { 73 Assert(!fOneSeg); 74 uAddr = uBaseAddr + pSymInfo->offSeg; 75 } 76 else 77 { 78 RTMsgError("Unsupported special segment %#x for %s in %s!", pSymInfo->iSeg, pSymInfo->szName, pszModule); 79 return; 80 } 81 82 RTPrintf("%RTptr %c %s\t[%s]\n", uAddr, chType, pSymInfo->szName, pszModule); 83 } 84 85 86 /** 87 * Produces a /proc/kallsyms compatible symbol listing of @a hDbgAs on standard 88 * output. 89 * 90 * @returns Exit code. 91 * @param hDbgAs The address space to dump. 92 */ 93 static RTEXITCODE ProduceKAllSyms(RTDBGAS hDbgAs) 94 { 95 /* 96 * Iterate modules. 97 */ 98 uint32_t cModules = RTDbgAsModuleCount(hDbgAs); 99 for (uint32_t iModule = 0; iModule < cModules; iModule++) 100 { 101 RTDBGMOD const hDbgMod = RTDbgAsModuleByIndex(hDbgAs, iModule); 102 const char * const pszModule = RTDbgModName(hDbgMod); 103 104 /* 105 * Iterate mappings of the module. 106 */ 107 RTDBGASMAPINFO aMappings[128]; 108 uint32_t cMappings = RT_ELEMENTS(aMappings); 109 int rc = RTDbgAsModuleQueryMapByIndex(hDbgAs, iModule, &aMappings[0], &cMappings, 0 /*fFlags*/); 110 if (RT_SUCCESS(rc)) 111 { 112 for (uint32_t iMapping = 0; iMapping < cMappings; iMapping++) 113 { 114 RTDBGSEGMENT SegInfo = {0}; 115 if (aMappings[iMapping].iSeg == NIL_RTDBGSEGIDX) 116 { 117 /* 118 * Flat mapping of the entire module. 119 */ 120 SegInfo.iSeg = NIL_RTDBGSEGIDX; 121 uint32_t cSymbols = RTDbgModSymbolCount(hDbgMod); 122 for (uint32_t iSymbol = 0; iSymbol < cSymbols; iSymbol++) 123 { 124 RTDBGSYMBOL SymInfo; 125 rc = RTDbgModSymbolByOrdinal(hDbgMod, iSymbol, &SymInfo); 126 if (RT_SUCCESS(rc)) 127 { 128 if ( SymInfo.iSeg != SegInfo.iSeg 129 && SymInfo.iSeg < RTDBGSEGIDX_SPECIAL_FIRST) 130 { 131 rc = RTDbgModSegmentByIndex(hDbgMod, SymInfo.iSeg, &SegInfo); 132 if (RT_FAILURE(rc)) 133 { 134 RTMsgError("RTDbgModSegmentByIndex(%s, %u) failed: %Rrc", pszModule, SymInfo.iSeg, rc); 135 continue; 136 } 137 } 138 PrintSymbolForKAllSyms(pszModule, &SymInfo, &SegInfo, aMappings[iMapping].Address, false); 139 } 140 else 141 RTMsgError("RTDbgModSymbolByOrdinal(%s, %u) failed: %Rrc", pszModule, iSymbol, rc); 142 } 143 } 144 else 145 { 146 /* 147 * Just one segment. 148 */ 149 rc = RTDbgModSegmentByIndex(hDbgMod, aMappings[iMapping].iSeg, &SegInfo); 150 if (RT_SUCCESS(rc)) 151 { 152 /** @todo */ 153 } 154 else 155 RTMsgError("RTDbgModSegmentByIndex(%s, %u) failed: %Rrc", pszModule, aMappings[iMapping].iSeg, rc); 156 } 157 } 158 } 159 else 160 RTMsgError("RTDbgAsModuleQueryMapByIndex failed: %Rrc", rc); 161 RTDbgModRelease(hDbgMod); 162 } 163 164 return RTEXITCODE_SUCCESS; 165 } 166 167 168 /** 169 * Dumps the address space. 170 */ 171 static void DumpAddressSpace(RTDBGAS hDbgAs, unsigned cVerbosityLevel) 172 { 173 RTPrintf("*** Address Space Dump ***\n"); 174 uint32_t cModules = RTDbgAsModuleCount(hDbgAs); 175 for (uint32_t iModule = 0; iModule < cModules; iModule++) 176 { 177 RTDBGMOD hDbgMod = RTDbgAsModuleByIndex(hDbgAs, iModule); 178 RTPrintf("Module #%u: %s\n", iModule, RTDbgModName(hDbgMod)); 179 180 RTDBGASMAPINFO aMappings[128]; 181 uint32_t cMappings = RT_ELEMENTS(aMappings); 182 int rc = RTDbgAsModuleQueryMapByIndex(hDbgAs, iModule, &aMappings[0], &cMappings, 0 /*fFlags*/); 183 if (RT_SUCCESS(rc)) 184 { 185 for (uint32_t iMapping = 0; iMapping < cMappings; iMapping++) 186 { 187 if (aMappings[iMapping].iSeg == NIL_RTDBGSEGIDX) 188 { 189 RTPrintf(" mapping #%u: %RTptr-%RTptr\n", 190 iMapping, 191 aMappings[iMapping].Address, 192 aMappings[iMapping].Address + RTDbgModImageSize(hDbgMod) - 1); 193 if (cVerbosityLevel > 2) 194 { 195 uint32_t cSegments = RTDbgModSegmentCount(hDbgMod); 196 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) 197 { 198 RTDBGSEGMENT SegInfo; 199 rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo); 200 if (RT_SUCCESS(rc)) 201 RTPrintf(" seg #%u: %RTptr LB %RTptr '%s'\n", 202 iSeg, SegInfo.uRva, SegInfo.cb, SegInfo.szName); 203 else 204 RTPrintf(" seg #%u: %Rrc\n", iSeg, rc); 205 } 206 } 207 } 208 else 209 { 210 RTDBGSEGMENT SegInfo; 211 rc = RTDbgModSegmentByIndex(hDbgMod, aMappings[iMapping].iSeg, &SegInfo); 212 if (RT_SUCCESS(rc)) 213 RTPrintf(" mapping #%u: %RTptr-%RTptr (segment #%u - '%s')\n", 214 iMapping, 215 aMappings[iMapping].Address, 216 aMappings[iMapping].Address + SegInfo.cb, 217 SegInfo.iSeg, SegInfo.szName); 218 else 219 RTPrintf(" mapping #%u: %RTptr-???????? (segment #%u) rc=%Rrc\n", 220 iMapping, aMappings[iMapping].Address, aMappings[iMapping].iSeg, rc); 221 } 222 223 if (cVerbosityLevel > 1) 224 { 225 uint32_t cSymbols = RTDbgModSymbolCount(hDbgMod); 226 RTPrintf(" %u symbols\n", cSymbols); 227 for (uint32_t iSymbol = 0; iSymbol < cSymbols; iSymbol++) 228 { 229 RTDBGSYMBOL SymInfo; 230 rc = RTDbgModSymbolByOrdinal(hDbgMod, iSymbol, &SymInfo); 231 if (RT_SUCCESS(rc)) 232 RTPrintf(" #%04u at %08x:%RTptr (%RTptr) %05llx %s\n", 233 SymInfo.iOrdinal, SymInfo.iSeg, SymInfo.offSeg, SymInfo.Value, 234 (uint64_t)SymInfo.cb, SymInfo.szName); 235 } 236 } 237 } 238 } 239 else 240 RTMsgError("RTDbgAsModuleQueryMapByIndex failed: %Rrc", rc); 241 RTDbgModRelease(hDbgMod); 242 } 243 RTPrintf("*** End of Address Space Dump ***\n"); 244 } 245 246 45 247 /** 46 248 * Tries to parse out an address at the head of the string. … … 152 354 { "--amd64", '6', RTGETOPT_REQ_NOTHING }, 153 355 { "--whatever", '*', RTGETOPT_REQ_NOTHING }, 356 { "--kallsyms", 'k', RTGETOPT_REQ_NOTHING }, 154 357 }; 155 358 … … 163 366 bool fCacheFile = false; 164 367 RTLDRARCH enmArch = RTLDRARCH_WHATEVER; 368 bool fKAllSyms = false; 165 369 166 370 RTGETOPTUNION ValueUnion; … … 179 383 case 'c': 180 384 fCacheFile = true; 385 break; 386 387 case 'k': 388 fKAllSyms = true; 181 389 break; 182 390 … … 217 425 " --amd64,--x86,--whatever\n" 218 426 " Selects the desired architecture.\n" 427 " -k,--kallsyms\n" 428 " Produce a /proc/kallsyms compatible symbol listing and quit.\n" 219 429 " -h, -?, --help\n" 220 430 " Display this help text and exit successfully.\n" … … 276 486 */ 277 487 if (cVerbosityLevel) 278 { 279 RTPrintf("*** Address Space Dump ***\n"); 280 uint32_t cModules = RTDbgAsModuleCount(hDbgAs); 281 for (uint32_t iModule = 0; iModule < cModules; iModule++) 282 { 283 RTDBGMOD hDbgMod = RTDbgAsModuleByIndex(hDbgAs, iModule); 284 RTPrintf("Module #%u: %s\n", iModule, RTDbgModName(hDbgMod)); 285 286 RTDBGASMAPINFO aMappings[128]; 287 uint32_t cMappings = RT_ELEMENTS(aMappings); 288 rc = RTDbgAsModuleQueryMapByIndex(hDbgAs, iModule, &aMappings[0], &cMappings, 0 /*fFlags*/); 289 if (RT_SUCCESS(rc)) 290 { 291 for (uint32_t iMapping = 0; iMapping < cMappings; iMapping++) 292 { 293 if (aMappings[iMapping].iSeg == NIL_RTDBGSEGIDX) 294 { 295 RTPrintf(" mapping #%u: %RTptr-%RTptr\n", 296 iMapping, 297 aMappings[iMapping].Address, 298 aMappings[iMapping].Address + RTDbgModImageSize(hDbgMod) - 1); 299 if (cVerbosityLevel > 2) 300 { 301 uint32_t cSegments = RTDbgModSegmentCount(hDbgMod); 302 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) 303 { 304 RTDBGSEGMENT SegInfo; 305 rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo); 306 if (RT_SUCCESS(rc)) 307 RTPrintf(" seg #%u: %RTptr LB %RTptr '%s'\n", 308 iSeg, SegInfo.uRva, SegInfo.cb, SegInfo.szName); 309 else 310 RTPrintf(" seg #%u: %Rrc\n", iSeg, rc); 311 } 312 } 313 } 314 else 315 { 316 RTDBGSEGMENT SegInfo; 317 rc = RTDbgModSegmentByIndex(hDbgMod, aMappings[iMapping].iSeg, &SegInfo); 318 if (RT_SUCCESS(rc)) 319 RTPrintf(" mapping #%u: %RTptr-%RTptr (segment #%u - '%s')\n", 320 iMapping, 321 aMappings[iMapping].Address, 322 aMappings[iMapping].Address + SegInfo.cb, 323 SegInfo.iSeg, SegInfo.szName); 324 else 325 RTPrintf(" mapping #%u: %RTptr-???????? (segment #%u) rc=%Rrc\n", 326 iMapping, aMappings[iMapping].Address, aMappings[iMapping].iSeg, rc); 327 } 328 329 if (cVerbosityLevel > 1) 330 { 331 uint32_t cSymbols = RTDbgModSymbolCount(hDbgMod); 332 RTPrintf(" %u symbols\n", cSymbols); 333 for (uint32_t iSymbol = 0; iSymbol < cSymbols; iSymbol++) 334 { 335 RTDBGSYMBOL SymInfo; 336 rc = RTDbgModSymbolByOrdinal(hDbgMod, iSymbol, &SymInfo); 337 if (RT_SUCCESS(rc)) 338 RTPrintf(" #%04u at %08x:%RTptr (%RTptr) %05llx %s\n", 339 SymInfo.iOrdinal, SymInfo.iSeg, SymInfo.offSeg, SymInfo.Value, 340 (uint64_t)SymInfo.cb, SymInfo.szName); 341 } 342 } 343 } 344 } 345 else 346 RTMsgError("RTDbgAsModuleQueryMapByIndex failed: %Rrc", rc); 347 RTDbgModRelease(hDbgMod); 348 } 349 RTPrintf("*** End of Address Space Dump ***\n"); 350 } 488 DumpAddressSpace(hDbgAs, cVerbosityLevel); 489 490 /* 491 * Produce the /proc/kallsyms output. 492 */ 493 if (fKAllSyms) 494 return ProduceKAllSyms(hDbgAs); 351 495 352 496 /* … … 438 582 RTStrmWrite(pOutput, pszStart, psz - pszStart); 439 583 RTStrmPutCh(pOutput, '\n'); 440 441 584 } 442 585
Note:
See TracChangeset
for help on using the changeset viewer.