From aa72c284e23566495e4dac4d2d85325751fb1bb8 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Mon, 14 Oct 2019 11:42:54 +0100 Subject: [PATCH] base: add the FmtStackTrace debug option If given, a stack trace is printed after every debug message. This helps to localize where debug messages are being called from, which is often the critical information needed to debug certain problems. Change-Id: I82b8990c0d286393d5bdab05f718be3e89eadc40 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22003 Reviewed-by: Brandon Potter Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/base/SConscript | 2 ++ src/base/trace.cc | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/base/SConscript b/src/base/SConscript index 548fda7e3..e2a3215d0 100644 --- a/src/base/SConscript +++ b/src/base/SConscript @@ -112,6 +112,8 @@ DebugFlag('Annotate', "State machine annotation debugging") DebugFlag('AnnotateQ', "State machine annotation queue debugging") DebugFlag('AnnotateVerbose', "Dump all state machine annotation details") DebugFlag('FmtFlag', "Show the --debug-flag that enabled each debug message") +DebugFlag('FmtStackTrace', + "Print a stack trace after every debug message") DebugFlag('FmtTicksOff', "Don't show tick count on debug messages") DebugFlag('GDBAcc', "Remote debugger accesses") DebugFlag('GDBExtra', "Dump extra information on reads and writes") diff --git a/src/base/trace.cc b/src/base/trace.cc index 6b18787c2..70d81a1ea 100644 --- a/src/base/trace.cc +++ b/src/base/trace.cc @@ -41,12 +41,15 @@ #include #include +#include "base/atomicio.hh" #include "base/debug.hh" #include "base/logging.hh" #include "base/output.hh" #include "base/str.hh" #include "debug/FmtFlag.hh" +#include "debug/FmtStackTrace.hh" #include "debug/FmtTicksOff.hh" +#include "sim/backtrace.hh" const std::string &name() { @@ -162,6 +165,11 @@ OstreamLogger::logMessage(Tick when, const std::string &name, stream << message; stream.flush(); + + if (DTRACE(FmtStackTrace)) { + print_backtrace(); + STATIC_ERR("\n"); + } } } // namespace Trace -- 2.30.2