Exemple #1
0
struct dso *dso__new(const char *name)
{
	struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1);

	if (self != NULL) {
		int i;
		strcpy(self->name, name);
		dso__set_long_name(self, self->name);
		dso__set_short_name(self, self->name);
		for (i = 0; i < MAP__NR_TYPES; ++i)
			self->symbols[i] = self->symbol_names[i] = RB_ROOT;
		self->slen_calculated = 0;
		self->origin = DSO__ORIG_NOT_FOUND;
		self->loaded = 0;
		self->sorted_by_name = 0;
		self->has_build_id = 0;
	}

	return self;
}
struct dso *vdso__dso_findnew(struct list_head *head)
{
	struct dso *dso = dsos__find(head, VDSO__MAP_NAME, true);

	if (!dso) {
		char *file;

		file = get_file();
		if (!file)
			return NULL;

		dso = dso__new(VDSO__MAP_NAME);
		if (dso != NULL) {
			dsos__add(head, dso);
			dso__set_long_name(dso, file);
		}
	}

	return dso;
}
HRESULT CaPerfDataWriter::setModulesAbsolutePath(const std::string& dirName)
{
    struct dirent* dent;
    const char* dirPath = dirName.c_str();
    DIR* dir = opendir(dirPath);
    HRESULT ret = S_OK;

    if (!dir)
    {
        OS_OUTPUT_FORMAT_DEBUG_LOG(OS_DEBUG_LOG_ERROR, L"cannot open %hs dir", dirPath);
        return E_FAIL;
    }

    while ((dent = readdir(dir)) != NULL)
    {
        char path[OS_MAX_PATH];
        struct stat st;

        /*sshfs might return bad dent->d_type, so we have to stat*/
        sprintf(path, "%s/%s", dirPath, dent->d_name);

        if (stat(path, &st))
        {
            continue;
        }

        if (S_ISDIR(st.st_mode))
        {
            if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
            {
                continue;
            }

            snprintf(path, sizeof(path), "%s/%s",
                     dirPath, dent->d_name);
            ret = setModulesAbsolutePath(path);

            if (ret < 0)
            {
                break;
            }
        }
        else
        {
            char* dot = strrchr(dent->d_name, '.');
            char  dso_name[OS_MAX_PATH];

            if (dot == NULL || strcmp(dot, ".ko"))
            {
                continue;
            }

            snprintf(dso_name, sizeof(dso_name), "[%.*s]", (int)(dot - dent->d_name), dent->d_name);

            strxfrchar(dso_name, '-', '_');

            // map = map_groups__find_by_name(self, MAP__FUNCTION, dso_name);
            // if (map == NULL)
            //  continue;
            kModuleNameMap::iterator it = m_kModuleNameMap.find(dso_name);

            if (it == m_kModuleNameMap.end())
            {
                continue;
            }

            snprintf(path, sizeof(path), "%s/%s", dirPath, dent->d_name);
            it->second.addAbsPath(path);
#if 0
            long_name = strdup(path);

            if (long_name == NULL)
            {
                ret = -1;
            }
            else
            {
                dso__set_long_name(map->dso, long_name);
                map->dso->lname_alloc = 1;
                dso__kernel_module_get_build_id(map->dso, "");
            }

#endif // 0
        }
    }

    // we are done dir
    closedir(dir);
    return ret;
}