VirtualBox

Changeset 90432 in vbox for trunk


Ignore:
Timestamp:
Jul 30, 2021 3:26:54 PM (4 years ago)
Author:
vboxsync
Message:

Debugger/DBGPlugInLinux: Added parsing of symbols of kernel modules so we can get more detailed stack traces when kernel modules are involved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/DBGPlugInLinuxModuleCodeTmpl.cpp.h

    r90408 r90432  
    3838*   Structures and Typedefs                                                                                                      *
    3939*********************************************************************************************************************************/
     40/**
     41 * Kernel module symbol (hasn't changed in ages).
     42 */
     43typedef struct RT_CONCAT(LNXMODKSYM,LNX_SUFFIX)
     44{
     45    LNX_ULONG_T         uValue;
     46    LNX_PTR_T           uPtrSymName;
     47} RT_CONCAT(LNXMODKSYM,LNX_SUFFIX);
     48
     49
    4050#if LNX_VER >= LNX_MK_VER(2,6,11)
    4151typedef struct RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX)
     
    376386
    377387/**
     388 * Loads the kernel symbols at the given start address.
     389 *
     390 * @returns VBox status code.
     391 * @param   hDbgMod             The module handle to add the loaded symbols to.
     392 * @param   uPtrSymStart        The start address of the array of symbols.
     393 * @param   cSyms               Number of symbols in the array.
     394 * @param 
     395 */
     396static int RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(PUVM pUVM, RTDBGMOD hDbgMod, LNX_PTR_T uPtrModuleStart, LNX_PTR_T uPtrSymStart, uint32_t cSyms)
     397{
     398    int rc = VINF_SUCCESS;
     399    DBGFADDRESS AddrSym;
     400    DBGFR3AddrFromFlat(pUVM, &AddrSym, uPtrSymStart);
     401
     402    while (   cSyms
     403           && RT_SUCCESS(rc))
     404    {
     405        RT_CONCAT(LNXMODKSYM,LNX_SUFFIX) aSyms[64];
     406        uint32_t cThisLoad = RT_MIN(cSyms, RT_ELEMENTS(aSyms));
     407
     408        rc = DBGFR3MemRead(pUVM, 0, &AddrSym, &aSyms[0], cThisLoad * sizeof(aSyms[0]));
     409        if (RT_SUCCESS(rc))
     410        {
     411            cSyms -= cThisLoad;
     412            DBGFR3AddrAdd(&AddrSym, cThisLoad * sizeof(aSyms[0]));
     413
     414            for (uint32_t i = 0; i < cThisLoad; i++)
     415            {
     416                char szSymName[128];
     417                DBGFADDRESS AddrSymName;
     418                rc = DBGFR3MemRead(pUVM, 0, DBGFR3AddrFromFlat(pUVM, &AddrSymName, aSyms[i].uPtrSymName),
     419                                   &szSymName[0], sizeof(szSymName));
     420                if (RT_FAILURE(rc))
     421                    break;
     422
     423                /* Verify string encoding - ignore the symbol if it fails. */
     424                rc = RTStrValidateEncodingEx(&szSymName[0], sizeof(szSymName), RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
     425                if (RT_FAILURE(rc))
     426                    continue;
     427
     428                Assert(aSyms[i].uValue >= uPtrModuleStart);
     429                rc = RTDbgModSymbolAdd(hDbgMod, szSymName, RTDBGSEGIDX_RVA, aSyms[i].uValue - uPtrModuleStart, 0 /*cb*/, 0 /*fFlags*/, NULL);
     430                if (RT_SUCCESS(rc))
     431                    LogFlowFunc(("Added symbol '%s' successfully\n", szSymName));
     432                else
     433                {
     434                    LogFlowFunc(("Adding symbol '%s' failed with: %Rrc\n", szSymName, rc));
     435                    rc = VINF_SUCCESS;
     436                }
     437            }
     438        }
     439    }
     440
     441    return rc;
     442}
     443
     444
     445/**
    378446 * Version specific module processing code.
    379447 */
     
    429497            rc = RTDbgAsModuleLink(hAs, hDbgMod, uPtrModuleCore, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/);
    430498            RTDbgAsRelease(hAs);
     499            if (RT_SUCCESS(rc))
     500            {
     501                rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, hDbgMod, uPtrModuleCore,
     502                                                                           Module.uPtrSyms, Module.num_syms);
     503                if (RT_FAILURE(rc))
     504                    LogRelFunc((" Faild to load symbols: %Rrc\n", rc));
     505
     506#if LNX_VER >= LNX_MK_VER(2,5,55)
     507                rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, hDbgMod, uPtrModuleCore,
     508                                                                           Module.uPtrGplSyms, Module.num_gpl_syms);
     509                if (RT_FAILURE(rc))
     510                    LogRelFunc((" Faild to load GPL symbols: %Rrc\n", rc));
     511#endif
     512
     513#if LNX_VER >= LNX_MK_VER(2,6,17)
     514                rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, hDbgMod, uPtrModuleCore,
     515                                                                           Module.uPtrGplFutureSyms, Module.num_gpl_future_syms);
     516                if (RT_FAILURE(rc))
     517                    LogRelFunc((" Faild to load future GPL symbols: %Rrc\n", rc));
     518#endif
     519
     520#if LNX_VER >= LNX_MK_VER(2,6,18)
     521                rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, hDbgMod, uPtrModuleCore,
     522                                                                           Module.uPtrUnusedSyms, Module.num_unused_syms);
     523                if (RT_FAILURE(rc))
     524                    LogRelFunc((" Faild to load unused symbols: %Rrc\n", rc));
     525
     526                rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, hDbgMod, uPtrModuleCore,
     527                                                                           Module.uPtrUnusedGplSyms, Module.num_unused_gpl_syms);
     528                if (RT_FAILURE(rc))
     529                    LogRelFunc((" Faild to load unused GPL symbols: %Rrc\n", rc));
     530#endif
     531            }
    431532        }
    432533        else
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