From 78f985af0e2d41a1cf6fb7b3b81928c17728f9e9 Mon Sep 17 00:00:00 2001 From: Cary R Date: Thu, 3 Mar 2011 18:54:46 -0800 Subject: [PATCH] Add trace command to interactive prompt to control statement tracing. This patch adds a trace command to the interactive prompt that can be used to control statement tracing when the code is instrumented (has %file_line opcodes). --- vvp/file_line.cc | 2 ++ vvp/stop.cc | 34 +++++++++++++++++++++++++++++++++- vvp/vpi_priv.h | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/vvp/file_line.cc b/vvp/file_line.cc index 6f8198be5..924f7d710 100644 --- a/vvp/file_line.cc +++ b/vvp/file_line.cc @@ -27,6 +27,7 @@ struct __vpiFileLine { }; bool show_file_line = false; +bool code_is_instrumented = false; static int file_line_get(int type, vpiHandle ref) { @@ -80,6 +81,7 @@ vpiHandle vpip_build_file_line(char*description, long file_idx, long lineno) /* Turn on the diagnostic output when we find a %file_line. */ show_file_line = true; + code_is_instrumented = true; obj->base.vpi_type = &vpip_file_line_rt; if (description) obj->description = vpip_name_string(description); diff --git a/vvp/stop.cc b/vvp/stop.cc index 07af64487..438a8785a 100644 --- a/vvp/stop.cc +++ b/vvp/stop.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2011 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 @@ -357,6 +357,36 @@ static void cmd_time(unsigned, char*[]) printf("%lu ticks\n", ticks); } +static void cmd_trace(unsigned argc, char*argv[]) +{ + assert(argc); + switch (argc) { + case 1: + show_file_line = true; + break; + default: + printf("Only using the first argument to trace.\n"); + case 2: + if ((strcmp(argv[1], "on") == 0) || (strcmp(argv[1], "1") == 0)) { + show_file_line = true; + } else show_file_line = false; + break; + } + + /* You can't trace a file if the compiler didn't insert the + * %file_line opcodes. */ + if (!code_is_instrumented) { + printf("The vvp input must be instrumented before tracing is " + "available.\n"); + printf("Recompile with the -pfileline=1 flag to instrument " + "the input.\n"); + show_file_line = false; + } else { + printf("Turning statement tracing %s.\n", + show_file_line ? "on" : "off"); + } +} + static void cmd_where(unsigned, char*[]) { struct __vpiScope*cur = stop_current_scope; @@ -412,6 +442,8 @@ static struct { "Single-step the scheduler for 1 event."}, { "time", &cmd_time, "Print the current simulation time."}, + { "trace", &cmd_trace, + "Control statement tracing (on/off) when the code is instrumented."}, { "where", &cmd_where, "Show current scope, and scope hierarchy stack."}, { 0, &cmd_unknown, 0} diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 49209dcfa..71c859fbc 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -45,6 +45,7 @@ #define _vpiDescription 0x1000004 extern bool show_file_line; +extern bool code_is_instrumented; extern vpiHandle vpip_build_file_line(char*description, long file_idx, long lineno);