1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //=================================================================
27 // eCosTestMonitorFilter.cpp
29 // Simple filter for monitoring data flowing through the client
31 //=================================================================
32 //=================================================================
33 //#####DESCRIPTIONBEGIN####
36 // Contributors: jskov
38 // Description: This filter sits between GDB and the test running on
39 // the target, allowing all transmitted data to be output.
41 // *Take* the time to move some of the functions here (which are shared
42 // with eCosTestSerialFilter, and probably DownloadFilter) and move
43 // them to some shared file.
44 //####DESCRIPTIONEND####
48 #include "eCosTestMonitorFilter.h"
50 CeCosTestMonitorFilter::CeCosTestMonitorFilter():
55 CeCosTestMonitorFilter::~CeCosTestMonitorFilter()
59 //------------------------
63 CeCosTestMonitorFilter::ConsoleWrite(const char* pszStr)
65 fputs(pszStr, stderr);
70 CeCosTestMonitorFilter::Trace(const char* pszFormat, ...)
74 va_start (marker, pszFormat);
76 for(int nLength=100;nLength;) {
77 char *buf=new char[1+nLength];
78 int n=vsnprintf(buf, nLength, pszFormat, marker );
80 nLength*=2; // NT behavior
81 } else if (n<nLength){
83 nLength=0; // trigger exit from loop
85 nLength=n+1; // UNIX behavior generally, or NT behavior when buffer size exactly matches required length
94 CeCosTestMonitorFilter::PrintHex(const unsigned char* d1, int len, data_origin_t origin/*=SF_TARGET*/)
102 int count = MIN(width, len);
106 p += sprintf(p, "T:");
109 p += sprintf(p, "H:");
112 p += sprintf(p, "%04x > ", offset);
114 for (i = 0; i < count; i++)
115 p += sprintf(p, "%02x ", d1[i]);
116 for ( ; i < width ; i++)
117 p += sprintf(p, ".. ");
119 // Print ASCII string
120 p += sprintf(p, "'");
121 for (i = 0; i < count; i++) {
123 if (' ' >= c || 'z' <= c)
125 p += sprintf(p, "%c", c);
138 SerialMonitorFunction(void*& pBuf,
144 CeCosTestMonitorFilter* p = (CeCosTestMonitorFilter*) pParem;
145 return p->FilterFunctionProper(pBuf, nRead);
149 CeCosTestMonitorFilter::FilterFunctionProper(void*& pBuf, unsigned int& nRead)
151 char* buffer = (char*) pBuf;
154 PrintHex((unsigned char*) buffer, nRead, m_eOrigin);