From: eLinux.org

Kdmx

Contents

overview

If the target board has a single serial port then a proxy on the host is
needed to be share the target port between the console and kgdb.

kdmx (kgdb demux) is one of the available proxy programs.

source location

The source is located in the agent-proxy git

  1. https://git.kernel.org/cgit/utils/kernel/kgdb/agent-proxy.git/
  2. git clone git://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git/

example 1 (simple)

This is a simple example, where I am using a USB serial port to connect
between my host and target.

I did all of the commands in “host window 1” before I did the commands
in “host window 2”.

I did all of the commands in “host window 2” before I did the commands
in “host window 3”.

  1. +--------------------- HOST -------------------------------------+ +-- TARGET --+
  2. | | | |
  3. | | | |
  4. v v v v
  5. terminal <----> /dev/pty/29 <----> +------+
  6. emulator | |
  7. | kdmx | <----> serial port <== cable ==> target console
  8. gdb <---------> /dev/pty/53 <----> | | /dev/ttyUSB0
  9. +------+

The absolute path of the kernel source directory is in
\${LINUX_SOURCE}.

The path of the kernel build directory, relative to the kernel source
directory, is in \${KBUILD_OUTPUT}

  1. $ echo ${LINUX_SOURCE}
  2. /xxx/linux--3.17
  3. $ echo ${KBUILD_OUTPUT}
  4. ../build/dragon_linus_3.17
  5. $ echo ${LINUX_SOURCE}/${KBUILD_OUTPUT}
  6. /xxx/linux--3.17/../build/dragon_linus_3.17
  7. ----- host window 1 - kdmx -----
  8. $ export PS1='[1]: '
  9. [1]: ./kdmx -n -d -p/dev/ttyUSB0 -b115200
  10. serial port: /dev/ttyUSB0
  11. Initalizing the serial port to 115200 8n1
  12. /dev/pts/29 is slave pty for for terminal emulator
  13. /dev/pts/53 is slave pty for gdb
  14. ----- host window 2 - terminal emulator -----
  15. # In this example, I am using the sysrq debug command instead of the
  16. # kernel command line 'kgdbwait' option to enter kgdb.
  17. #
  18. # The minicom "-o" option tells it not to initialize, so it does not
  19. # send the "Init string" (defaults to "At S7=45 S0=0...") when you run
  20. # minicom.
  21. $ export PS1='[2]: '
  22. [2]: minicom -o -w -p /dev/pts/29
  23. Welcome to minicom 2.5
  24. OPTIONS: I18n
  25. Compiled on May 2 2011, 10:05:24.
  26. Port /dev/tty8
  27. Press CTRL-A Z for help on special keys
  28. # Now in minicom, connected to the target console.
  29. # CONFIG_PRINTK_TIME=y, so timestamps will be added to
  30. # printk() messages to the console.
  31. $ export PS1='% '
  32. % cat /proc/version
  33. Linux version 3.17.0-dirty (frank@ussvlx) (gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT Mon Oct 6 10:19:37 PDT 2014
  34. % echo g >/proc/sysrq-trigger
  35. [ 24.246292] SysRq : DEBUG
  36. [ 24.247184] Entering KGDB
  37. ----- host window 3 - gdb -----
  38. $ export PS1='[3]: '
  39. [3]: echo ${CROSS_COMPILE}
  40. arm-eabi-
  41. [3]: cd ${LINUX_SOURCE}
  42. [3]: strings $KBUILD_OUTPUT/vmlinux | grep "^Linux version"
  43. Linux version 3.17.0-dirty (frank@ussvlx) (gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT Mon Oct 6 10:19:37 PDT 2014
  44. Linux version
  45. [3]: ${CROSS_COMPILE}gdb $KBUILD_OUTPUT/vmlinux
  46. GNU gdb (GDB) 7.3.1-gg2
  47. Copyright (C) 2011 Free Software Foundation, Inc.
  48. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  49. This is free software: you are free to change and redistribute it.
  50. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
  51. and "show warranty" for details.
  52. This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
  53. For bug reporting instructions, please see:
  54. <http://www.gnu.org/software/gdb/bugs/>...
  55. Reading symbols from /xxx/git_linus/build/dragon_linus_3.17/vmlinux...done.
  56. (gdb) target remote /dev/pts/53
  57. Remote debugging using /dev/pts/53
  58. kgdb_breakpoint ()
  59. at /xxx/git_linus/linux--3.17/kernel/debug/debug_core.c:1050
  60. 1050 arch_kgdb_breakpoint();
  61. (gdb) b sys_sync
  62. Breakpoint 1 at 0xc031d450: file /xxx/git_linus/linux--3.17/fs/sync.c, line 103.
  63. (gdb) c
  64. Continuing.

example 2 (automate paths of gdb pty and terminal emulator pty)

Keeping track of the paths of the pty slaves created by kdmx can be
annoying, so the status file feature has been added in kdmx version
141210a to automate use of the paths by gdb and the terminal emulator.

The status file feature is enabled with the ‘-s’ option, which will
create files containing the paths of the gdb slave pty and the terminal
emulator pty. Each time a slave pty is opened, the contents of the
respective status file is updated. The ‘-s’ option provides the path,
including a root for the file name, for the location of the status
files. The strings ‘_gdb’ and ‘_trm’ will be appended to the path to
form the names of the status files.

The absolute path of the kernel source directory is in
\${LINUX_SOURCE}.

The path of the kernel build directory, relative to the kernel source
directory, is in \${KBUILD_OUTPUT}

  1. $ echo ${LINUX_SOURCE}
  2. /xxx/linux--3.18
  3. $ echo ${KBUILD_OUTPUT}
  4. ../build/dragon_linus_3.18
  5. $ echo ${LINUX_SOURCE}/${KBUILD_OUTPUT}
  6. /xxx/linux--3.18/../build/dragon_linus_3.18

In this example, I place the status files in my kernel build directory.

  1. ----- host window 1 - kdmx -----
  2. $ export PS1='[1]: '
  3. [1]: kdmx -n -d -p/dev/ttyUSB0 -b115200 -s${LINUX_SOURCE}/${KBUILD_OUTPUT}/zzz__kdmx_pty
  4. gdb status file: /xxx/linux--3.18/../build/dragon_linus_3.18/zzz__kdmx_pty_gdb
  5. terminal emulator status file: /xxx/linux--3.18/../build/dragon_linus_3.18/zzz__kdmx_pty_trm
  6. serial port: /dev/ttyUSB0
  7. Initalizing the serial port to 115200 8n1
  8. /dev/pts/44 is slave pty for terminal emulator
  9. /dev/pts/45 is slave pty for gdb
  10. Use <ctrl>C to terminate program

Here are the contents of the status files:

  1. $ ls -l ${LINUX_SOURCE}/${KBUILD_OUTPUT}/zzz__kdmx_pty*
  2. -rw-r----- 1 frank frank_group 12 Dec 10 22:07 /xxx/linux--3.18/../build/dragon_linus_3.18/zzz__kdmx_pty_gdb
  3. -rw-r----- 1 frank frank_group 12 Dec 10 22:07 /xxx/linux--3.18/../build/dragon_linus_3.18/zzz__kdmx_pty_trm
  4. $ for k in `ls ${LINUX_SOURCE}/${KBUILD_OUTPUT}/zzz__kdmx_pty*`; do echo "$k:" ; cat $k; echo ; done
  5. /xxx/linux--3.18/../build/dragon_linus_3.18/zzz__kdmx_pty_gdb:
  6. /dev/pts/45
  7. /xxx/linux--3.18/../build/dragon_linus_3.18/zzz__kdmx_pty_trm:
  8. /dev/pts/44

The terminal emulator slave pty path is retrieved from the proper status
file and provided to minicom:

  1. ----- host window 2 - terminal emulator -----
  2. $ export PS1='[2]: '
  3. [2]: minicom -o -w -p `cat ${LINUX_SOURCE}/${KBUILD_OUTPUT}/zzz__kdmx_pty_trm`
  4. Welcome to minicom 2.5
  5. OPTIONS: I18n
  6. Compiled on May 2 2011, 10:05:24.
  7. Port /dev/tty8
  8. Press CTRL-A Z for help on special keys
  9. $ export PS1='% '
  10. % cat /proc/version
  11. Linux version 3.18.0-dirty (frank@ussvlx) (gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT Mon Dec 8 12:27:26 PST 2014
  12. % echo g > /proc/sysrq-trigger
  13. [210227.044514] SysRq : DEBUG

The task of getting the path of the gdb slave pty into gdb is a little
bit more complicated. (Any suggestions of a more straightforward method
are welcome.)

The following shell script is used to invoke the proper gdb and create a
user defined gdb command to connect to the correct pty path. The
\${CROSS_COMPILE} ensures that the gdb built for the target
architecture is used.

  1. #! /bin/bash
  2. kgdb_set_pty_cmd=`mktemp --tmpdir kgdb_set_pty_cmd.XXXXXXXXXX` || exit 1
  3. # user defined command
  4. #
  5. # \x5c is '\'
  6. #
  7. echo -e \
  8. "define tr" \
  9. "\ndont-repeat" \
  10. "\necho target remote" \
  11. "`cat ${LINUX_SOURCE}/${KBUILD_OUTPUT}/zzz__kdmx_pty_gdb`" \
  12. "\x5cn" \
  13. "\ntarget remote" \
  14. `cat ${LINUX_SOURCE}/${KBUILD_OUTPUT}/zzz__kdmx_pty_gdb` \
  15. "\nend" \
  16. "\n" \
  17. "\ndocument tr" \
  18. "\ntarget remote to the kdmx gdb pty" \
  19. "\n" \
  20. "\nThe kdmx gdb pty to be used is: " \
  21. `cat ${LINUX_SOURCE}/${KBUILD_OUTPUT}/zzz__kdmx_pty_gdb` \
  22. "\nThe kdmx gdb pty was determined at gdb startup. If the kdmx gdb pty" \
  23. "\nhas changed since then, restart gdb" \
  24. "\n" \
  25. "\nend" \
  26. > ${kgdb_set_pty_cmd}
  27. echo "${CROSS_COMPILE}gdb -x ${kgdb_set_pty_cmd} $KBUILD_OUTPUT/vmlinux"
  28. ${CROSS_COMPILE}gdb -x ${kgdb_set_pty_cmd} $KBUILD_OUTPUT/vmlinux
  29. rm ${kgdb_set_pty_cmd}
  30. ----- host window 3 - gdb -----
  31. $ export PS1='[3]: '
  32. [3]: echo ${CROSS_COMPILE}
  33. arm-eabi-
  34. [3]: cd ${LINUX_SOURCE}
  35. [3]: tcgdb
  36. arm-eabi-gdb -x /tmp/kgdb_set_pty_cmd.4xKNf2ah0T ../build/dragon_linus_3.18/vmlinux
  37. GNU gdb (GDB) 7.3.1-gg2
  38. Copyright (C) 2011 Free Software Foundation, Inc.
  39. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  40. This is free software: you are free to change and redistribute it.
  41. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
  42. and "show warranty" for details.
  43. This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
  44. For bug reporting instructions, please see:
  45. <http://www.gnu.org/software/gdb/bugs/>...
  46. Reading symbols from /local/nobackup/src/git_linus/build/dragon_linus_3.18/vmlinux...done.
  47. (gdb) help tr
  48. target remote to the kdmx gdb pty
  49. The kdmx gdb pty to be used is: /dev/pts/45
  50. The kdmx gdb pty was determined at gdb startup. If the kdmx gdb pty
  51. has changed since then, restart gdb
  52. (gdb) tr
  53. target remote /dev/pts/45
  54. kgdb_breakpoint () at /local/nobackup/src/git_linus/linux--3.18/kernel/debug/debug_core.c:1050
  55. 1050 arch_kgdb_breakpoint();
  56. (gdb) b sys_sync
  57. Breakpoint 1 at 0xc031f7b4: file /local/nobackup/src/git_linus/linux--3.18/fs/sync.c, line 103.
  58. (gdb) c
  59. Continuing.