Importing large programs in FramaC - c

I have just started learning FramaC for testing of IOT programs. Is there a way to analyse large programs such as IoT OS in Frama C efficiently? How to import single modules without compiling for analysis as the presence of header files is causing errors.How can we import only certain modules and then analyze them. Any advice would be appreciated. Thank You.
root#nirnai:/home/vboxuser# frama-c-gui
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)
Error creating proxy: The connection is closed (g-io-error-quark, 18)
(frama-c-gui:2821): dconf-WARNING **: 16:22:40.318: failed to commit changes to dconf: The connection is closed
/home/vboxuser/Downloads/RIOT-master/core/thread.c:29:10: fatal error: thread.h: No such file or directory
29 | #include "thread.h"
| ^~~~~~~~~~
compilation terminated.
(frama-c-gui:2821): dconf-WARNING **: 16:22:50.987: failed to commit changes to dconf: The connection is closed

You can't avoid having all the #include needed to analyze a C source file. In fact Frama-C uses an external pre-processor (GNU cpp by default), and this pre-processor needs to be provided all the appropriate headers. On the other hand, depending on the kind of analysis you want to do, you may be able to analyze C source files one by one or not: typically the WP plug-in provides a modular analysis, while an Eva analysis usually requires having the body of all the functions that can be called from the entry point you have chosen.
Now, in order for us to give a more meaningful answer, you need to show us exactly how you intend to parse your source files with Frama-C, that is by using the command line tool and not the menu in the GUI. Usually, you need to provide some pre-processing directives, either via the -cpp-extra-args option or a compilation database file and the -json-compilation-database option. Chapter 5 of the Frama-C user manual explains in detail how to provide the appropriate pre-processing arguments. In addition, Chapter 12 introduces the various scripts that help setting up an appropriate environment for analyzing complex projects with Frama-C.
On a side note (because of the #include <thread.h> in your question), note that Frama-C is not equipped now to deal with multi-threaded programs: depending on whether a shared memory variable is declared volatile or not, analyses will either assume that the value is completely unknown or will only change when assigned explicitly in the code (i.e. ignoring possible interaction from another thread).

Related

Codenamone One Online Build Failure

We added new features to our data collection mobile application after two -three months of inactivity, only for the build to keep failing.
This is the stack trace
ll-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
1 error; aborting
:transformClassesWithDexForRelease FAILED
:transformClassesWithDexForRelease (Thread[Daemon worker,5,main]) completed. Took 11.045 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --verbose --force-jumbo --num-threads=4 --output /tmp/build8570106392456281219xxx/Application/build/intermediates/transforms/dex/release/0 --min-sdk-version 15 /tmp/build8570106392456281219xxx/Application/build/intermediates/transforms/proguard/release/0.jar}
You or one of the cn1libs you are using included a javax.xml package as part of the code. We migrated to build target 27 over the weekend and I'm guessing that Google made checks for this sort of problem more rigid.
I see a lot of keep statements in your build hints so I'm guessing this was done intentionally.

Omnimark file processing fails

We have the omnimark script that takes 2gb sgml file size as input and output the file which is around 2.2 gb.The script is called from unix shell script and we are facing issues that sometimes script runs successfully and sometime it just aborted with no error....any idea or suggestions how to debug this?
I have seen this type of issue before in running OmniMark v5.3 when the script bombs due to lack of server resources/memory.
If you've specified writing to a log file, e.g. using -log logfilename.txt, then you would see something like an error code #3000 "insufficient memory error".
http://developers.omnimark.com/docs/html/error/3000.htm
If no log file, then initial step would be to run the script in a console session so that any such abort message is visible.
Stilo have a page listing fixes in various versions of OmniMark
http://developers.omnimark.com/docs/html/concept/806.htm
This mentions a variety of memory-related issues in various versions of the software (e.g. use of certain translate rules) which may help some investigation.
Alternatively, you could add to the script writing to a debug log file (with a global switch to activate debug on or off (so you don't waste further I/O resources when you don't need to)). Debug log file should be unbuffered. At certain breakpoints in the script add a message. The more verbose the better at narrowing down where/when the error is, but with the size of file I suggest it's a I/O or memory error.
Also depends what version of OmniMark you're using.

Compiling using VS tools and Tup build-system

I am trying to compile an interpreter for the J programming language called "unbox" which can be found at: https://github.com/iocane/unbox
It uses the tup build-system and the github instructions specify to use the tup command from the Visual Studio tools prompt. I downloaded Visual Studio 2015 Community but it doesn't come with the exact prompt mentioned in the instructions so I used the VS2015 x86 x64 Cross Tools Command Prompt. After installing tup and adding it to my path, I navigated to the directory where I cloned "unbox" and typed tup.
However, this is where the problems start, after typing tup I get the following:
* 1) CC src/libj\a.c
a.c
*** tup errors ***
tup error: File 'C:\Users\I\AppData\Local\Microsoft\VSCommon\14.0\SQM\VCToolsTelemetry.dat' was written to, but is not in .tup/db. You probably should specify it as an output
*** Command ID=663 ran successfully, but tup failed to save the dependencies.
* 2) CC src/libj\af.c
af.c
*** tup errors ***
tup error: File 'C:\Users\I\AppData\Local\Microsoft\VSCommon\14.0\SQM\VCToolsTelemetry.dat' was written to, but is not in .tup/db. You probably should specify it as an output
*** Command ID=667 ran successfully, but tup failed to save the dependencies.
* 3) CC src/libj\ai.c
ai.c
*** tup errors ***
tup error: File 'C:\Users\I\AppData\Local\Microsoft\VSCommon\14.0\SQM\VCToolsTelemetry.dat' was written to, but is not in .tup/db. You probably should specify it as an output
*** Command ID=669 ran successfully, but tup failed to save the dependencies.
* 4) CC src/libj\ab.c
ab.c
*** tup errors ***
tup error: File 'C:\Users\I\AppData\Local\Microsoft\VSCommon\14.0\SQM\VCToolsTelemetry.dat' was written to, but is not in .tup/db. You probably should specify it as an output
*** Command ID=665 ran successfully, but tup failed to save the dependencies.
[ ETA~=30s Remaining=130 Active=0 ] 2%
*** tup: 4 jobs failed.
As you can see, the file VCToolsTelemetry.dat was not specified in tup's database.
Does anybody know a way to prevent Visual Studio from using VSToolsTelemetry.dat at all? Or should I contact the unbox developer and have him add that file to the db?
Any help is much appreciated.
The solution was given by Christian Fillion in this comment.
This Microsoft page explains what that file is for and how to prevent Visual Studio tools from writing to it:
By default, the Visual Studio installation enables customer feedback. You can configure Visual Studio to disable customer feedback on individual computers by changing the value of the following registry key to string "0".
The key referred to is OptIn. According to that page, it is located in HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\VisualStudio\SQM, although it could also be in HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VSCommon\14.0\SQM (this was the case in my Windows 10 laptop).
(The Microsoft page also says it should be a string, but in my case it's a DWORD and it works fine.)
Or should I contact the unbox developer and have him add that file to the db?
What's happening is that Tup, a file-based build system, requires that all outputs of a command be specified, but this file is not, and so Tup complains when it detects that it's written to. For Tup, there is no difference between creating and writing to a file — in both cases, it's an ‘output’. Thus, Tup doesn't handle situations in which several commands write to the same file. This often causes problems with caches, which are designed to be written to incrementally. If I recall correctly, Tup has a workaround implemented whereby it ignores output files whose path comprises any component with a leading period. In Linux environments, a directory whose name starts with a leading period is considered ‘hidden’, unlike in Windows, where this feature is implemented with a file-system attribute. This workaround thus generally fails with Windows native tools, which don't rely on such naming convention. A more flexible solution on Tup's side would be a way of telling Tup to ignore certain outputs, either in a system or user basis or from within Tupfiles.
It wouldn't be possible to list this file as an output because it would become an output of all invocations of CL.EXE (and possibly other Visual Studio tools), and this doesn't make sense per Tup's design. There's definitely no intention to make room in it for files which are read from and written to by the same command, since it's impossible to automate such scenario. Even if this file was only written to, I think there are no intentions to support incrementally-written outputs.
Since the project seems to be committed to some platforms and provides build instructions for them, it seems reasonable to point out the issue and the solution to them so they can include it in the instructions.

How does a Client (Written in C) listens to a request on Linux OS?

I am a beginner and I want to understand some basics of Client-Server applications written in C (I understand web based server-client applications written in Java, PHP ,etc).
To be more specific, I am talking about ZABBIX which is a client-server tool (Zabbix_server is a server and zabbix_agentd is a client, both written in C).
Zabbix_server asks zabbix_agentd for data and zabbix_agents responds accordingly.
I have imported zabbix codes on Eclipse and have tried to debug to understand codes. A complete execution of zabbix_agentd on Eclipse just launched the daemon successfully and created a child process. But when I check the log, I find that different functions are being called which had not come in the way while debugging. It means, these functions are called by some process, may be inetd, etc. (correct me if i am wrong). I tried to find inetd on RHEL 6.4 OS, but it was no where found (using "service inetd status", "find").
So, how those functions are being called? Can anyone please give me ideas about that?
Please suggest me how to use those calling requests to further debug my client application.
One thing I have noticed while debugging Eclipse is that, I get below error after calling fork():
No source available for "fork() at 0x36ca0acbc0"
I couldn't understand the impact of the above error as the daemon keeps on working after this error also.
I browsed through similar error different people getting and found that their binaries were not linked to sources. However, my binaries are linked to sources also. I mean, expanding the binary of zabbix_agentd shows several *.h and *.c files.
As this error terminates the debugger immediately but the line of code at this occurrence is the last line of the source file also. So, I cannot say if I need to take care for this error.
Is this error the reason why I am not able to view other functions being called?
Please let me know if more information is required.
Thanks in advance.
Regards,
Rohit

Is there any way to replicate a memory can't be read error message in my C# application?

Let me state upfront that I truly appreciate any assistance on this issue.
I have a C# (2.0) application. This is relatively simple application that executes stored procedures based on an XML file that is passed as a command line parameter.
We use it as a tool to call different stored procedures. This application does some logging and for the most part works very well.
The application reads the stored procedure name and parameters from an XML file. It sets up a connection string and SQL Command object (System.Data.SqlClient.SqlCommand).
Then it runs the stored procedure with the ExecuteReader method.
Unfortunately on a handful of occasions this application has generated the following error:
“Application popup: StoredProcLauncher.exe - Application Error : The instruction
at "0x7c82c912" referenced memory at "0x00000000". The memory could not be "read”
This error has appeared on multiple servers so it must be a code issue.
It seems that when our production server rolls a certain number it belches out this memory error.
The problem is I don’t see this issue on development. I can’t replicate it so I’m stuck.
Is there any way to simulate this error. Can I fill up the memory on my local PC somehow to attempt to replicate this error?
Does anyone know some common coding issues that might result in an error like this?
Does anyone have some rope I can borrow?
One way to do this is to wrap the offending code in a try catch block and writing the stack trace and error message to the windows application event log, text file, email, etc.
This will give you some line numbers and additional information.
Also note, you may need to deploy this in debug mode or at least copy the .pdb file with the application exe/dll so it can get the debug symbols. Can't remember off the top of my head how that works, but I think when you deploy in release mode you may loose some valuable debug information.
The instruction at "0x7c82c912" referenced memory at "0x00000000"
This is an access violation:
An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access. This usually occurs because a pointer has a bad value.
Why does your program have unmanaged/unsafe code? For doing what you described it needs no native code.
Alas, the code crashes and now is not the time to wonder how is ending up calling native code. To solve the issue you're going to have to catch a dump and analyze the dump. See Capturing Application Crash Dumps. There are tools that specialize in this, like breakpad. there are also services that can help you collect and track crashes generated from your app, like crittercism.com or AirBrake. I even created one for myself and made it public bugcollect.com.

Resources