Пример #1
0
void CmdInstrument::validateAndWriteToTable(DebuggerProxy &proxy) {
  if (!proxy.getInjTables()) {
    proxy.setInjTables(new InjectionTables());
  }
  InjectionTableInt64* tablePC = nullptr;
  InjectionTableSD* tableFEntry = nullptr;

  for (int i = 0; i < (int)m_ips.size(); i++) {
    InstPointInfoPtr ipi = m_ips[i];
    const Injection* inj =
      InjectionCache::GetInjection(ipi->m_code, ipi->m_desc);
    if (!inj) { // error in the code
      continue;
    }
    if (ipi->m_locType == InstPointInfo::LocHere ||
        ipi->m_locType == InstPointInfo::LocFileLine) {
      // bytecode address
      const uchar *pc = ipi->lookupPC();
      if (pc == nullptr) {
        continue;
      }
      if (tablePC == nullptr) {
        tablePC = new InjectionTableInt64();
      }
      ipi->m_valid = true;
      (*tablePC)[(int64_t)pc] = inj;
    }
    if (ipi->m_locType == InstPointInfo::LocFuncEntry) {
      StackStringData sd(ipi->m_func.c_str(), ipi->m_func.size(), AttachLiteral);
      const StringData* sdCache = InjectionCache::GetStringData(&sd);
      if (tableFEntry == nullptr) {
        tableFEntry = new InjectionTableSD();
      }
      ipi->m_valid = true;
      (*tableFEntry)[sdCache] = inj;
    }
  }

  proxy.getInjTables()->setInt64Table(InstHookTypeBCPC, tablePC);
  proxy.getInjTables()->setSDTable(InstHookTypeFuncEntry, tableFEntry);

  proxy.writeInjTablesToThread();
}
Пример #2
0
void CmdInstrument::readFromTable(DebuggerProxy &proxy) {
  proxy.readInjTablesFromThread();
  m_ips.clear();
  if (!proxy.getInjTables()) {
    // nothing there
    return;
  }
  // Bytecode address
  InjectionTableInt64* tablePC =
    proxy.getInjTables()->getInt64Table(InstHookTypeBCPC);
  if (tablePC) {
    for (InjectionTableInt64::const_iterator it = tablePC->begin();
         it != tablePC->end(); ++it) {
      const Injection* inj = it->second;
      InstPointInfoPtr ipi(new InstPointInfo());
      ipi->m_valid = true;
      if (inj->m_desc) {
        ipi->m_desc = inj->m_desc->data();
      }
      ipi->m_locType = InstPointInfo::LocFileLine;
      // TODO use pc to figure out m_file and m_line
      // uchar* pc = (uchar*)it->first;
      m_ips.push_back(ipi);
    }
  }
  InjectionTableSD* tableFEntry =
    proxy.getInjTables()->getSDTable(InstHookTypeFuncEntry);
  if (tableFEntry) {
    for (InjectionTableSD::const_iterator it = tableFEntry->begin();
         it != tableFEntry->end(); ++it) {
      const Injection* inj = it->second;
      InstPointInfoPtr ipi(new InstPointInfo());
      ipi->m_valid = true;
      if (inj->m_desc) {
        ipi->m_desc = inj->m_desc->data();
      }
      ipi->m_func = it->first->data();
      ipi->m_locType = InstPointInfo::LocFuncEntry;
      m_ips.push_back(ipi);
    }
  }
}