예제 #1
0
void
reopen_exec_file(void)
{
#if 0				/* FIXME */
  if (exec_bfd)
    bfd_reopen(exec_bfd);
#else
  char *filename;
  int res;
  struct stat st;
  long mtime;

  /* APPLE LOCAL begin gdb_quitting */
  /* Do NOT do any of this if we are quitting.  */
  if (gdb_quitting)
    return;
  /* APPLE LOCAL end gdb_quitting */

  /* Do NOT do anything if the current target is NOT exec. */
  if (exec_bfd == NULL || (strcmp(target_shortname, "exec") != 0))
    return;

  /* If the timestamp of the exec file has changed, reopen it. */
  /* APPLE LOCAL comment */
  /* The whole world may have changed, so just unset all breakpoints: */
  filename = xstrdup(bfd_get_filename(exec_bfd));
  make_cleanup(xfree, filename);
  mtime = bfd_get_mtime(exec_bfd);
  res = stat(filename, &st);

  if (res == -1) {
    warning("stat failed with errno %d (i.e. \"%s\").\n", errno,
            strerror(errno));
  }

  if (mtime && (mtime != st.st_mtime))
    {
      exec_open(filename, 0);
      /* APPLE LOCAL begin hooks */
      tell_breakpoints_objfile_changed(NULL);
      /* APPLE LOOCAL cache lookup values for improved performance  */
      symtab_clear_cached_lookup_values();
      tell_objc_msgsend_cacher_objfile_changed(NULL);
      /* APPLE LOCAL end hooks */
    }
#endif /* 0 */
}
예제 #2
0
파일: fl.c 프로젝트: pavel-krush/fl
void do_command(const char *command_line) {
	skip_spaces(&command_line);

	char *command = parse_word(&command_line);
	if (command == NULL)
		return;

	skip_spaces(&command_line);

	int command_length = strlen(command);

	#define CMD_COND1(str) ( ( command_length == sizeof(str) - 1 && !strcmp(command, str) ) )
	#define CMD_COND2(str) ( ( command_length == 1 && command[0] == str[0] ) || ( ( command_length == sizeof(str) - 1 ) && !strcmp(command, str) ) )

	#define  PARSE_ID(fail_label) int *id; id = parse_int(&command_line); \
		if (!id) { printf("ID required\n"); goto fail_label; } \
		if (*id < 0 || *id >= files_count) { printf("Invalid ID. Valid values are from %d to %d\n", 0, files_count); goto fail_label; }

	if (CMD_COND2("help")) {
		exec_help();
	}
	else if (CMD_COND2("info")) {
		exec_info();
	}
	// open ID mode
	else if (CMD_COND2("open")) {
		char *mode = NULL;
		PARSE_ID(open_cleanup)

		skip_spaces(&command_line);

		mode = parse_until_space(&command_line);
		if (!mode) {
			printf("MODE required\n");
			goto open_cleanup;
		}

		exec_open(*id, mode);

		open_cleanup:
			if (id) free(id);
			if (mode) free(mode);
			goto cleanup;
	}
	else if (CMD_COND2("lock")) {
		char *operation = NULL;

		PARSE_ID(lock_cleanup)

		skip_spaces(&command_line);

		operation = parse_until_space(&command_line);
		if (!operation) {
			printf("Operation required\n");
			goto lock_cleanup;
		}

		int op;

		if (!strcmp(operation, "shnb"))
			op = LOCK_SH | LOCK_NB;
		else if (!strcmp(operation, "sh"))
			op = LOCK_SH;
		else if (!strcmp(operation ,"exnb"))
			op = LOCK_EX | LOCK_NB;
		else if (!strcmp(operation, "ex"))
			op = LOCK_EX;
		else if (!strcmp(operation, "unnb"))
			op = LOCK_UN | LOCK_NB;
		else if (!strcmp(operation, "un"))
			op = LOCK_UN;
		else {
			printf("Invalid <operation>\n");
			goto lock_cleanup;
		}

		exec_lock(*id, op);

		lock_cleanup:
			if (id) free(id);
			if (operation) free(operation);
			goto cleanup;
	}
	else if (CMD_COND2("close")) {
		PARSE_ID(close_cleaup)

		exec_close(*id);

		close_cleaup:
			if (id) free(id);
			goto cleanup;
	}
	else if (CMD_COND2("seek")) {
		int *offset = NULL;
		char *whence_str = NULL;

		PARSE_ID(seek_cleanup)

		skip_spaces(&command_line);

		int sign = 1;
		if (command_line[0] == '-') {
			sign = -1;
			command_line++;
		}

		offset = parse_int(&command_line);
		if (!offset) {
			printf("Invalid <offset>\n");
			goto seek_cleanup;
		}
		*offset = *offset * sign;

		skip_spaces(&command_line);

		whence_str = parse_until_space(&command_line);
		if (!whence_str) {
			printf("Invalid <whence>. Valid values are: set, end, cur\n");
			goto seek_cleanup;
		}

		int whence = 0;

		if (!strcmp(whence_str, "set")) {
			whence = SEEK_SET;
		}
		else if (!strcmp(whence_str, "end")) {
			whence = SEEK_END;
		}
		else if (!strcmp(whence_str, "cur")) {
			whence = SEEK_CUR;
		}

		exec_seek(*id, *offset, whence);

		seek_cleanup:
			if (id) free(id);
			if (offset) free(offset);
			if (whence_str) free(whence_str);
			goto cleanup;
	}
	else if (CMD_COND2("tell")) {
		PARSE_ID(tell_cleanup)

		skip_spaces(&command_line);

		exec_tell(*id);

		tell_cleanup:
			if (id) free(id);
			goto cleanup;
	}
	else if (CMD_COND2("write")) {
		printf("not implemented\n");
		goto write_cleanup;
		write_cleanup:
			goto cleanup;
	}
	else if (CMD_COND2("read")) {
		int *length = NULL;
		PARSE_ID(read_cleanup);

		skip_spaces(&command_line);

		int hex = 0;

		if (command_line[0] == 'x') {
			hex = 1;
			command_line++;
			skip_spaces(&command_line);
		}

		length = parse_int(&command_line);
		if (!length) {
			printf("Invalid <length>\n");
			goto read_cleanup;
		}

		exec_read(*id, *length, hex);

		read_cleanup:
			if (id) free(id);
			if (length) free(length);
			goto cleanup;
	}
	else if (CMD_COND1("truncate")) {
		int *length = NULL;
		PARSE_ID(truncate_cleanup)

		skip_spaces(&command_line);

		length = parse_int(&command_line);
		if (!length) {
			printf("Invalid <length>\n");
			goto truncate_cleanup;
		}

		exec_truncate(*id, *length);

		truncate_cleanup:
			if (id) free(id);
			if (length) free(length);
			goto cleanup;
	}
	else {
		printf("Unknown command\n");
	}

cleanup:
	free(command);
}