Guest User

Untitled

a guest
Jun 19th, 2024
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. I'm trying to cross debug the linux kernel on a ARM target and a x86_64 host. I am using PetaLinux, which uses Yocto Linux internally, to build the linux image. I have enabled debug information and kgdb for the kernel:
  2.  
  3.  
  4. ```
  5. CONFIG_DEBUG_KERNEL=y
  6. CONFIG_DEBUG_INFO=y
  7. CONFIG_KGDB_SERIAL_CONSOLE=y
  8. CONFIG_KGDB=y
  9. CONFIG_FRAME_POINTER=y
  10.  
  11. ```
  12.  
  13.  
  14. At first, I register the kgdboc module:
  15.  
  16.  
  17. ```
  18.  
  19. echo ttyPS0 > /sys/module/kgdboc/parameters/kgdboc
  20.  
  21. ```
  22.  
  23.  
  24. Then, I trigger a breakpoint:
  25.  
  26.  
  27. ```
  28.  
  29. echo g > /proc/sysrq-trigger
  30.  
  31. ```
  32.  
  33.  
  34. Now, i close minicom and i connect with gdb using the cross gdb used by PetaLinux (aarch64-linux-gnu-gdb):
  35.  
  36. ```
  37.  
  38. $ aarch64-linux-gnu-gdb vmlinux
  39.  
  40. (gdb)set serial baud 115200
  41. (gdb)set debug remote 1
  42. (gdb)set architecture armv7
  43. (gdb)set substitute-path /usr/src/debug/linux-xlnx/6.1.30-xilinx-v2023.2+git999-r0 /home/test/repos/linux-xlnx
  44. (gdb)target remote /dev/ttyACM0
  45.  
  46. ```
  47.  
  48.  
  49. I'm able to continue, set breakpoints and step through the code.
  50.  
  51.  
  52. I tested the debugging by setting breakpoints in the kernel code which i could trigger from the commandline. In particular, I set a breakpoint at meminfo_proc_show, which can be triggered by executing cat /proc/meminfo from the target. I can step through the code until the following instruction is executed:
  53.  
  54.  
  55. ```
  56.  
  57. │ 0xc02ae480 <meminfo_proc_show+68> bl 0xc082ca80 <memset>
  58.  
  59. ```
  60.  
  61.  
  62. A branch link to memset. Memset for ARM is defined in the linux kernel in assembly. Using objdump in vmlinux, i can confirm that memset is present in the kernel binary. Additionally, normal execution of the function does not halt the cpu. Other branch link instructions also do not halt the cpu. When I set a breakpoint right after the bl memset instruction and continue, the execution stops at the breakpoint right after the bl memset instruction. The problem only occurs when i stepi/nexti over the bl memset instruction. I enable set debug remote 1 to have a more verbose log. This is the log after stepi of bl memset:
  63.  
  64.  
  65. ```
  66.  
  67. (gdb) si
  68. Sending packet: $Z0,c02ae43c,4#6b...Ack
  69. Packet received: OK
  70. Sending packet: $Z0,c02ae474,4#40...Ack
  71. Packet received: OK
  72. Sending packet: $Z0,c02ae484,4#41...Ack
  73. Packet received: OK
  74. Sending packet: $mc02ae470,4#f3...Ack
  75. Packet received: 82f915eb
  76. Sending packet: $mc02ae470,4#f3...Ack
  77. Packet received: 82f915eb
  78. Sending packet: $mc082ca80,4#f6...Ack
  79. Packet received: 033010e2
  80. Sending packet: $mc02ae470,4#f3...Ack
  81. Packet received: 82f915eb
  82. Sending packet: $mc02ae470,4#f3...Ack
  83. Packet received: 82f915eb
  84. Sending packet: $mc02ae470,4#f3...Ack
  85. Packet received: 82f915eb
  86. Sending packet: $Z0,c082ca80,4#3f...Ack
  87. Packet received: OK
  88. Sending packet: $c#63...Ack
  89.  
  90. ```
  91.  
  92.  
  93. Some breakpoints are set and the execution is continued, but the execution never stops. From here, the board is not responsive and cannot break/continue the board from gdb. After a while, the board reports that the cpu has halted.
  94.  
  95.  
  96. I even tried KGDBoE, which is just KGDB over ethernet instead of console, but i got the same results.
  97.  
  98.  
  99. Being desperate, I tried gdb for qemu, which works flawlessly!
  100.  
  101.  
  102.  
  103. Can anyone help me? Is the KGDB setup wrong? I have no idea how to continue from here.
  104.  
  105.  
Advertisement
Add Comment
Please, Sign In to add comment