Skip to content

Commit

Permalink
assert: Print the backtrace for critical and kernel assertions
Browse files Browse the repository at this point in the history
Improve debug ergonomics by allowing developers to backtrack from the
assertion through the call-stack. This is important for generic code,
for example, when dealing with assertions inside free().

Change-Id: I0c9c767c50acf3ee3bbe0a891441429299e2d239
Signed-off-by: Andrew Jeffery <andrewrj@au1.ibm.com>
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/66118
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Corey V. Swenson <cswenson@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
Andrew Jeffery authored and dcrowell77 committed Oct 2, 2018
1 parent 8a4663c commit 797f6fc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib/assert.C
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@
#include <kernel/terminate.H>
#include <sys/misc.h>
#include <kernel/kernel_reasoncodes.H>
#include <kernel/taskmgr.H>

/** Hook location for trace module to set up when loaded. */
namespace TRACE { void (*traceCallback)(void*, size_t) = NULL; };

extern "C" void __assert(AssertBehavior i_assertb, const char* i_file,
int i_line)
{
if ((i_assertb == ASSERT_CRITICAL) && (KernelMisc::in_kernel_mode()))

task_t* task = NULL;

if (KernelMisc::in_kernel_mode())
{
i_assertb = ASSERT_KERNEL;
task = TaskManager::getCurrentTask();

if (i_assertb == ASSERT_CRITICAL)
{
i_assertb = ASSERT_KERNEL;
}
}

switch (i_assertb)
Expand All @@ -72,6 +81,8 @@ extern "C" void __assert(AssertBehavior i_assertb, const char* i_file,
printk("Assertion failed @%p on line %s:%d. (Crit_Assert)\n",
linkRegister(), i_file, i_line);

KernelMisc::printkBacktrace(task);

// Need to call the external CritAssert system call
cpu_crit_assert(reinterpret_cast<uint64_t>(linkRegister()));
break;
Expand All @@ -80,6 +91,8 @@ extern "C" void __assert(AssertBehavior i_assertb, const char* i_file,
printk("Assertion failed @%p on line %s:%d. (kassert)\n",
linkRegister(), i_file, i_line);

KernelMisc::printkBacktrace(task);

/*@
* @errortype
* @moduleid KERNEL::MOD_KERNEL_INVALID
Expand Down

0 comments on commit 797f6fc

Please sign in to comment.