VirtualBox

Changeset 58873 in vbox


Ignore:
Timestamp:
Nov 26, 2015 2:20:06 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
104359
Message:

SUPDrv: linux debugging aid, cleanups.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r58872 r58873  
    395395    /** Hack for seeing the module in perf, dtrace and other stack crawlers. */
    396396    struct module                  *pLnxModHack;
    397     /** Hack for seeing the module in perf, dtrace and other stack crawlers .
    398      * Required for Linux v3.19+. */
    399     struct supdrv_ftrace_ops       *pLnxFTraceHack;
    400397#endif
    401398    /** Whether it's loaded by the native loader or not. */
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r58872 r58873  
    6464# define SUPDRV_LINUX_HAS_SAFE_MSR_API
    6565# include <asm/msr.h>
    66 #endif
    67 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) && defined(CONFIG_DYNAMIC_FTRACE)
    68 # include <linux/ftrace.h>
    6966#endif
    7067
     
    984981#endif
    985982
    986 #if 0 /* instant host lockup, can't be bothered debugging it */
    987 #if defined(VBOX_WITH_NON_PROD_HACK_FOR_PERF_STACKS) \
    988  && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) \
    989  && defined(CONFIG_MODULES_TREE_LOOKUP) \
    990  && defined(CONFIG_DYNAMIC_FTRACE)
    991 
    992 /**
    993  * Using a static array here because that's what is suggested in the docs to
    994  * avoid/reduce potential race conditions.
    995  */
    996 static struct supdrv_ftrace_ops
    997 {
    998     struct ftrace_ops   Core;
    999     bool volatile       fUsed;
    1000 } g_aFTraceOps[16] __read_mostly;
    1001 
    1002 /** Stub function for the ugly debug hack below. */
    1003 static void notrace __attribute__((optimize("-fomit-frame-pointer")))
    1004 supdrvLnxFTraceStub(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct pt_regs *regs)
    1005 {
    1006      return;
    1007 }
    1008 
    1009 #endif
    1010 #endif
    1011 
    1012983
    1013984void VBOXCALL   supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
     
    1026997
    1027998    pImage->pLnxModHack    = NULL;
    1028     pImage->pLnxFTraceHack = NULL;
    1029999
    10301000# ifdef CONFIG_MODULES_TREE_LOOKUP
     
    10801050    {
    10811051        int rc = VINF_SUCCESS;
    1082         //size_t cch;
    10831052# ifdef CONFIG_KALLSYMS
    10841053        Elf_Sym *paSymbols = (Elf_Sym *)(pMyMod + 1);
     
    10891058        INIT_LIST_HEAD(&pMyMod->list);  /* just in case */
    10901059
    1091         /* Come up with a good name that perf can translate with minimum help... */
    1092 #  if 0
    1093         cch = strlen(pszFilename);
    1094         if (cch < sizeof(pMyMod->name))
    1095             memcpy(pMyMod->name, pszFilename, cch + 1);
    1096         else
    1097         {
    1098             const char *pszTmp = pszFilename;
    1099             for (;;)
    1100             {
    1101                 /* skip one path component. */
    1102                 while (*pszTmp == '/')
    1103                     pszTmp++, cch--;
    1104                 while (*pszTmp != '/' && *pszTmp != '\0')
    1105                     pszTmp++, cch--;
    1106 
    1107                 /* If we've skipped past the final component, hack something up based on the module name. */
    1108                 if (*pszTmp != '/')
    1109                 {
    1110                     RTStrPrintf(pMyMod->name, sizeof(pMyMod->name), "/opt/VirtualBox/%s", pImage->szName);
    1111                     break;
    1112                 }
    1113                 /* When we've got space for two dots and the remaining path, we're done. */
    1114                 if (cch + 2 < sizeof(pMyMod->name))
    1115                 {
    1116                     pMyMod->name[0] = '.';
    1117                     pMyMod->name[1] = '.';
    1118                     memcpy(&pMyMod->name[2], pszTmp, cch + 1);
    1119                     break;
    1120                 }
    1121             }
    1122         }
    1123 #  else
    11241060        /* Perf only matches up files with a .ko extension (maybe .ko.gz),
    11251061           so in order for this crap to work smoothly, we append .ko to the
     
    11301066                done  */
    11311067        RTStrPrintf(pMyMod->name, sizeof(pMyMod->name), "%s", pImage->szName);
    1132 #  endif
    11331068
    11341069        /* sysfs bits. */
     
    13151250            mutex_unlock(&module_mutex);
    13161251
    1317 #if 0 /* Horrible, non-working hack.  Debug when __mod_tree_remove can't be found on a box we care about.  */
    1318 # if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) && defined(CONFIG_MODULES_TREE_LOOKUP)
    1319 #  if defined(CONFIG_DYNAMIC_FTRACE)
    1320             /*
    1321              * Starting with 4.2 there's the module tree lookup which thwarts
    1322              * the above module hack.  So, we must install an additional hack
    1323              * to get the job done.  This relies on dynmaic ftrace trampolines
    1324              * and is just as ugly as the above.  Only for debugging!!
    1325              */
    1326             uint32_t i = 0;
    1327             while (i < RT_ELEMENTS(g_aFTraceOps)
    1328                    && ASMAtomicXchgBool(&g_aFTraceOps[i].fUsed, true) == true)
    1329                 i++;
    1330             if (i < RT_ELEMENTS(g_aFTraceOps))
    1331             {
    1332                 struct supdrv_ftrace_ops *pOps = &g_aFTraceOps[i];
    1333                 pOps->Core.func              = supdrvLnxFTraceStub;
    1334                 pOps->Core.flags             = /*FTRACE_OPS_FL_RECURSION_SAFE | FTRACE_OPS_FL_STUB |*/ FTRACE_OPS_FL_DYNAMIC;
    1335                 pOps->Core.trampoline        = (uintptr_t)pImage->pvImage;
    1336                 pOps->Core.trampoline_size   = (uintptr_t)pImage->cbImageBits;
    1337 
    1338                 rc = register_ftrace_function(&pOps->Core);
    1339                 if (rc == 0)
    1340                     pImage->pLnxFTraceHack = pOps;
    1341                 else
    1342                     printk(KERN_ERR "vboxdrv: register_ftrace_function failed: %d\n", rc);
    1343             }
    1344 #  else
    1345 #   error "Sorry, without CONFIG_DYNAMIC_FTRACE currently not possible to get proper stack traces"
    1346 #  endif
    1347 # endif
    1348 #endif
    13491252            /*
    13501253             * Test it.
     
    13711274#else
    13721275    pImage->pLnxModHack    = NULL;
    1373     pImage->pLnxFTraceHack = NULL;
    13741276#endif
    13751277    NOREF(pDevExt); NOREF(pImage);
     
    14021304        IPRT_LINUX_RESTORE_EFL_AC();
    14031305    }
    1404 
    1405 #if 0 /* Butt-ugly and ain't working yet. */
    1406 # if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) && defined(CONFIG_MODULES_TREE_LOOKUP)
    1407 #  if defined(CONFIG_DYNAMIC_FTRACE)
    1408     {
    1409         /*
    1410          * Undo the ftrace hack.
    1411          */
    1412         struct supdrv_ftrace_ops *pOps = pImage->pLnxFTraceHack;
    1413         pImage->pLnxFTraceHack = NULL;
    1414         if (pOps)
    1415         {
    1416             IPRT_LINUX_SAVE_EFL_AC();
    1417             int rc = unregister_ftrace_function(&pOps->Core);
    1418             if (rc == 0)
    1419                 ASMAtomicWriteBool(&pOps->fUsed, false);
    1420             else
    1421                 printk(KERN_ERR "vboxdrv: unregister_ftrace_function failed: %d\n", rc);
    1422             IPRT_LINUX_RESTORE_EFL_AC();
    1423         }
    1424     }
    1425 #  else
    1426 #   error "Sorry, without CONFIG_DYNAMIC_FTRACE currently not possible to get proper stack traces"
    1427 #  endif
    1428 # endif
    1429 #endif
    14301306
    14311307#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