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

Suppose Windows10, WSL and ubuntu18 are installed on your PC. Putty is installed in your Windows.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
git clone git://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
cd agent-proxy ; make ; sudo cp agent-proxy /usr/bin

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 linux_module_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 linux_module_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 :5551" .
Configure Start Timeout and Connect Timeout as "30".

15. Login ubuntu18 with Putty.

16. Assume you have a COM40 to connect to the armboard. COM40 will be mapped as /dev/ttyS40 in ubuntu18.
Run agent-proxy as a daemon and then telnet with port 5550 to communicate with armboard.
Then run below commands:

echo ttyHSL0,115200> /sys/module/kgdboc/parameters/kgdboc
echo g > /proc/sysrq-trigger

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

18. Swith to the Putty and insmod the module test.ko

19. 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

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


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