예제 #1
0
gtVAddr BaseStackWalkContext::GetImageLoadAddress(gtVAddr virtualAddr, gtVAddr& baseAddr) const
{
    assert(NULL != m_pWorkingSet);
    gtVAddr loadAddr;
    ExecutableFile* pExe = m_pWorkingSet->FindModule(virtualAddr);

    if (NULL != pExe)
    {
        baseAddr = pExe->GetImageBase();
        loadAddr = pExe->GetLoadAddress();
    }
    else
    {
        baseAddr = 0ULL;
        loadAddr = 0ULL;
    }

    return loadAddr;
}
예제 #2
0
bool JavaJncReader::Open(const wchar_t* pWFileName)
{
    JncPcStackInfoMap::iterator it;
    char fileName[261];

    memset(fileName, 0, sizeof(fileName));

    if (nullptr == pWFileName)
    {
        return false;
    }

    wcstombs(fileName, pWFileName, 260);

    ExecutableFile* pExecutable = ExecutableFile::Open(pWFileName);

    if (nullptr == pExecutable)
    {
        return false;
    }

    m_sectionCounts =  pExecutable->GetSectionsCount();

    // Get The .text section
    unsigned codeSecIndex = pExecutable->LookupSectionIndex(".text");
    gtRVAddr codeStartRva = 0, codeEndRva = 0;
    pExecutable->GetSectionRvaLimits(codeSecIndex, codeStartRva, codeEndRva);

    m_pCodeBuf   = pExecutable->GetSectionBytes(codeSecIndex);
    m_loadAddr   = static_cast<gtRVAddr>(codeStartRva) + pExecutable->GetImageBase();
    m_textOffset = codeStartRva;
    m_textSize   = codeEndRva - codeStartRva;

    if (nullptr == m_pCodeBuf || m_textSize <= 0)
    {
        delete pExecutable;
        return false;
    }

    // Get the .stringtable
    m_string_table_buf = pExecutable->GetSectionBytes(pExecutable->LookupSectionIndex(".stringtable"));

    if (nullptr == m_string_table_buf)
    {
        // JNC Files for Native methods won't have stringtable, bc2src and pc2bc sections..
        m_pExecutable = pExecutable;
        return true;
    }

    if (!_process_stringtable_section())
    {
        delete pExecutable;
        m_pExecutable = nullptr;
        return false;
    }

    // Process .bc2src
    m_pBc2srcBuf = pExecutable->GetSectionBytes(pExecutable->LookupSectionIndex(".bc2src"));

    if (nullptr == m_pBc2srcBuf)
    {
        delete pExecutable;
        m_pExecutable = nullptr;
        return false;
    }

    if (!_process_bc2src_section())
    {
        delete pExecutable;
        m_pExecutable = nullptr;
        return false;
    }

    // Process the .pc2bc
    m_pPc2bcBuf = pExecutable->GetSectionBytes(pExecutable->LookupSectionIndex(".pc2bc"));

    if (nullptr == m_pPc2bcBuf)
    {
        OS_OUTPUT_FORMAT_DEBUG_LOG(OS_DEBUG_LOG_DEBUG, L"Warning: file %hs does not have pc-to-byte code information", fileName);
        delete pExecutable;
        m_pExecutable = nullptr;
        return false;
    }

    if (!_process_pc2bc_section())
    {
        delete pExecutable;
        m_pExecutable = nullptr;
        return false;
    }

    // Setup inline information map
    if (!_process_inline_map())
    {
        delete pExecutable;
        m_pExecutable = nullptr;
        return false;
    }

    // DEBUG:  dump the java inline entries
    // DumpJavaInlineMap();

    // Identify the main method for this JNC
    if (m_jncPcStackInfoMap.empty())
    {
        // If there is no PC stack info, we should still be able to
        //  provide disassembly details. Hence return true;
        return true;
    }

    it = m_jncPcStackInfoMap.begin();
    m_mainMethodId = it->second->methods[it->second->numstackframes - 1];
    m_methodName   = m_jncMethodMap[m_mainMethodId].name;
    m_srcFile      = m_jncMethodMap[m_mainMethodId].sourceName;

    if (m_jncMethodMap[m_mainMethodId].lineNumberVec.size() > 0)
    {
        m_startLine = m_jncMethodMap[m_mainMethodId].lineNumberVec[0].line_number;

        m_possibleEndLine =
            m_jncMethodMap[m_mainMethodId].lineNumberVec[m_jncMethodMap[m_mainMethodId].lineNumberVec.size() - 1].line_number;
    }

    m_mainInlineDepth = it->second->numstackframes;

    for (unsigned int i = 0; i < m_addressRangeTable.size(); i++)
    {
        if (m_addressRangeTable[i].id == m_mainMethodId)
        {
            m_addressRangeTable[i].pc_start = m_loadAddr;
        }
    }

    m_pExecutable = pExecutable;
    return true;
}