Skip to content

Commit

Permalink
assert: Include file name in assert output
Browse files Browse the repository at this point in the history
Printing the line number without an associated file is almost
meaningless; add the file name to improve debug ergonomics.

Change-Id: I454876ccc567cb58066362caced7efbaf92cfe62
Signed-off-by: Andrew Jeffery <andrewrj@au1.ibm.com>
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/66117
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>
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/67386
  • Loading branch information
Andrew Jeffery authored and dcrowell77 committed Oct 16, 2018
1 parent 175679c commit 72084f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2011,2015 */
/* Contributors Listed Below - COPYRIGHT 2011,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -78,6 +78,7 @@ enum AssertBehavior
*
* @param[in] i_assertb - Internal enumeration used by macros to communicate
* desired behavior.
* @param[in] i_file - The file in which the assert exists
* @param[in] i_line - Line number at which the assert macro was called.
*
* Current Behaviors:
Expand All @@ -93,7 +94,7 @@ enum AssertBehavior
* user-space dispatching.
*/
NO_RETURN
void __assert(AssertBehavior i_assertb, int i_line);
void __assert(AssertBehavior i_assertb, const char* i_file, int i_line);

#ifdef __HOSTBOOT_MODULE // Only allow traced assert in module code.

Expand Down Expand Up @@ -132,7 +133,7 @@ void __assert(AssertBehavior i_assertb, int i_line);
__ASSERT_DO_TRACE(expr, __VA_ARGS__); \
__assert((__ASSERT_HAS_TRACE(__VA_ARGS__) ? \
ASSERT_TRACE_DONE : ASSERT_TRACE_NOTDONE),\
__LINE__);\
__FILE__, __LINE__);\
}\
}

Expand All @@ -147,7 +148,7 @@ void __assert(AssertBehavior i_assertb, int i_line);
{\
if (unlikely(!(expr)))\
{\
__assert(ASSERT_KERNEL, __LINE__);\
__assert(ASSERT_KERNEL, __FILE__, __LINE__);\
}\
}

Expand All @@ -163,7 +164,7 @@ void __assert(AssertBehavior i_assertb, int i_line);
{\
if (unlikely(!(expr)))\
{\
__assert(ASSERT_CRITICAL, __LINE__);\
__assert(ASSERT_CRITICAL, __FILE__, __LINE__);\
}\
}

Expand Down
15 changes: 8 additions & 7 deletions src/lib/assert.C
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
/** 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, int i_line)
extern "C" void __assert(AssertBehavior i_assertb, const char* i_file,
int i_line)
{

task_t* task = NULL;
Expand Down Expand Up @@ -70,15 +71,15 @@ extern "C" void __assert(AssertBehavior i_assertb, int i_line)
}
else
{
printk("Assertion failed @%p on line %d.\n",
linkRegister(), i_line);
printk("Assertion failed @%p at %s:%d.\n",
linkRegister(), i_file, i_line);
}
task_crash();
break;

case ASSERT_CRITICAL: // Critical task, trace not available.
printk("Assertion failed @%p on line %d.(Crit_Assert)\n",
linkRegister(), i_line);
printk("Assertion failed @%p on line %s:%d. (Crit_Assert)\n",
linkRegister(), i_file, i_line);

KernelMisc::printkBacktrace(task);

Expand All @@ -87,8 +88,8 @@ extern "C" void __assert(AssertBehavior i_assertb, int i_line)
break;

case ASSERT_KERNEL: // Kernel assert called.
printk("Assertion failed @%p on line %d. (kassert)\n",
linkRegister(), i_line);
printk("Assertion failed @%p on line %s:%d. (kassert)\n",
linkRegister(), i_file, i_line);

KernelMisc::printkBacktrace(task);

Expand Down
11 changes: 7 additions & 4 deletions src/runtime/rt_assert.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* COPYRIGHT International Business Machines Corp. 2013,2014 */
/* Contributors Listed Below - COPYRIGHT 2013,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
Expand All @@ -28,12 +30,13 @@
/** 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, int i_line)
extern "C" void __assert(AssertBehavior i_assertb, const char* i_file,
int i_line)
{
if (i_assertb != ASSERT_TRACE_DONE)
{
printk("Assertion failed @%p on line %d.\n",
linkRegister(), i_line);
printk("Assertion failed @%p on line %s:%d.\n",
linkRegister(), i_file, i_line);
}

g_hostInterfaces->assert();
Expand Down

0 comments on commit 72084f6

Please sign in to comment.