2

I have an entry point that I want to run pdg-dot on, however after I moved the header files to be in the right place I get this syntax error.

gtkwin.c:77:[kernel] user error: syntax error

In the source code that line is just a GdkPixmap declaration. How do I get Frama-C to create my .dot file now?

This is my command and the output:

frama-c -main pt_main -pdg -pdg-dot ptmain gtkwin.c 
[kernel] preprocessing with "gcc -C -E -I.  gtkwin.c"
gtkwin.c:77:[kernel] user error: syntax error
[kernel] user error: skipping file "gtkwin.c" that has errors.
[kernel] Frama-C aborted: invalid user input.

It should just be running through my function and creating the .dot file. I've tried just commenting the line out and I still get the same syntax error somehow.

Adam
  • 33
  • 7
  • 3
    You''ll need to post something more than a vague description please. http://stackoverflow.com/help/mcve – Weather Vane Jul 11 '15 at 17:42
  • What is line 77 of `gtkwin.c`, and lines around that line? – Daniel Trebbien Jul 12 '15 at 17:05
  • @DanielTrebbien This is line 77: GdkPixmap *pixmap; Everything around it is also declarations inside of the struct gui_data. Sorry the formatting is off I'm new to posting on stackoverflow – Adam Jul 12 '15 at 17:41

2 Answers2

3

By any chance are you using gtkwin.c from PuTTY for Unix? Line 77 of PuTTY's gtkwin.c is also GdkPixmap *pixmap;.

You might be seeing "user error: syntax error" because the C file is not fully preprocessed, or there might be some syntax that Frama-C does not recognize. For example, when I try the following command on Mac OS 10.10.4:

CPP="gcc -E `pkg-config --cflags gtk+-2.0 gdk-2.0` -I/opt/X11/include -I/usr/include -I. -Icharset -Iunix" \
frama-c -kernel-msg-key pp -no-cpp-gnu-like -main pt_main -pdg -pdg-dot ptmain unix/gtkwin.c

(Note that I had to comment out #include <gdk/gdkx.h> because my GTK+ build uses the quartz backend rather than the X11 backend.)

I get:

[kernel] Parsing unix/gtkwin.c (with preprocessing)
/usr/include/sys/qos.h:124:[kernel] user error: syntax error
[kernel] user error: stopping on file "unix/gtkwin.c" that has errors.
[kernel] Frama-C aborted: invalid user input.

In the frama-c command above, I added -kernel-msg-key pp. This option to frama-c allows you to see the preprocessing command that the kernel used. With -kernel-msg-key pp, you should see something like the following in the frama-c output:

[kernel:pp] preprocessing with "..."

Run the command listed in quotes and redirect the preprocessed output to a temporary file. Using the line number information added by the preprocessor, you will need to find the corresponding line in the preprocessed output. In my case, line 124 of /usr/include/sys/qos.h corresponded to line 9896 of the preprocessed output:

enum { QOS_CLASS_USER_INTERACTIVE __attribute__((availability(macosx,introduced=10.10))) = 0x21, QOS_CLASS_USER_INITIATED __attribute__((availability(macosx,introduced=10.10))) = 0x19, QOS_CLASS_DEFAULT __attribute__((availability(macosx,introduced=10.10))) = 0x15, QOS_CLASS_UTILITY __attribute__((availability(macosx,introduced=10.10))) = 0x11, QOS_CLASS_BACKGROUND __attribute__((availability(macosx,introduced=10.10))) = 0x09, QOS_CLASS_UNSPECIFIED __attribute__((availability(macosx,introduced=10.10))) = 0x00, }; typedef unsigned int qos_class_t;

I am probably seeing the "user error: syntax error" message because the __attribute__((availability(macosx,introduced=10.10))) syntax is not recognized. And in fact, once I added -D '__attribute__(...)=' to the CPP command to remove all attributes, I saw different errors:

/usr/include/sys/_types/_sigset_t.h:30:[kernel] user error: redefinition of 'sigset_t' in the same scope. Previous declaration was at FRAMAC_SHARE/libc/__fc_define_sigset_t.h:25
unix/gtkwin.c:143:[kernel] warning: Calling undeclared function GDK_DISPLAY. Old style K&R code?
unix/gtkwin.c:1766:[kernel] warning: Calling undeclared function GDK_ROOT_WINDOW. Old style K&R code?
unix/gtkwin.c:2636:[kernel] warning: Calling undeclared function GDK_WINDOW_XWINDOW. Old style K&R code?

I am using Frama-C Sodium-20150201.


TL;DR Try looking at the preprocessed input file.

Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
  • 1
    Thanks for this incredibly detailed answer. It seems that our parser does not support attributes on enum declarations (which I think is a GCC extension). Your solution to #define out `__attribute__` is probably the best solution for the time being. – byako Jul 13 '15 at 10:07
  • @DanielTrebbien I thought I had it working however I went to open the file and ended up getting the same error as before even with the pre-processed file. I tried using the extra Frama-C commands you included however those gave me errors as well. Namely: ``frama-c -kernel-msg-key pp -no-cpp-gnu-like -main pt_main -pdg -pdg-dot gtkwin.i [kernel] user error: option `-no-cpp-gnu-like' is unknown. use `frama-c -help' for more information. [kernel] Frama-C aborted: invalid user input.`` – Adam Jul 14 '15 at 20:50
  • @DanielTrebbien also yes I am using PuTTY for Unix – Adam Jul 14 '15 at 20:57
  • Hi @Adam. Try without the `-no-cpp-gnu-like` option. I only use that because Mac comes with Clang preinstalled, not gcc and GNU tools. – Daniel Trebbien Jul 14 '15 at 22:26
  • 1
    @Adam option `-no-cpp-gnu-like` is new in Frama-C Sodium. @Daniel Trebbien: for the usage we have in mind, Clang preprocessor is compatible enough with GCC, so you can instead set `-cpp-gnu-like`. – byako Jul 15 '15 at 12:04
0

So I ran the pre-processing and Frama-C command without -no-cpp-gnu-like. It seemed to give me a more in depth reason to why Frama-C won't run on the file, although I'm having trouble understanding it aside from it telling me to report a bug. Is this really a bug I need to report or a common Frama-C flag? Here is the dump when I tried to run Frama-C.

[kernel] /* compiler builtin: 
[kernel]    void *__builtin_frame_address(unsigned int);   */
gtkwin.c:77:[kernel] user error: syntax error
[kernel] Current source was: /usr/share/frama-c/libc/__fc_builtin_for_normalization.i:43
[kernel] The full backtrace is:
[kernel] Raised at file "cil/src/frontc/frontc.ml", line 127, characters 10-29
[kernel] Called from file "cil/src/frontc/frontc.ml", line 86, characters 13-38
[kernel] Called from file "cil/src/frontc/frontc.ml", line 140, characters 13-32
[kernel] Called from file "src/kernel/file.ml", line 913, characters 6-23
[kernel] Called from file "src/kernel/file.ml", line 1049, characters 23-30
[kernel] Re-raised at file "src/kernel/file.ml", line 1055, characters 52-55
[kernel] Called from file "list.ml", line 84, characters 24-34
[kernel] Called from file "src/kernel/file.ml", line 1046, characters 6-495
[kernel] Called from file "src/kernel/file.ml", line 1933, characters 12-30
[kernel] Called from file "src/kernel/file.ml", line 2017, characters 4-27
[kernel] Called from file "src/kernel/ast.ml", line 103, characters 2-28
[kernel] Called from file "src/kernel/ast.ml", line 114, characters 53-71
[kernel] Called from file "src/kernel/boot.ml", line 29, characters 6-20
[kernel] Called from file "src/kernel/cmdline.ml", line 732, characters 2-9
[kernel] Called from file "src/kernel/cmdline.ml", line 212, characters 4-8
[kernel] 
[kernel] Unexpected error (Parsing.Parse_error).
[kernel] Please report as 'crash' at http://bts.frama-c.com/.
[kernel] Your Frama-C version is Fluorine-20130601.
[kernel] Note that a version and a backtrace alone often do not contain enough
[kernel] information to understand the bug. Guidelines for reporting bugs are at:
[kernel] http://bts.frama-c.com/dokuwiki/doku.php?id=mantis:frama-c:bug_reporting_guidelines

Above it were a bunch more compiler builtin warnings, not sure if they are necessary to help understand the output or not. It seems like the pre-processing fixes some errors but not the one I need.

Adam
  • 33
  • 7
  • It seems that Daniel managed to parse this file. Can you try to upgrade Frama-C to Sodium, and report whether the crash stills occurs? If so, I will try to investigate. – byako Jul 15 '15 at 15:50
  • Actually, Daniel's parsing also failed, for other reasons. Still, upgrading to Sodium may help. – byako Jul 15 '15 at 15:51
  • Any suggestions on how to do that? I downloaded my version directly from the website, does Frama-C have an update option within it or will I have to get a whole new download and if so where do I get that? – Adam Jul 15 '15 at 15:55
  • You should install Sodium the same way you installed Fluorine: download the tarball, then configure/make/install. (Unless you downloaded a binary, but in this case, which one?) – byako Jul 15 '15 at 16:05
  • yeah it turns out I have the Sodium tarball unpacked, tried going through the install and have a lot of missing files. Not sure how I installed Fluorine since all I did was download and unpack the tarball... – Adam Jul 15 '15 at 16:15
  • I suggest you start another question for the compilation problem, and then we will come back to this one later. – byako Jul 15 '15 at 17:22