diff --git a/vvp/Makefile.in b/vvp/Makefile.in index 4d91b9d1d..6f4c4cb80 100644 --- a/vvp/Makefile.in +++ b/vvp/Makefile.in @@ -16,7 +16,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.15 2001/05/01 01:09:39 steve Exp $" +#ident "$Id: Makefile.in,v 1.16 2001/05/05 23:55:46 steve Exp $" # # SHELL = /bin/sh @@ -42,6 +42,7 @@ STRIP = @STRIP@ CPPFLAGS = -I. -I$(srcdir)/.. @CPPFLAGS@ @DEFS@ -DMODULE_DIR=\"$(libdir)/ivl\" CXXFLAGS = @CXXFLAGS@ LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ dllib=@DLLIB@ rdynamic=@rdynamic@ @@ -60,11 +61,11 @@ check: all V = vpi_modules.o vpi_const.o vpi_iter.o vpi_mcd.o vpi_priv.o \ vpi_scope.o vpi_signal.o vpi_tasks.o vpi_time.o -O = main.o parse.o parse_misc.o lexor.o compile.o functor.o symbols.o \ -codes.o vthread.o schedule.o tables.o udp.o memory.o $V +O = main.o parse.o parse_misc.o lexor.o compile.o debug.o functor.o \ +symbols.o codes.o vthread.o schedule.o tables.o udp.o memory.o $V vvp: $O - $(CXX) $(rdynamic) $(CXXFLAGS) $(LDFLAGS) -o vvp $O $(dllib) + $(CXX) $(rdynamic) $(CXXFLAGS) $(LDFLAGS) -o vvp $O $(LIBS) $(dllib) %.o: %.cc diff --git a/vvp/codes.h b/vvp/codes.h index 4786e51d3..909114d7b 100644 --- a/vvp/codes.h +++ b/vvp/codes.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: codes.h,v 1.23 2001/05/02 23:16:50 steve Exp $" +#ident "$Id: codes.h,v 1.24 2001/05/05 23:55:46 steve Exp $" #endif @@ -40,6 +40,7 @@ extern bool of_ADD(vthread_t thr, vvp_code_t code); extern bool of_AND(vthread_t thr, vvp_code_t code); extern bool of_ASSIGN(vthread_t thr, vvp_code_t code); extern bool of_ASSIGN_MEM(vthread_t thr, vvp_code_t code); +extern bool of_BREAKPOINT(vthread_t thr, vvp_code_t code); extern bool of_CMPS(vthread_t thr, vvp_code_t code); extern bool of_CMPU(vthread_t thr, vvp_code_t code); extern bool of_CMPX(vthread_t thr, vvp_code_t code); @@ -127,6 +128,9 @@ extern void codespace_dump(FILE*fd); /* * $Log: codes.h,v $ + * Revision 1.24 2001/05/05 23:55:46 steve + * Add the beginnings of an interactive debugger. + * * Revision 1.23 2001/05/02 23:16:50 steve * Document memory related opcodes, * parser uses numbv_s structures instead of the diff --git a/vvp/compile.cc b/vvp/compile.cc index 5f1d69801..3d1800322 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: compile.cc,v 1.53 2001/05/02 23:16:50 steve Exp $" +#ident "$Id: compile.cc,v 1.54 2001/05/05 23:55:46 steve Exp $" #endif # include "compile.h" @@ -73,6 +73,7 @@ const static struct opcode_table_s opcode_table[] = { { "%and", of_AND, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%assign", of_ASSIGN, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} }, { "%assign/m",of_ASSIGN_MEM,3,{OA_MEM_PTR,OA_BIT1, OA_BIT2} }, + { "%breakpoint", of_BREAKPOINT, 0, {OA_NONE, OA_NONE, OA_NONE} }, { "%cmp/s", of_CMPS, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%cmp/u", of_CMPU, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%cmp/x", of_CMPX, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, @@ -1044,6 +1045,9 @@ void compile_dump(FILE*fd) /* * $Log: compile.cc,v $ + * Revision 1.54 2001/05/05 23:55:46 steve + * Add the beginnings of an interactive debugger. + * * Revision 1.53 2001/05/02 23:16:50 steve * Document memory related opcodes, * parser uses numbv_s structures instead of the diff --git a/vvp/config.h.in b/vvp/config.h.in index 14362e2a3..57ae4ea40 100644 --- a/vvp/config.h.in +++ b/vvp/config.h.in @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: config.h.in,v 1.3 2001/03/22 21:26:53 steve Exp $" +#ident "$Id: config.h.in,v 1.4 2001/05/05 23:55:46 steve Exp $" #endif # define SIZEOF_UNSIGNED_LONG 0 @@ -27,6 +27,7 @@ # undef HAVE_DLFCN_H # undef HAVE_DL_H +# undef HAVE_LIBREADLINE # define LU "" # define TU "" @@ -35,8 +36,15 @@ # define MODULE_DIR "." #endif +#if defined(HAVE_LIBREADLINE) +# define WITH_DEBUG 1 +#endif + /* * $Log: config.h.in,v $ + * Revision 1.4 2001/05/05 23:55:46 steve + * Add the beginnings of an interactive debugger. + * * Revision 1.3 2001/03/22 21:26:53 steve * Compile in a default VPI module dir. * diff --git a/vvp/configure.in b/vvp/configure.in index 9cce1504a..d10e22af1 100644 --- a/vvp/configure.in +++ b/vvp/configure.in @@ -10,6 +10,9 @@ AC_PROG_INSTALL AC_CHECK_SIZEOF(unsigned long) AC_CHECK_SIZEOF(unsigned) +AC_CHECK_LIB(termcap, tputs) +AC_CHECK_LIB(readline, readline) + # -- # Look for a dl library to use. First look for the standard dlopen # functions, and failing that look for the HP specific shl_load function. diff --git a/vvp/debug.cc b/vvp/debug.cc new file mode 100644 index 000000000..26d076221 --- /dev/null +++ b/vvp/debug.cc @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2001 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) +#ident "$Id: debug.cc,v 1.1 2001/05/05 23:55:46 steve Exp $" +#endif + +/* + * This file provides a simple command line debugger for the vvp + * runtime. It is a means to interract with the user running the + * simulation. + */ + +# include "config.h" + +#if defined(WITH_DEBUG) + +# include "debug.h" +# include "schedule.h" +# include +# include +# include +# include +# include + + +static bool interact_flag = false; + +static void cmd_go(unsigned, char*[]) +{ + interact_flag = false; +} + +static void cmd_time(unsigned, char*[]) +{ + unsigned long ticks = schedule_simtime(); + printf("%lu ticks\n", ticks); +} + +static void cmd_unknown(unsigned argc, char*argv[]) +{ + printf("Unknown command: %s\n", argv[0]); +} + +struct { + const char*name; void (*proc)(unsigned argc, char*argv[]); +} cmd_table[] = { + { "go", &cmd_go}, + { "time", &cmd_time}, + { 0, &cmd_unknown} +}; + +void breakpoint(void) +{ + printf("** VVP Interactive Debugger **\n"); + printf("Current simulation time is %lu ticks.\n", schedule_simtime()); + + interact_flag = true; + while (interact_flag) { + char*input = readline("> "); + unsigned argc = 0; + char**argv = new char*[strlen(input)/2]; + + for (char*cp = input+strspn(input, " ") + ; *cp; cp += strspn(cp, " ")) { + argv[argc] = cp; + + cp += strcspn(cp, " "); + if (*cp) + *cp++ = 0; + + argc += 1; + } + + if (argc > 0) { + unsigned idx; + for (idx = 0 ; cmd_table[idx].name ; idx += 1) + if (strcmp(cmd_table[idx].name, argv[0]) == 0) + break; + + cmd_table[idx].proc (argc, argv); + } + + delete[] argv; + free(input); + } +} + +#endif +/* + * $Log: debug.cc,v $ + * Revision 1.1 2001/05/05 23:55:46 steve + * Add the beginnings of an interactive debugger. + * + */ + diff --git a/vvp/debug.h b/vvp/debug.h new file mode 100644 index 000000000..a32738d90 --- /dev/null +++ b/vvp/debug.h @@ -0,0 +1,33 @@ +#ifndef __debug_H +#define __debug_H +/* + * Copyright (c) 2001 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) +#ident "$Id: debug.h,v 1.1 2001/05/05 23:55:46 steve Exp $" +#endif + +extern void breakpoint(void); + +/* + * $Log: debug.h,v $ + * Revision 1.1 2001/05/05 23:55:46 steve + * Add the beginnings of an interactive debugger. + * + */ +#endif diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index a0e392dc5..4a1d5567b 100644 --- a/vvp/opcodes.txt +++ b/vvp/opcodes.txt @@ -1,7 +1,7 @@ /* * Copyright (c) 2001 Stephen Williams (steve@icarus.com) * - * $Id: opcodes.txt,v 1.17 2001/05/02 23:16:50 steve Exp $ + * $Id: opcodes.txt,v 1.18 2001/05/05 23:55:46 steve Exp $ */ @@ -50,6 +50,17 @@ by index register 3. Bit address zero is the LSB of the first memory word. +* %breakpoint + +This instruction unconditionally breaks the simulator into the +interactive debugger. The idea is to stop the simulator here and give +the user a chance to display the state of the simulation using +debugger commands. + +This may not work on all platforms. If run-time debugging is compiled +out, then this function is a no-op. + + * %cmp/u , , * %cmp/s , , diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 96db63395..970032421 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -17,11 +17,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vthread.cc,v 1.34 2001/05/02 23:16:50 steve Exp $" +#ident "$Id: vthread.cc,v 1.35 2001/05/05 23:55:46 steve Exp $" #endif # include "vthread.h" # include "codes.h" +# include "debug.h" # include "schedule.h" # include "functor.h" # include "vpi_priv.h" @@ -338,6 +339,14 @@ bool of_ASSIGN_MEM(vthread_t thr, vvp_code_t cp) return true; } +bool of_BREAKPOINT(vthread_t thr, vvp_code_t cp) +{ +#if defined(WITH_DEBUG) + breakpoint(); +#endif + return true; +} + bool of_CMPS(vthread_t thr, vvp_code_t cp) { unsigned eq = 1; @@ -969,6 +978,9 @@ bool of_ZOMBIE(vthread_t thr, vvp_code_t) /* * $Log: vthread.cc,v $ + * Revision 1.35 2001/05/05 23:55:46 steve + * Add the beginnings of an interactive debugger. + * * Revision 1.34 2001/05/02 23:16:50 steve * Document memory related opcodes, * parser uses numbv_s structures instead of the