problems compiling and running Nachos - nachos

First issue: I am trying to import stdlib.h in order to use functions like malloc() and rand(). I am working in threadtest.cc , folder threads. This is the error I get after
#include <stdlib.h>
In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:146:33: error: declaration of ‘double atof(const char*) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
from ../threads/system.h:12,
from ../threads/threadtest.cc:13:
../machine/sysdep.h:62:8: error: from previous declaration ‘double atof(const char*)’
In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:149:33: error: declaration of ‘int atoi(const char*) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
from ../threads/system.h:12,
from ../threads/threadtest.cc:13:
../machine/sysdep.h:61:5: error: from previous declaration ‘int atoi(const char*)’
In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:771:60: error: declaration of ‘int abs(int) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
from ../threads/system.h:12,
from ../threads/threadtest.cc:13:
../machine/sysdep.h:63:5: error: from previous declaration ‘int abs(int)’
../threads/threadtest.cc: In function ‘void shout(int)’:
../threads/threadtest.cc:83:25: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
What can be a reason for this?
Second issue: I am trying to give a forked new thread a name.
Thread * t = new Thread ("my id");
t->Fork(shout, S);
And testing it in function shout:
printf ("%s", currentThread->getName());
This example works fine.
However, if I want to give the thread a "dynamic" id, I use:
sprintf(id, "%d", i);
Thread * t = new Thread (id);
With the same printf for currentThread->getName() it gets me junk:
x�ӿ����_ ���
I have used example from the Nachos documentation as well as tried different ways to transmit a dynamic id using string functions, but nothing worked, only junk.
Thank you for any answers.

I had the same problem in my Nachos homework.
My roommate said maybe it's a incompatibility problem, and suggested that I delete "stdlib.h".
It worked!

Related

SysCTypes errors when using NetCDF.chpl?

I have a simple Chapel program to test the NetCDF module:
use NetCDF;
use NetCDF.C_NetCDF;
var f: int = ncopen("ppt2020_08_20.nc", NC_WRITE);
var status: int = nc_close(f);
and when I compile with:
chpl -I/usr/include -L/usr/lib/x86_64-linux-gnu -lnetcdf hello.chpl
it produces a list of errors about SysCTypes:
$CHPL_HOME/modules/packages/NetCDF.chpl:57: error: 'c_int' undeclared (first use this function)
$CHPL_HOME/modules/packages/NetCDF.chpl:77: error: 'c_char' undeclared (first use this function)
...
Would anyone see what my error is? I tried adding use SysCTypes; to my program, but that didn't seem to have an effect.
Sorry for the delayed response and for this bad behavior. This is a bug that's crept into the NetCDF module which seems not to have been caught by Chapel's nightly testing. To work around it, edit $CHPL_HOME/modules/packages/NetCDF.chpl, adding the line:
public use SysCTypes, SysBasic;
within the declaration of the C_NetCDF module (around line 50 in my copy of the sources). If you would consider filing this bug as an issue on the Chapel GitHub issue tracker, that would be great as well, though we'll try to get this fixed in the next release in any case.
With that change, your program almost compiles for me, except that nc_close() takes a c_int argument rather than a Chapel int. You could either lean on Chapel's type inference to cause this to happen:
var f = ncopen("ppt2020_08_20.nc", NC_WRITE);
or explicitly declare f to be of type c_int:
var f: c_int = ncopen("ppt2020_08_20.nc", NC_WRITE);
And then as one final note, I believe you should be able to drop the -lnetcdf from your chpl command-line as using the NetCDF module should cause this requirement to automatically be added.
Thanks for bringing this bug to our attention!

Frama-C aborted Invalid user input

I am very new to Frama-c and I got an issue when I am trying to open a C source file.
The error shows as
"fatal error: event.h: No such file or directory. Compilation terminated".
[kernel] Parsing FRAMAC_SHARE/libc/__fc_builtin_for_normalization.i (no preprocessing)
[kernel] Parsing WorkSpace/bipbuffer.c (with preprocessing)
[kernel] user error: failed to run: gcc -E -C -I. -dD -D__FRAMAC__ -nostdinc -D__FC_MACHDEP_X86_32 -I/usr/share/frama-c/libc -o '/tmp/bipbuffer.ce6d077.i' '/home/xxx/WorkSpace/bipbuffer.c' you may set the CPP environment variable to select the proper preprocessor command or use the option "-cpp-command".
[kernel] user error: stopping on file "/home/xxx/WorkSpace/bipbuffer.c" that has errors. Add'-kernel-msg-key pp' for preprocessing command.
So bascially I am trying to open a C source file but it returns an error like this. I aslo tried other very simple C files like hello world and other slicing functions, it works well.
I thought it was because I didn't have the dependencies of 'event.h' but it still return these errors after I installed the libevent dependencies. I am not sure if I need to manually set some path of the dependencies for frama-c
Here is part of the C file (Source link: https://memcached.org/) that I would like to open:
#include "stdio.h"
#include <stdlib.h>
/* for memcpy */
#include <string.h>
#include "bipbuffer.h"
static size_t bipbuf_sizeof(const unsigned int size)
{
return sizeof(bipbuf_t) + size;
}
int bipbuf_unused(const bipbuf_t* me)
{
if (1 == me->b_inuse)
/* distance between region B and region A */
return me->a_start - me->b_end;
else
return me->size - me->a_end;
}
......
Thanks,
Compilers and other tools working with C source code need to know where to find header files. There are some standard places where they look automatically, but Frama-C has fewer of those than (and different ones from) a normal compiler.
You need to find out where event.h is installed, then pass something like -cpp-extra-args "-I /path/to/directory/" to Frama-C. Pass the directory name only, not including the name event.h itself.
In addition to Isabelle Newbie's answer, I'd like to point out that the Chlorine version of Frama-C, whose beta has been recently announced, features a new option -json-compilation-database that attempts to read the arguments to be passed to the pre-processor from a compilation database.
Such database can be generated directly by cmake, but there are solutions for make-based project such as the one you refer to, in particular bear, which intercepts the commands launched by make to build the database.
Here's a detailed summary of how you could proceed, using the new -json-compilation-database option from Frama-C 17 Chlorine, plus an extra script list_files.py (which is not in the beta, but will be available in the final 17 release, and can be downloaded here):
Get the source files you want to analyze with Frama-C, run ./configure, and if possible try to disable optional dependencies from external libraries; for instance, some code bases include optional dependencies based on availability of libraries/system features, but have fallback options (resorting to standard C library or POSIX functions). The more you give Frama-C, the better the chances of analyzing it well, so if such external libraries are not essential, excluding them might help get a more "POSIXy" code, which should help. This is typically visible in config.h files, in macros commonly named HAVE_*.
Compile and install Build EAR or some equivalent tool to obtain a compile_commands.json file.
Run bear make (or cmake with flag CMAKE_EXPORT_COMPILE_COMMANDS) to get the compile_commands.json file.
Run the aforementioned list_files.py in the directory containing compile_commands.json to obtain the list of C sources used during compilation.
Run Frama-C (17 Chlorine or newer), giving it the list of sources found in the previous step, plus option -json-compilation-database . to parse the compile_commands.json and, hopefully, get the appropriate preprocessing flags.
Ideally, this should suffice, but in practice, this is rarely enough. In particular due to the presence of external libraries and non-C99, non-POSIX functions, the following steps are always needed.
6. Inclusion of external libraries
At this step, Frama-C will complain about the lack of event.h. You'll have to include the headers of this library yourself. Note: copying headers directly from your /usr/include is not likely to work, due to several architecture-specific definitions, especially files such as bits/*.h..
Instead, consider downloading the external libraries and preparing them (e.g. running ./configure at least). Then manually add the extra include directory via -cpp-extra-args="-I <path/to/your/sources/for/libevent.h>/include".
7. Inclusion of missing non-POSIX headers
Some other headers may be missing, in particular GNU- or BSD-specific sources (e.g. sysexits.h). Get these headers and add them when necessary. The error message in this case comes from the preprocessor (gcc) and is similar to this:
memcached.c:51:10: fatal error: sysexits.h: No such file or directory
#include <sysexits.h>
^~~~~~~~~~~~
compilation terminated.
8. Definition of missing non-POSIX types and constants
At this point, all necessary headers should be available, but parsing with Frama-C may still fail. This is due to usage of non-POSIX type definitions (e.g. caddr_t, struct ling), non-POSIX constants (e.g. MAXPATHLEN, SOCK_NONBLOCK, NI_MAXSERV). Error messages typically resemble the following:
[kernel] memcached.c:3261: Failure: Cannot resolve variable MAXPATHLEN
Constants are often easy to provide manually, by grepping what's available in your /usr/include.
Type definitions, on the other hand, may require some copy-pasting at the right places, especially if they depend on other types which are also missing. This step is hardly automatizable, but relatively straightforward once you get used to some specific error messages.
For instance, the following error message is related to a missing type definition (caddr_t):
[kernel] Parsing memcached.c (with preprocessing)
[kernel] memcached.c:1074:
syntax error:
Location: line 1074, between columns 38 and 47, before or at token: c
1072 *hdr++ = 0;
1073 *hdr++ = 0;
1074 assert((void *) hdr == (caddr_t)c->msglist[i].msg_iov[0].iov_base + UDP_HEADER_SIZE);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1075 }
1076
Note that the token just before c is (caddr_t), which has never been defined (it is often defined as either void * or char *).
The following error message is related to an incomplete type, i.e., a struct used somewhere but never defined:
[kernel] memcached.c:5811: User Error:
variable `ling' has initializer but incomplete type
It means that variable ling's type, which is struct linger (non-POSIX), has never been defined. In this case, we can copy it from our /usr/include/bits/socket.h:
struct linger
{
int l_onoff; /* Nonzero to linger on close. */
int l_linger; /* Time to linger. */
};
Note: if there are POSIX constants/definitions missing from Frama-C's libc, consider notifying its developers, or proposing pull requests in Frama-C's Github.
9. Fixing incompatible and missing function prototypes
Parsing is likely to succeed after the previous step, but it may still fail due to incompatible function prototypes. For instance, you may get:
[kernel] User Error: Incompatible declaration for usleep:
different integer types int and unsigned int
First declaration was at assoc.c:238
Current declaration is at items.c:1573
This is the consequence of a warning emitted earlier:
[kernel:typing:implicit-function-declaration] slabs.c:1150: Warning:
Calling undeclared function usleep. Old style K&R code?
It means that function usleep is called, but it does not have a prototype, therefore Frama-C uses the pre-C99 convention of "implicit int": it generates such a prototype, but later in the code, an actual declaration of usleep is found, and its type is not int. Hence the error.
To prevent this, you need to ensure usleep's prototype is properly included. Since it is not POSIX.1-2008, you need to either define/undefine the appropriate macros (see unistd.h), or add your own prototype.
At the end, this should allow Frama-C to parse the files and build an AST.
However, there are several missing prototypes yet; we were just lucky that none conflicted with actual declarations. Ideally, you'll consider the parsing stage done when there are no more messages such as implicit-function-declaration and similar warnings.
Some of the missing prototypes in memcached, such as getsubopt, are POSIX and should be integrated into Frama-C's standard library. Others might make part of a small library of non-standard stubs, to be reused for other software.
Contributing with results for future reuse
Successful conclusion of the parsing stage for such open source libraries is enough to consider them for integration into this repository of open source case studies, so that future users can start their analyses without having to redo all of these steps. (The repository is oriented towards Eva, but not exclusively: parsing is useful for all of Frama-C plug-ins.)

Multiple classes in a single file leads to overload warnings

I've recently started playing around with the closure compiler and ES6, and I've noticed something that I think is a bit strange. When I compile the following code:
export class Test
{
constructor(arg)
{
this.arg = arg;
}
}
class Test2
{
constructor(diffArg)
{
this.diffArg = diffArg;
}
}
I get this output when I compile with ADVANCED:
java -jar closure-compiler-v20170910.jar --compilation_level ADVANCED --language_in ECMASCRIPT6_TYPED --language_out ECMASCRIPT5 --js_output_file ui.js --js javascript/*.js --externs javascript/externs/externs.js --jscomp_off missingProperties
Test.js:11: WARNING - Function and method overloads are not supported and type information might be lost
constructor(diffArg)
^^^^^^^^^^^^^^^^^^^^^^
Test.js:5: ERROR - variable arg is undeclared
this.arg = arg;
^^^
It looks like the compiler is complaining because there are two functions with the same name in the file - even though they are in different classes - and the error comes in because the second function replaces the first. If I compile with SIMPLE, I get the warning but not the error, and the emitted code seems to contain the second constructor definition. To get the code to compile properly, I need to put each class into its own file.
My question is whether this is expected behavior or not - I don't believe that there is anything in the ES6 spec about only having one class per file, and since each function is in a different class, I would have expected that I can use the same name for each of them (especially for the constructor). Is there a way to get around this, or is having each class in its own file the right way to go?

Error during compile of Megablink demo using freeRTOS for atmega2560 using WinAVR

The following RTOS .c files compile fine during 'make':
task.c, queue.c, tasks.c, croutines.c, list.c
Then I get the following error:
serial.c: In function 'xSerialPortReInit'
serial.c: 665:error: 'ulWantedBaud' undeclared (first use in this
function)
serial.c: 665:error: (Each undeclared identifier is reported only
once for each function it appears in)
make: ***[serial.o]Error 1
I have checked that all include files identified in serial.c are available
Why do you think it is an include file problem? ulWantedBaud is more likely to be a function parameter, or file scope variable, that is misspelled. The AVR demo in the official FreeRTOS download (whic is very old and probably not the best reference) contains a serial port init function with such a parameter, although not a re-init function as per your post:
xComPortHandle xSerialPortInitMinimal( uint32_t ulWantedBaud, uint8_t uxQueueLength );
(This snippet is from http://www.freertos.org/a00098.html)

warning undefined reference to arduino due in multiwii

I try to compile multiwii code on DUE https://github.com/HefnySco/MultiWii_DUE
I keep getting
C:\Users\MCA9A~1.HEF\AppData\Local\Temp\build4616066844745192383.tmp\EEPROM.cpp.o: In function eeprom_write_block(void*, void*, unsigned int)
C:\Users\MCA9A~1.HEF\AppData\Local\Temp\build4616066844745192383.tmp/Sensors.cpp:307: warning: undefined reference toWire'
I made a separate project to simulate the case and created file called class1.cpp and included Wire_DUE.h and then called it from the main project class Sample1.cpp and it worked using the very same Wire_DUE code.
Kindly advise
At last after 4 days I found the answer.
I used this in def.h
#if defined (__CM3_REV)
#define ARDUINO_DUE
#endif
and when I updated to this
#if defined (ARDUINO_ARCH_SAM)
#define ARDUINO_DUE
#endif
it works .... pls not that in both cases ARDUINO_DUE is defined .... but not sure what is the difference exactly as in both ways ARDUINO_DUE is active.... seems that in some .cpp files it is not active due to other declarations that conflict with __CM3_REV

Resources