Hello, dear friends!
Let’s say, I have a code fragment like this:
(* Read a binary file into an array of integers )
let make_bin_array f =
let ic = open_in_bin f in
let rec makelist lst =
( Catch expected end-of-file error; exit gracefully *)
try let b = (input_byte ic) in b::(makelist lst)
with End_of_file → close_in ic; lst
in Array.of_list (makelist )
let arr = make_bin_array “c:\Bin_Code.bin”;;
It was compiled: #ocamlc -g myCode.ml
I am trying to debug it in Visual Code on Debian 9.x using ocamlearlybird 1.1.0. The debugging session starts OK, i can put breakpoints and step into the code.
Three questions arise:
1.execution does not start at the entry point of the program but falls through into the system library, namely, stdlib.ml. What can be done about it?
2.Breakpoints do not stick on a arbitrary line, but just on some line where there is debugging event happening. What exactly prevents a breakpoint from sticking on certain lines?
3.When execution finally gets to the last line: let arr = make_bin_array “c:\Bin_Code.bin”;;
I would like to check the “value” of “arr”, i put a watch on it, is shows type, but is says “Not available”.
I have found this useful piece of info, which sheds some light on my problem:
Functional values are not data, therefore there is no reason or way to print them.
In general, in OCaml there is no canonical value representation or printing, like in Python, for example. For each type one can write a function that will print some representation of values of this type. It is totally arbitrary and up to a developer discretion.
Another thing to understand about OCaml, is that programs written in OCaml are compiled to machine code, and there are no types or any other runtime supporting information, available during program execution.
So, there is not notion of type, but what was the purpose of “-g” switch i used when compiling?
My third and last question is what should i do to see or print the value of my “arr”?
Could somebody be so kind and show an example of a function, which would print that value?
As you can see, i am coming from a completely different realm of C programming and debugging and am having really rough times here…
Thanks a lot in advance! your help is greatly appreciated!