1# Debug configuration options
2
3# Copyright (c) 2015 Wind River Systems, Inc.
4# SPDX-License-Identifier: Apache-2.0
5
6
7menu "System Monitoring Options"
8
9menuconfig THREAD_ANALYZER
10	bool "Enable Thread analyzer"
11	select INIT_STACKS
12	select THREAD_MONITOR
13	select THREAD_STACK_INFO
14	select THREAD_RUNTIME_STATS
15	help
16	  Enable thread analyzer functionality and all the required modules.
17	  This module may be used to debug thread configuration issues, e.g.
18	  stack size configuration to find stack overflow or to find stacks
19	  which may be optimized.
20
21if THREAD_ANALYZER
22module = THREAD_ANALYZER
23module-str = thread analyzer
24source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
25
26choice
27	prompt "Thread analysis print mode"
28
29config THREAD_ANALYZER_USE_LOG
30	bool "Use logger output"
31	select LOG
32	help
33	  Use logger output to print thread information.
34
35config THREAD_ANALYZER_USE_PRINTK
36	bool "Use printk function"
37	help
38	  Use kernel printk function to print thread information.
39
40endchoice
41
42config THREAD_ANALYZER_RUN_UNLOCKED
43	bool "Run analysis with interrupts unlocked"
44	default y
45	help
46	  The thread analysis takes quite a long time.
47	  Every thread it finds is analyzed word by word to find any that
48	  does not match the magic number.
49	  Normally while thread are analyzed the k_thread_foreach function
50	  is used.
51	  While this is a safe run from the thread list perspective it may lock
52	  the interrupts for a long time - long enough to disconnect when
53	  Bluetooth communication is used.
54	  Setting this flag will force thread analyzer to use
55	  the k_thread_foreach_unlocked function.
56	  This will allow the interrupts to be processed while the thread is
57	  analyzed.
58	  For the limitation of such configuration see the k_thread_foreach
59	  documentation.
60
61config THREAD_ANALYZER_AUTO
62	bool "Run periodic thread analysis in a thread"
63	help
64	  Run the thread analyzer automatically, without the need to add
65	  any code to the application.
66	  Thread analysis would be called periodically.
67
68if THREAD_ANALYZER_AUTO
69
70config THREAD_ANALYZER_AUTO_INTERVAL
71	int "Thread analysis interval"
72	default 60
73	range 5 3600
74	help
75	  The time in seconds to call thread analyzer periodic printing function.
76
77config THREAD_ANALYZER_AUTO_STACK_SIZE
78	int "Stack size for the periodic thread analysis thread"
79	default 1024
80
81endif # THREAD_ANALYZER_AUTO
82
83endif # THREAD_ANALYZER
84
85
86endmenu
87
88menu "Debugging Options"
89
90config DEBUG
91	bool "Build kernel with debugging enabled"
92	help
93	  Build a kernel suitable for debugging.  Right now, this option
94	  only disables optimization, more debugging variants can be selected
95	  from here to allow more debugging.
96
97config ASAN
98	bool "Build with address sanitizer"
99	depends on ARCH_POSIX
100	help
101	  Builds Zephyr with Address Sanitizer enabled. This is currently
102	  only supported by boards based on the posix architecture, and requires a
103	  recent-ish compiler with the ``-fsanitize=address`` command line option,
104	  and the libasan library.
105
106	  Note that at exit leak detection is disabled for 64-bit boards when
107	  GCC is used due to potential risk of a deadlock in libasan.
108	  This behavior can be changes by adding leak_check_at_exit=1 to the
109	  environment variable ASAN_OPTIONS.
110
111config ASAN_NOP_DLCLOSE
112	bool "Override host OS dlclose() with a NOP"
113	default y if HAS_SDL
114	depends on ASAN
115	help
116	  Override host OS dlclose() with a NOP.
117
118	  This NOP implementation is needed as workaround for a known limitation in
119	  LSAN (leak sanitizer) that if dlcose is called before performing the leak
120	  check, "<unknown module>" is reported in the stack traces during the leak
121	  check and these can not be suppressed, see
122	  https://github.com/google/sanitizers/issues/89 for more info.
123
124config UBSAN
125	bool "Build with undefined behavior sanitizer"
126	depends on ARCH_POSIX
127	help
128	  Builds Zephyr with Undefined Behavior Sanitizer enabled.
129	  This is currently only supported by boards based on the posix
130	  architecture, and requires a recent-ish compiler with the
131	  ``-fsanitize=undefined`` command line option.
132
133config STACK_USAGE
134	bool "Generate stack usage information"
135	help
136	  Generate an extra file that specifies the maximum amount of stack used,
137	  on a per-function basis.
138
139config STACK_SENTINEL
140	bool "Enable stack sentinel"
141	select THREAD_STACK_INFO
142	depends on MULTITHREADING
143	depends on !USERSPACE
144	help
145	  Store a magic value at the lowest addresses of a thread's stack.
146	  Periodically check that this value is still present and kill the
147	  thread gracefully if it isn't. This is currently checked in four
148	  places:
149
150	  1) Upon any context switch for the outgoing thread
151	  2) Any hardware interrupt that doesn't context switch, the check is
152	     performed for the interrupted thread
153	  3) When a thread returns from its entry point
154	  4) When a thread calls k_yield() but doesn't context switch
155
156	  This feature doesn't prevent corruption and the system may be
157	  in an unusable state. However, given the bizarre behavior associated
158	  with stack overflows, knowledge that this is happening is very
159	  useful.
160
161	  This feature is intended for those systems which lack hardware support
162	  for stack overflow protection, or have insufficient system resources
163	  to use that hardware support.
164
165config PRINTK
166	bool "Send printk() to console"
167	default y
168	help
169	  This option directs printk() debugging output to the supported
170	  console device, rather than suppressing the generation
171	  of printk() output entirely. Output is sent immediately, without
172	  any mutual exclusion or buffering.
173
174config PRINTK_BUFFER_SIZE
175	int "printk() buffer size"
176	depends on PRINTK
177	depends on USERSPACE
178	default 32
179	help
180	  If userspace is enabled, printk() calls are buffered so that we do
181	  not have to make a system call for every character emitted. Specify
182	  the size of this buffer.
183
184config EARLY_CONSOLE
185	bool "Send stdout at the earliest stage possible"
186	help
187	  This option will enable stdout as early as possible, for debugging
188	  purpose. For instance, in case of STDOUT_CONSOLE being set it will
189	  initialize its driver earlier than normal, in order to get the stdout
190	  sent through the console at the earliest stage possible.
191
192config ASSERT
193	bool "Enable __ASSERT() macro"
194	default y if TEST
195	help
196	  This enables the __ASSERT() macro in the kernel code. If an assertion
197	  fails, the policy for what to do is controlled by the implementation
198	  of the assert_post_action() function, which by default will trigger
199	  a fatal error.
200
201	  Disabling this option will cause assertions to compile to nothing,
202	  improving performance and system footprint.
203
204config ASSERT_LEVEL
205	int "__ASSERT() level"
206	default 2
207	range 0 2
208	depends on ASSERT
209	help
210	  This option specifies the assertion level used by the __ASSERT()
211	  macro. It can be set to one of three possible values:
212
213	  Level 0: off
214	  Level 1: on + warning in every file that includes __assert.h
215	  Level 2: on + no warning
216
217config SPIN_VALIDATE
218	bool "Enable spinlock validation"
219	depends on ASSERT
220	depends on MULTITHREADING
221	depends on MP_NUM_CPUS <= 4
222	default y if !FLASH || FLASH_SIZE > 32
223	help
224	  There's a spinlock validation framework available when asserts are
225	  enabled. It adds a relatively hefty overhead (about 3k or so) to
226	  kernel code size, don't use on platforms known to be small.
227
228config FORCE_NO_ASSERT
229	bool "Force-disable no assertions"
230	help
231	  This boolean option disables Zephyr assertion testing even
232	  in circumstances (twister) where it is enabled via
233	  CFLAGS and not Kconfig.  Added solely to be able to work
234	  around compiler bugs for specific tests.
235
236config ASSERT_VERBOSE
237	bool "Enable verbose assertions"
238	default y
239	help
240	  This option enables printing an assert message with information about
241	  the assertion that occurred. This includes printing the location,
242	  the conditional expression and additional message specific to the
243	  assert.
244
245config ASSERT_NO_FILE_INFO
246	bool "Disable file info for asserts"
247	help
248	  This option removes the name and the path of the source file
249	  in which the assertion occurred. Enabling this will save
250	  target code space, and thus may be necessary for tiny targets.
251
252config ASSERT_NO_COND_INFO
253	bool "Disable condition info for asserts"
254	help
255	  This option removes the assert condition from the printed assert
256	  message. Enabling this will save target code space, and thus may be
257	  necessary for tiny targets. It is recommended to disable condition
258	  info before disabling file info since the condition can be found in
259	  the source using file info.
260
261config ASSERT_NO_MSG_INFO
262	bool "Disable message for asserts"
263	help
264	  This option removes the additional message from the printed assert.
265	  Enabling this will save target code space, and thus may be
266	  necessary for tiny targets. It is recommended to disable message
267	  before disabling file info since the message can be found in the
268	  source using file info.
269
270config OVERRIDE_FRAME_POINTER_DEFAULT
271	bool "Override compiler defaults for -fomit-frame-pointer"
272	help
273	  Omitting the frame pointer prevents the compiler from putting the stack
274	  frame pointer into a register. Saves a few instructions in function
275	  prologues/epilogues and frees up a register for general-purpose use,
276	  which can provide good performance improvements on register-constrained
277	  architectures like x86. On some architectures (including x86) omitting
278	  frame pointers impedes debugging as local variables are harder to
279	  locate. At -O1 and above gcc will enable -fomit-frame-pointer
280	  automatically but only if the architecture does not require if for
281	  effective debugging.
282
283	  Choose Y if you want to override the default frame pointer behavior
284	  of your compiler, otherwise choose N.
285
286config OMIT_FRAME_POINTER
287	bool "Omit frame pointer"
288	depends on OVERRIDE_FRAME_POINTER_DEFAULT
289	help
290	  Choose Y for best performance. On some architectures (including x86)
291	  this will favor code size and performance over debugability.
292
293	  Choose N in you wish to retain the frame pointer. This option may
294	  be useful if your application uses runtime backtracing and does not
295	  support parsing unwind tables.
296
297	  If unsure, disable OVERRIDE_FRAME_POINTER_DEFAULT to allow the compiler
298	  to adopt sensible defaults for your architecture.
299
300
301#
302# Generic Debugging Options
303#
304config DEBUG_INFO
305	bool "Enable system debugging information"
306	help
307	  This option enables the addition of various information that can be
308	  used by debuggers in debugging the system, or enable additional
309	  debugging information to be reported at runtime.
310
311config EXCEPTION_STACK_TRACE
312	bool "Attempt to print stack traces upon exceptions"
313	default y
314	depends on PRINTK
315	depends on DEBUG_INFO
316	depends on !OMIT_FRAME_POINTER
317	help
318	  If the architecture fatal handling code supports it, attempt to
319	  print a stack trace of function memory addresses when an
320	  exception is reported.
321
322#
323# Miscellaneous debugging options
324#
325config OPENOCD_SUPPORT
326	bool "OpenOCD support (DEPRECATED)"
327	select DEBUG_THREAD_INFO
328	help
329	  This is deprecated, please use DEBUG_THREAD_INFO instead.
330
331config DEBUG_THREAD_INFO
332	bool "Thread awareness support"
333	depends on !SMP
334	select THREAD_MONITOR
335	select THREAD_NAME
336	help
337	  This option exports an array of offsets to kernel structs to allow
338	  for debugger RTOS plugins to determine the state of running threads.
339
340rsource "coredump/Kconfig"
341endmenu
342
343config GDBSTUB
344	bool "GDB remote serial protocol support [EXPERIMENTAL]"
345	depends on ARCH_HAS_GDBSTUB
346	help
347	  This option enable support the target using GDB, or any other
348	  application that supports GDB protocol.
349
350if GDBSTUB
351
352choice
353	prompt "GDB backend"
354
355config GDBSTUB_SERIAL_BACKEND
356	bool "Use serial backend"
357	depends on SERIAL
358	help
359	  Use serial as backenf for GDB
360
361endchoice
362
363config GDBSTUB_SERIAL_BACKEND_NAME
364	string "Serial Name"
365	depends on GDBSTUB_SERIAL_BACKEND
366	default "UART_0"
367	help
368	  Use serial as backenf for GDB
369
370
371endif
372