Skip to contentSkip to conversation

Add BUG() debugger entry points x86

PATCH New Jeffrey Merkey 2 participants 2 messages Jan 29, 2016 x86

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 Add BUG() debugger entry points x86

This patch series adds a config option which can be set during compile to direct the compiler to output a breakpoint instruction anywhere a BUG() macro has been placed in the kernel to trigger the system to enter a debugger if a bug is detected by the system. Use of this compile time option also allows conditional breakpoints to be set anywhere in the kernel.

This addition is extremely useful for debugging hard and soft lockups real time and quickly from a console debugger, and other areas of the kernel.

---
 arch/x86/include/asm/bug.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/include/asm/bug.h +4 -0
index ba38ebb..6319f3e0 100644
@@ -27,7 +27,11 @@ do {								\
 #else
 #define BUG()							\
 do {								\
+#ifdef CONFIG_DEBUG_BREAK
+	asm volatile("int3");					\
+#else
 	asm volatile("ud2");					\
+#endif
 	unreachable();						\
 } while (0)
 #endif
Signature · 1 line
1.8.3.1
#1 lore raw
reproduce:

Hi Jeffrey,

[auto build test ERROR on v4.5-rc1]
[also build test ERROR on next-20160129]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Jeffrey-Merkey/Add-BUG-debugger-entry-points/20160130-022335
config: i386-tinyconfig (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

In file included from include/linux/bug.h:4:0,
from include/linux/page-flags.h:9, from kernel/bounds.c:9:

>> arch/x86/include/asm/bug.h:28:13: error: '#' is not followed by a macro parameter
    #define BUG()       \
                ^
>> arch/x86/include/asm/bug.h:31:6: error: expected '(' before 'volatile'
     asm volatile("int3");     \
         ^
>> arch/x86/include/asm/bug.h:32:1: error: stray '#' in program
    #else
    ^
>> arch/x86/include/asm/bug.h:32:2: error: expected identifier or '(' before 'else'
    #else
     ^
   arch/x86/include/asm/bug.h:34:1: error: stray '#' in program
    #endif
    ^
>> arch/x86/include/asm/bug.h:34:2: error: unknown type name 'endif'
    #endif
     ^
>> arch/x86/include/asm/bug.h:35:2: error: function declaration isn't a prototype [-Werror=strict-prototypes]
     unreachable();      \
     ^
   In file included from include/linux/compiler.h:56:0,
                    from include/uapi/linux/stddef.h:1,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/page-flags.h:8,
                    from kernel/bounds.c:9:
>> include/linux/compiler-gcc.h:199:23: warning: conflicting types for built-in function '__builtin_unreachable'
    #define unreachable() __builtin_unreachable()
                          ^
>> arch/x86/include/asm/bug.h:35:2: note: in expansion of macro 'unreachable'
     unreachable();      \
     ^
   In file included from include/linux/bug.h:4:0,
                    from include/linux/page-flags.h:9,
                    from kernel/bounds.c:9:
>> arch/x86/include/asm/bug.h:36:1: error: expected identifier or '(' before '}' token
    } while (0)
    ^
>> arch/x86/include/asm/bug.h:36:3: error: expected identifier or '(' before 'while'
    } while (0)
      ^
   In file included from include/linux/kernel.h:5:0,
                    from include/asm-generic/bug.h:13,
                    from arch/x86/include/asm/bug.h:39,
                    from include/linux/bug.h:4,
                    from include/linux/page-flags.h:9,
                    from kernel/bounds.c:9:
>> /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h:98:9: error: unknown type name '__gnuc_va_list'
    typedef __gnuc_va_list va_list;
            ^

cc1: some warnings being treated as errors make[2]: *** [kernel/bounds.s] Error 1 make[2]: Target '__build' not remade because of errors. make[1]: *** [prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [sub-make] Error 2

vim +28 arch/x86/include/asm/bug.h

68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  22  		     : : "i" (__FILE__), "i" (__LINE__),	\
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  23  		     "i" (sizeof(struct bug_entry)));		\
a5fc5eba arch/x86/include/asm/bug.h David Daney     2009-12-04  24  	unreachable();						\
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  25  } while (0)
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  26  
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  27  #else
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17 @28  #define BUG()							\
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  29  do {								\
26a805e0 arch/x86/include/asm/bug.h Jeffrey Merkey  2016-01-29  30  #ifdef CONFIG_DEBUG_BREAK
26a805e0 arch/x86/include/asm/bug.h Jeffrey Merkey  2016-01-29 @31  	asm volatile("int3");					\
26a805e0 arch/x86/include/asm/bug.h Jeffrey Merkey  2016-01-29 @32  #else
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  33  	asm volatile("ud2");					\
26a805e0 arch/x86/include/asm/bug.h Jeffrey Merkey  2016-01-29 @34  #endif
a5fc5eba arch/x86/include/asm/bug.h David Daney     2009-12-04 @35  	unreachable();						\
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17 @36  } while (0)
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  37  #endif
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  38  
68fdc55c include/asm-x86/bug.h      Thomas Gleixner 2007-10-17  39  #include <asm-generic/bug.h>

:::::: The code at line 28 was first introduced by commit
:::::: 68fdc55c48fd2e8f4938a1e815216c25baf8a17e x86: unify include/asm/bug_32/64.h

:::::: TO: Thomas Gleixner <[email protected]> :::::: CC: Thomas Gleixner <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation