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