diff --git a/examples/xspice/d_process/README b/examples/xspice/d_process/README index 9031425c6..4405737c4 100644 --- a/examples/xspice/d_process/README +++ b/examples/xspice/d_process/README @@ -34,7 +34,11 @@ before ngspice prog-pipes.cir, and in another shell: needs to be started. -NOTE on debugging. On Linux or Cygwin on Windows, gdb can be attached to +The file checks.cir can be run to test the error handling in d_process. + +============================================================================== + +NOTE ON DEBUGGING. On Linux or Cygwin on Windows, gdb can be attached to the running d_process programs, or in --pipe mode with fifos, the graycode example can be run when invoked from gdb. @@ -42,13 +46,16 @@ From a Windows Powershell, WinDbg can be attached to a running d_process program. To enable the debugging hooks in the programs (graycode.c, prog1in4out.c, -prog4in1out.c), edit them to #define ENABLE_DEBUGGING. +prog4in1out.c), edit them to #define ENABLE_DEBUGGING. The debugging +hooks are in the debugging.h include file. Each program prints (to stderr) its process id when started. This makes it easier to know the process when attaching a debugger. All the programs (graycode.c, prog1in4out.c, prog4in1out.c) contain a call -to sleep to give you time to attach a debugger. This is enabled by: +to debug_info() which calls sleep() to give you time to attach a debugger. +Just after the sleep() call, there is a call to known_bp() on which you can +set a breakpoint. The sleep() is enabled by: export GO_TO_SLEEP=1 (on Linux, Cygwin) $env:go_to_sleep = '1' (on Windows Powershell) diff --git a/examples/xspice/d_process/checks.cir b/examples/xspice/d_process/checks.cir new file mode 100644 index 000000000..5953d8ab8 --- /dev/null +++ b/examples/xspice/d_process/checks.cir @@ -0,0 +1,44 @@ +checks.cir test error handling. + +*** analysis type *** +.tran .01us 10us +v1 1 0 DC 1.0 +v2 2 0 DC 0.0 + +.model d_osc1 d_osc (cntl_array=[-1.0 0.0 1.0 2.0] ++ freq_array=[1.0e6 1.0e6 4.0e6 4.0e6] ++ rise_delay=1.0e-6 fall_delay=2.0e-6) + +a1 1 clk1 d_osc1 +a2 2 clk2 d_osc1 + +** Too few outputs, 4 required +ap0 null clk1 null [q2 q3 q4] proc0 +.model proc0 d_process (process_file="graycode" process_params=["none"]) + +ap1 [clk2] clk1 null [o1 o2 o3 o4] proc1 +.model proc1 d_process (process_file="prog1in4out" process_params=["opt1", "qwerty"]) + +ap2 [o1 o2 o3 o4] clk1 null [zeros] proc2 +** Non existent process_file or missing fifos +** Unsupported fifo on Windows VisualC +.model proc2 d_process (process_file="badprog4in1out|" process_params=["abc", "99"]) + +ap3 [q1 q2 q3 q4] clk1 null [qzeros] proc3 +** Non existent process_file +.model proc3 d_process (process_file="prog4in1outxxx") + +an1 [o1 ~o2 o3] reseto dand1 +.model dand1 d_and(inertial_delay=true rise_delay=1ns fall_delay=50ns) + +ap4 [clk2] clk1 reseto [b1 b2 b3 b4] proc4 +** Empty process_file name +.model proc4 d_process (process_file="") + +.control +run +edisplay +quit +.endc +.end + diff --git a/examples/xspice/d_process/debugging.h b/examples/xspice/d_process/debugging.h new file mode 100644 index 000000000..44c3aa18b --- /dev/null +++ b/examples/xspice/d_process/debugging.h @@ -0,0 +1,40 @@ +#ifndef INCLUDED_DEBUGGING_H +#define INCLUDED_DEBUGGING_H + +static int known_bp(int iargc) +{ + return iargc; +} + +void debug_info(int argc, char **argv) +{ +#if defined(_MSC_VER) || defined(__MINGW64__) + fprintf(stderr, "%s pid %d\n", argv[0], _getpid()); +#else + fprintf(stderr, "%s pid %d\n", argv[0], getpid()); +#endif + +#if !defined(_MSC_VER) && !defined(__MINGW64__) + if (getenv("GO_TO_SLEEP")) { + sleep(40); + } +#endif +#if defined(__MINGW64__) + if (getenv("GO_TO_SLEEP")) { + sleep(40); + } +#endif +#if defined(_MSC_VER) + if (getenv("GO_TO_SLEEP")) { + Sleep(60000); + } +#endif + + (void)known_bp(argc); + + for (int i=0; i prog if $oscompiled = 1 | $oscompiled = 8 ; MS Windows shell start gtkwave prog1-4.vcd --script nggtk.tcl else - shell gtkwave prog1-4.vcd --script nggtk.tcl & + if $oscompiled = 7 ; macOS, manual tweaking required (mark, insert, Zoom Fit) + shell open -a gtkwave prog1-4.vcd + else ; Linux and others + shell gtkwave prog1-4.vcd --script nggtk.tcl & + end end quit .endc .end - - - - - diff --git a/examples/xspice/d_process/prog1in4out.c b/examples/xspice/d_process/prog1in4out.c index bb384cc6c..50c49d5aa 100644 --- a/examples/xspice/d_process/prog1in4out.c +++ b/examples/xspice/d_process/prog1in4out.c @@ -24,10 +24,7 @@ static int compute( //#define ENABLE_DEBUGGING 1 #ifdef ENABLE_DEBUGGING -static int known_bp(int iargc) -{ - return iargc; -} +#include "debugging.h" #endif int main(int argc, char *argv[]) { @@ -64,35 +61,9 @@ int main(int argc, char *argv[]) { #endif #ifdef ENABLE_DEBUGGING -#if defined(_MSC_VER) || defined(__MINGW64__) - fprintf(stderr, "%s pid %d\n", argv[0], _getpid()); -#else - fprintf(stderr, "%s pid %d\n", argv[0], getpid()); + debug_info(argc, argv); #endif -#if !defined(_MSC_VER) && !defined(__MINGW64__) - if (getenv("GO_TO_SLEEP")) { - sleep(40); - } -#endif -#if defined(__MINGW64__) - if (getenv("GO_TO_SLEEP")) { - sleep(40); - } -#endif -#if defined(_MSC_VER) - if (getenv("GO_TO_SLEEP")) { - Sleep(60000); - } -#endif - - (void)known_bp(argc); - - for (int i=0; i