Exemplo n.º 1
0
XPathExpression*
XPathEvaluator::CreateExpression(const nsAString& aExpression,
                                 nsINode* aResolver, ErrorResult& aRv)
{
    nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
    XPathEvaluatorParseContext pContext(aResolver,
                                        !(doc && doc->IsHTMLDocument()));
    return CreateExpression(aExpression, &pContext, doc, aRv);
}
Exemplo n.º 2
0
int StackTrace::GetCallStack(Address* callStack, int maxDepth, int entriesToSkip)
{
    PCONTEXT pContext(0);
    HMODULE hKernel32Dll = GetModuleHandle("kernel32.dll");
    void (WINAPI *pRtlCaptureContext)(PCONTEXT);
    *(void**)&pRtlCaptureContext = GetProcAddress(hKernel32Dll, "RtlCaptureContext");
    CONTEXT context;
    if (pRtlCaptureContext)
    {
        memset(&context, 0, sizeof(context));
        context.ContextFlags = CONTEXT_FULL;
        pRtlCaptureContext(&context);
        pContext = &context;
    }
    // +1 -> skip over "us"
    return GetCallStack(pContext, callStack,  maxDepth, entriesToSkip + 1);
}
Exemplo n.º 3
0
nsresult
nsXPathEvaluator::CreateExpression(const nsAString & aExpression,
                                   nsIDOMXPathNSResolver *aResolver,
                                   nsTArray<int32_t> *aNamespaceIDs,
                                   nsTArray<nsCString> *aContractIDs,
                                   nsCOMArray<nsISupports> *aState,
                                   nsIDOMXPathExpression **aResult)
{
    nsresult rv;
    if (!mRecycler) {
        nsRefPtr<txResultRecycler> recycler = new txResultRecycler;
        NS_ENSURE_TRUE(recycler, NS_ERROR_OUT_OF_MEMORY);
        
        rv = recycler->init();
        NS_ENSURE_SUCCESS(rv, rv);
        
        mRecycler = recycler;
    }

    nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
    nsXPathEvaluatorParseContext pContext(aResolver, aNamespaceIDs,
                                          aContractIDs, aState,
                                          !(doc && doc->IsHTML()));

    nsAutoPtr<Expr> expression;
    rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext,
                                  getter_Transfers(expression));
    if (NS_FAILED(rv)) {
        if (rv == NS_ERROR_DOM_NAMESPACE_ERR) {
            return NS_ERROR_DOM_NAMESPACE_ERR;
        }

        return NS_ERROR_DOM_INVALID_EXPRESSION_ERR;
    }

    nsCOMPtr<nsIDOMDocument> document = do_QueryReferent(mDocument);

    *aResult = new nsXPathExpression(expression, mRecycler, document);
    if (!*aResult) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    NS_ADDREF(*aResult);
    return NS_OK;
}
Exemplo n.º 4
0
NS_IMETHODIMP
nsXPathEvaluator::CreateExpression(const nsAString & aExpression,
                                   nsIDOMXPathNSResolver *aResolver,
                                   nsIDOMXPathExpression **aResult)
{
    nsresult rv = NS_OK;
    if (!mRecycler) {
        nsRefPtr<txResultRecycler> recycler = new txResultRecycler;
        NS_ENSURE_TRUE(recycler, NS_ERROR_OUT_OF_MEMORY);
        
        rv = recycler->init();
        NS_ENSURE_SUCCESS(rv, rv);
        
        mRecycler = recycler;
    }

    nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
    ParseContextImpl pContext(aResolver, !doc || doc->IsCaseSensitive());
    nsAutoPtr<Expr> expression;
    rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext,
                                  getter_Transfers(expression));
    if (NS_FAILED(rv)) {
        if (rv == NS_ERROR_DOM_NAMESPACE_ERR) {
            return NS_ERROR_DOM_NAMESPACE_ERR;
        }

        return NS_ERROR_DOM_INVALID_EXPRESSION_ERR;
    }

    *aResult = new nsXPathExpression(expression, mRecycler);
    if (!*aResult) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    NS_ADDREF(*aResult);
    return NS_OK;
}
EXPORT_C void CMemSpyEngineHelperHeap::OutputCellListingUserL( const CMemSpyThread& aThread )
    {
    // Suspend the process
    iEngine.ProcessSuspendLC( aThread.Process().Id() );

    // Free cells
    RArray<TMemSpyDriverFreeCell> freeCells;
    CleanupClosePushL( freeCells );

    // Info section
    TMemSpyHeapInfo heapInfo;
    const TInt error = iEngine.Driver().GetHeapInfoUser( heapInfo, aThread.Id(), freeCells );
    if ( error == KErrNone )
        {
        UpdateSharedHeapInfoL( aThread.Process().Id(), aThread.Id(), heapInfo );
        }
    if  ( error == KErrNone && heapInfo.Type() != TMemSpyHeapInfo::ETypeUnknown )
        {
        // Get thread name for context
        const TFullName pName( aThread.FullName() );

        // Begin a new data stream
        _LIT( KMemSpyFolder, "Heap\\Cell List" );
        _LIT( KMemSpyContext, "Cell List - %S" );
        HBufC* context = HBufC::NewLC( KMaxFileName );
        TPtr pContext( context->Des() );
        pContext.Format( KMemSpyContext, &pName );
        iEngine.Sink().DataStreamBeginL( pContext, KMemSpyFolder );
        CleanupStack::PopAndDestroy( context );

        // Set prefix for overall listing
        iEngine.Sink().OutputPrefixSetFormattedLC( KMemSpyPrefixCellList, &pName );

        // Start new section
        _LIT(KHeader, "CELL LISTING");
        iEngine.Sink().OutputSectionHeadingL( KHeader, '=' );

        // Prepare temp buffers
        TBuf<KMaxFullName + 100> printFormat;
        HBufC* tempBuffer = HBufC::NewLC( 2048 );
        TPtr pTempBuffer( tempBuffer->Des() );

        // Print initial info
        OutputHeapInfoL( heapInfo, pName, &freeCells );

        // Code segments (needed for map file reading...)
        _LIT(KCellListCodeSegInfoFormat, "CodeSegs - ");
        iEngine.HelperCodeSegment().OutputCodeSegmentsL( aThread.Process().Id(), printFormat, KCellListCodeSegInfoFormat, '-', ETrue );
    
        // Now walk the heap!
        TInt r = iEngine.Driver().WalkHeapInit( aThread.Id() );
        if  ( r == KErrNone )
            {
             _LIT(KHeader2, "Cells");
            iEngine.Sink().OutputSectionHeadingL( KHeader2, '-' );

            TMemSpyDriverCellType cellType;
            TAny* cellAddress;
            TInt cellLength;
            TInt cellNestingLevel;
            TInt cellAllocationNumber;
            TInt cellHeaderSize;
            TAny* cellPayloadAddress;
            TBuf8<4> cellData;
            //
            r = iEngine.Driver().WalkHeapNextCell( aThread.Id(), cellType, cellAddress, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
            while( r == KErrNone )
                {
                TUint fourByteCellData = 0;
                TPtrC pType(KNullDesC);
                //
				if (cellType & EMemSpyDriverAllocatedCellMask)
					{
                    r = iEngine.Driver().WalkHeapReadCellData( cellAddress, cellData, 4 );
                    if  ( r == KErrNone )
                        {
                        fourByteCellData = DescriptorAsDWORD( cellData );
                        }
                    pType.Set(KCellTypeGoodAllocatedCell);
                    }
				else if (cellType & EMemSpyDriverFreeCellMask)
					{
                    pType.Set(KCellTypeGoodFreeCell);
					}
				else if (cellType & EMemSpyDriverBadCellMask)
					{
					switch (cellType)
						{
					case EMemSpyDriverHeapBadAllocatedCellSize:
						pType.Set(KCellTypeBadAllocatedCellSize);
						break;
					case EMemSpyDriverHeapBadAllocatedCellAddress:
						pType.Set(KCellTypeBadAllocatedCellAddress);
						break;
					case EMemSpyDriverHeapBadFreeCellAddress:
						pType.Set(KCellTypeBadFreeCellAddress);
						break;
					case EMemSpyDriverHeapBadFreeCellSize:
						pType.Set(KCellTypeBadFreeCellSize);
						break;
					default:
						pType.Set(KCellTypeBad);
						break;
						}
					}
				else
					{
                    pType.Set(KCellTypeUnknown);
                    }

                if  ( r == KErrNone )
                    {
                    pTempBuffer.Format( KCellListLineFormat, &pType, cellAddress, cellLength, cellAllocationNumber, cellNestingLevel, fourByteCellData, cellPayloadAddress, cellHeaderSize );
                    iEngine.Sink().OutputLineL( pTempBuffer );
                    //
                    r = iEngine.Driver().WalkHeapNextCell( aThread.Id(), cellType, cellAddress, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
                    }
                }
            //
            iEngine.Driver().WalkHeapClose();
            }
        CleanupStack::PopAndDestroy( tempBuffer );
        CleanupStack::PopAndDestroy(); // clear prefix

        iEngine.Sink().DataStreamEndL();
        }

    CleanupStack::PopAndDestroy( &freeCells );
    CleanupStack::PopAndDestroy(); // resume process
    }
void CMemSpyEngineHelperHeap::OutputHeapDataKernelL(const TMemSpyHeapInfo& aHeapInfo, 
                                                    TBool aCreateDataStream, 
                                                    const RArray<TMemSpyDriverCell>* aCells)
    {
    TFullName threadName;
    MemSpyEngineUtils::GetKernelHeapThreadName( threadName, EFalse );

    // Begin a new data stream
    if  ( aCreateDataStream )
        {
        _LIT( KMemSpyFolder, "Heap\\Data" );
        _LIT( KMemSpyContext, "Heap Data - %S" );
        HBufC* context = HBufC::NewLC( KMaxFileName );
        TPtr pContext( context->Des() );
        pContext.Format( KMemSpyContext, &threadName );
        iEngine.Sink().DataStreamBeginL( pContext, KMemSpyFolder );
        CleanupStack::PopAndDestroy( context );
        }

    TBuf<KMaxFullName + 100> printFormat;

    // Start marker
    iEngine.Sink().OutputLineFormattedL( KMemSpyMarkerHeapData, &KNullDesC, aHeapInfo.Tid() );

    // Set overall prefix
    iEngine.Sink().OutputPrefixSetFormattedLC( KMemSpyPrefixHeapData, &threadName );

    // Info section
    OutputHeapInfoL( aHeapInfo, threadName, aCells );

    // Code segments (needed for map file reading...)
    _LIT(KCellListCodeSegInfoFormat, "CodeSegs - ");
    iEngine.HelperCodeSegment().OutputCodeSegmentsL( aHeapInfo.Pid(), printFormat, KCellListCodeSegInfoFormat, '-', ETrue );

    // Dump section
    _LIT(KHeaderDump, "Heap Data");
    iEngine.Sink().OutputSectionHeadingL( KHeaderDump, '-' );

    HBufC8* data = HBufC8::NewLC( 4096 * 12 );
    TPtr8 pData(data->Des());
    TUint remaining = 0;
    TUint readAddress = 0;

    TInt r = iEngine.Driver().GetHeapDataKernel(aHeapInfo.Tid(), pData, readAddress, remaining);
    TUint prevEndAddress = readAddress + pData.Length();
    if (r == KErrNone)
        {
        while (r == KErrNone)
            {
            if (readAddress > prevEndAddress)
                {
                // We've hit a discontinuity, ie one or more unmapped pages
                _LIT(KBreak, "........");
                iEngine.Sink().OutputLineL(KBreak);
                }
            _LIT(KHeapDumpDataFormat, "%S");
            iEngine.Sink().OutputBinaryDataL(KHeapDumpDataFormat, pData.Ptr(), (const TUint8*) readAddress, pData.Length());
            readAddress += pData.Length();
            if (remaining > 0)
                {
                prevEndAddress = readAddress;
                r = iEngine.Driver().GetHeapDataKernelNext(aHeapInfo.Tid(), pData, readAddress, remaining);
                }
            else
                break;
            }
        }
    else
        {
        _LIT( KHeapFetchError, "Heap error: %d");
        iEngine.Sink().OutputLineFormattedL( KHeapFetchError, r );
        }

    CleanupStack::PopAndDestroy( data );

    CleanupStack::PopAndDestroy(); // clear prefix

    // End marker
    iEngine.Sink().OutputLineFormattedL( KMemSpyMarkerHeapData, &KMemSpySinkTagClose, aHeapInfo.Tid() );

    if  ( aCreateDataStream )
        {
        iEngine.Sink().DataStreamEndL();
        }
    }
void CMemSpyEngineHelperHeap::OutputHeapDataUserL(const TProcessId& aPid, 
                                                  const TThreadId& aTid, 
                                                  const TDesC& aThreadName, 
                                                  const TMemSpyHeapInfo& aInfo, 
                                                  TBool aCreateDataStream, 
                                                  const RArray<TMemSpyDriverCell>* aCells )
    {
    TBuf<KMaxFullName + 100> printFormat;

    // Begin a new data stream
    if  ( aCreateDataStream )
        {
        _LIT( KMemSpyFolder, "Heap\\Data" );
        _LIT( KMemSpyContext, "Heap Data - %S" );
        HBufC* context = HBufC::NewLC( KMaxFileName );
        TPtr pContext( context->Des() );
        pContext.Format( KMemSpyContext, &aThreadName );
        iEngine.Sink().DataStreamBeginL( pContext, KMemSpyFolder );
        CleanupStack::PopAndDestroy( context );
        }

    // Get the heap info first of all
    iEngine.ProcessSuspendLC( aPid );

    // Start marker
    iEngine.Sink().OutputLineFormattedL( KMemSpyMarkerHeapData, &KNullDesC, (TUint) aTid );

    // Set overall prefix
    iEngine.Sink().OutputPrefixSetFormattedLC( KMemSpyPrefixHeapData, &aThreadName );

    // Info section
    OutputHeapInfoL( aInfo, aThreadName, aCells );

    // Code segments (needed for map file reading...)
    _LIT(KCellListCodeSegInfoFormat, "CodeSegs - ");
    iEngine.HelperCodeSegment().OutputCodeSegmentsL( aPid, printFormat, KCellListCodeSegInfoFormat, '-', ETrue );

    // Dump section
    _LIT(KHeaderDump, "Heap Data");
    iEngine.Sink().OutputSectionHeadingL( KHeaderDump, '-' );

    HBufC8* data = HBufC8::NewLC( 4096 * 12 );
    TPtr8 pData(data->Des());
    TUint remaining = 0;
    TUint readAddress = 0;

    // When we obtained the heap info, we also obtained a checksum of all the free cells
    // within the specified heap. We validate that this hasn't changed at the time we
    // request the heap data for paranoia purposes (There have been "Issues" with MemSpy
    // not actually suspending a process between fetching heap info & heap data, causing
    // a mismatch in free cell information).
    const TUint32 checksum = aInfo.AsRHeap().Statistics().StatsFree().Checksum();
    TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::OutputHeapDataUserL() - checksum: 0x%08x", checksum ) );

    TInt r = iEngine.Driver().GetHeapData( aTid, checksum, pData, readAddress, remaining );
	TUint prevEndAddress = readAddress + pData.Length();
    if (r == KErrNone)
        {
        while (r == KErrNone)
            {
			if (readAddress > prevEndAddress)
				{
				// We've hit a discontinuity, ie one or more unmapped pages
				_LIT(KBreak, "........");
				iEngine.Sink().OutputLineL(KBreak);
				}
            _LIT(KHeapDumpDataFormat, "%S");
            iEngine.Sink().OutputBinaryDataL(KHeapDumpDataFormat, pData.Ptr(), (const TUint8*) readAddress, pData.Length());
			readAddress += pData.Length();
            if (remaining > 0)
				{
				prevEndAddress = readAddress;
                r = iEngine.Driver().GetHeapDataNext(aTid, pData, readAddress, remaining);
				}
            else
                break;
            }
        }
    else
        {
        _LIT( KHeapFetchError, "Heap error: %d");
        iEngine.Sink().OutputLineFormattedL( KHeapFetchError, r );
        }

    CleanupStack::PopAndDestroy( data );

    CleanupStack::PopAndDestroy(); // clear prefix
    CleanupStack::PopAndDestroy(); // resume process

    // End marker
    iEngine.Sink().OutputLineFormattedL( KMemSpyMarkerHeapData, &KMemSpySinkTagClose, (TUint) aTid );

    if  ( aCreateDataStream )
        {
        iEngine.Sink().DataStreamEndL();
        }
    }