简体   繁体   English

调试如何在用C编程的MCU系统中进行

[英]How debugging works in MCU systems programmed in C

As I understand, on linux systems debugging is done via the ptrace sys-call. 据我了解,在Linux系统上,调试是通过ptrace sys-call完成的。
I would like to know how would I write a debugger for a micro-controller (no-OS). 我想知道如何为微控制器(无OS)编写调试器。
Let us for the sake of simplicity assume the case of a software debugger for a board like Arduino Due (ARM based). 为了简单起见,让我们假设使用诸如Arduino Due (基于ARM)之类的板的软件调试器。

  • What would I have to learn to accomplish such a project, assuming I have a fair idea on how debuggers work on Linux and Windows 假设我对调试器在Linux和Windows上的工作方式有一个很好的了解,那么我将学到什么来完成这样的项目
  • How different would programming a debugger for a MCU system be? 为MCU系统编程调试器有何不同? (I can't use sys-calls) (我不能使用系统调用)
  • Is debugging achievable via USB or serial interface? 是否可以通过USB或串行接口进行调试?
  • Which languages should I use? 我应该使用哪种语言? (C, C++, Arm assembly) (C,C ++,Arm汇编)
  • How can the armgcc compiler help me with my project (are there flag options such as -g etc?) armgcc编译器如何为我的项目提供帮助(是否有-g等标志选项?)

I plan to implement the debugger as a command line Linux utility. 我计划将调试器实现为命令行Linux实用程序。

Most modern processors, including the ARM on the Arduino Due have on-chip debug support accesses via a JTAG interface. 包括Arduino Due上的ARM在内的大多数现代处理器均具有通过JTAG接口进行的片上调试支持。 The Cortex-M3 on-chip debug supports 8 hardware breakpoints and some other features - with code running in flash memory you cannot set software breakpoints. Cortex-M3片上调试支持8个硬件断点和一些其他功能-由于代码在闪存中运行,因此您无法设置软件断点。

The JTAG interface itself is rather simple, but you will need special hardware to support it from a PC. JTAG接口本身非常简单,但是您将需要特殊的硬件才能从PC支持它。 Depending of performance and features a JTAG debugger may vary in cost hugely from very low to serious money. 根据性能和功能的不同,JTAG调试器的成本可能从非常低到昂贵的价格差异很大。 Software to interface the JTAG to the debugger software is required. 需要将JTAG连接到调试器软件的软件。 OpenOCD is an open source tool for interfacing JTAG/On-chip debug to GDB allowing GDB-ARM to be hosted on a PC to debug the remote ARM target. OpenOCD是一个开放源代码工具,用于将JTAG /片上调试与GDB接口,允许将GDB-ARM托管在PC上以调试远程ARM目标。

You could in theory write your own software to to access the OCD via JTAG. 从理论上讲,您可以编写自己的软件来通过JTAG访问OCD。 I have never considered implementating a target hosted debugger on a microcontroller, although I have used VxWorks on ARM9, SrongARM and x86 and it has limited support for target hosted debugging. 尽管我已经在ARM9,SrongARM和x86上使用了VxWorks,并且它对目标托管调试的支持有限,但我从未考虑过在微控制器上实现目标托管调试器。 The utility of target hosted debug is limited by the lack of the source code and symbol table information that is available to a hosted debugger to support source-level debugging. 目标托管调试的实用程序受到缺少源代码和符号表信息的限制,这些信息和符号表信息可用于托管调试器以支持源级调试。

Even so, I believe that it is possible to access the on-chip debug from the target itself see ARM's documentation for details. 即使这样,我相信也可以从目标本身访问片上调试, 有关详细信息,请参阅ARM文档。

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

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