Create a project with source code and debug armlinux device driver over serial port and adb

Suppose Windows10, WSL and ubuntu18 are installed on your PC. Ssh server, gdb-multiarch and agent-proxy are installed in the ubuntu18. There is a project folder /home/srcdbg/project/module_prj in the ubuntu18 whose host name is localhost. The linux kernel source code is cross-compiled in ubuntu18 or the source code is mapped on a folder in ubuntu18. Here are steps to create a new project.

1. Preparation for ubuntu18.
sudo apt-get install openssh-server gdb-multiarch

2. Please refer to https://www.kernel.org/doc/html/v4.14/dev-tools/kgdb.html for kernel config options for kgdb.
Please Note: When using kgdboc with a UART, the UART driver must implement two callbacks in the struct uart_ops. Example from drivers/8250.c:
#ifdef CONFIG_CONSOLE_POLL
.poll_get_char = serial8250_get_poll_char,
.poll_put_char = serial8250_put_poll_char,
#endif

Here is an example set of .config symbols to enable for kgdb:
# CONFIG_STRICT_KERNEL_RWX is not set
CONFIG_FRAME_POINTER=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y

3. Select File > New > Solution... > Wizard... and then click the OK button.

4. Enter the name of the project and click Next button.

5. Enter the correct Remote host, Port, Username, Password, Initial path and click Next button.

6. Click Next button.

7. Click Next button.

8. Click Finish button.

9. Enter the solution File name and click Save button.

10. Enter the project File name and click Save button.

11. Right click the srcdbg_test project and select Add > Add Existing Remote File to add the project files.

12. Select the needed folders and files and click Open button.

13. Select Build > Synchronize Files... to synchronize files and build the project symbols.

14. Right click the srcdbg_test project and select Properties.
Make sure it's an absolute path of the "Attach to program" line.
Change Attach to program as "-i=mi /home/srcdbg/project/module_prj/vmlinux".
Configure Debug start command as "-exec-continue".
Configure Entry function as "do_init_module".
Configure Postdebug command as "target remote /dev/ttyS40" .
Configure Start Timeout and Connect Timeout as "30".

15. Connect to the armboard with adb shell. Then run below commands:
echo ttyHSL0,115200> /sys/module/kgdboc/parameters/kgdboc
echo g > /proc/sysrq-trigger

16. Select Debug > Start Debugging to communicate with the remote target.

17. Swith to the adb window and insmod the module test.ko

18. Create a script file named add_mod_bp.txt with below contents. Modify the bold parts according to the actual situation of your project. Please note that
addmod is a proprietary command defined by srcdbg to load module.

addmod "/home/srcdbg/project/module_prj/test.ko"
break hello_init
continue

19. Select Tools > External Tools to create an external tool submenu named add_mod_bp to run the script add_mod_bp.txt.


20. Select Tools > add_mod_bp to run the script add_mod_bp.txt to debug the project.