크래프톤 정글 일지

[PintOS] project 3.2.1 - anonymous 디버깅

나한나한나한나 2024. 6. 7. 16:22

booting은 되는데 executing이 문제다.

/* Runs the task specified in ARGV[1]. */
static void
run_task (char **argv) {
	const char *task = argv[1];

	printf ("Executing '%s':\n", task);
#ifdef USERPROG
	if (thread_tests){
		run_test (task);
	} else {
		process_wait (process_create_initd (task));
	}
#else
printf("\n여기까지는 오냐?\n");
	run_test (task);
#endif
	printf ("Execution of '%s' complete.\n", task);
}

project 3 라서 else로 빠지는 줄 알았는데, #ifdef USERPROG쪽으로 빠지나보다.

/* Runs the task specified in ARGV[1]. */
static void
run_task (char **argv) {
	const char *task = argv[1];

	printf ("Executing '%s':\n", task);
#ifdef USERPROG
	if (thread_tests){
    printf("\n여기니?11111111\n");
		run_test (task);
	} else {
    printf("\n여기니?22222222\n");
		process_wait (process_create_initd (task));
	}
#else
printf("\n여기까지는 오냐?\n");
	run_test (task);
#endif
	printf ("Execution of '%s' complete.\n", task);
}

task부터 확인해보자

    printf("\ntask:%s\n", task);
		process_wait (process_create_initd (task));

문제없음

 

file_name 확인

tid_t process_create_initd(const char *file_name)
{
	char *fn_copy;
	tid_t tid;
printf("****file_name:%s******\n", file_name)
	/* Make a copy of FILE_NAME.
	 * Otherwise there's a race between the caller and load(). */
	fn_copy = palloc_get_page(0);
	if (fn_copy == NULL)
		return TID_ERROR;
	strlcpy(fn_copy, file_name, PGSIZE);

	char *save_ptr;
	strtok_r(file_name, " ", &save_ptr);

	/* Create a new thread to execute FILE_NAME. */
	tid = thread_create(file_name, PRI_DEFAULT, initd, fn_copy);
	if (tid == TID_ERROR)
		palloc_free_page(fn_copy);
	return tid;
}

문제없음

 

process_wait이 문제인가

int process_wait(tid_t child_tid UNUSED)
{
	/* XXX: Hint) The pintos exit if process_wait (initd), we recommend you
	 * XXX:       to add infinite loop here before
	 * XXX:       implementing the process_wait. */
	struct thread *child = get_child_process(child_tid);
	if (child == NULL) // 자식이 아니면 -1을 반환한다.
		return -1;
printf("*********%d********\n", child_tid);
printf("*********여기가 문제인 것 같은데********\n");
	// 자식이 종료될 때까지 대기한다. (process_exit에서 자식이 종료될 때 sema_up 해줄 것이다.)
	sema_down(&child->wait_sema);
	// 자식이 종료됨을 알리는 `wait_sema` signal을 받으면 현재 스레드(부모)의 자식 리스트에서 제거한다.
	list_remove(&child->child_elem);
	// 자식이 완전히 종료되고 스케줄링이 이어질 수 있도록 자식에게 signal을 보낸다.
	sema_up(&child->exit_sema);

	return child->exit_status; // 자식의 exit_status를 반환한다.
}

딱히 문제없음

 

모르겠다... gdb 돌려봐야할듯

sema_down(&child->wait_sema);를 하자마자 args-single: exit(-1)이 뜨면서 종료당했다. 여기가 문제인듯

 

gdb 포기...

 

gpt에게 물어봤더니

process_wait 함수에서 args-single 테스트가 실패하는 문제를 해결하려면, 스택 증가와 관련된 기능을 구현해야 합니다. 이 기능을 구현하면 페이지 폴트가 발생했을 때 필요한 스택 페이지를 할당하고, 스택 크기를 동적으로 늘릴 수 있습니다.

스택 증가 기능을 구현하기 위해서는 다음 단계를 따르세요:

  1. 페이지 폴트 핸들러에서 스택 접근 식별:
    • vm_try_handle_fault 함수에서 페이지 폴트가 스택 접근인지 식별합니다.
    • 식별된 경우 vm_stack_growth 함수를 호출하여 스택 크기를 증가시킵니다.
  2. 스택 증가 함수 구현:
    • vm_stack_growth 함수에서 필요한 페이지를 할당하여 스택 크기를 증가시킵니다.

process_wait 함수에서 args-single 테스트가 실패하는 문제를 해결하려면, 스택 증가와 관련된 기능을 구현해야 합니다. 

씨발