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