VirtualBox

Changeset 74982 in vbox for trunk


Ignore:
Timestamp:
Oct 22, 2018 7:53:20 PM (6 years ago)
Author:
vboxsync
Message:

MakeAlternativeSource: Use codeview debug info to avoid jump tables generated by the compiler. Increased verbosity to include address, source file and line numbers in the output. Don't allow address override prefix when no operands accessing memory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/BiosCommonCode/MakeAlternativeSource.cpp

    r69120 r74982  
    5151    uint32_t    uFlatAddr;
    5252    uint32_t    cb;
     53    /** RVA into g_hSymMod. */
     54    uint32_t    uRva;
    5355} BIOSSEG;
    5456/** Pointer to a BIOS segment. */
     
    9799*********************************************************************************************************************************/
    98100/** The verbosity level.*/
    99 static unsigned         g_cVerbose = 1 /*0*/;
     101static unsigned         g_cVerbose = 2 /*0*/;
    100102/** Pointer to the BIOS image. */
    101103static uint8_t const   *g_pbImg;
     
    111113/** List of BIOSOBJFILE. */
    112114static RTLISTANCHOR     g_ObjList;
     115
     116/** Debug module with symbols. */
     117static RTDBGMOD         g_hSymMod = NIL_RTDBGMOD;
    113118
    114119/** The output stream. */
     
    633638static void disGetNextSymbolWorker(uint32_t uFlatAddr, uint32_t cbMax, uint32_t *poff, PRTDBGSYMBOL pSym)
    634639{
    635     RTINTPTR off = 0;
    636     int rc = RTDbgModSymbolByAddr(g_hMapMod, RTDBGSEGIDX_RVA, uFlatAddr, RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL, &off, pSym);
     640    RTINTPTR offMap = RTINTPTR_MAX;
     641    RTDBGSYMBOL MapSym;
     642    int rcMap = RTDbgModSymbolByAddr(g_hMapMod, RTDBGSEGIDX_RVA, uFlatAddr, RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL, &offMap, &MapSym);
     643
     644    RTINTPTR off = RTINTPTR_MAX;
     645    int rc = RTDbgModSymbolByAddr(g_hSymMod, RTDBGSEGIDX_RVA, uFlatAddr - g_uBiosFlatBase,
     646                                  RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL, &off, pSym);
     647    if (   RT_SUCCESS(rc)
     648        && RT_ABS(off) <= RT_ABS(offMap))
     649        pSym->Value += g_uBiosFlatBase;
     650    else
     651    {
     652        *pSym = MapSym;
     653        off   = offMap;
     654        rc    = rcMap;
     655    }
    637656    if (RT_SUCCESS(rc))
    638657    {
     
    641660        {
    642661            *poff = (uint32_t)-off;
     662
     663            /* Mangle symbols the assembler might confuse with instructions. */
     664            size_t cchName = strlen(pSym->szName);
     665            if (   cchName <= 4
     666                && (   strcmp("wait", pSym->szName) == 0
     667                    || strcmp("hlt", pSym->szName) == 0))
     668            {
     669                memmove(&pSym->szName[1], &pSym->szName[0], cchName);
     670                pSym->szName[0] = '_';
     671                pSym->szName[cchName + 1] = '_';
     672                pSym->szName[cchName + 2] = '\0';
     673            }
    643674            return;
    644675        }
     
    858889    RT_NOREF_PV(pszSymbol);
    859890    return true;
     891}
     892
     893
     894static bool disIsMemoryParameter(PCDISOPPARAM pParam, uint16_t fParam)
     895{
     896    return fParam != OP_PARM_NONE
     897        && DISUSE_IS_EFFECTIVE_ADDR(pParam->fUse);
     898}
     899
     900
     901static bool disAccessesMemory(PCDISCPUSTATE pCpuState)
     902{
     903    PCDISOPCODE pCurInstr = pCpuState->pCurInstr;
     904    return disIsMemoryParameter(&pCpuState->Param1, pCurInstr->fParam1)
     905        || disIsMemoryParameter(&pCpuState->Param2, pCurInstr->fParam2)
     906        || disIsMemoryParameter(&pCpuState->Param3, pCurInstr->fParam3)
     907        || disIsMemoryParameter(&pCpuState->Param4, pCurInstr->fParam4);
    860908}
    861909
     
    10791127            unsigned    cbInstr;
    10801128            DISCPUSTATE CpuState;
     1129            CpuState.ModRM.Bits.Mod = 3;
    10811130            int rc = DISInstrWithReader(uFlatAddr, fIs16Bit ? DISCPUMODE_16BIT : DISCPUMODE_32BIT,
    10821131                                        disReadOpcodeBytes, NULL, &CpuState, &cbInstr);
     
    10841133                && cbInstr <= cb
    10851134                && CpuState.pCurInstr
    1086                 && CpuState.pCurInstr->uOpcode != OP_INVALID)
     1135                && CpuState.pCurInstr->uOpcode != OP_INVALID
     1136                && CpuState.pCurInstr->uOpcode != OP_ILLUD2
     1137                && (   !(CpuState.fPrefix & DISPREFIX_ADDRSIZE)
     1138                    || disAccessesMemory(&CpuState)))
    10871139            {
    10881140                char szTmp[4096];
     
    10981150                    while (cch < 72)
    10991151                        szTmp[cch++] = ' ';
    1100                     RTStrPrintf(&szTmp[cch], sizeof(szTmp) - cch, "; %#x", uFlatAddr);
     1152
     1153                    RTDBGLINE LineInfo = {0};
     1154                    RTINTPTR  offLine = -1;
     1155                    int rcLine = RTDbgModLineByAddr(g_hSymMod, RTDBGSEGIDX_RVA, uFlatAddr - g_uBiosFlatBase,  &offLine, &LineInfo);
     1156                    if (RT_SUCCESS(rcLine) && offLine == 0 && cch < sizeof(szTmp) - 16)
     1157                        RTStrPrintf(&szTmp[cch], sizeof(szTmp) - cch, "; %#x %Rbn:%u",
     1158                                    uFlatAddr, LineInfo.szFilename, LineInfo.uLineNo);
     1159                    else
     1160                        RTStrPrintf(&szTmp[cch], sizeof(szTmp) - cch, "; %#x", uFlatAddr);
    11011161                }
    11021162
     
    12371297static RTEXITCODE ParseSymFile(const char *pszBiosSym)
    12381298{
    1239 #if 1
    1240     /** @todo use RTDbg* later. (Just checking for existance currently.) */
    1241     PRTSTREAM hStrm;
    1242     int rc = RTStrmOpen(pszBiosSym, "rb", &hStrm);
     1299    int rc = RTDbgModCreateFromImage(&g_hSymMod, pszBiosSym, "VBoxBios",  RTLDRARCH_WHATEVER, NIL_RTDBGCFG);
    12431300    if (RT_FAILURE(rc))
    12441301        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening '%s': %Rrc", pszBiosSym, rc);
    1245     RTStrmClose(hStrm);
    1246 #else
    1247     RTDBGMOD hDbgMod;
    1248     int rc = RTDbgModCreateFromImage(&hDbgMod, pszBiosSym, "VBoxBios", 0 /*fFlags*/);
    1249     RTMsgInfo("RTDbgModCreateFromImage -> %Rrc\n", rc);
    1250 #endif
     1302
     1303    if (g_cVerbose > 0)
     1304    {
     1305        /* Show segments */
     1306        RTDBGSEGIDX cSegs = RTDbgModSegmentCount(g_hSymMod);
     1307        for (RTDBGSEGIDX iSeg = 0; iSeg < cSegs; iSeg++)
     1308        {
     1309            RTDBGSEGMENT SegInfo;
     1310            rc = RTDbgModSegmentByIndex(g_hSymMod, iSeg, &SegInfo);
     1311            if (RT_SUCCESS(rc))
     1312                RTMsgInfo("Seg#%u: %05RX64 LB %04RX64 rva %04RX64 %s\n", iSeg, SegInfo.Address, SegInfo.cb, SegInfo.uRva, SegInfo.szName);
     1313            else
     1314                RTMsgInfo("Seg#%u: RTDbgModSegmentByIndex -> %Rrc\n", iSeg, rc);
     1315
     1316        }
     1317    }
    12511318    return RTEXITCODE_SUCCESS;
    12521319}
     
    12651332    va_list va;
    12661333    va_start(va, pszFormat);
    1267     RTMsgError("%s:%d: %N", pMap->pszMapFile, pMap->iLine, pszFormat, va);
     1334    RTMsgError("%s:%d: %N", pMap->pszMapFile, pMap->iLine, pszFormat, &va);
    12681335    va_end(va);
    12691336    return false;
     
    17551822                g_aSegs[j] = Tmp;
    17561823            }
     1824        g_aSegs[i].uRva = g_aSegs[i].uFlatAddr - g_aSegs[0].uFlatAddr;
     1825
    17571826        if (g_cVerbose > 0)
    1758             RTStrmPrintf(g_pStdErr, "segment at %08x / %04x:%04x LB %04x %s / %s / %s\n",
     1827            RTStrmPrintf(g_pStdErr, "segment at %08x / %04x / %04x:%04x LB %04x %s / %s / %s\n",
    17591828                         g_aSegs[i].uFlatAddr,
     1829                         g_aSegs[i].uRva,
    17601830                         g_aSegs[i].Address.sel,
    17611831                         g_aSegs[i].Address.off,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette