/*
 * This is where we actually parse the memory map lines.
 */
static int mem_map_add_string(target_context_t *tc,
			      const char *desc)
{
	mem_region_t *mr = NULL;
	char *ptr = NULL, *s = NULL, *tok;
	int i = 0;

	mr = region_new();

	/* strtok_r modifies its first argument, so we duplicate
	   'desc' before using it */
	for (s = xstrdup(desc);
#ifndef WIN32
	     (tok = strtok_r(ptr ? NULL : s, " \t\n", &ptr));
#else
	     (tok = strtok(ptr ? NULL : s, " \t\n"));
#endif
	     /* nada */) {
#ifdef WIN32
		ptr = (ptr ? ptr : s) + strlen (tok) + 1;
#endif

		/* order of tokens is fixed */
		switch (i++) {
		case 0:
			if (parse_addrs(mr, tok) < 0)
				goto failure;
			break;
		case 1:
			mr->type = region_type(tok);
			if (mr->type == MEMTYPE_INVALID)
				goto failure;
			break;
		case 2:
			/* name is always valid */
			mr->name = xstrdup(tok);
			break;
		default:
			/* there can be any number of options */
			if (parse_opt(mr, tok) < 0)
				goto failure;
		}
	}
	if (i < 3)
		goto failure;
	mem_map_add(tc, mr);
	free(s);
	return 0;

failure:
	if (tok)
		bad_desc(desc, desc + (tok - s));
	else
		bad_desc(desc, desc + strlen(desc));
	free(mr);
	free(s);
	return -1;
}
예제 #2
0
파일: main.c 프로젝트: grugq/tg-community
static int add_map( mem_map_t map, const char * arg ) {
	unsigned int target;
	opdis_off_t offset, size;
	opdis_vma_t vma;

	parse_memspec( arg, &target, &offset, &size, &vma );
	if ( offset == OPDIS_INVALID_ADDR || vma == OPDIS_INVALID_ADDR ) {
		fprintf( stderr, 
			"Invalid map memspec '%s' : VMA and offset required\n",
			 arg );
		return 0;
	}

	return mem_map_add( map, target, offset, size, vma );
}