当前位置: 首页>>代码示例>>C++>>正文


C++ ModulesMap::insert方法代码示例

本文整理汇总了C++中ModulesMap::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ ModulesMap::insert方法的具体用法?C++ ModulesMap::insert怎么用?C++ ModulesMap::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModulesMap的用法示例。


在下文中一共展示了ModulesMap::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fillModules

/**
 * Determine all loaded modules as well as the process module itself for the given process id.
 */
NaviError LinuxSystem::fillModules(pid_t pid, ModulesMap& modules) {
  std::string filename = "/proc/" + zylib::zycon::toString(pid) + "/maps";

  msglog->log(LOG_ALL, "Trying to read the modules map from file %s",
              filename.c_str());

  std::ifstream file(filename.c_str());

  if (!file) {
    msglog->log(LOG_ALWAYS, "Error: Couldn't read modules map file");

    return NaviErrors::COULDNT_READ_MEMORY;
  }

  std::vector < std::string > lines;

  std::string line;

  while (std::getline(file, line)) {
    msglog->log(LOG_ALL, "Successfully read line %s from modules map file",
                line.c_str());

    lines.push_back(line);
  }

// 08048000-08053000 r-xp 00000000 08:01 282412     /usr/bin/kdeinit
// 08053000-08054000 r--p 0000a000 08:01 282412     /usr/bin/kdeinit
// 08054000-08055000 rw-p 0000b000 08:01 282412     /usr/bin/kdeinit
// 09f73000-0a016000 rw-p 09f73000 00:00 0          [heap]
// b6638000-b6672000 rw-p b6672000 00:00 0
// b66bb000-b66d9000 r-xp 00000000 08:01 352021     /usr/lib/kde3/plugins/styles/plastik.so
// b66d9000-b66da000 r--p 0001d000 08:01 352021     /usr/lib/kde3/plugins/styles/plastik.so
// b66da000-b66db000 rw-p 0001e000 08:01 352021     /usr/lib/kde3/plugins/styles/plastik.so
// b66db000-b66e1000 r--s 00000000 08:01 396230     /var/cache/fontconfig/945677eb7aeaf62f1d50efc3fb3ec7d8-x86.cache-2
// b66e1000-b66e4000 r--s 00000000 08:01 396239     /var/cache/fontconfig/e383d7ea5fbe662a33d9b44caf393297-x86.cache-2
// b66e4000-b66e5000 r--s 00000000 08:01 396225     /var/cache/fontconfig/4c73fe0c47614734b17d736dbde7580a-x86.cache-2
// b66e5000-b66e8000 r--s 00000000 08:01 396231     /var/cache/fontconfig/a755afe4a08bf5b97852ceb7400b47bc-x86.cache-2
// b66e8000-b66ef000 r--s 00000000 08:01 396608     /var/cache/fontconfig/6d41288fd70b0be22e8c3a91e032eec0-x86.cache-2
// b66ef000-b66f7000 r--s 00000000 08:01 396240     /var/cache/fontconfig/e3de0de479f42330eadf588a55fb5bf4-x86.cache-2
// b66f7000-b6702000 r--s 00000000 08:01 396220     /var/cache/fontconfig/0f34bcd4b6ee430af32735b75db7f02b-x86.cache-2
// b6702000-b6709000 r--s 00000000 08:01 396234     /var/cache/fontconfig/d52a8644073d54c13679302ca1180695-x86.cache-2

  std::string lastName = "";
  CPUADDRESS start = 0;
  CPUADDRESS end = 0;

  for (std::vector<std::string>::iterator Iter = lines.begin();
      Iter != lines.end(); ++Iter) {
    std::string line = *Iter;

    size_t position = line.find("/");

    if (position != std::string::npos) {
      // OK, we found a line with a name; now we gotta figure out if we found a new module
      // or just with a new section in the same module.

      std::string name = line.substr(position);

      // TODO: Only works in 32bit platforms
      std::string startString = Iter->substr(0, 8);
      std::string endString = Iter->substr(9, 8);

      if (name != lastName) {
        // We found a new module, so we can take the information from the previous
        // module and add  the previous module to the list of modules.

        if (lastName != "") {
          Module newModule(getModuleName(lastName), lastName, start,
                           end - start);
          modules.insert(std::make_pair(lastName, newModule));
        }

        lastName = name;
        start = zylib::zycon::parseHexString < CPUADDRESS > (startString);
        end = zylib::zycon::parseHexString < CPUADDRESS > (endString);
      } else {
        // The module in the current line is the same module we already processed
        // in the previous line. Only the end information has to be updated in this
        // case.

        end = zylib::zycon::parseHexString < CPUADDRESS > (endString);
      }
    } else if (lastName != "") {
      // We found a line without a name and the previous module has
      // a valid name => Add the previous module to the list of modules.

      Module newModule(getModuleName(lastName), lastName, start, end - start);
      modules.insert(std::make_pair(lastName, newModule));

      lastName = "";
    }
  }

  if (lastName != "") {
    // Add the last module in the list.

    Module newModule(getModuleName(lastName), lastName, start, end - start);
//.........这里部分代码省略.........
开发者ID:0x90erator,项目名称:binnavi,代码行数:101,代码来源:LinuxSystem.cpp


注:本文中的ModulesMap::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。