gnuk/ChibiOS_2.0.8/docs/html/article_debug.html
2010-11-30 13:54:43 +09:00

126 lines
8.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ChibiOS/RT: Debugging ChibiOS/RT applications</title>
<link href="custom.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<table style="text-align: center; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 80px;"><img alt="ChibiOS/RT Logo" src="logo_small.png"></td>
<td><big><big>ChibiOS/RT</big></big><br><br>Architecture - Reference Manual - Guides</td>
<td style="width: 80px;"></td>
</tr>
</tbody>
</table>
<hr size="1">
<!-- Generated by Doxygen 1.7.1 -->
<div class="navigation" id="top">
<div class="tabs">
<ul class="tablist">
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="navpath">
<ul>
<li><a class="el" href="main.html">ChibiOS/RT</a> </li>
<li><a class="el" href="articles.html">Articles and Code Samples</a> </li>
<li><a class="el" href="page_kb.html">Knowledge Base</a> </li>
</ul>
</div>
</div>
<div class="header">
<div class="headertitle">
<h1>Debugging ChibiOS/RT applications </h1> </div>
</div>
<div class="contents">
<p>ChibiOS/RT offers several mechanisms that can help in the debug phase of the development cycle.</p>
<h2>What this guide does not cover</h2>
<p>This guide assumes knowledge in following areas:</p>
<ul>
<li>General knowledge of embedded development.</li>
<li>RTOS concepts.</li>
<li>Setup of your specific target hardware and toolchain.</li>
<li>Knowledge of your toolchain. The guide will explain what you need to do, not how it is done using you specific debugger, compiler, JTAG probe and target hardware.</li>
</ul>
<h2>Helpful debugging configuration settings</h2>
<p>There are several settings in your kernel configuration file (see <a class="el" href="chconf_8h.html">templates/chconf.h</a>) that you may want to enable during debugging and in general during the whole development process.</p>
<ul>
<li><code>CH_OPTIMIZE_SPEED=FALSE</code>, this disables inlining into the kernel code and makes it easier to debug using your debugger, you may also want to reduce or disable compiler optimizations (-O0 using GCC).</li>
<li><code>CH_DBG_ENABLE_CHECKS=TRUE</code>, this setting enables the checks on the API parameters, useful to understand if you are passing wrong parameters to the OS functions.</li>
<li><code>CH_DBG_ENABLE_ASSERTS=TRUE</code>, this setting enables the OS internal consistency checks, this can trap several kind of errors in the user code (or in the kernel itself).</li>
<li><code>CH_DBG_ENABLE_STACK_CHECK=TRUE</code>, this setting enables checks on threads stack overflow. Note that this option is not available in all ports, check your port documentation. If not supported then it is silently ignored, see also the article <a class="el" href="article_stacks.html">Stacks and stack sizes</a>.</li>
<li><code>CH_DBG_FILL_THREADS=TRUE</code>, this setting enables the threads workspace filling, this can help examining the stack usage from your debugger.</li>
</ul>
<p>Note that all the failed checks lock the kernel into the <code><a class="el" href="group__core.html#gaffa627cc34d473a5c1b00810798c1592" title="Halts the system.">port_halt()</a></code> function. In order to assess what triggered the lock the global variable <code>panic_msg</code> must be inspected using the debugger, the variable is a pointer to an error message (a zero terminated string), the pointer may contain <code>NULL</code> if the lock was triggered by a stack overflow.</p>
<h2>Common errors and symptoms</h2>
<p>There are some common errors while using an RTOS, use the following table as a check list, if your problem is not a generic programming error then probably it is one of the following common RTOS/embedded related mistakes:</p>
<ul>
<li>Insufficient stack allocated to one or more threads.<br/>
Common symptoms:<ul>
<li>Target instability.</li>
<li>Target locked into the <code><a class="el" href="group__core.html#gaffa627cc34d473a5c1b00810798c1592" title="Halts the system.">port_halt()</a></code> function.</li>
<li>Target trapped into an exception handler (architecture dependent).</li>
<li>Target apparent self reset (not real resets usually).</li>
</ul>
</li>
<li>Insufficient stack allocated to the IRQ stack (in those architectures that have a separate IRQ stack, ARM as example).<br/>
Common symptoms:<ul>
<li>Target instability.</li>
<li>Target trapped into an exception handler (architecture dependent).</li>
<li>Target apparent self reset (not real resets usually).</li>
</ul>
</li>
<li>Use of a non reentrant function from within an interrupt handler, as example most C runtime functions.<br/>
Common symptoms:<ul>
<li>Target instability.</li>
<li>Unexpected application behavior.</li>
</ul>
</li>
<li>Missing use of a mutual exclusion mechanism to protect data (or non reentrant code) shared among multiple threads and/or threads and interrupt handlers, see also the article <a class="el" href="article_mutual_exclusion.html">Mutual Exclusion guide</a>.<br/>
Common symptoms:<ul>
<li>Target instability.</li>
<li>Unexpected application behavior.</li>
</ul>
</li>
<li>Use of S-class or I-class APIs outside a proper lock state, see the <a class="el" href="concepts.html">Kernel Concepts</a> article, specifically the <a class="el" href="concepts.html#api_suffixes">API Names Suffixes</a> and <a class="el" href="concepts.html#system_states">System States</a> sections.<br/>
Common symptoms:<ul>
<li>Target instability.</li>
<li>Target trapped into an exception handler (architecture dependent).</li>
<li>Target apparent self reset (not real resets usually).</li>
</ul>
</li>
<li>Use of a non I-class API from an interrupt handler, see the <a class="el" href="concepts.html">Kernel Concepts</a> article, specifically the <a class="el" href="concepts.html#api_suffixes">API Names Suffixes</a> and <a class="el" href="concepts.html#system_states">System States</a> sections.<br/>
Common symptoms:<ul>
<li>Target instability.</li>
<li>Target trapped into an exception handler (architecture dependent).</li>
<li>Target apparent self reset (not real resets usually).</li>
</ul>
</li>
<li>Wrong threads priority assignment. One of the most critical things to do when designing an RTOS based application is to assign correct priorities to the threads in the system.<br/>
Common symptoms:<ul>
<li>Excessive or unpredictable response times.</li>
<li>Threads that appear to be never executed (CPU intensive threads at higher priority).</li>
</ul>
</li>
</ul>
<h2>General suggestions</h2>
<p>For the less expert users, there are several things you may do in order to minimize the need for debugging:</p>
<ul>
<li>Read carefully the documentation first.</li>
<li>Try to find a code examples for things are you going to do, good sources are: the documentation, the test code, under "./test" you will find examples for almost any API in the ChibiOS/RT kernel and most common RTOS related tasks, under "./testhal" there are examples regarding the various device drivers, the various demos contain good code samples too).</li>
<li>Start your application from an existing demo, add things one at a time and test often, if you add too many things at once then finding a small problem can become a debugging nightmare. Follow the cycle: think, implement, test, repeat.</li>
<li>If you are stuck for too much time then consider asking for advice.</li>
<li>Report bugs and problems, bugs can be fixed, problems can become new articles in the documentation (this and other documentation articles spawned from questions in the forum or in the tracker).</li>
<li>Never give up :-)</li>
</ul>
</div>
<hr size="1"><address style="text-align: right;"><small>
Generated on Sun Nov 28 2010 14:09:54 for ChibiOS/RT by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.7.1</small></address>
</body>
</html>