0
votes

I am trying to use Frama-c via python application. This python application sets some env variables and system path. From this application, I am calling Frama-c as a python process as following:

cmd = ['/usr/local/bin/frama-c', '-wp', '-wp-print', '-wp-out', '/home/user/temp','/home/user/project/test.c']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)

When this code is executed from Python application I am getting following error:

[kernel] Parsing FRAMAC_SHARE/libc/__fc_builtin_for_normalization.i (no preprocessing)
[kernel] warning: your preprocessor is not known to handle option ` -nostdinc'. If pre-processing fails because of it, please add -no-cpp-gnu-like option to Frama-C's command-line. If you do not want to see this warning again, use explicitely -cpp-gnu-like option.
[kernel] warning: your preprocessor is not known to handle option `-dD'. If pre-processing fails because of it, please add -no-cpp-gnu-like option to Frama-C's command-line. If you do not want to see this warning again, use explicitely -cpp-gnu-like option.
[kernel] Parsing 2675891095.c (with preprocessing)
[kernel] System error: /usr/bin/gcc -c -C -E -I.  -dD -nostdinc -D__FC_MACHDEP_X86_32 -I/usr/local/share/frama-c/libc -o '/tmp/2675891095.cc8bf16.i' '/home/user/project/test.c': No child processes

I am finding it hard to debug what is causing the error:

System error: /usr/bin/gcc -c -C -E -I. -dD -nostdinc -D__FC_MACHDEP_X86_32 -I/usr/local/share/frama-c/libc -o '/tmp/2675891095.cc8bf16.i' '/home/user/project/test.c': No child processes

Is there a way to generate more error log from Frama-c that might help me figure out the issue?

Note that this error only occur when I start the process(to execute Frama-c) from my application, and not if I start it from a python console. And it happens only on Linux machine and not on Windows machine.

Any help is appreciated. Thanks!!

Update : I realized that by using -kernel-debug flag I can obtain stack trace. So I tried the option and get the following information:

Fatal error: exception Sys_error("gcc -E -C -I. -dD -D__FRAMAC__ -nostdinc -D__FC_MACHDEP_X86_32 -I/usr/local/share/frama-c/libc -o '/tmp/2884428408.c2da79b.i' '/home/usr/project/test.c': No child processes")

Raised by primitive operation at file "src/kernel_services/ast_queries/file.ml", line 472, characters 9-32

Called from file "src/kernel_services/ast_queries/file.ml", line 517, characters 14-26

Called from file "src/kernel_services/ast_queries/file.ml", line 703, characters 46-59

Called from file "list.ml", line 84, characters 24-34

Called from file "src/kernel_services/ast_queries/file.ml", line 703, characters 17-76

Called from file "src/kernel_services/ast_queries/file.ml", line 1587, characters 24-47

Called from file "src/kernel_services/ast_queries/file.ml", line 1667, characters 4-27

Called from file "src/kernel_services/ast_data/ast.ml", line 108, characters 2-28

Called from file "src/kernel_services/ast_data/ast.ml", line 116, characters 53-71

Called from file "src/kernel_internals/runtime/boot.ml", line 29, characters 6-20

Called from file "src/kernel_services/cmdline_parameters/cmdline.ml", line 787, characters 2-9

Called from file "src/kernel_services/cmdline_parameters/cmdline.ml", line 817, characters 18-64

Called from file "src/kernel_services/cmdline_parameters/cmdline.ml", line 228, characters 4-8

Re-raised at file "src/kernel_services/cmdline_parameters/cmdline.ml", line 244, characters 12-15

Called from file "src/kernel_internals/runtime/boot.ml", line 72, characters 2-127

And I looked at the file "src/kernel_services/ast_queries/file.ml", line 472 and the code executed is Sys.command cpp_command.

I am not sure why "No Child Processes" error is thrown when trying to execute execute gcc.

Update: I have Ocaml version: 4.02.3, Python version: 2.7.8 and Frama-C version: Silicon-20161101

1
It might help to know what system you're running on: Linux, Windows, macOS? - Jeffrey Scofield
It is happening only on Linux machine and not on the Windows machine. - Gunjan Aggarwal
Could you also specify the versions of OCaml and Python you're using? There are some related issues (such as this one) that only apply to specific versions of Python and/or OCaml. - anol
I have Ocaml version: 4.02.3, Python version: 2.7.8 and Frama-C version: Silicon-20161101 - Gunjan Aggarwal
I am unfortunately unable to reproduce it. Using Python 2.7.12, OCaml 4.02.3 and Frama-C Silicon, if I copy your code and then add, say, p.communicate(), it outputs the result of running WP on the program, without errors. Maybe adding the entire Python script and file.c itself could help reproducing it... - anol

1 Answers

0
votes

I know nothing about Frama-C. However, the error message is coming from somebody's (OCaml's? Python's?) runtime, indicating that a system call failed with the ECHILD error. The two system calls that system() makes are fork() and waitpid(). It's the latter system call that can return ECHILD. What it means is that there's no child process to wait for. One good possibility is that the fork() failed. fork() fails when the system is full of processes (unlikely) or when a per-user process limit has been reached. You could check whether you're running up against a limit of this kind.

Another possibility that occurs to me is that some other part of the code is already handling child processes using signal handling (SIGCHLD). So the reason there's no child process to wait for is that it has already been handled elsewhere. This gets complicated pretty fast, so I would hope this isn't the problem.