OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [ecostest/] [common/] [eCosTestMonitorFilter.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
//=================================================================
23
//
24
//        eCosTestMonitorFilter.cpp
25
//
26
//        Simple filter for monitoring data flowing through the client
27
//
28
//=================================================================
29
//=================================================================
30
//#####DESCRIPTIONBEGIN####
31
//
32
// Author(s):     jskov
33
// Contributors:  jskov
34
// Date:          2000-03-16
35
// Description:   This filter sits between GDB and the test running on
36
//                the target, allowing all transmitted data to be output.
37
//
38
// *Take* the time to move some of the functions here (which are shared
39
// with eCosTestSerialFilter, and probably DownloadFilter) and move
40
// them to some shared file.
41
//####DESCRIPTIONEND####
42
 
43
#include "eCosStd.h"
44
 
45
#include "eCosTestMonitorFilter.h"
46
 
47
CeCosTestMonitorFilter::CeCosTestMonitorFilter():
48
  m_bOptVerbose(false)
49
{
50
}
51
 
52
CeCosTestMonitorFilter::~CeCosTestMonitorFilter()
53
{
54
}
55
 
56
//------------------------
57
// Output helpers.
58
 
59
void
60
CeCosTestMonitorFilter::ConsoleWrite(const char* pszStr)
61
{
62
    fputs(pszStr, stderr);
63
    fflush(stderr);
64
}
65
 
66
void
67
CeCosTestMonitorFilter::Trace(const char* pszFormat, ...)
68
{
69
 
70
  va_list marker;
71
  va_start (marker, pszFormat);
72
 
73
  for(int nLength=100;nLength;) {
74
    char *buf=new char[1+nLength];
75
    int n=vsnprintf(buf, nLength, pszFormat, marker );
76
    if(-1==n){
77
      nLength*=2;  // NT behavior
78
    } else if (n<nLength){
79
      ConsoleWrite(buf);
80
      nLength=0;   // trigger exit from loop
81
    } else {
82
      nLength=n+1; // UNIX behavior generally, or NT behavior when buffer size exactly matches required length
83
    }
84
    delete [] buf;
85
  }
86
 
87
  va_end (marker);
88
}
89
 
90
void
91
CeCosTestMonitorFilter::PrintHex(const unsigned char* d1, int len, data_origin_t origin/*=SF_TARGET*/)
92
{
93
    int offset = 0;
94
    int i;
95
    char buf[128];
96
    int width = 8;
97
 
98
    while (len) {
99
        int count = MIN(width, len);
100
        char* p = buf;
101
        switch (origin) {
102
        case MF_TARGET:
103
            p += sprintf(p, "T:");
104
            break;
105
        case MF_HOST:
106
            p += sprintf(p, "H:");
107
            break;
108
        }
109
        p += sprintf(p, "%04x > ", offset);
110
        // Print hex values.
111
        for (i = 0; i < count; i++)
112
            p += sprintf(p, "%02x ", d1[i]);
113
        for (     ; i < width   ; i++)
114
            p += sprintf(p, ".. ");
115
 
116
        // Print ASCII string
117
        p += sprintf(p, "'");
118
        for (i = 0; i < count; i++) {
119
            int c = d1[i];
120
            if (' ' >= c || 'z' <= c)
121
                c = '.';
122
            p += sprintf(p, "%c", c);
123
        }
124
        sprintf(p, "'\n");
125
 
126
        Trace("%s", buf);
127
 
128
        len -= count;
129
        offset += count;
130
        d1 += count;
131
    }
132
}
133
 
134
bool CALLBACK
135
SerialMonitorFunction(void*& pBuf,
136
                      unsigned int& nRead,
137
                      CeCosSerial& serial,
138
                      CeCosSocket& socket,
139
                      void* pParem)
140
{
141
    CeCosTestMonitorFilter* p = (CeCosTestMonitorFilter*) pParem;
142
    return p->FilterFunctionProper(pBuf, nRead);
143
}
144
 
145
bool
146
CeCosTestMonitorFilter::FilterFunctionProper(void*& pBuf, unsigned int& nRead)
147
{
148
    char* buffer = (char*) pBuf;
149
 
150
    if (m_bOptVerbose)
151
        PrintHex((unsigned char*) buffer, nRead, m_eOrigin);
152
 
153
    return true;
154
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.