VirtualBox

Changeset 12817 in vbox


Ignore:
Timestamp:
Sep 30, 2008 1:31:41 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
37172
Message:

Debugger: making some progress.

Location:
trunk/src/VBox/Debugger
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/VBoxDbgGui.cpp

    r12462 r12817  
    149149    if (!m_pDbgStats)
    150150    {
    151 #ifdef VBOXDBG_USE_QT4
    152         m_pDbgStats = new VBoxDbgStats(m_pVM, "*x*"); /// @todo the QTreeWidget/QTreeView sucks big time. it freezes the app for 30+ seconds. Need to write a new item model I fear. 'ing crap!!!
    153 #else
    154151        m_pDbgStats = new VBoxDbgStats(m_pVM);
    155 #endif
    156152        connect(m_pDbgStats, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
    157153        repositionStatistics();
  • trunk/src/VBox/Debugger/VBoxDbgStatsQt4.cpp

    r12706 r12817  
    198198     * Nodes not matched by the pattern will become invisible.
    199199     *
     200     * @returns true if we reset the model and it's necessary to set the root index.
    200201     * @param   a_rPatStr       The selection pattern.
    201202     */
    202     virtual void update(const QString &a_rPatStr) = 0;
     203    virtual bool updateStats(const QString &a_rPatStr) = 0;
    203204
    204205    /**
     
    224225
    225226    /** Creates and insert a node under the given parent. */
    226     static PDBGGUISTATSNODE createAndInsertNode(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition = UINT32_MAX);
     227    static PDBGGUISTATSNODE createAndInsertNode(PDBGGUISTATSNODE pParent, const char *pszName, size_t cchName, uint32_t iPosition/* = UINT32_MAX*/);
    227228
    228229    /**
     
    255256
    256257    /**
    257      * Check if the second node is an ancestor to the first one.
     258     * Check if the first node is an ancestor to the second one.
    258259     *
    259260     * @returns true/false.
    260      * @param   pNode       The first node.
    261      * @param   pAncestor   The second node, the alleged ancestor. */
    262     static bool isNodeAncestorOf(PCDBGGUISTATSNODE pNode, PCDBGGUISTATSNODE pAncestor);
     261     * @param   pAncestor   The first node, the alleged ancestor.
     262     * @param   pDescendant The second node, the alleged descendant.
     263     */
     264    static bool isNodeAncestorOf(PCDBGGUISTATSNODE pAncestor, PCDBGGUISTATSNODE pDescendant);
    263265
    264266    /**
     
    266268     *
    267269     * @returns Pointer to the next node, NULL if we've reached the end or
    268      *          was handed a NULL node..
     270     *          was handed a NULL node.
    269271     * @param   pNode       The current node.
    270272     */
    271273    static PDBGGUISTATSNODE nextNode(PDBGGUISTATSNODE pNode);
     274
     275    /**
     276     * Advance to the next node in the tree that contains data.
     277     *
     278     * @returns Pointer to the next data node, NULL if we've reached the end or
     279     *          was handed a NULL node.
     280     * @param   pNode       The current node.
     281     */
     282    static PDBGGUISTATSNODE nextDataNode(PDBGGUISTATSNODE pNode);
    272283
    273284    /**
     
    275286     *
    276287     * @returns Pointer to the previous node, NULL if we've reached the end or
    277      *          was handed a NULL node..
     288     *          was handed a NULL node.
    278289     * @param   pNode       The current node.
    279290     */
    280291    static PDBGGUISTATSNODE prevNode(PDBGGUISTATSNODE pNode);
     292
     293    /**
     294     * Advance to the previous node in the tree that contains data.
     295     *
     296     * @returns Pointer to the previous data node, NULL if we've reached the end or
     297     *          was handed a NULL node.
     298     * @param   pNode       The current node.
     299     */
     300    static PDBGGUISTATSNODE prevDataNode(PDBGGUISTATSNODE pNode);
    281301
    282302    /**
     
    429449     * Nodes not matched by the pattern will become invisible.
    430450     *
     451     * @returns true if we reset the model and it's necessary to set the root index.
    431452     * @param   a_rPatStr       The selection pattern.
    432453     */
    433     virtual void update(const QString &a_rPatStr);
     454    virtual bool updateStats(const QString &a_rPatStr);
    434455
    435456protected:
    436457    /**
    437      * Enumeration callback used by update.
     458     * Enumeration callback used by updateStats.
    438459     */
    439460    static DECLCALLBACK(int) updateCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
     
    666687        a_pNode->papChildren[i] = NULL;
    667688    }
    668     a_pNode->cChildren = 0;
    669689
    670690    /* free the resources we're using */
     
    693713        a_pNode->pDescStr = NULL;
    694714    }
     715
     716#ifdef VBOX_STRICT
     717    /* poison it. */
     718    a_pNode->pParent++;
     719    a_pNode->Data.pStr++;
     720    a_pNode->pDescStr++;
     721    a_pNode->papChildren++;
     722    a_pNode->cChildren = 8442;
     723#endif
    695724
    696725    /* Finally ourselves */
     
    784813    if (pParent)
    785814    {
    786         uint32_t const iPosition = pNode->iSelf;
     815        uint32_t iPosition = pNode->iSelf;
    787816        Assert(pParent->papChildren[iPosition] == pNode);
    788         uint32_t iShift = --pParent->cChildren;
    789         while (iShift-- > iPosition)
    790         {
    791             PDBGGUISTATSNODE pChild = pParent->papChildren[iShift + 1];
    792             pParent->papChildren[iShift] = pChild;
    793             pChild->iSelf = iShift;
    794         }
     817        uint32_t const cChildren = --pParent->cChildren;
     818        for (; iPosition < cChildren; iPosition++)
     819        {
     820            PDBGGUISTATSNODE pChild = pParent->papChildren[iPosition + 1];
     821            pParent->papChildren[iPosition] = pChild;
     822            pChild->iSelf = iPosition;
     823        }
     824#ifdef VBOX_STRICT /* poison */
     825        pParent->papChildren[iPosition] = (PDBGGUISTATSNODE)0x42;
     826#endif
    795827    }
    796828
     
    903935     * Reset and init the node if the type changed.
    904936     */
    905     if (    enmType != pNode->enmType
    906         &&  pNode->enmType != STAMTYPE_INVALID)
    907     {
    908         resetNode(pNode);
     937    if (enmType != pNode->enmType)
     938    {
     939        if (pNode->enmType != STAMTYPE_INVALID)
     940            resetNode(pNode);
    909941        initNode(pNode, enmType, pvSample, enmUnit, pszDesc);
    910942        pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
     
    10741106    else
    10751107    {
    1076         cch -= pNode->cchName - 1;
     1108        cch -= pNode->cchName + 1;
    10771109        AssertReturn(cch > 0, -1);
    10781110        off = getNodePath(pNode->pParent, psz, cch);
     
    10891121
    10901122/*static*/ bool
    1091 VBoxDbgStatsModel::isNodeAncestorOf(PCDBGGUISTATSNODE pNode, PCDBGGUISTATSNODE pAncestor)
    1092 {
    1093     while (pNode)
    1094     {
    1095         pNode = pNode->pParent;
    1096         if (pNode == pAncestor)
     1123VBoxDbgStatsModel::isNodeAncestorOf(PCDBGGUISTATSNODE pAncestor, PCDBGGUISTATSNODE pDescendant)
     1124{
     1125    while (pDescendant)
     1126    {
     1127        pDescendant = pDescendant->pParent;
     1128        if (pDescendant == pAncestor)
    10971129            return true;
    10981130    }
     
    11331165
    11341166/*static*/ PDBGGUISTATSNODE
     1167VBoxDbgStatsModel::nextDataNode(PDBGGUISTATSNODE pNode)
     1168{
     1169    do
     1170        pNode = nextNode(pNode);
     1171    while (     pNode
     1172           &&   pNode->enmType == STAMTYPE_INVALID);
     1173    return pNode;
     1174}
     1175
     1176
     1177/*static*/ PDBGGUISTATSNODE
    11351178VBoxDbgStatsModel::prevNode(PDBGGUISTATSNODE pNode)
    11361179{
     
    11411184        return NULL;
    11421185
    1143     /* previous sibling's grand-most child (better expression anyone?). */
     1186    /* previous sibling's latest decendant (better expression anyone?). */
    11441187    if (pNode->iSelf > 0)
    11451188    {
     
    11501193    }
    11511194
    1152     /* ascend to the parent (if any). */
    1153     return pNode->pParent;
     1195    /* ascend to the parent. */
     1196    return pParent;
     1197}
     1198
     1199
     1200/*static*/ PDBGGUISTATSNODE
     1201VBoxDbgStatsModel::prevDataNode(PDBGGUISTATSNODE pNode)
     1202{
     1203    do
     1204        pNode = prevNode(pNode);
     1205    while (     pNode
     1206           &&   pNode->enmType == STAMTYPE_INVALID);
     1207    return pNode;
    11541208}
    11551209
     
    12811335    if (!pParent)
    12821336    {
    1283         printf("parent: root\n");
     1337//        printf("parent: root\n");
    12841338        return QModelIndex(); /* we're root */
    12851339    }
     
    16601714            pThis->m_fUpdateInsertRemove = true;
    16611715            /** @todo optimize insert since that is a normal occurence. */
     1716            Assert(pszName[0] == '/');
     1717            Assert(pThis->m_szUpdateParent[pThis->m_cchUpdateParent - 1] == '/');
    16621718
    16631719            /* Start with the current parent node and look for a common ancestor
    1664                hoping that this is faster than going from the root. */
    1665             PDBGGUISTATSNODE const pPrev = prevNode(pNode);
     1720               hoping that this is faster than going from the root (saves lookup). */
     1721            PDBGGUISTATSNODE const pPrev = prevDataNode(pNode);
     1722            pNode = pNode->pParent;
    16661723            while (pNode != pThis->m_pRoot)
    16671724            {
     
    16731730                pNode = pNode->pParent;
    16741731            }
     1732            Assert(pThis->m_szUpdateParent[pThis->m_cchUpdateParent - 1] == '/');
    16751733
    16761734            /* Decent until we've found/created the node pszName indicates,
     
    16791737            {
    16801738                /* Find the end of this component. */
    1681                 const char *pszStart = &pszName[pThis->m_cchUpdateParent];
    1682                 const char *pszEnd = strchr(pszStart, '/');
     1739                const char *const pszSubName = &pszName[pThis->m_cchUpdateParent];
     1740                const char *pszEnd = strchr(pszSubName, '/');
    16831741                if (!pszEnd)
    1684                     pszEnd = strchr(pszStart, '/');
    1685                 char *pszSubName = &pThis->m_szUpdateParent[pThis->m_cchUpdateParent];
    1686                 size_t cchSubName = pszEnd - pszStart;
     1742                    pszEnd = strchr(pszSubName, '\0');
     1743                size_t cchSubName = pszEnd - pszSubName;
    16871744
    16881745                /* Add the name to the path. */
    1689                 memcpy(pszSubName, pszStart, cchSubName);
     1746                memcpy(&pThis->m_szUpdateParent[pThis->m_cchUpdateParent], pszSubName, cchSubName);
    16901747                pThis->m_cchUpdateParent += cchSubName;
     1748                pThis->m_szUpdateParent[pThis->m_cchUpdateParent++] = '/';
    16911749                pThis->m_szUpdateParent[pThis->m_cchUpdateParent] = '\0';
    1692 
    1693                 if (pNode->cChildren)
     1750                Assert(pThis->m_cchUpdateParent < sizeof(pThis->m_szUpdateParent));
     1751
     1752                if (!pNode->cChildren)
    16941753                {
    16951754                    /* first child */
    1696                     pNode = createAndInsertNode(pNode, pszSubName, UINT32_MAX);
     1755                    pNode = createAndInsertNode(pNode, pszSubName, cchSubName, UINT32_MAX);
    16971756                    AssertReturn(pNode, VERR_NO_MEMORY);
    16981757                }
     
    17051764                    {
    17061765                        int32_t i = iStart + (iLast + 1 - iStart) / 2;
    1707                         int iDiff = strcmp(pszSubName, pNode->papChildren[i]->pszName);
     1766                        int iDiff = memcmp(pszSubName, pNode->papChildren[i]->pszName, cchSubName);
     1767                        if (!iDiff)
     1768                            iDiff = '\0' - pNode->papChildren[i]->pszName[cchSubName];
    17081769                        if (iDiff > 0)
    17091770                        {
     
    17111772                            if (iStart > iLast)
    17121773                            {
    1713                                 pNode = createAndInsertNode(pNode, pszSubName, iStart);
     1774                                pNode = createAndInsertNode(pNode, pszSubName, cchSubName, iStart);
    17141775                                AssertReturn(pNode, VERR_NO_MEMORY);
    17151776                                break;
     
    17211782                            if (iLast < iStart)
    17221783                            {
    1723                                 pNode = createAndInsertNode(pNode, pszSubName, i);
     1784                                pNode = createAndInsertNode(pNode, pszSubName, cchSubName, i);
    17241785                                AssertReturn(pNode, VERR_NO_MEMORY);
    17251786                                break;
     
    17331794                    }
    17341795                }
    1735 
    1736                 pThis->m_szUpdateParent[pThis->m_cchUpdateParent++] = '/';
    1737                 pThis->m_szUpdateParent[pThis->m_cchUpdateParent] = '\0';
    1738                 Assert(pThis->m_cchUpdateParent < sizeof(pThis->m_szUpdateParent));
    17391796            }
    1740             Assert(pszName[pThis->m_cchUpdateParent - 1] == '\0');
     1797            Assert(   !memcmp(pszName, pThis->m_szUpdateParent, pThis->m_cchUpdateParent - 2)
     1798                   && pszName[pThis->m_cchUpdateParent - 1] == '\0');
    17411799
    17421800            /* Remove all the nodes between pNode and pPrev but keep all
    17431801               of pNode's ancestors (or it'll get orphaned). */
    17441802            PDBGGUISTATSNODE pCur = prevNode(pNode);
    1745             Assert(pCur != pPrev);
    17461803            while (pCur != pPrev)
    17471804            {
    1748                 PDBGGUISTATSNODE pAdv = prevNode(pCur);
     1805                PDBGGUISTATSNODE pAdv = prevNode(pCur); Assert(pAdv || !pPrev);
    17491806                if (!isNodeAncestorOf(pCur, pNode))
     1807                {
    17501808                    removeAndDestroyNode(pCur);
     1809                }
    17511810                pCur = pAdv;
    17521811            }
    17531812
    17541813            /* Removed the data from all ancestors of pNode that it doesn't share them pPrev. */
    1755             pCur = pNode->pParent;
    1756             while (!isNodeAncestorOf(pCur, pPrev))
     1814            if (pPrev)
    17571815            {
    1758                 resetNode(pNode);
    1759                 pCur = pCur->pParent;
     1816                pCur = pNode->pParent;
     1817                while (!isNodeAncestorOf(pCur, pPrev))
     1818                {
     1819                    resetNode(pNode);
     1820                    pCur = pCur->pParent;
     1821                }
    17601822            }
    17611823
    17621824            /* Finally, adjust the globals (szUpdateParent is one level too deep). */
    1763             Assert(pThis->m_cchUpdateParent > pNode->cchName - 1);
    1764             pThis->m_cchUpdateParent -= pNode->cchName - 1;
     1825            Assert(pThis->m_cchUpdateParent > pNode->cchName + 1);
     1826            pThis->m_cchUpdateParent -= pNode->cchName + 1;
    17651827            pThis->m_szUpdateParent[pThis->m_cchUpdateParent] = '\0';
    17661828            pThis->m_pUpdateParent = pNode->pParent;
     
    18251887        pThis->m_cchUpdateParent += pNode->cchName;
    18261888        pThis->m_szUpdateParent[pThis->m_cchUpdateParent++] = '/';
     1889        pThis->m_szUpdateParent[pThis->m_cchUpdateParent] = '\0';
    18271890        pThis->m_pUpdateParent = pNode;
    18281891    }
     
    18331896        Assert(pThis->m_pUpdateParent == pNode->pParent);
    18341897    }
    1835     else
     1898    else if (pThis->m_iUpdateChild != UINT32_MAX)
    18361899    {
    18371900        /* move up and down- / on-wards */
     
    18501913                break;
    18511914            }
    1852             Assert(pThis->m_cchUpdateParent > pNode->cchName);
    1853             pThis->m_cchUpdateParent -= pNode->cchName - 1;
    1854             pThis->m_szUpdateParent[pThis->m_cchUpdateParent] = '\0';
     1915            Assert(pThis->m_cchUpdateParent > pNode->cchName + 1);
     1916            pThis->m_cchUpdateParent -= pNode->cchName + 1;
    18551917
    18561918            /* try advance */
     
    18731935                }
    18741936                Assert(pNode->enmType != STAMTYPE_INVALID);
     1937                pThis->m_szUpdateParent[pThis->m_cchUpdateParent] = '\0';
    18751938                pThis->m_iUpdateChild = pNode->iSelf;
    18761939                pThis->m_pUpdateParent = pNode->pParent;
     
    18781941            }
    18791942        }
    1880 
    1881     }
     1943    }
     1944    /* else: we're at the end */
     1945
    18821946    return VINF_SUCCESS;
    18831947}
    18841948
    18851949
    1886 void
    1887 VBoxDbgStatsModelVM::update(const QString &a_rPatStr)
    1888 {
     1950bool
     1951VBoxDbgStatsModelVM::updateStats(const QString &a_rPatStr)
     1952{
     1953    Assert(m_pRoot);
     1954    Assert(m_pRoot->enmType == STAMTYPE_INVALID);
     1955
    18891956    /*
    18901957     * Find the first child with data and set it up as the 'next'
    18911958     * node to be updated.
    18921959     */
    1893     PDBGGUISTATSNODE pFirst = m_pRoot;
    1894     while (pFirst && pFirst->enmType == STAMTYPE_INVALID)
    1895         pFirst = nextNode(pFirst);
     1960    PDBGGUISTATSNODE pFirst = nextDataNode(m_pRoot);
    18961961    if (pFirst)
    18971962    {
    18981963        m_iUpdateChild = pFirst->iSelf;
    1899         m_pUpdateParent = pFirst;
     1964        m_pUpdateParent = pFirst->pParent; Assert(m_pUpdateParent);
    19001965        m_cchUpdateParent = getNodePath(m_pUpdateParent, m_szUpdateParent, sizeof(m_szUpdateParent) - 1);
    1901         AssertReturnVoid(m_cchUpdateParent >= 1);
     1966        AssertReturn(m_cchUpdateParent >= 1, false);
    19021967        m_szUpdateParent[m_cchUpdateParent++] = '/';
    19031968        m_szUpdateParent[m_cchUpdateParent] = '\0';
     
    19201985
    19211986    /** @todo the way we update this stuff is independent of the source (XML, file, STAM), our only
    1922      * ASSUMPTION is that the input is strictly ordered by (full) name. So, all this stuff should
    1923      * really move up into the parent class. */
    1924     stamEnum(a_rPatStr, updateCallback, this);
     1987     * ASSUMPTION is that the input is strictly ordered by (fully slashed) name. So, all this stuff
     1988     * should really move up into the parent class. */
     1989    int rc = stamEnum(a_rPatStr, updateCallback, this);
     1990
     1991    /* Remove any nodes following the last in the update. */
     1992    if (    RT_SUCCESS(rc)
     1993        &&  m_iUpdateChild != UINT32_MAX)
     1994    {
     1995        PDBGGUISTATSNODE const pLast = prevDataNode(m_pUpdateParent->papChildren[m_iUpdateChild]);
     1996        for (;;)
     1997        {
     1998            PDBGGUISTATSNODE pNode = nextNode(pLast);
     1999            if (!pNode)
     2000                break;
     2001char szFoo[1024];
     2002getNodePath(pNode, szFoo, 1024); fprintf(stderr, "removing pNode=%p: %s\n", pNode, szFoo);
     2003if (pLast) getNodePath(pLast, szFoo, 1024); else szFoo[0] = '\0';
     2004                                 fprintf(stderr, "         pLast=%p: %s\n", pLast, szFoo);
     2005            removeAndDestroyNode(pNode);
     2006        }
     2007        m_fUpdateInsertRemove = true;
     2008    }
    19252009
    19262010    if (m_fUpdateInsertRemove)
     
    19842068        }
    19852069    }
     2070
     2071    return m_fUpdateInsertRemove;
    19862072}
    19872073
     
    24792565
    24802566
    2481 void VBoxDbgStatsView::update(const QString &rPatStr)
    2482 {
    2483     m_pModel->update(rPatStr);
     2567void VBoxDbgStatsView::updateStats(const QString &rPatStr)
     2568{
     2569    if (m_pModel->updateStats(rPatStr))
     2570        setRootIndex(m_pModel->getRootIndex()); /// @todo this is a hack?
    24842571
    24852572#if 0 /* later */
     
    25022589}
    25032590
    2504 void VBoxDbgStatsView::reset(const QString &rPatStr)
     2591void VBoxDbgStatsView::resetStats(const QString &rPatStr)
    25052592{
    25062593    stamReset(rPatStr);
     
    29793066void VBoxDbgStats::refresh()
    29803067{
    2981     m_pView->update(m_PatStr);
     3068    m_pView->updateStats(m_PatStr);
    29823069}
    29833070
  • trunk/src/VBox/Debugger/VBoxDbgStatsQt4.h

    r12478 r12817  
    6868     * @param   rPatStr     Selection pattern. NULL means everything, see STAM for further details.
    6969     */
    70     void update(const QString &rPatStr);
     70    void updateStats(const QString &rPatStr);
    7171
    7272    /**
     
    7676     * @param   rPatStr     Selection pattern. NULL means everything, see STAM for further details.
    7777     */
    78     void reset(const QString &rPatStr);
     78    void resetStats(const QString &rPatStr);
    7979
    8080private:
Note: See TracChangeset for help on using the changeset viewer.

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