summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2015-12-04 00:12:58 +0000
committerAndreas Sandberg <andreas.sandberg@arm.com>2015-12-04 00:12:58 +0000
commitdaa53da594d04925d10e792df804110d6a7bf2a2 (patch)
treef60a1b5722256718fea2fe93fb70e45b28022268 /src/base
parenta1aeff27ce2978bb5fd0a3da66878d914cfb4da2 (diff)
downloadgem5-daa53da594d04925d10e792df804110d6a7bf2a2.tar.xz
sim: Add support for generating back traces on errors
Add functionality to generate a back trace if gem5 crashes (SIGABRT or SIGSEGV). The current implementation uses glibc's stack traversal support if available and stubs out the call to print_backtrace() otherwise.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/atomicio.hh24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/base/atomicio.hh b/src/base/atomicio.hh
index 5e703f315..bfd1e35e5 100644
--- a/src/base/atomicio.hh
+++ b/src/base/atomicio.hh
@@ -41,4 +41,28 @@
ssize_t atomic_read(int fd, void *s, size_t n);
ssize_t atomic_write(int fd, const void *s, size_t n);
+/**
+ * Statically allocate a string and write it to a file descriptor.
+ *
+ * @warning The return value will from atomic_write will be ignored
+ * which means that errors will be ignored. This is normally fine as
+ * this macro is intended to be used in fatal signal handlers where
+ * error handling might not be feasible.
+ */
+#define STATIC_MSG(fd, m) \
+ do { \
+ static const char msg[] = m; \
+ atomic_write(fd, msg, sizeof(msg) - 1); \
+ } while(0)
+
+/**
+ * Statically allocate a string and write it to STDERR.
+ *
+ * @warning The return value will from atomic_write will be ignored
+ * which means that errors will be ignored. This is normally fine as
+ * this macro is intended to be used in fatal signal handlers where
+ * error handling might not be feasible.
+ */
+#define STATIC_ERR(m) STATIC_MSG(STDERR_FILENO, m)
+
#endif // __BASE_ATOMICIO_HH__