sim: Make it possible to override the breakpoint length check.
[gem5.git] / src / base / misc.cc
index afb48ca801064a19d7229e03b8750d229984d6ec..d95c2ff53951af9807a223a24a20ed23bda8c78f 100644 (file)
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2014 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
  * Copyright (c) 2002-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * Authors: Nathan Binkert
+ *          Andreas Sandberg
  */
 
-#include <iostream>
+#include <cstdlib>
+#include <cstring>
 #include <string>
 
 #include "base/cprintf.hh"
 #include "base/misc.hh"
 #include "base/output.hh"
 #include "base/trace.hh"
-#include "base/varargs.hh"
-#include "sim/host.hh"
+#include "base/types.hh"
 #include "sim/core.hh"
 
 using namespace std;
 
-void
-__panic(const char *func, const char *file, int line, const char *fmt,
-    CPRINTF_DEFINITION)
-{
-    string format = "panic: ";
-    format += fmt;
-    switch (format[format.size() - 1]) {
-      case '\n':
-      case '\r':
-        break;
-      default:
-        format += "\n";
-    }
-
-    format += " @ cycle %d\n[%s:%s, line %d]\n";
-
-    CPrintfArgsList args(VARARGS_ALLARGS);
-
-    args.push_back(curTick);
-    args.push_back(func);
-    args.push_back(file);
-    args.push_back(line);
+bool want_warn = true;
+bool want_info = true;
+bool want_hack = true;
 
-    ccprintf(cerr, format.c_str(), args);
+bool warn_verbose = false;
+bool info_verbose = false;
+bool hack_verbose = false;
 
-    abort();
-}
-
-void
-__fatal(const char *func, const char *file, int line, const char *fmt,
-    CPRINTF_DEFINITION)
+static void
+newline_if_needed(std::ostream &stream, const char *format)
 {
-    CPrintfArgsList args(VARARGS_ALLARGS);
-    string format = "fatal: ";
-    format += fmt;
+    const size_t format_len(strlen(format));
 
-    switch (format[format.size() - 1]) {
+    switch (format_len ? format[format_len - 1] : '\0') {
       case '\n':
       case '\r':
         break;
       default:
-        format += "\n";
+        stream << std::endl;
     }
+}
 
-    format += " @ cycle %d\n[%s:%s, line %d]\n";
-    format += "Memory Usage: %ld KBytes\n";
-
-    args.push_back(curTick);
-    args.push_back(func);
-    args.push_back(file);
-    args.push_back(line);
-    args.push_back(memUsage());
-
-    ccprintf(cerr, format.c_str(), args);
-
-    exit(1);
+void
+__exit_epilogue(int code,
+                const char *func, const char *file, int line,
+                const char *format)
+{
+    newline_if_needed(std::cerr, format);
+
+    ccprintf(std::cerr,
+             " @ tick %d\n"
+             "[%s:%s, line %d]\n"
+             "Memory Usage: %ld KBytes\n",
+             curTick(), func, file, line, memUsage());
+
+    if (code < 0)
+        abort();
+    else
+        exit(code);
 }
 
 void
-__warn(const char *func, const char *file, int line, const char *fmt,
-    CPRINTF_DEFINITION)
+__base_message_epilogue(std::ostream &stream, bool verbose,
+                        const char *func, const char *file, int line,
+                        const char *format)
 {
-    string format = "warn: ";
-    format += fmt;
+    newline_if_needed(stream, format);
 
-    switch (format[format.size() - 1]) {
-      case '\n':
-      case '\r':
-        break;
-      default:
-        format += "\n";
+    if (verbose) {
+        ccprintf(stream, " @ cycle %d\n[%s:%s, line %d]\n",
+                 curTick(), func, file, line);
     }
-
-#ifdef VERBOSE_WARN
-    format += " @ cycle %d\n[%s:%s, line %d]\n";
-#endif
-
-    CPrintfArgsList args(VARARGS_ALLARGS);
-
-#ifdef VERBOSE_WARN
-    args.push_back(curTick);
-    args.push_back(func);
-    args.push_back(file);
-    args.push_back(line);
-#endif
-
-    ccprintf(cerr, format.c_str(), args);
-    if (simout.isFile(*outputStream))
-        ccprintf(*outputStream, format.c_str(), args);
 }