2017-04-05 7 views
4

스택 오버 플로우를위한 OCaml 스택 트레이스가 잘립니다. 오류는 스택 오버 플로우 (최종 f5()failwith "Oops"에 변경이 하지 때 스택 트레이스스택 오버플로 후에 OCaml에서 완성되지 않은 스택 추적을 어떻게 얻을 수 있습니까?

let rec f0() = 1 + f1() 
    and f1() = 1 + f2() 
    and f2() = 1 + f3() 
    and f3() = 1 + f4() 
    and f4() = 1 + f5() 
    and f5() = 1 + f5() 

let _ = 
    Printexc.record_backtrace true; 
    f0() 

Fatal error: exception Stack overflow 
Raised by primitive operation at file "stackoverflow.ml", line 6, characters 20-25 
Called from file "stackoverflow.ml", line 6, characters 20-25 
… 
Called from file "stackoverflow.ml", line 6, characters 20-25 

대비 : 예를 들어, 다음 프로그램은 아래와 스택 트레이스를 생성

Fatal error: exception Failure("Oops") 
Raised at file "pervasives.ml", line 30, characters 22-33 
Called from file "stackoverflow.ml", line 6, characters 20-35 
Called from file "stackoverflow.ml", line 5, characters 20-25 
Called from file "stackoverflow.ml", line 4, characters 20-25 
Called from file "stackoverflow.ml", line 3, characters 20-25 
Called from file "stackoverflow.ml", line 2, characters 20-25 
Called from file "stackoverflow.ml", line 1, characters 20-25 
Called from file "stackoverflow.ml", line 10, characters 2-7 

OCaml이 스택 트레이스를 자르지 않게하려면 어떻게해야합니까?

답변

2

:

(ocd) run 
[...] 
Uncaught exception: Stack_overflow 
(ocd) backstep 
(ocd) bt 

당신은 ocamlc하는 디버그 플래그를 추가 할 수 있습니다 : ocamldebug에 다음

ocamlc stackoverflow.ml -o stackoverflow 
ocamldebug stackoverflow 

을 (-g) 디버거에서 추가 작업을 수행합니다.

4

결과를 재현 할 때 의심되는 번호 인 1024 개의 백 트레이스가 표시됩니다.

는 사실, 나는 도서관이 byterun/CAML 1024의 하드 코딩 된 최대 역 추적 크기를 부과하는 것을 볼/backtrace_prim.h :

#define BACKTRACE_BUFFER_SIZE 1024 

당신은 당신이 원하는 경우 새 표준 라이브러리를 구축해야 할 수도 있습니다 큰 backtraces.

ocamlc을 사용하여 약간의 테스트를 수행했으며 오버플로가 발생할 때 (기본 스택 크기로) 약 262,000 개의 활성 스택 프레임을 볼 수 있습니다.

은 (OCaml의 4.04에 대한 올바른 파일 이름 편집했다.)가 역 추적 버퍼 오버 플로우하지 않도록

2

당신은 예를 들어, 스택을 제한 할 (바이트 코드 테스트)

$ env OCAMLRUNPARAM=b,l=1000 ./test 
[...] 
Called from file "test.ml", line 6, characters 20-25 
Called from file "test.ml", line 6, characters 20-25 
Called from file "test.ml", line 5, characters 20-25 
Called from file "test.ml", line 4, characters 20-25 
Called from file "test.ml", line 3, characters 20-25 
Called from file "test.ml", line 2, characters 20-25 
Called from file "test.ml", line 1, characters 20-25 
Called from file "test.ml", line 10, characters 2-7 
당신은 스택 추적을 얻을 ocamldebug 사용할 수 있습니다