QTools  8.0.4
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.4"
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_MIN_VERSION = 660, // minimum required version
48 QS_RECORD_SIZE_MAX = 512, // max QS record size [bytes]
49 QS_LINE_LEN_MAX = 8192, // max length of a QSPY line [chars]
50 QS_FNAME_LEN_MAX = 256, // max length of filenames [chars]
51 QS_SEQ_LIST_LEN_MAX = 1024, // max length of the Seq list [chars]
52 QS_DNAME_LEN_MAX = 64, // max dictionary name length [chars]
53};
54
55// pointer to the callback function for customized QS record parsing
56typedef int (*QSPY_CustParseFun)(QSpyRecord * const me);
57typedef void (*QSPY_resetFun)(void);
58
59void QSpyRecord_init (QSpyRecord * const me,
60 uint8_t const *start, uint32_t tot_len);
62uint32_t QSpyRecord_getUint32(QSpyRecord * const me, uint8_t size);
63int32_t QSpyRecord_getInt32 (QSpyRecord * const me, uint8_t size);
64uint64_t QSpyRecord_getUint64(QSpyRecord * const me, uint8_t size);
65int64_t QSpyRecord_getInt64 (QSpyRecord * const me, uint8_t size);
66char const *QSpyRecord_getStr (QSpyRecord * const me);
67uint8_t const *QSpyRecord_getMem(QSpyRecord * const me,
68 uint8_t size,
69 uint32_t *pNum);
70
71// QSPY configuration and high-level interface ...............................
72// QSPY configuration parameters. @sa QSPY_config()
73typedef struct {
74 uint32_t qpDate; // e.g., 241008, 0 means "no-target-info"
75 uint16_t qpVersion; // e.g., 732
76 uint8_t qpType; // 1==qpc, 2==qpcpp
77 uint8_t endianness;
78 uint8_t objPtrSize;
79 uint8_t funPtrSize;
80 uint8_t tstampSize;
81 uint8_t sigSize;
82 uint8_t evtSize;
83 uint8_t queueCtrSize;
84 uint8_t poolCtrSize;
85 uint8_t poolBlkSize;
86 uint8_t tevtCtrSize;
87 uint8_t tbuild[6];
89
90typedef uint64_t KeyType;
91typedef uint32_t SigType;
92typedef uint64_t ObjType;
93
94void QSPY_config(QSpyConfig const *config,
95 QSPY_CustParseFun custParseFun);
97void QSPY_configMatFile(void *matFile);
98
99void QSPY_reset(void);
100void QSPY_parse(uint8_t const *buf, uint32_t nBytes);
101void QSPY_txReset(void);
102
103// command options
104enum {
108};
109bool QSPY_command(uint8_t cmdId, uint8_t opt);
110
111void QSPY_sendEvt (QSpyRecord const * const qrec);
112void QSPY_sendObj (QSpyRecord const * const qrec);
113void QSPY_sendCmd (QSpyRecord const * const qrec);
114void QSPY_sendTP (QSpyRecord const * const qrec);
115void QSPY_showNote(QSpyRecord const * const qrec);
116
117uint32_t QSPY_encode(uint8_t *dstBuf, uint32_t dstSize,
118 uint8_t const *srcBuf, uint32_t srcBytes);
119uint32_t QSPY_encodeResetCmd(uint8_t *dstBuf, uint32_t dstSize);
120uint32_t QSPY_encodeInfoCmd (uint8_t *dstBuf, uint32_t dstSize);
121uint32_t QSPY_encodeTickCmd (uint8_t *dstBuf, uint32_t dstSize, uint8_t rate);
122
123SigType QSPY_findSig(char const *name, ObjType obj);
124KeyType QSPY_findObj(char const *name);
125KeyType QSPY_findFun(char const *name);
126KeyType QSPY_findUsr(char const *name);
127KeyType QSPY_findEnum(char const *name, uint8_t group);
128
129#define SIG_NOT_FOUND ((SigType)-1)
130#define KEY_NOT_FOUND ((KeyType)-1)
131
132void QSPY_cleanup(void); // cleanup after the run
133
134char const* QSPY_tstampStr(void);
135
136void QSPY_onPrintLn(void); // callback to print the last line of output
137
138// prints information message to the QSPY output (without sending it to FE)
139void QSPY_printInfo(void);
140
141// prints error message to the QSPY output (sending it to FE)
143
144// last human-readable line of output from QSPY ..............................
145#define QS_LINE_OFFSET 8
147 // output forwarded to the back-end...
148 REG_OUT, // regular output from the Target
149 ERR_OUT, // error output from QSPY
150 // ...
151 BE_OUT, // last message forwarded to the back-end
152
153 // output NOT forwarded to the back-end...
154 INF_OUT, // internal info from QSPY
155 USR_OUT, // generic user message from BE
156 TST_OUT, // test message from BE
157};
158typedef struct {
160 int len; // the length of the composed string
161 int rec; // the corresponding QS record ID
162 int type; // the type of the output
163 int rx_status; // the type of the RX status
165
182
183// returns the "group" of a given QS record-ID
185
186// last output generated
188
189// beginning of QSPY line to print
190extern char const * const QSPY_line;
191
192#define SNPRINTF_LINE(format_, ...) do { \
193 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET], \
194 (QS_LINE_LEN_MAX - QS_LINE_OFFSET), \
195 format_, __VA_ARGS__); \
196 if ((0 < n_) && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET)) { \
197 QSPY_output.len = n_; \
198 } \
199 else { \
200 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
201 } \
202} while (0)
203
204#define SNPRINTF_APPEND(format_, ...) do { \
205 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET + QSPY_output.len],\
206 (QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len), \
207 format_, __VA_ARGS__); \
208 if ((0 < n_) \
209 && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len)) { \
210 QSPY_output.len += n_; \
211 } \
212 else { \
213 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
214 } \
215} while (0)
216
217#define CONFIG_UPDATE(member_, new_, diff_) \
218 if (QSPY_conf.member_ != (new_)) { \
219 QSPY_conf.member_ = (new_); \
220 (diff_) = 1U; \
221 } else (void)0
222
223// Dictionaries ..............................................................
224typedef struct {
227} DictEntry;
228
236
238 DictEntry* sto, uint32_t capacity);
239void Dictionary_config(Dictionary* const me, int keySize);
240char const* Dictionary_at(Dictionary* const me, unsigned idx);
241void Dictionary_put(Dictionary* const me, KeyType key, char const* name);
242char const* Dictionary_get(Dictionary* const me, KeyType key, char* buf);
244KeyType Dictionary_findKey(Dictionary* const me, char const* name);
246
252
260
262 SigDictEntry* sto, uint32_t capacity);
263void SigDictionary_config(SigDictionary* const me, int ptrSize);
265 SigType sig, ObjType obj, char const* name);
266char const* SigDictionary_get(SigDictionary* const me,
267 SigType sig, ObjType obj, char* buf);
269 SigType sig, ObjType obj);
271 char const* name, ObjType obj);
274
275// simplified string_copy() implementation "good enough" for the intended use
276int string_copy(char *dest, size_t dest_size, char const *src);
277
278//============================================================================
279// facilities used by the QSPY host app only (but not for QSPY parser)
280#ifdef QSPY_APP
281
282// commands to QSPY; @sa "packet IDs" in qutest.py or qview.py scripts
283typedef enum {
284 QSPY_ATTACH = 128, // attach to the QSPY Back-End
285 QSPY_DETACH, // detach from the QSPY Back-End
286 QSPY_SAVE_DICT, // save dictionaries to a file in QSPY
287 QSPY_TEXT_OUT, // toggle text output to a file in QSPY
288 QSPY_BIN_OUT, // toggle binary output to a file in QSPY
289 QSPY_MATLAB_OUT, // toggle Matlab output to a file in QSPY
290 QSPY_SEQUENCE_OUT, // toggle Sequence output to a file in QSPY
291 QSPY_SEND_EVENT, // send event (QSPY supplying signal)
292 QSPY_SEND_AO_FILTER, // send Local Filter (QSPY supplying addr)
293 QSPY_SEND_CURR_OBJ, // send current Object (QSPY supplying addr)
294 QSPY_SEND_COMMAND, // send command (QSPY supplying cmdId)
295 QSPY_SEND_TEST_PROBE, // send Test-Probe (QSPY supplying apiId)
296 QSPY_CLEAR_SCREEN, // clear the QSPY screen
297 QSPY_SHOW_NOTE, // show a note in QSPY output
298 // ...
299} QSpyCommands;
300
301extern QSpyConfig QSPY_conf;
302extern Dictionary QSPY_funDict;
303extern Dictionary QSPY_objDict;
304extern Dictionary QSPY_usrDict;
305extern SigDictionary QSPY_sigDict;
306extern Dictionary QSPY_enumDict[8];
307
308void QSPY_setExternDict(char const* dictName);
309QSpyStatus QSPY_readDict(void);
310QSpyStatus QSPY_writeDict(void);
311
312bool QDIC_isActive(void);
313
314void Dictionary_write(Dictionary const* const me, FILE* stream);
315bool Dictionary_read(Dictionary* const me, FILE* stream);
316
317void SigDictionary_write(SigDictionary const* const me, FILE* stream);
318bool SigDictionary_read(SigDictionary* const me, FILE* stream);
319char const* QSPY_getMatDict(char const* s);
320
321void QSEQ_configFile(void *seqFile);
322bool QSEQ_isActive(void);
323void QSEQ_config(void* seqFile, char const* seqList);
324void QSEQ_updateDictionary(char const* name, KeyType key);
325int QSEQ_find(KeyType key);
326void QSEQ_genHeader(void);
327void QSEQ_genPost(uint32_t tstamp, int src, int dst, char const* sig,
328 bool isAttempt);
329void QSEQ_genPostLIFO(uint32_t tstamp, int src, char const* sig);
330void QSEQ_genTran(uint32_t tstamp, int obj, char const* state);
331void QSEQ_genPublish(uint32_t tstamp, int obj, char const* sig);
332void QSEQ_genAnnotation(uint32_t tstamp, int obj, char const* ann);
333void QSEQ_genTick(uint32_t rate, uint32_t nTick);
334void QSEQ_dictionaryReset(void);
335
336void QSPY_configChanged(void);
337
338#endif // QSPY_APP
339
340#ifdef __cplusplus
341}
342#endif
343
344#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:90
@ QS_SEQ_LIST_LEN_MAX
Definition qspy.h:51
@ QS_RECORD_SIZE_MAX
Definition qspy.h:48
@ QS_MIN_VERSION
Definition qspy.h:47
@ QS_DNAME_LEN_MAX
Definition qspy.h:52
@ QS_FNAME_LEN_MAX
Definition qspy.h:50
@ QS_LINE_LEN_MAX
Definition qspy.h:49
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:91
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:56
void SigDictionary_ctor(SigDictionary *const me, SigDictEntry *sto, uint32_t capacity)
QSPY_LastOutputType
Definition qspy.h:146
@ INF_OUT
Definition qspy.h:154
@ BE_OUT
Definition qspy.h:151
@ ERR_OUT
Definition qspy.h:149
@ USR_OUT
Definition qspy.h:155
@ REG_OUT
Definition qspy.h:148
@ TST_OUT
Definition qspy.h:156
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:166
@ GRP_MP
Definition qspy.h:174
@ GRP_TST
Definition qspy.h:170
@ GRP_INF
Definition qspy.h:168
@ GRP_TE
Definition qspy.h:175
@ GRP_EQ
Definition qspy.h:173
@ GRP_USR
Definition qspy.h:180
@ GRP_DIC
Definition qspy.h:169
@ GRP_MTX
Definition qspy.h:179
@ GRP_ERR
Definition qspy.h:167
@ GRP_QF
Definition qspy.h:176
@ GRP_SEM
Definition qspy.h:178
@ GRP_AO
Definition qspy.h:172
@ GRP_SM
Definition qspy.h:171
@ GRP_SC
Definition qspy.h:177
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:105
@ CMD_OPT_TOGGLE
Definition qspy.h:107
@ CMD_OPT_ON
Definition qspy.h:106
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:92
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:57
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:145
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:224
char name[QS_DNAME_LEN_MAX]
Definition qspy.h:226
KeyType key
Definition qspy.h:225
int capacity
Definition qspy.h:232
DictEntry * sto
Definition qspy.h:231
DictEntry notFound
Definition qspy.h:230
int entries
Definition qspy.h:233
int keySize
Definition qspy.h:234
char buf[QS_LINE_OFFSET+QS_LINE_LEN_MAX]
Definition qspy.h:159
int rx_status
Definition qspy.h:163
uint8_t qpType
Definition qspy.h:76
uint8_t queueCtrSize
Definition qspy.h:83
uint8_t tevtCtrSize
Definition qspy.h:86
uint8_t evtSize
Definition qspy.h:82
uint8_t tstampSize
Definition qspy.h:80
uint8_t funPtrSize
Definition qspy.h:79
uint16_t qpVersion
Definition qspy.h:75
uint8_t poolBlkSize
Definition qspy.h:85
uint8_t tbuild[6]
Definition qspy.h:87
uint32_t qpDate
Definition qspy.h:74
uint8_t objPtrSize
Definition qspy.h:78
uint8_t poolCtrSize
Definition qspy.h:84
uint8_t endianness
Definition qspy.h:77
uint8_t sigSize
Definition qspy.h:81
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:247
char name[QS_DNAME_LEN_MAX]
Definition qspy.h:250
SigType sig
Definition qspy.h:248
ObjType obj
Definition qspy.h:249
int capacity
Definition qspy.h:256
SigDictEntry notFound
Definition qspy.h:254
SigDictEntry * sto
Definition qspy.h:255
int entries
Definition qspy.h:257
int ptrSize
Definition qspy.h:258