From cb3981e5fcd62578883d6cae68b2d427767a47e7 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Wed, 13 Nov 2013 09:32:40 +0100 Subject: [PATCH 01/20] automake: don't treat warnings as errors. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4a81bb1..4f880af 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ # common initialisation of autotools #### AC_INIT([SimulAVR], [1.1dev], [simulavr-devel@nongnu.org]) -AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign]) +AM_INIT_AUTOMAKE([1.10 -Wall foreign]) AC_PREREQ([2.61]) AC_CONFIG_MACRO_DIR([m4]) AM_MAINTAINER_MODE From 74c903349a322830c795d5916279962f5cabcd8c Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Tue, 19 Nov 2013 19:26:34 +0100 Subject: [PATCH 02/20] src/avrerror.h: fix a number of compilation warnings. --- src/avrerror.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/avrerror.h b/src/avrerror.h index 0a8d7b0..c75ceca 100644 --- a/src/avrerror.h +++ b/src/avrerror.h @@ -32,8 +32,12 @@ #define ATTRIBUTE_NORETURN __declspec(noreturn) #define ATTRIBUTE_PRINTF(string_arg, first_arg) #elif defined(__GNUC__) +#ifndef ATTRIBUTE_NORETURN #define ATTRIBUTE_NORETURN __attribute__((noreturn)) +#endif +#ifndef ATTRIBUTE_PRINTF #define ATTRIBUTE_PRINTF(string_arg, first_arg) __attribute__ ((format (printf, string_arg, first_arg))) +#endif #else #define ATTRIBUTE_NORETURN #define ATTRIBUTE_PRINTF(string_arg, first_arg) From faa97b1137e043c693e6b7290ac9e4185ee50d3d Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 16 Nov 2013 17:00:57 +0100 Subject: [PATCH 03/20] src/avrerror.cpp: fix MESSAGE handling. --- src/avrerror.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/avrerror.cpp b/src/avrerror.cpp index 1c26b47..2015b85 100644 --- a/src/avrerror.cpp +++ b/src/avrerror.cpp @@ -133,9 +133,10 @@ void SystemConsoleHandler::vfmessage(const char *file, int line, const char *fmt va_start(ap, fmt); vsnprintf(messageStringBuffer, sizeof(messageStringBuffer), mfmt, ap); va_end(ap); - if(fmt[strlen(fmt) - 1] != '\n') - *wrnStream << std::endl; *msgStream << messageStringBuffer; + if(fmt[strlen(fmt) - 1] != '\n') + *msgStream << std::endl; + msgStream->flush(); } void SystemConsoleHandler::vfwarning(const char *file, int line, const char *fmt, ...) { From 65957743fdc96b243f9ac7bc4136ced336491b13 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 16 Nov 2013 23:10:06 +0100 Subject: [PATCH 04/20] src/avrerror.cpp: simplify plain messages. --- src/avrerror.cpp | 8 +++++--- src/avrerror.h | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/avrerror.cpp b/src/avrerror.cpp index 2015b85..a67d656 100644 --- a/src/avrerror.cpp +++ b/src/avrerror.cpp @@ -127,11 +127,13 @@ void SystemConsoleHandler::TraceNextLine(void) { } } -void SystemConsoleHandler::vfmessage(const char *file, int line, const char *fmt, ...) { +void SystemConsoleHandler::vfmessage(const char *fmt, ...) { va_list ap; - char *mfmt = getFormatString("MESSAGE", file, line, fmt); + snprintf(formatStringBuffer, sizeof(formatStringBuffer), + "MESSAGE %s", fmt); va_start(ap, fmt); - vsnprintf(messageStringBuffer, sizeof(messageStringBuffer), mfmt, ap); + vsnprintf(messageStringBuffer, sizeof(messageStringBuffer), + formatStringBuffer, ap); va_end(ap); *msgStream << messageStringBuffer; if(fmt[strlen(fmt) - 1] != '\n') diff --git a/src/avrerror.h b/src/avrerror.h index c75ceca..9e752f9 100644 --- a/src/avrerror.h +++ b/src/avrerror.h @@ -74,8 +74,8 @@ class SystemConsoleHandler { void TraceNextLine(void); //! Format and send a message to message stream (default stdout) - void vfmessage(const char *file, int line, const char *fmt, ...) - ATTRIBUTE_PRINTF(4, 5); + void vfmessage(const char *fmt, ...) + ATTRIBUTE_PRINTF(2, 3); //! Format and send a warning message to warning stream (default stderr) void vfwarning(const char *file, int line, const char *fmt, ...) ATTRIBUTE_PRINTF(4, 5); @@ -127,7 +127,7 @@ extern int global_verbose_on; //! Helper function for writing trace (trace IO access) void trioaccess(const char *t, unsigned char val); -#define avr_message(fmt, ...) sysConHandler.vfmessage(__FILE__, __LINE__, fmt, ## __VA_ARGS__) +#define avr_message(fmt, ...) sysConHandler.vfmessage(fmt, ## __VA_ARGS__) #define avr_warning(fmt, ...) sysConHandler.vfwarning(__FILE__, __LINE__, fmt, ## __VA_ARGS__) #define avr_failure(fmt, ...) sysConHandler.vferror(__FILE__, __LINE__, fmt, ## __VA_ARGS__) #define avr_error(fmt, ...) sysConHandler.vffatal(__FILE__, __LINE__, fmt, ## __VA_ARGS__) From 179be746c0a228b571b89a29d3adcd72291afebe Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 16 Nov 2013 23:37:37 +0100 Subject: [PATCH 05/20] Use avr_message() for verbose messages. This enhances encapsulation and simplifies code, both of which are generally considered to be a good thing. --- src/avrdevice.cpp | 3 +-- src/avrerror.cpp | 3 +++ src/cmd/main.cpp | 50 ++++++++++++++++------------------------------- src/hwstack.cpp | 3 +-- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/avrdevice.cpp b/src/avrdevice.cpp index 37b236d..aff75a7 100644 --- a/src/avrdevice.cpp +++ b/src/avrdevice.cpp @@ -275,8 +275,7 @@ int AvrDevice::Step(bool &untilCoreStepFinished, SystemClockOffset *nextStepIn_n } if(EP.end() != find(EP.begin(), EP.end(), PC)) { - if(global_verbose_on) - cout << "Simulation finished!" << endl; + avr_message("Simulation finished!"); SystemClock::Instance().stop(); dump_manager->cycle(); return 0; diff --git a/src/avrerror.cpp b/src/avrerror.cpp index a67d656..4156160 100644 --- a/src/avrerror.cpp +++ b/src/avrerror.cpp @@ -128,6 +128,9 @@ void SystemConsoleHandler::TraceNextLine(void) { } void SystemConsoleHandler::vfmessage(const char *fmt, ...) { + if ( ! global_verbose_on) + return; + va_list ap; snprintf(formatStringBuffer, sizeof(formatStringBuffer), "MESSAGE %s", fmt); diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp index a4dca69..9c7ce5b 100644 --- a/src/cmd/main.cpp +++ b/src/cmd/main.cpp @@ -257,37 +257,31 @@ int main(int argc, char *argv[]) { cerr << "maxRunTime is zero" << endl; exit(1); } - if(global_verbose_on) - cout << "Maximum Run Time: " << maxRunTime << endl; + avr_message("Maximum Run Time: %lld", maxRunTime); break; case 'u': - if(global_verbose_on) - cout << "Run with User Interface at Port 7777" << endl; + avr_message("Run with User Interface at Port 7777"); userinterface_flag = 1; break; case 'f': - if(global_verbose_on) - cout << "File to load: " << optarg << endl; + avr_message("File to load: %s", optarg); filename = optarg; break; case 'd': - if(global_verbose_on) - cout << "Device to simulate: " << optarg << endl; + avr_message("Device to simulate: %s", optarg); devicename = optarg; break; case 'g': - if(global_verbose_on) - cout << "Running as gdb-server" << endl; + avr_message("Running as gdb-server"); gdbserver_flag = 1; break; case 'G': - if(global_verbose_on) - cout << "Running with debug information from gdbserver" << endl; + avr_message("Running with debug information from gdbserver"); global_gdb_debug = 1; gdbserver_flag = 1; break; @@ -297,13 +291,12 @@ int main(int argc, char *argv[]) { cerr << "GDB Server Port is not a number" << endl; exit(1); } - if(global_verbose_on) - cout << "Running on port: " << optarg << endl; + avr_message("Running on port: %ld", global_gdbserver_port); break; case 't': - if(global_verbose_on) - cout << "Running in Trace Mode with maximum " << linestotrace << " lines per file" << endl; + avr_message("Running in Trace Mode with maximum %lld lines per file", + linestotrace); sysConHandler.SetTraceFile(optarg, linestotrace); break; @@ -395,33 +388,26 @@ int main(int argc, char *argv[]) { //if we want to insert some special "pipe" Registers we could do this here: if(readFromPipeFileName != "") { - if(global_verbose_on) - cout << "Add ReadFromPipe-Register at 0x" - << hex << readFromPipeOffset - << " and read from file: " << readFromPipeFileName << endl; + avr_message("Add ReadFromPipe-Register at 0x%lx and read from file: %s", + readFromPipeOffset, readFromPipeFileName.c_str()); dev1->ReplaceIoRegister(readFromPipeOffset, new RWReadFromFile(dev1, "FREAD", readFromPipeFileName.c_str())); } if(writeToPipeFileName != "") { - if(global_verbose_on) - cout << "Add WriteToPipe-Register at 0x" - << hex << writeToPipeOffset - << " and write to file: " << writeToPipeFileName << endl; + avr_message("Add WriteToPipe-Register at 0x%lx and write to file: %s", + writeToPipeOffset, writeToPipeFileName.c_str()); dev1->ReplaceIoRegister(writeToPipeOffset, new RWWriteToFile(dev1, "FWRITE", writeToPipeFileName.c_str())); } if(writeToAbort) { - if(global_verbose_on) - cout << "Add WriteToAbort-Register at 0x" << hex - << writeToAbort << endl; + avr_message("Add WriteToAbort-Register at 0x%lx", writeToAbort); dev1->ReplaceIoRegister(writeToAbort, new RWAbort(dev1, "ABORT")); } if(writeToExit) { - if(global_verbose_on) - cout << "Add WriteToExit-Register at 0x" << hex << writeToExit << endl; + avr_message("Add WriteToExit-Register at 0x%lx", writeToExit); dev1->ReplaceIoRegister(writeToExit, new RWExit(dev1, "EXIT")); } @@ -433,8 +419,7 @@ int main(int argc, char *argv[]) { //if we have a file we can check out for termination lines. vector::iterator ii; for(ii = terminationArgs.begin(); ii != terminationArgs.end(); ii++) { - if(global_verbose_on) - cout << "Termination or Breakpoint Symbol: " << *ii << endl; + avr_message("Termination or Breakpoint Symbol: %s", (*ii).c_str()); dev1->RegisterTerminationSymbol((*ii).c_str()); } @@ -456,8 +441,7 @@ int main(int argc, char *argv[]) { SystemClock::Instance().Run(maxRunTime); } } else { // gdb should be activated - if(global_verbose_on) - cout << "Going to gdb..." << endl; + avr_message("Going to gdb..."); GdbServer gdb1(dev1, global_gdbserver_port, global_gdb_debug, globalWaitForGdbConnection); SystemClock::Instance().Add(&gdb1); SystemClock::Instance().Endless(); diff --git a/src/hwstack.cpp b/src/hwstack.cpp index c28bf17..e08b990 100644 --- a/src/hwstack.cpp +++ b/src/hwstack.cpp @@ -322,8 +322,7 @@ void ThreadList::OnPop() new_thread->m_ip = 0x0000; new_thread->m_alive = true; - if(global_verbose_on) - fprintf(stderr, "Context switch at PC 0x%05x from thread %d to %d\n", addr, m_cur_thread, n); + avr_message("Context switch at PC 0x%05x from thread %d to %d\n", addr, m_cur_thread, n); m_cur_thread = n; } From 4f6fa7c9406c2dd8595e933e8f6294c5e23f85cf Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 16 Nov 2013 22:32:56 +0100 Subject: [PATCH 06/20] Swap -v and -V command line parameters. About every tool on this planet uses a lowercase v for "verbose", do it here, too. --- doc/mdate-sh | 2 +- doc/simulavr.texi | 4 ++-- doc/usage.rst | 4 ++-- src/cmd/main.cpp | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/mdate-sh b/doc/mdate-sh index 83d2700..c3dfb1b 100755 --- a/doc/mdate-sh +++ b/doc/mdate-sh @@ -45,7 +45,7 @@ Report bugs to . EOF exit $? ;; - -v | --v*) + -V | --v*) echo "mdate-sh $scriptversion" exit $? ;; diff --git a/doc/simulavr.texi b/doc/simulavr.texi index 5f95962..117941b 100644 --- a/doc/simulavr.texi +++ b/doc/simulavr.texi @@ -179,9 +179,9 @@ no matter if it is ever reached or not. run with user interface for external pin handling at port 7777. This does not open any graphics but activates the interface to communicate with the environment simulation. -@item -v --version +@item -V --version show the software version of simulavr -@item -V --verbose +@item -v --verbose output some hints to console @item -W --writetopipe , add a special pipe register to device at IO-Offset and opens for writing diff --git a/doc/usage.rst b/doc/usage.rst index b7b7aef..a9bc38f 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -8,10 +8,10 @@ Invoke simulavr:: Common options -------------- -``-v, --version`` +``-V, --version`` show the software version of simulavr -``-V, --verbose`` +``-v, --verbose`` output some hints to console ``-h, --help`` diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp index 9c7ce5b..ca60731 100644 --- a/src/cmd/main.cpp +++ b/src/cmd/main.cpp @@ -120,7 +120,7 @@ const char Usage[] = "-e --writetoexit \n" " add a special register at IO-offset\n" " which exits simulator run\n" - "-V --verbose output some hints to console\n" + "-v --verbose output some hints to console\n" "-T --terminate