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