QTools 8.1.2
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.1.2"
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 = 65528, // 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 = 128, // 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,
122 uint8_t rate);
123
124SigType QSPY_findSig(char const *name, ObjType obj);
125KeyType QSPY_findObj(char const *name);
126KeyType QSPY_findFun(char const *name);
127KeyType QSPY_findUsr(char const *name);
128KeyType QSPY_findEnum(char const *name, uint8_t group);
129
130#define SIG_NOT_FOUND ((SigType)-1)
131#define KEY_NOT_FOUND ((KeyType)-1)
132
133void QSPY_cleanup(void); // cleanup after the run
134
135char const* QSPY_tstampStr(void);
136
137void QSPY_onPrintLn(void); // callback to print the last line of output
138
139// prints information message to the QSPY output (without sending it to FE)
140void QSPY_printInfo(void);
141
142// prints error message to the QSPY output (sending it to FE)
144
145// last human-readable line of output from QSPY ..............................
146#define QS_LINE_OFFSET 8
148 // output forwarded to the back-end...
149 REG_OUT, // regular output from the Target
150 ERR_OUT, // error output from QSPY
151 // ...
152 BE_OUT, // last message forwarded to the back-end
153
154 // output NOT forwarded to the back-end...
155 INF_OUT, // internal info from QSPY
156 USR_OUT, // generic user message from BE
157 TST_OUT, // test message from BE
158};
159typedef struct {
161 int len; // the length of the composed string
162 int rec; // the corresponding QS record ID
163 int type; // the type of the output
164 int rx_status; // the type of the RX status
166
167// Record groups (extend enum QS_Groups from qpc_qs.h)
174
175// returns the "group" of a given QS record-ID
176int QSPY_getGroup(int recId);
177
178// last output generated
180
181// beginning of QSPY line to print
182extern char const * const QSPY_line;
183
184#define SNPRINTF_LINE(format_, ...) do { \
185 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET], \
186 (QS_LINE_LEN_MAX - QS_LINE_OFFSET), \
187 format_, __VA_ARGS__); \
188 if ((0 < n_) && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET)) { \
189 QSPY_output.len = n_; \
190 } \
191 else { \
192 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
193 } \
194} while (0)
195
196#define SNPRINTF_APPEND(format_, ...) do { \
197 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET + QSPY_output.len],\
198 (QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len), \
199 format_, __VA_ARGS__); \
200 if ((0 < n_) \
201 && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len)) { \
202 QSPY_output.len += n_; \
203 } \
204 else { \
205 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
206 } \
207} while (0)
208
209#define CONFIG_UPDATE(member_, new_, diff_) \
210 if (QSPY_conf.member_ != (new_)) { \
211 QSPY_conf.member_ = (new_); \
212 (diff_) = 1U; \
213 } else (void)0
214
215// Dictionaries ..............................................................
216typedef struct {
219} DictEntry;
220
228
230 DictEntry* sto, uint32_t capacity);
231void Dictionary_config(Dictionary* const me, int keySize);
232char const* Dictionary_at(Dictionary* const me, unsigned idx);
233void Dictionary_put(Dictionary* const me, KeyType key, char const* name);
234char const* Dictionary_get(Dictionary* const me, KeyType key, char* buf);
236KeyType Dictionary_findKey(Dictionary* const me, char const* name);
238
244
252
254 SigDictEntry* sto, uint32_t capacity);
255void SigDictionary_config(SigDictionary* const me, int ptrSize);
257 SigType sig, ObjType obj, char const* name);
258char const* SigDictionary_get(SigDictionary* const me,
259 SigType sig, ObjType obj, char* buf);
261 SigType sig, ObjType obj);
263 char const* name, ObjType obj);
266
267// simplified string_copy() implementation "good enough" for the intended use
268int string_copy(char *dest, size_t dest_size, char const *src);
269
270//============================================================================
271// facilities used by the QSPY host app only (but not for QSPY parser)
272#ifdef QSPY_APP
273
274// commands to QSPY; @sa "packet IDs" in qutest.py or qview.py scripts
275typedef enum {
276 QSPY_ATTACH = 128, // attach to the QSPY Back-End
277 QSPY_DETACH, // detach from the QSPY Back-End
278 QSPY_SAVE_DICT, // save dictionaries to a file in QSPY
279 QSPY_TEXT_OUT, // toggle text output to a file in QSPY
280 QSPY_BIN_OUT, // toggle binary output to a file in QSPY
281 QSPY_MATLAB_OUT, // toggle Matlab output to a file in QSPY
282 QSPY_SEQUENCE_OUT, // toggle Sequence output to a file in QSPY
283 QSPY_SEND_EVENT, // send event (QSPY supplying signal)
284 QSPY_SEND_AO_FILTER, // send Local Filter (QSPY supplying addr)
285 QSPY_SEND_CURR_OBJ, // send current Object (QSPY supplying addr)
286 QSPY_SEND_COMMAND, // send command (QSPY supplying cmdId)
287 QSPY_SEND_TEST_PROBE, // send Test-Probe (QSPY supplying apiId)
288 QSPY_CLEAR_SCREEN, // clear the QSPY screen
289 QSPY_SHOW_NOTE, // show a note in QSPY output
290 // ...
291} QSpyCommands;
292
293extern QSpyConfig QSPY_conf;
294extern Dictionary QSPY_funDict;
295extern Dictionary QSPY_objDict;
296extern Dictionary QSPY_usrDict;
297extern SigDictionary QSPY_sigDict;
298extern Dictionary QSPY_enumDict[8];
299
300void QSPY_setExternDict(char const* dictName);
301QSpyStatus QSPY_readDict(void);
302QSpyStatus QSPY_writeDict(void);
303
304bool QDIC_isActive(void);
305
306void Dictionary_write(Dictionary const* const me, FILE* stream);
307bool Dictionary_read(Dictionary* const me, FILE* stream);
308
309void SigDictionary_write(SigDictionary const* const me, FILE* stream);
310bool SigDictionary_read(SigDictionary* const me, FILE* stream);
311char const* QSPY_getMatDict(char const* s);
312
313void QSEQ_configFile(void *seqFile);
314bool QSEQ_isActive(void);
315void QSEQ_config(void* seqFile, char const* seqList);
316void QSEQ_updateDictionary(char const* name, KeyType key);
317int QSEQ_find(KeyType key);
318void QSEQ_genHeader(void);
319void QSEQ_genPost(uint32_t tstamp, int src, int dst, char const* sig,
320 bool isAttempt);
321void QSEQ_genPostLIFO(uint32_t tstamp, int src, char const* sig);
322void QSEQ_genTran(uint32_t tstamp, int obj, char const* state);
323void QSEQ_genPublish(uint32_t tstamp, int obj, char const* sig);
324void QSEQ_genAnnotation(uint32_t tstamp, int obj, char const* ann);
325void QSEQ_genTick(uint32_t rate, uint32_t nTick);
326void QSEQ_dictionaryReset(void);
327
328void QSPY_configChanged(void);
329
330#endif // QSPY_APP
331
332#ifdef __cplusplus
333}
334#endif
335
336#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:147
@ INF_OUT
Definition qspy.h:155
@ BE_OUT
Definition qspy.h:152
@ ERR_OUT
Definition qspy.h:150
@ USR_OUT
Definition qspy.h:156
@ REG_OUT
Definition qspy.h:149
@ TST_OUT
Definition qspy.h:157
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
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
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)
QSpyGroups_plus
Definition qspy.h:168
@ QSPY_GRP_ERR
Definition qspy.h:169
@ QSPY_GRP_INF
Definition qspy.h:170
@ QSPY_GRP_DIC
Definition qspy.h:171
@ QSPY_GRP_TST
Definition qspy.h:172
uint8_t const * QSpyRecord_getMem(QSpyRecord *const me, uint8_t size, uint32_t *pNum)
void(* QSPY_resetFun)(void)
Definition qspy.h:57
int QSPY_getGroup(int recId)
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:146
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:216
char name[QS_DNAME_LEN_MAX]
Definition qspy.h:218
KeyType key
Definition qspy.h:217
int capacity
Definition qspy.h:224
DictEntry * sto
Definition qspy.h:223
DictEntry notFound
Definition qspy.h:222
int entries
Definition qspy.h:225
int keySize
Definition qspy.h:226
char buf[QS_LINE_OFFSET+QS_LINE_LEN_MAX]
Definition qspy.h:160
int rx_status
Definition qspy.h:164
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:239
char name[QS_DNAME_LEN_MAX]
Definition qspy.h:242
SigType sig
Definition qspy.h:240
ObjType obj
Definition qspy.h:241
int capacity
Definition qspy.h:248
SigDictEntry notFound
Definition qspy.h:246
SigDictEntry * sto
Definition qspy.h:247
int entries
Definition qspy.h:249
int ptrSize
Definition qspy.h:250