<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>On debug method(How to implement the &amp;quot;TRACE&amp;quot; macro?)</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/16298/on-debug-method-how-to-implement-the-trace-macro</link><description> Dear all,my footprint of 51 on my project board is PLCC44,so the ICE can&amp;#39;t be used(footprint is DIP40).I have to connect the 51&amp;#39;s serial port to PC and dump everthing I need to it.So the program of debug version are full of &amp;quot;printf&amp;quot; statements which</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/122241?ContentTypeID=1</link><pubDate>Mon, 22 Dec 2003 09:52:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e5afb0b9-a971-4b32-a28f-837a013ea40a</guid><dc:creator>Aleksei Selishev</dc:creator><description>&lt;p&gt;BTW, the free AGSI-based &amp;quot;trace window&amp;quot; plugin for C51:&lt;br /&gt;
&lt;a href="http://embedded0.nm.ru/en/downloads.html" target="_blank"&gt;http://embedded0.nm.ru/en/downloads.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/110672?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 21:31:06 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:90197749-8204-4f41-bd1f-795fd3966dc3</guid><dc:creator>Jim King</dc:creator><description>&lt;p&gt;Thank all of friends,thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/95989?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 17:20:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:86f82bd5-638f-47b7-b7e5-374a15c681dc</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;You need something like this:&lt;pre&gt;ifdef DEBUG
//Debug mode - TRACE causes printf output
#include &amp;lt;stdio.h&amp;gt;
#define TRACE(params) printf params;
#else
//Release mode - TRACE expands to nothing!
#define TRACE(params)
#endif // DEBUG&lt;/pre&gt;and use it like this:&lt;pre&gt;void some_func( char x )
{
   TRACE( (&amp;quot;Entered some_func( %bX )&amp;quot;, x) )
   :
   :
}&lt;/pre&gt;Note the use of two sets of parentheses - the outer set is part of the macro &amp;quot;call&amp;quot;, and the inner set is taken as part of the parameter passed to the macro - and hence appears in (or disappears with) the macro expansion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/95990?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 17:10:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ddbab048-1f50-4b27-8065-7f390435f210</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;macros such as HIBYTE,LOBYTE etc,we must define it ourselves.A direct way is to steal the codes from the windows SDK or MFC&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Be very careful!&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Not only are you dealing with a different Compiler, but also a completely different target.&lt;br /&gt;
&lt;br /&gt;
You can&amp;#39;t just steal them - you will need to read them carefully &amp;amp; fully understand them to be able to decide if they will give the right resuls with Keil C51, or what modifications are required!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/95993?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 17:06:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5c0b44f6-255c-4133-aeda-fbcf1ebe0fcc</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;More adaptors:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.winslowadaptics.co.uk/" target="_blank"&gt;http://www.winslowadaptics.co.uk/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
(some are in the RS catalogue).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/72156?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 15:20:32 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:98b22115-d17a-4ab8-b677-b5334de99219</guid><dc:creator>Alan Preuss</dc:creator><description>&lt;p&gt;Ironwood has a line of 8051 adapters (DIP40 to PLCC44) that you may want to check out.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.ironwoodelectronics.com/" target="_blank"&gt;http://www.ironwoodelectronics.com/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Alan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/110678?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 10:44:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5de2f864-1694-41c6-b1df-7712ff049d2a</guid><dc:creator>Jim King</dc:creator><description>&lt;p&gt;What&amp;#39;s wrong with my arg list?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/41417?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 07:48:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:58eeaa95-e1a0-48c4-a8a5-2b9fb445508d</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;i&gt;my footprint of 51 on my project board is PLCC44,so the ICE can&amp;#39;t be used(footprint is DIP40).&lt;/i&gt;&lt;br /&gt;
CEIBO, for one has a converter whatshamacallit where you plug the DIP in the top and plug the bottom in your PLCC socket.&lt;br /&gt;
&lt;br /&gt;
Erik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/95995?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 06:24:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fe15c9c9-e665-4c55-bac0-be3047b90b92</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;That error C214 you got almost certainly has nothing to do with the TRACE macro as such, but with the argument list you passed it.&lt;br /&gt;
&lt;br /&gt;
#defining DEBUG or RELEASE is supposed to be done by the project / makefile, so you can decide at compile time, outside the code, which modules to compile with the debug printouts active.&lt;br /&gt;
&lt;br /&gt;
Seriously, though: if you need to look into Microsoft SDKs to rip off a HIBYTE() macro instead of rolling your own, that&amp;#39;s a strong sign you&amp;#39;re in well over your head already.  You&amp;#39;ll have to brush up your knowledge of the C programming language considerably before you go on working on embedded software, I think.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/72155?ContentTypeID=1</link><pubDate>Fri, 19 Dec 2003 00:41:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:abec3858-fa29-4694-bf53-64062037cd11</guid><dc:creator>Jim King</dc:creator><description>&lt;p&gt;Many thanks,Davis.You give a very smart way.But the following statements&lt;br /&gt;
&lt;pre&gt;
typedef unsigned long ULONG;
ULONG xdata * data pMem = 0;
TRACE ((&amp;quot;Read Value:%lXH\n&amp;quot;, *pMem));
&lt;/pre&gt;
cause error.It&amp;#39;s error C214: illegal pointer conversion.I don&amp;#39;t know why.And,the invoke way &amp;quot;TRACE ((&amp;quot;...&amp;quot;));&amp;quot; looks a little strange that anybody else may get confused.Further more,if we have a defined  TRACE macro,shall we define _DEBUG or _RELEASE in every source files?&lt;br /&gt;
&lt;br /&gt;
    Do you have an alternative way to implement this macro just like MFC gives us?I have tried to define the TRACE as a function.&lt;br /&gt;
&lt;pre&gt;
//debug.h
#ifndef __DEBUG_H__
#define __DEBUG_H__

#ifdef _RELEASE
//release mode
#define TRACE(const char * format, ...)//cause error
#else
//debug mode
#include &amp;lt;stdio.h&amp;gt;
void TRACE (const char * format, ...);
#endif //_RELEASE

#endif //__DEBUG_H__

//debug.c
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdarg.h&amp;gt;

void TRACE (const char * format, ...)
{
	va_list ap;
	va_start (ap, format);
	printf (format, ap)
	va_end (ap);
}
&lt;/pre&gt;
    The TRACE function of the debug mode is successfully compiled,but the TRACE macro of the release mode isn&amp;#39;t.I have searched the MFC source code and wanted to look for the definition of the TRACE macro,but I cound&amp;#39;t find it.&lt;br /&gt;
&lt;br /&gt;
    I know MFC needs PC and I don&amp;#39;t want to port MFC to keil.For keil don&amp;#39;t define some convenient macros such as HIBYTE,LOBYTE etc,we must define it ourselves.A direct way is to steal the codes from the windows SDK or MFC.Now I need a TRACE macro to simplify the development and I&amp;#39;m not skillful enough.Please help me.Thank you very much.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/41416?ContentTypeID=1</link><pubDate>Thu, 18 Dec 2003 17:12:46 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0b1fa6e1-6fba-479c-9876-dae860f45de6</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;MFC implement it for us while Keil C don&amp;#39;t.&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Yes, and MFC &lt;b&gt;&lt;i&gt;requires&lt;/i&gt;&lt;/b&gt; Win32, a Pentium processor running at several hundred MHz, several hundred MB of hard drive space, tens of MB of RAM, &lt;i&gt;etc, etc, etc,...&lt;/i&gt; - while Keil C don&amp;#39;t &lt;i&gt;(sic)&lt;/i&gt;!&lt;br /&gt;
&lt;br /&gt;
So no surprises there, then!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/86610?ContentTypeID=1</link><pubDate>Thu, 18 Dec 2003 17:07:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a7dcb8fb-1f36-49dd-8ba6-cf2a71913c44</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;The extra level of parenthesis works fine with C51.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: On debug method(How to implement the "TRACE" macro?)</title><link>https://community.arm.com/thread/41413?ContentTypeID=1</link><pubDate>Thu, 18 Dec 2003 11:51:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:be10bce2-e5be-4db9-9c84-8c875efb2b55</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;&lt;i&gt;MFC implement it for us while Keil C don&amp;#39;t&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
I&amp;#39;ll get back to you when I&amp;#39;m done with my port of MFC to the 8051.  I still have some issues with the DirectX 9 support for multiprocessor support.&lt;br /&gt;
&lt;br /&gt;
In the meantime, it&amp;#39;s a pretty easy macro to write:&lt;br /&gt;
&lt;br /&gt;
#if DEBUG&lt;br /&gt;
#define TRACE(args)  printf(args)&lt;br /&gt;
#else&lt;br /&gt;
#define TRACE(args)&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
Define DEBUG, and you get your debug code.  Don&amp;#39;t define it, and the statements all vanish.&lt;br /&gt;
&lt;br /&gt;
If I&amp;#39;ve got a fancy CLI to play with, I like to add a &amp;quot;debug level&amp;quot; to the macro to control verbosity of the output.  I assign the debug output to &amp;quot;high&amp;quot;, &amp;quot;medium&amp;quot;, &amp;quot;low&amp;quot; levels of detail (1, 2, 3).  Then, I can use an &amp;#39;if&amp;#39; statement to compare to a dynamically controlled debug level variable so that I&amp;#39;m not always buried in the maximum spew from the debug code, but can turn it on when I want.  A little more macro sleight-of-hand lets you selectively compile out debug levels you don&amp;#39;t want in the code.&lt;br /&gt;
&lt;br /&gt;
Different preprocessors seem to handle the problem of variable arguments differently.  That is, if you have&lt;br /&gt;
&lt;br /&gt;
printf (&amp;quot;%d %d %d\n&amp;quot;, d1, d2, d2);&lt;br /&gt;
&lt;br /&gt;
you may or may not be able to call&lt;br /&gt;
&lt;br /&gt;
TRACE (&amp;quot;%d %d %d\n&amp;quot;, d1, d2, d2);&lt;br /&gt;
&lt;br /&gt;
since there are four actual arguments to TRACE but only one formal argument declared.  Some preprocessors simply make the last argument match all arguments to the macro.  If I recall correctly, C99 actually adds support for variadic macro declarations.  But I also can sometimes get away with an extra level of parens:&lt;br /&gt;
&lt;br /&gt;
TRACE ((&amp;quot;%d %d %d\n&amp;quot;, d1, d2, d2));&lt;br /&gt;
&lt;br /&gt;
which is a little ugly, but groups all the arguments into one single one for the macro expansion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>