共用方式為


IDiaLineNumber

存取資訊,此資訊描述從映像文字的位元組區塊對應至來源檔案行號的流程。

語法

IDiaLineNumber : IUnknown

依照 Vtable 順序的方法

下表顯示 IDiaLineNumber 方法。

方法 描述
IDiaLineNumber::get_compiland 擷取編譯的符號參考,該符號會貢獻影像文字的位元組。
IDiaLineNumber::get_sourceFile 擷取來源檔案物件的參考。
IDiaLineNumber::get_lineNumber 擷取來源檔案中的行號。
IDiaLineNumber::get_lineNumberEnd 擷取陳述式或運算式結尾處的以一起始來源行號。
IDiaLineNumber::get_columnNumber 擷取運算式或陳述式開始處的資料行編號。
IDiaLineNumber::get_columnNumberEnd 擷取運算式或陳述式結尾處的資料行編號。
IDiaLineNumber::get_addressSection 擷取區塊開始處的記憶體位址的區段部分。
IDiaLineNumber::get_addressOffset 擷取區塊開始處的記憶體位址的位移部分。
IDiaLineNumber::get_relativeVirtualAddress 擷取區塊的映像相對虛擬位址 (RVA)。
IDiaLineNumber::get_virtualAddress 擷取區塊的虛擬位址 (VA)。
IDiaLineNumber::get_length 擷取區塊中的位元組數目。
IDiaLineNumber::get_sourceFileId 擷取參與此行之來源檔案的唯一原始程式檔識別碼。
IDiaLineNumber::get_statement 擷取旗標,指出這個行資訊描述程式來源中的陳述式開頭。
IDiaLineNumber::get_compilandId 擷取編譯的唯一識別碼,並參與這一行。

備註

呼叫端注意事項

呼叫 IDiaEnumLineNumbers::ItemIDiaEnumLineNumbers::Next 方法來取得此介面。

範例

下列函式會顯示函式中使用的行號 (以 pSymbol 表示)。

void dumpFunctionLines( IDiaSymbol* pSymbol, IDiaSession* pSession )
{
    ULONGLONG length = 0;
    DWORD     isect  = 0;
    DWORD     offset = 0;

    pSymbol->get_addressSection( &isect );
    pSymbol->get_addressOffset( &offset );
    pSymbol->get_length( &length );
    if ( isect != 0 && length > 0 )
    {
        CComPtr< IDiaEnumLineNumbers > pLines;
        if ( SUCCEEDED( pSession->findLinesByAddr(
                                      isect,
                                      offset,
                                      static_cast<DWORD>( length ),
                                      &pLines)
                      )
           )
        {
            CComPtr< IDiaLineNumber > pLine;
            DWORD celt      = 0;
            bool  firstLine = true;

            while ( SUCCEEDED( pLines->Next( 1, &pLine, &celt ) ) &&
                    celt == 1 )
            {
                DWORD offset;
                DWORD seg;
                DWORD linenum;
                CComPtr< IDiaSymbol >     pComp;
                CComPtr< IDiaSourceFile > pSrc;

                pLine->get_compiland( &pComp );
                pLine->get_sourceFile( &pSrc );
                pLine->get_addressSection( &seg );
                pLine->get_addressOffset( &offset );
                pLine->get_lineNumber( &linenum );
                printf( "\tline %d at 0x%x:0x%x\n", linenum, seg, offset );
                pLine = NULL;
                if ( firstLine )
                {
                    // sanity check
                    CComPtr< IDiaEnumLineNumbers > pLinesByLineNum;
                    if ( SUCCEEDED( pSession->findLinesByLinenum(
                                                  pComp,
                                                  pSrc,
                                                  linenum,
                                                  0,
                                                  &pLinesByLineNum)
                                  )
                       )
                    {
                        CComPtr< IDiaLineNumber > pLine;
                        DWORD celt;
                        while ( SUCCEEDED( pLinesByLineNum->Next( 1, &pLine, &celt ) ) &&
                                celt == 1 )
                        {
                            DWORD offset;
                            DWORD seg;
                            DWORD linenum;

                            pLine->get_addressSection( &seg );
                            pLine->get_addressOffset( &offset );
                            pLine->get_lineNumber( &linenum );
                            printf( "\t\tfound line %d at 0x%x:0x%x\n", linenum, seg, offset );
                            pLine = NULL;
                        }
                    }
                    firstLine = false;
                }
            }
        }
    }
}

需求

標頭: Dia2.h

程式庫: diaguids.lib

DLL: msdia80.dll

另請參閱