> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Enable kernel debugging

This section describes kernel debugging features that are used to diagnose system and performance issues.

## **Enable dynamic debug**

The `debugfs` file system allows you to debug the kernel by enabling logs at runtime. When verifying a particular scenario, use the `debugfs` file system to enable logs for the specific time.

By default, dynamic debug is disabled. To enable `debugfs` in the kernel, do the following:

1. Enable the `CONFIG_DYNAMIC_DEBUG` kernel configuration option.
2. Recompile and reflash the build.
3. To mount the `debugfs` file system, run the following commands:
   ```text theme={null}
   mount -o rw,remount /
   ```
   ```text theme={null}
   mount -t debugfs none /sys/kernel/debug
   ```
   1. Verify whether dynamic debug is enabled by checking that the following path exists:
      ```text theme={null}
      cd /sys/kernel/debug/dynamic_debug
      ```
   2. If the directory exists, verify the defined logs:
      ```text theme={null}
      cat /sys/kernel/debug/dynamic_debug/control
      ```
4. Enable debug logs for the files or functions that require debugging.
   For example:
   * To enable all `debugfs` logs in the `mdp.c` file, run the following command:
     ```text theme={null}
     echo 'file mdp.c +p' > /sys/kernel/debug/dynamic_debug/control
     ```
   * To enable the log at line 2921 in the `mdp.c` file, run the following command:
     ```text theme={null}
     echo 'file mdp.c line 2921 +p' > /sys/kernel/debug/dynamic_debug/control
     ```
5. Verify logs using the `dmesg` command or run the following command:
   ```text theme={null}
   cat /proc/kmsg
   ```
   For more information, see [Documentation/dynamic-debug-howto.txt](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/dynamic-debug-howto.rst).

## **Enable kernel debugging options**

You can enable kernel configuration options to debug various issues such as memory leak, lock-related, and mutex problems. To see the available kernel debugging options, invoke `menuconfig`. For more information about kernel debugging options, see [Configure the kernel](https://dragonwingdocs.qualcomm.com/System/Kernel/install-and-boot-the-kernel)

The following are some debugging options:

Kernel hacking

\[\*] Kernel debugging

\[\*] Detect Soft Lockups

\[ ] Collect scheduler statistics

\[\*] Debug slab memory allocations

\[\*] Memory leak debugging

\[\*] Mutex debugging, deadlock detection

\[\*] Spinlock debugging

\[\*] Sleep-inside-spinlock checking

\[ ] kobject debugging

\[ ] Highmem debugging

\[ ] Compile the kernel with debug info

<Note>
  If you enable any of these debugging options, the kernel slows down marginally. Therefore, if you notice any decrease in performance, disable the kernel debug configuration options.
</Note>
