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