QTools  8.0.1
Collection of Host-Based Tools
Loading...
Searching...
No Matches
qspy.h
Go to the documentation of this file.
1//============================================================================
2// QSPY software tracing host-side utility
3//
4// Q u a n t u m L e a P s
5// ------------------------
6// Modern Embedded Software
7//
8// Copyright(C) 2005 Quantum Leaps, LLC.All rights reserved.
9//
10// This software is licensed under the terms of the Quantum Leaps
11// QSPY SOFTWARE TRACING HOST UTILITY SOFTWARE END USER LICENSE.
12// Please see the file LICENSE-qspy.txt for the complete license text.
13//
14// Quantum Leaps contact information :
15// <www.state-machine.com/licensing>
16// <info@state-machine.com>
17//============================================================================
18#ifndef QSPY_H_
19#define QSPY_H_
20
21#define QSPY_VER "8.0.0"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27// low-level facilities for configuring QSpy and parsing QS records .....
32
33// typedef for inclusion of qpc_qs.h
34typedef uint16_t QSignal;
35
36// QSPY record being processed
37typedef struct {
38 uint8_t const *start; // start of the record
39 uint8_t const *pos; // current position in the stream
40 uint32_t tot_len; // total length of the record, including chksum
41 int32_t len; // current length of the stream
42 uint8_t rec; // the record-ID (see enum QSpyRecords in qs.h)
44
45// limits
46enum {
47 QS_RECORD_SIZE_MAX = 512, // max QS record size [bytes]
48 QS_LINE_LEN_MAX = 8192, // max length of a QSPY line [chars]
49 QS_FNAME_LEN_MAX = 256, // max length of filenames [chars]
50 QS_SEQ_LIST_LEN_MAX = 1024, // max length of the Seq list [chars]
51 QS_DNAME_LEN_MAX = 64, // max dictionary name length [chars]
52};
53
54// pointer to the callback function for customized QS record parsing
55typedef int (*QSPY_CustParseFun)(QSpyRecord * const me);
56typedef void (*QSPY_resetFun)(void);
57
58void QSpyRecord_init (QSpyRecord * const me,
59 uint8_t const *start, uint32_t tot_len);
61uint32_t QSpyRecord_getUint32(QSpyRecord * const me, uint8_t size);
62int32_t QSpyRecord_getInt32 (QSpyRecord * const me, uint8_t size);
63uint64_t QSpyRecord_getUint64(QSpyRecord * const me, uint8_t size);
64int64_t QSpyRecord_getInt64 (QSpyRecord * const me, uint8_t size);
65char const *QSpyRecord_getStr (QSpyRecord * const me);
66uint8_t const *QSpyRecord_getMem(QSpyRecord * const me,
67 uint8_t size,
68 uint32_t *pNum);
69
70// QSPY configuration and high-level interface ...............................
71// QSPY configuration parameters. @sa QSPY_config()
72typedef struct {
73 uint32_t qpDate; // e.g., 241008, 0 means "no-target-info"
74 uint16_t qpVersion; // e.g., 732
75 uint8_t qpType; // 1==qpc, 2==qpcpp
76 uint8_t endianness;
77 uint8_t objPtrSize;
78 uint8_t funPtrSize;
79 uint8_t tstampSize;
80 uint8_t sigSize;
81 uint8_t evtSize;
82 uint8_t queueCtrSize;
83 uint8_t poolCtrSize;
84 uint8_t poolBlkSize;
85 uint8_t tevtCtrSize;
86 uint8_t tbuild[6];
88
89typedef uint64_t KeyType;
90typedef uint32_t SigType;
91typedef uint64_t ObjType;
92
93void QSPY_config(QSpyConfig const *config,
94 QSPY_CustParseFun custParseFun);
96void QSPY_configMatFile(void *matFile);
97
98void QSPY_reset(void);
99void QSPY_parse(uint8_t const *buf, uint32_t nBytes);
100void QSPY_txReset(void);
101
102// command options
103enum {
107};
108bool QSPY_command(uint8_t cmdId, uint8_t opt);
109
110void QSPY_sendEvt(QSpyRecord const * const qrec);
111void QSPY_sendObj(QSpyRecord const * const qrec);
112void QSPY_sendCmd(QSpyRecord const * const qrec);
113void QSPY_sendTP (QSpyRecord const * const qrec);
114void QSPY_showNote(QSpyRecord const * const qrec);
115
116uint32_t QSPY_encode(uint8_t *dstBuf, uint32_t dstSize,
117 uint8_t const *srcBuf, uint32_t srcBytes);
118uint32_t QSPY_encodeResetCmd(uint8_t *dstBuf, uint32_t dstSize);
119uint32_t QSPY_encodeInfoCmd (uint8_t *dstBuf, uint32_t dstSize);
120uint32_t QSPY_encodeTickCmd (uint8_t *dstBuf, uint32_t dstSize, uint8_t rate);
121
122SigType QSPY_findSig(char const *name, ObjType obj);
123KeyType QSPY_findObj(char const *name);
124KeyType QSPY_findFun(char const *name);
125KeyType QSPY_findUsr(char const *name);
126KeyType QSPY_findEnum(char const *name, uint8_t group);
127
128#define SIG_NOT_FOUND ((SigType)-1)
129#define KEY_NOT_FOUND ((KeyType)-1)
130
131void QSPY_cleanup(void); // cleanup after the run
132
133char const* QSPY_tstampStr(void);
134
135void QSPY_onPrintLn(void); // callback to print the last line of output
136
137// prints information message to the QSPY output (without sending it to FE)
138void QSPY_printInfo(void);
139
140// prints error message to the QSPY output (sending it to FE)
142
143// last human-readable line of output from QSPY ..............................
144#define QS_LINE_OFFSET 8
146 // output forwarded to the back-end...
147 REG_OUT, // regular output from the Target
148 ERR_OUT, // error output from QSPY
149 // ...
150 BE_OUT, // last message forwarded to the back-end
151
152 // output NOT forwarded to the back-end...
153 INF_OUT, // internal info from QSPY
154 USR_OUT, // generic user message from BE
155 TST_OUT, // test message from BE
156};
157typedef struct {
159 int len; // the length of the composed string
160 int rec; // the corresponding QS record ID
161 int type; // the type of the output
162 int rx_status; // the type of the RX status
164
181
182// returns the "group" of a given QS record-ID
184
185// last output generated
187
188// beginning of QSPY line to print
189extern char const * const QSPY_line;
190
191#define SNPRINTF_LINE(format_, ...) do { \
192 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET], \
193 (QS_LINE_LEN_MAX - QS_LINE_OFFSET), \
194 format_, __VA_ARGS__); \
195 if ((0 < n_) && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET)) { \
196 QSPY_output.len = n_; \
197 } \
198 else { \
199 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
200 } \
201} while (0)
202
203#define SNPRINTF_APPEND(format_, ...) do { \
204 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET + QSPY_output.len],\
205 (QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len), \
206 format_, __VA_ARGS__); \
207 if ((0 < n_) \
208 && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len)) { \
209 QSPY_output.len += n_; \
210 } \
211 else { \
212 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
213 } \
214} while (0)
215
216#define CONFIG_UPDATE(member_, new_, diff_) \
217 if (QSPY_conf.member_ != (new_)) { \
218 QSPY_conf.member_ = (new_); \
219 (diff_) = 1U; \
220 } else (void)0
221
222// Dictionaries ..............................................................
223typedef struct {
226} DictEntry;
227
235
237 DictEntry* sto, uint32_t capacity);
238void Dictionary_config(Dictionary* const me, int keySize);
239char const* Dictionary_at(Dictionary* const me, unsigned idx);
240void Dictionary_put(Dictionary* const me, KeyType key, char const* name);
241char const* Dictionary_get(Dictionary* const me, KeyType key, char* buf);
243KeyType Dictionary_findKey(Dictionary* const me, char const* name);
245
251
259
261 SigDictEntry* sto, uint32_t capacity);
262void SigDictionary_config(SigDictionary* const me, int ptrSize);
264 SigType sig, ObjType obj, char const* name);
265char const* SigDictionary_get(SigDictionary* const me,
266 SigType sig, ObjType obj, char* buf);
268 SigType sig, ObjType obj);
270 char const* name, ObjType obj);
273
274// simplified string_copy() implementation "good enough" for the intended use
275int string_copy(char *dest, size_t dest_size, char const *src);
276
277//============================================================================
278// facilities used by the QSPY host app only (but not for QSPY parser)
279#ifdef QSPY_APP
280
281// commands to QSPY; @sa "packet IDs" in qutest.py or qview.py scripts
282typedef enum {
283 QSPY_ATTACH = 128, // attach to the QSPY Back-End
284 QSPY_DETACH, // detach from the QSPY Back-End
285 QSPY_SAVE_DICT, // save dictionaries to a file in QSPY
286 QSPY_TEXT_OUT, // toggle text output to a file in QSPY
287 QSPY_BIN_OUT, // toggle binary output to a file in QSPY
288 QSPY_MATLAB_OUT, // toggle Matlab output to a file in QSPY
289 QSPY_SEQUENCE_OUT, // toggle Sequence output to a file in QSPY
290 QSPY_SEND_EVENT, // send event (QSPY supplying signal)
291 QSPY_SEND_AO_FILTER, // send Local Filter (QSPY supplying addr)
292 QSPY_SEND_CURR_OBJ, // send current Object (QSPY supplying addr)
293 QSPY_SEND_COMMAND, // send command (QSPY supplying cmdId)
294 QSPY_SEND_TEST_PROBE, // send Test-Probe (QSPY supplying apiId)
295 QSPY_CLEAR_SCREEN, // clear the QSPY screen
296 QSPY_SHOW_NOTE, // show a note in QSPY output
297 // ...
298} QSpyCommands;
299
300extern QSpyConfig QSPY_conf;
301extern Dictionary QSPY_funDict;
302extern Dictionary QSPY_objDict;
303extern Dictionary QSPY_usrDict;
304extern SigDictionary QSPY_sigDict;
305extern Dictionary QSPY_enumDict[8];
306
307void QSPY_setExternDict(char const* dictName);
308QSpyStatus QSPY_readDict(void);
309QSpyStatus QSPY_writeDict(void);
310
311bool QDIC_isActive(void);
312
313void Dictionary_write(Dictionary const* const me, FILE* stream);
314bool Dictionary_read(Dictionary* const me, FILE* stream);
315
316void SigDictionary_write(SigDictionary const* const me, FILE* stream);
317bool SigDictionary_read(SigDictionary* const me, FILE* stream);
318char const* QSPY_getMatDict(char const* s);
319
320void QSEQ_configFile(void *seqFile);
321bool QSEQ_isActive(void);
322void QSEQ_config(void* seqFile, char const* seqList);
323void QSEQ_updateDictionary(char const* name, KeyType key);
324int QSEQ_find(KeyType key);
325void QSEQ_genHeader(void);
326void QSEQ_genPost(uint32_t tstamp, int src, int dst, char const* sig,
327 bool isAttempt);
328void QSEQ_genPostLIFO(uint32_t tstamp, int src, char const* sig);
329void QSEQ_genTran(uint32_t tstamp, int obj, char const* state);
330void QSEQ_genPublish(uint32_t tstamp, int obj, char const* sig);
331void QSEQ_genAnnotation(uint32_t tstamp, int obj, char const* ann);
332void QSEQ_genTick(uint32_t rate, uint32_t nTick);
333void QSEQ_dictionaryReset(void);
334
335void QSPY_configChanged(void);
336
337#endif // QSPY_APP
338
339#ifdef __cplusplus
340}
341#endif
342
343#endif // QSPY_H_
QSpyStatus
Definition qspy.h:28
@ QSPY_SUCCESS
Definition qspy.h:30
@ QSPY_ERROR
Definition qspy.h:29
void Dictionary_config(Dictionary *const me, int keySize)
void QSPY_sendTP(QSpyRecord const *const qrec)
SigType QSPY_findSig(char const *name, ObjType obj)
void SigDictionary_reset(SigDictionary *const me)
void Dictionary_ctor(Dictionary *const me, DictEntry *sto, uint32_t capacity)
char const * Dictionary_at(Dictionary *const me, unsigned idx)
int32_t QSpyRecord_getInt32(QSpyRecord *const me, uint8_t size)
QSpyStatus QSpyRecord_OK(QSpyRecord *const me)
void QSPY_resetAllDictionaries(void)
uint32_t QSpyRecord_getUint32(QSpyRecord *const me, uint8_t size)
uint64_t KeyType
Definition qspy.h:89
@ QS_SEQ_LIST_LEN_MAX
Definition qspy.h:50
@ QS_RECORD_SIZE_MAX
Definition qspy.h:47
@ QS_DNAME_LEN_MAX
Definition qspy.h:51
@ QS_FNAME_LEN_MAX
Definition qspy.h:49
@ QS_LINE_LEN_MAX
Definition qspy.h:48
uint32_t QSPY_encodeResetCmd(uint8_t *dstBuf, uint32_t dstSize)
uint64_t QSpyRecord_getUint64(QSpyRecord *const me, uint8_t size)
uint32_t SigType
Definition qspy.h:90
int64_t QSpyRecord_getInt64(QSpyRecord *const me, uint8_t size)
int SigDictionary_find(SigDictionary *const me, SigType sig, ObjType obj)
int(* QSPY_CustParseFun)(QSpyRecord *const me)
Definition qspy.h:55
void SigDictionary_ctor(SigDictionary *const me, SigDictEntry *sto, uint32_t capacity)
QSPY_LastOutputType
Definition qspy.h:145
@ INF_OUT
Definition qspy.h:153
@ BE_OUT
Definition qspy.h:150
@ ERR_OUT
Definition qspy.h:148
@ USR_OUT
Definition qspy.h:154
@ REG_OUT
Definition qspy.h:147
@ TST_OUT
Definition qspy.h:155
char const * Dictionary_get(Dictionary *const me, KeyType key, char *buf)
void QSPY_reset(void)
KeyType Dictionary_findKey(Dictionary *const me, char const *name)
char const * SigDictionary_get(SigDictionary *const me, SigType sig, ObjType obj, char *buf)
void QSPY_sendCmd(QSpyRecord const *const qrec)
void QSPY_cleanup(void)
void SigDictionary_config(SigDictionary *const me, int ptrSize)
char const * QSPY_tstampStr(void)
void QSPY_printInfo(void)
QSPY_LastOutput QSPY_output
QSRreRecGroup
Definition qspy.h:165
@ GRP_MP
Definition qspy.h:173
@ GRP_TST
Definition qspy.h:169
@ GRP_INF
Definition qspy.h:167
@ GRP_TE
Definition qspy.h:174
@ GRP_EQ
Definition qspy.h:172
@ GRP_USR
Definition qspy.h:179
@ GRP_DIC
Definition qspy.h:168
@ GRP_MTX
Definition qspy.h:178
@ GRP_ERR
Definition qspy.h:166
@ GRP_QF
Definition qspy.h:175
@ GRP_SEM
Definition qspy.h:177
@ GRP_AO
Definition qspy.h:171
@ GRP_SM
Definition qspy.h:170
@ GRP_SC
Definition qspy.h:176
char const * QSpyRecord_getStr(QSpyRecord *const me)
void QSPY_sendEvt(QSpyRecord const *const qrec)
int string_copy(char *dest, size_t dest_size, char const *src)
void QSPY_parse(uint8_t const *buf, uint32_t nBytes)
char const *const QSPY_line
SigType SigDictionary_findSig(SigDictionary *const me, char const *name, ObjType obj)
void Dictionary_put(Dictionary *const me, KeyType key, char const *name)
void QSPY_configTxReset(QSPY_resetFun txResetFun)
KeyType QSPY_findObj(char const *name)
@ CMD_OPT_OFF
Definition qspy.h:104
@ CMD_OPT_TOGGLE
Definition qspy.h:106
@ CMD_OPT_ON
Definition qspy.h:105
QSRreRecGroup QSPY_getGroup(int recId)
void QSPY_onPrintLn(void)
uint32_t QSPY_encodeTickCmd(uint8_t *dstBuf, uint32_t dstSize, uint8_t rate)
KeyType QSPY_findEnum(char const *name, uint8_t group)
void QSPY_printError(void)
void QSPY_config(QSpyConfig const *config, QSPY_CustParseFun custParseFun)
void QSPY_showNote(QSpyRecord const *const qrec)
uint64_t ObjType
Definition qspy.h:91
uint32_t QSPY_encodeInfoCmd(uint8_t *dstBuf, uint32_t dstSize)
void QSPY_configMatFile(void *matFile)
uint32_t QSPY_encode(uint8_t *dstBuf, uint32_t dstSize, uint8_t const *srcBuf, uint32_t srcBytes)
int Dictionary_find(Dictionary *const me, KeyType key)
uint8_t const * QSpyRecord_getMem(QSpyRecord *const me, uint8_t size, uint32_t *pNum)
void(* QSPY_resetFun)(void)
Definition qspy.h:56
void QSpyRecord_init(QSpyRecord *const me, uint8_t const *start, uint32_t tot_len)
void QSPY_sendObj(QSpyRecord const *const qrec)
#define QS_LINE_OFFSET
Definition qspy.h:144
KeyType QSPY_findFun(char const *name)
void Dictionary_reset(Dictionary *const me)
void QSPY_txReset(void)
bool QSPY_command(uint8_t cmdId, uint8_t opt)
KeyType QSPY_findUsr(char const *name)
uint16_t QSignal
Definition qspy.h:34
void SigDictionary_put(SigDictionary *const me, SigType sig, ObjType obj, char const *name)
Definition qspy.h:223
char name[QS_DNAME_LEN_MAX]
Definition qspy.h:225
KeyType key
Definition qspy.h:224
int capacity
Definition qspy.h:231
DictEntry * sto
Definition qspy.h:230
DictEntry notFound
Definition qspy.h:229
int entries
Definition qspy.h:232
int keySize
Definition qspy.h:233
char buf[QS_LINE_OFFSET+QS_LINE_LEN_MAX]
Definition qspy.h:158
int rx_status
Definition qspy.h:162
uint8_t qpType
Definition qspy.h:75
uint8_t queueCtrSize
Definition qspy.h:82
uint8_t tevtCtrSize
Definition qspy.h:85
uint8_t evtSize
Definition qspy.h:81
uint8_t tstampSize
Definition qspy.h:79
uint8_t funPtrSize
Definition qspy.h:78
uint16_t qpVersion
Definition qspy.h:74
uint8_t poolBlkSize
Definition qspy.h:84
uint8_t tbuild[6]
Definition qspy.h:86
uint32_t qpDate
Definition qspy.h:73
uint8_t objPtrSize
Definition qspy.h:77
uint8_t poolCtrSize
Definition qspy.h:83
uint8_t endianness
Definition qspy.h:76
uint8_t sigSize
Definition qspy.h:80
int32_t len
Definition qspy.h:41
uint8_t const * start
Definition qspy.h:38
uint8_t const * pos
Definition qspy.h:39
uint32_t tot_len
Definition qspy.h:40
uint8_t rec
Definition qspy.h:42
Definition qspy.h:246
char name[QS_DNAME_LEN_MAX]
Definition qspy.h:249
SigType sig
Definition qspy.h:247
ObjType obj
Definition qspy.h:248
int capacity
Definition qspy.h:255
SigDictEntry notFound
Definition qspy.h:253
SigDictEntry * sto
Definition qspy.h:254
int entries
Definition qspy.h:256
int ptrSize
Definition qspy.h:257