简体   繁体   English

从AMD主机调试在Intel目标上运行的linux内核-如何将控制权返还给gdb?

[英]Debug linux kernel running on Intel target from AMD host - how to return control to gdb?

I have compiled kernel 3.13.0-55 on Ubuntu on both AMD and Intel machines. 我已经在AMD和Intel机器上的Ubuntu上编译了内核3.13.0-55。 I tried to copy compiled kernel to Intel target but it won't boot with that one. 我试图将已编译的内核复制到Intel目标,但它无法与此目标一起启动。 Therefore I have compiled the same version of kernel on that Intel. 因此,我在该Intel上编译了相同版本的内核。 I can run this kernel on Intel and Intel waits for kgdb to attach to it. 我可以在Intel上运行该内核,并且Intel等待kgdb附加到它。 I do it on AMD with 我在AMD上用

target remote /dev/ttyS0

and I am able to step into kernel code over serial connection. 而且我能够通过串行连接进入内核代码。 I do continue then, and if I set some breakpoints, for example at vfs_read then yes - it is hit. 然后我继续,如果我设置了一些断点,例如在vfs_read那么可以-是命中。 But when I write g to /proc/sysrq-trigger on the target Intel, after I typed continue in gdb on host and Intel continued to run, then the target halts, and I cannot return the control to debugger running on AMD any more. 但是,当我在目标Intel上的/ proc / sysrq-trigger中写入g时,在主机上的gdb中键入Continue并继续运行I​​ntel之后,目标停止了,并且我无法再将控件返回给在AMD上运行的调试器。 Writing g to /proc/sysrq-trigger halts the Intel but control isn't returned to the AMD gdb. 将g写入/ proc / sysrq-trigger会暂停Intel,但控制权不会返回给AMD gdb。

I suspected this might be caused due to it is not EXACTLY same (not copied) version of kernel, but copied version of kernel from target machine doesn't change this behavior either. 我怀疑这可能是由于内核版本不完全相同(未复制)引起的,但是从目标计算机复制的内核版本也无法更改此行为。 How should I troubleshoot this problem? 我应该如何解决这个问题? How to return the control to debugger? 如何将控件返回给调试器? What can I test/verify/check? 我可以测试/验证/检查什么? What additional info do you need? 您还需要什么其他信息? Please let me know. 请告诉我。 Enable Magic SysRq is set in kernel config. 启用Magic SysRq在内核配置中设置。

uname -a:

AMD:  3.13.11-ckt20 #5 SMP Tue Jun 30 17:52:33 BST 2015 x86_64 x86_64 x86_64 GNU/Linux

Intel: 3.13.11-ckt20 #2 SMP Tue Jun 30 17:10:47 BST 2015 x86_64 x86_64 x86_64 GNU/Linux

GDB sesion: GDB会议:

peter@peterubuntu0:~/kernel$ sudo gdb vmlinux_intel 
Reading symbols from vmlinux_intel...done.
(gdb) set serial baud 115200
(gdb) set debug remote 1
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
Sending packet: $qSupported:multiprocess+;xmlRegisters=i386;qRelocInsn+#b5...Ack
Packet received: 
Packet qSupported (supported-packets) is NOT supported
Sending packet: $Hg0#df...Ack
Packet received: OK
Sending packet: $qTStatus#49...Ack
Packet received: 
Packet qTStatus (trace-status) is NOT supported
Sending packet: $?#3f...Ack
Packet received: S05
Sending packet: $Hc-1#09...Ack
Packet received: OK
Sending packet: $qC#b4...Ack
Packet received: QC01
Sending packet: $qAttached#8f...Ack
Packet received: 
Packet qAttached (query-attached) is NOT supported
Sending packet: $qOffsets#4b...Ack
Packet received: 
Sending packet: $g#67...Ack
Packet received: 2f000000000000000000000000000000a80b0000000000006c1c0000000000006c1c000000000000460200000000000038de8b260388ffff38de8b260388ffff960000000000000022020000000000000100000000000000aaaaaa00000000002084ca81ffffffffe30000000000000000000000000000000000000000000000f4201081ffffffff0202000010000000000000000000000000000000
kgdb_breakpoint () at kernel/debug/debug_core.c:1042
1042        wmb(); /* Sync point after breakpoint */
Sending packet: $qSymbol::#5b...Ack
Packet received: 
Packet qSymbol (symbol-lookup) is NOT supported
(gdb) c
Continuing.
Sending packet: $vCont?#49...Ack
Packet received: 
Packet vCont (verbose-resume) is NOT supported
Sending packet: $Hc0#db...Ack
Packet received: OK
Sending packet: $c#63...Ack




^Casync_remote_interrupt called            // this is where I did Ctrl+C
remote_stop called
^Casync_remote_interrupt_twice called      // and Ctrl-C again
Interrupted while waiting for the program.
Give up (and stop debugging it)? (y or n) y
Quit

EDIT: 编辑:

Though it doesn't work when I try to debug Intel from Amd (both running the same kernel 3.13.11-ckt20 SMP 2015 x86_64 x86_64 x86_64 GNU/Linux ): target - Intel(R) Core(TM)2 Duo CPU E8500 @ 3.16GHz host - AMD FX(tm)-4100 Quad-Core Processor 虽然当我尝试从Amd调试英特尔(运行相同的内核3.13.11-ckt20 SMP 2015 x86_64 x86_64 x86_64 GNU / Linux)时无法正常工作:目标-Intel(R)Core(TM)2 Duo CPU E8500 @ 3.16GHz主机-AMD FX(tm)-4100四核处理器

it works in the opposite direction: target - AMD FX(tm)-4100 Quad-Core Processor host - Intel(R) Core(TM)2 Duo CPU E8500 @ 3.16GHz 它的工作方向相反:目标-AMD FX(tm)-4100四核处理器主机-Intel(R)Core(TM)2 Duo CPU E8500 @ 3.16GHz

Maybe it is related to hardware breakpoints, registers, cpu implementation? 也许与硬件断点,寄存器,CPU实现有关?

When you set breakpoints and write continue , you can do a ctrl + c on gdb to write a new command , for example : info registers to see registers status from the start to your breakpoints . 设置断点并继续写入时,可以在gdb上执行ctrl + c来编写新命令,例如: info registers以查看从头到断点的寄存器状态。

Or Try out this using Qemu and gdb . 或者使用Qemu和gdb尝试一下。 you can use 您可以使用

Qemu -s -S , qemu will listen on localhost:1234 Qemu -s -S ,qemu将在localhost:1234上侦听

then in gdb use target remote localhost:1234 然后在gdb中使用target remote localhost:1234

If you invoke qemu from within gdb, you'll probably want to skip SIGUSR1 ("handle SIGUSR1 noprint"). 如果从gdb中调用qemu,则可能要跳过SIGUSR1(“处理SIGUSR1 noprint”)。

You can also invoke qemu with the -gdb option (or -s shortcut) which provides a gdb stub. 您还可以使用提供gdb存根的-gdb选项(或-s快捷方式)调用qemu。 You can then connect from any machine on the network (start up gdb, then use "target remote :"). 然后,您可以从网络上的任何计算机进行连接(启动gdb,然后使用“ target remote:”)。 See the man page for more information. 有关更多信息,请参见手册页。

Depending on what you are trying to debug, it may help to use the -S option to qemu (which freezes the CPU on startup), so you can get qemu up, attach gdb and get it set up, then continue. 根据您要调试的内容,对qemu使用-S选项可能会有所帮助(这会在启动时冻结CPU),因此您可以启动qemu,附加gdb并进行设置,然后继续。

On some architectures, using hardware breakpoints (gdb hbreak command) may work better than software breakpoints (gdb break command) 在某些体系结构上,使用硬件断点(gdb hbreak命令)可能比软件断点(gdb break命令)更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM