[Contents] [TitleIndex] [WordIndex

How to debug an external source code linked to Scilab with Visual Studio

With Scilab 5 , you can debug an external source code linked to Scilab with Visual Studio 200x.

Here , a easy example:

You need :

- Scilab 5.x (rev.26727 or more)

- Visual Studio C++ 200x (Pro or express) - example files intfun1.c, fun1.c, fun2.c

intfun1.c

#include "stack-c.h"
#include "stackTypeVariable.h"
extern int fun1 ( double *x, double *y);
int intfun1(char *fname)
{
  int m1,n1,l1;
  CheckRhs(1,1);
  CheckLhs(1,1);
  GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); /* Note that this code is deprecated and should be replaced by API_Scilab */
  fun1(stk(l1),stk(l1));
  LhsVar(1) = 1;
  return 0;
}

fun2.c

extern double fun2();
void fun1(double *x, double *y)
{
  *y=fun2(*x)/(*x);
}

fun1.c

#include <math.h>
double fun2(double x)
{
  return( sin(x+1.));
}

copy files in a directory ( here d:\example_debug )

launch visual studio launch scilab

--> setenv('DEBUG_SCILAB_DYNAMIC_LINK','YES')

This command defines 'DEBUG_SCILAB_DYNAMIC_LINK' environment variable.

External code built with ilib_build will use debug mode.

By default , you built with release mode .

--> cd d:\example_debug
--> files=['fun1.c','fun2.c','intfun1.c'];
--> ilib_build('foo',['scifun1','intfun1'],files,[]);

creates a dll (dynamic link), see help ilib_build

--> exec loader.sce

load dynamic library in scilab

We can call scifun1 primitive in scilab This primitive calls intfun1 C function

Go to in Visual Studio File -> Open -> File ...

and select intfun1.c

Attach scilab process to Visual Studio debugger

Debug -> Attach to Process ...

d__attachtoprocess.jpg

and select scilab process (wscilex.exe)

Put a breakpoint in intfunc.c

d_breakpoint.jpg

for example, on fun1(stk(l1),stk(l1));

go to scilab and call your primitive (here scifun1)

--> scifun1(33)

Visual studio stops code on your breakpoint.

You can debug your code source ...

If you want to open the debugger each time an exception is raised by Scilab, open Debug->Exception:

debug_visual.jpg

And check all the exception you want to catch.

Now, each time Scilab will print this kind of message:

Warning !!! Scilab has found a critical error (EXCEPTION_ACCESS_VIOLATION)

Visual studio will open the debugger on the problematic piece of code of your code.


2022-09-08 09:27