infer icon indicating copy to clipboard operation
infer copied to clipboard

How to debug Infer line-by-line?

Open jiseongg opened this issue 3 years ago • 9 comments

I have a question about how to debug Infer line-by-line. According to #536, that debugging environment doesn't seem to be prepared. However, I'm confused because the section Debugging OCaml Code in CONTRIBUTING.md assumes someone may use ocamldebug. Following is the situation I've faced, which implies what I want to do, including some information of my environment.

  • [x] Infer version v1.0.0-7be85f40a
  • [x] Ubuntu 18.04.5 LTS VirtualBox machine
  • [x] ocamldebug <PATH_TO_BIN>/infer analyze --pulse-only
  • [x] output of ocamldebug
	OCaml Debugger version 4.11.1

(ocd) goto 0
Loading program... /home/vagrant/github/facebook/infer/examples/c_hello/../../infer/bin/infer is not a bytecode file.
(ocd)
  • [ ] If possible, a minimal example to reproduce your problem (for instance, some code where infer reports incorrectly, together with the way you run infer to reproduce the incorrect report).

I think this is because of executable file format of Infer, not a bytecode but a native code. Is there any way to produce a bytecode executable file for Infer in current build system? I hope there is a way to do that with some environment setup, to use ocamldebug like the section Debugging OCaml Code in CONTRIBUTING.md.

If not, how about supporting it? If possible, I want to contribute for that support. I think Infer framework is a quite large software, having a steep learning curve. And if line-by-line debugging is possible, it'll mitigate the difficulty of studying it.

jiseongg avatar Mar 18 '21 09:03 jiseongg

You need to build infer in bytecode mode first. make byte will do that for you.

jvillard avatar Mar 18 '21 11:03 jvillard

@jvillard Should I do that from Infer root directory again? It seems that running make byte in the project root directory also builds the facebook-clang-plugins again, even though I had built Infer completely before with ./build-infer.sh. It will take really long time. Thus, I stopped it and did it again in infer/src directory to check if it works.

After running make BUILD_MODE=dev-noerror -C infer/src byte, infer.bc.exe is generated and infer binary is updated. However, "not a bytecode file" message still remains and I cannot debug it with ocamldebug.

jiseongg avatar Mar 18 '21 11:03 jiseongg

You're right, make byte doesn't produce something that ocamldebug can consume anymore, I think since 786a72574fc6943c5635f3cb1a7abb417013c9b5 so that way of debugging infer is not available anymore.

jvillard avatar Mar 18 '21 12:03 jvillard

I think so, too. Is that normal situation for OCaml project or only for Infer? Since I'm newbie in such large project written in OCaml, I'm just curious.

Then the only way to debug Infer is to use Logging module to print internal data, right?

jiseongg avatar Mar 20 '21 09:03 jiseongg

@jiseongg Have you found any other good debugging methods? and Can you recommend any debugging methods that you have used in your projects?

From. Seoul, Korea too :)

MarsMan13 avatar Oct 01 '23 12:10 MarsMan13

Currently, make byte is building infer with the byte_complete mode.

byte_complete for building a bytecode executable as a native self-contained executable, i.e., an executable that doesn’t require the ocamlrun program to run and doesn’t require the C stubs to be installed as shared object files.

https://dune.readthedocs.io/en/stable/dune-files.html#linking-modes

And it does not seem to work well with ocamldebug.

https://github.com/ocaml/ocaml/issues/9344

Therefore, to run ocamldebug, we need to build it as the byte mode and run it with proper libarary paths, e.g.

  • replace all .bc.exe to .bc in infer/src/Makefile
  • replace all byte_complete to byte in infer/src/dune.in
~/infer/infer/src$ make byte

~/infer/infer/src$ CAML_LD_LIBRARY_PATH=../_build/default/src/c_stubs:$CAML_LD_LIBRARY_PATH ocamldebug ../bin/infer.bc --version
	OCaml Debugger version 4.14.0

(ocd) goto 0
Loading program... done.
Time: 0
Beginning of program.
(ocd) run
Infer version v1.1.0-ed404b4acb
Copyright 2009 - present Facebook. All Rights Reserved.
Time: 11399552
Program exit.

Then the only way to debug Infer is to use Logging module to print internal data, right?

Yes. But, for me, Logging has worked well for developing/debugging Infer in most of the cases so far.

skcho avatar Oct 02 '23 13:10 skcho

@skcho Thank you for your response! It has been a great help in using/debugging Infer!

MarsMan13 avatar Oct 02 '23 13:10 MarsMan13

@MarsMan13, At the time, I failed to figure out the solution about using ocamldebug, and I forgot about this issue. Hope @skcho 's answer helped. :)

Anyway, I used Logging.debug_dev function, which could print anything I wanted to html files. (I had read this from CONTRIBUTING.md)

jiseongg avatar Oct 04 '23 01:10 jiseongg

@jiseongg Thank you for your response!!!! Yes! @skcho 's solution is very useful for me!! Thank you!!

MarsMan13 avatar Oct 07 '23 11:10 MarsMan13