Skip to content

Commit 1924b1f

Browse files
committed
Book: added section on calltree analysis; a few clarifications in the troubleshooting section.
Fix window resize with the mouse (GUI utilities). Fix file dialog "double free" bug (GUI utilities). BMProfile: demangle C++ names.; extra checks on parameters, before running; fix in using default GUI settings when no INI file is found. BMDebug: fix in console history; fix in breakpoint handling by mouse click in the margin; fix "clear" option in "trace" command; pass DWARF symbol table to CTF decoding. BMTrace: option to disable "live view" (so overflow of the trace queue is avoided); panel for status; improvements in CTF loading. Add calltree utility. Gruvbox colour scheme (with adaptions) for the GUI utilities. Add -v (version) option to all utilities. swotrace: bug fix in precision timestamp in Linux version; signal queue overflow. nuklear: merged PRs #463, #482 & #486.
1 parent 335566e commit 1924b1f

40 files changed

+1402
-485
lines changed

BlackMagicProbe.pdf

40.2 KB
Binary file not shown.

doc/bmdebug.png

-22.9 KB
Loading

doc/bmflash.png

-19.7 KB
Loading

doc/bmprofile-top.png

1.48 KB
Loading

doc/bmtrace.png

-23.4 KB
Loading

examples/function_trace.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* Example functions for function enter/exit tracing via GCC instrumentation.
2+
* It is based on SWO tracing, and should be used with the function_trace.tsdl
3+
* file.
4+
*
5+
* Routines for initializing the micro-controller for TRACESWO are not included,
6+
* as these are (in part) dependend on the particular micro-controller.
7+
*
8+
*
9+
* Copyright 2022 CompuPhase
10+
*
11+
* This software is provided 'as-is', without any express or implied
12+
* warranty. In no event will the authors be held liable for any damages
13+
* arising from the use of this software.
14+
*
15+
* Permission is granted to anyone to use this software for any purpose,
16+
* including commercial applications, and to alter it and redistribute it
17+
* freely, subject to the following restrictions:
18+
*
19+
* 1. The origin of this software must not be misrepresented; you must not
20+
* claim that you wrote the original software. If you use this software
21+
* in a product, an acknowledgment in the product documentation would be
22+
* appreciated but is not required.
23+
* 2. Altered source versions must be plainly marked as such, and must not be
24+
* misrepresented as being the original software.
25+
* 3. This notice may not be removed or altered from any source distribution.
26+
*/
27+
28+
#include <stdint.h>
29+
30+
#if !defined ITM_TCR_ITMENA
31+
#define ITM_TCR_ITMENA ITM_TCR_ITMENA_Msk
32+
#endif
33+
34+
__attribute__((no_instrument_function))
35+
void trace_xmit(int stream_id, const unsigned char *data, unsigned size)
36+
{
37+
if ((ITM->TCR & ITM_TCR_ITMENA) != 0UL && /* ITM tracing enabled */
38+
(ITM->TER & (1 << channel)) != 0UL) /* ITM channel enabled */
39+
{
40+
/* collect and transmit bytes in packets of 4 bytes */
41+
uint32_t value = 0, shift = 0;
42+
while (size-- > 0) {
43+
value |= (uint32_t)*data++ << shift;
44+
shift += 8;
45+
if (shift >= 32) {
46+
/* in the waiting loop, use an empty statement and not __NOP();
47+
although __NOP() is an inline function, it would still be
48+
instrumented */
49+
while (ITM->PORT[channel].u32 == 0UL)
50+
{}
51+
ITM->PORT[channel].u32 = value;
52+
value = shift = 0;
53+
}
54+
}
55+
/* transmit last collected bytes */
56+
if (shift > 0) {
57+
while (ITM->PORT[channel].u32 == 0UL)
58+
{}
59+
ITM->PORT[channel].u32 = value;
60+
}
61+
}
62+
}
63+
64+
__attribute__((no_instrument_function))
65+
void __cyg_profile_func_enter(void *this_fn, void *call_site)
66+
{
67+
(void)call_site;
68+
trace_function_profile_enter((unsigned long)this_fn);
69+
}
70+
__attribute__((no_instrument_function))
71+
void __cyg_profile_func_exit(void *this_fn, void *call_site)
72+
{
73+
(void)call_site;
74+
trace_function_profile_exit((unsigned long)this_fn);
75+
}
76+

examples/function_trace.tsdl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* TSDL file suitable for tracing function entries and exits.
2+
*
3+
* The source code must be compiled with GCC option -finstrument-functions.
4+
* The code must also supply a function trace_xmit(), as explained in the
5+
* book. An * important note is that trace_xmit() must be declared with
6+
* __attribute__((no_instrument_function))
7+
*/
8+
trace {
9+
major = 1;
10+
minor = 8;
11+
packet.header := struct {
12+
uint16_t magic;
13+
};
14+
};
15+
16+
stream function_profile {
17+
id = 31;
18+
event.header := struct {
19+
uint16_t id;
20+
};
21+
};
22+
23+
typealias integer {
24+
size = 32;
25+
signed = false;
26+
base = symaddress;
27+
} := code_address;
28+
29+
event function_profile::enter {
30+
attribute = "no_instrument_function";
31+
fields := struct {
32+
code_address symbol;
33+
};
34+
};
35+
36+
event function_profile::exit {
37+
attribute = "no_instrument_function";
38+
fields := struct {
39+
code_address symbol;
40+
};
41+
};

examples/traceswo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Implementation of functions to transmit data or strings over the TRACESWO
22
* wire of the ARM Cortex micro-controllers.
33
*
4-
* These routines pack the bytes to * transmit into 32-bit words, in order to
4+
* These routines pack the bytes to transmit into 32-bit words, in order to
55
* minimize overhead (each item that is transmitted over the TRACESWO pin is
66
* prefixed with a 1-byte header, so that when tranmitting single bytes, each
77
* byte has that 1-byte header overhead).

source/Makefile.linux

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,20 @@ OBJLIST_BMTRACE = bmtrace.o bmcommon.o bmp-scan.o bmp-script.o bmp-support.o \
106106

107107
OBJLIST_BMSCAN = bmscan.o bmp-scan.o tcpip.o
108108

109+
OBJLIST_CALLTREE = calltree.o
110+
109111
OBJLIST_POSTLINK = elf-postlink.o elf.o
110112

111113
OBJLIST_TRACEGEN = tracegen.o parsetsdl.o
112114

113115

114-
project: bmdebug bmflash bmprofile bmtrace bmscan elf-postlink tracegen
116+
project: bmdebug bmflash bmprofile bmscan bmtrace calltree elf-postlink tracegen
115117

116118
depend :
117119
makedepend -b -fmakefile.dep $(OBJLIST_BMDEBUG:.o=.c) $(OBJLIST_BMFLASH:.o=.c) \
118-
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMTRACE:.o=.c) \
119-
$(OBJLIST_BMSCAN:.o=.c) $(OBJLIST_POSTLINK:.o=.c) \
120-
$(OBJLIST_TRACEGEN:.o=.c)
120+
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMSCAN:.o=.c) \
121+
$(OBJLIST_BMTRACE:.o=.c) $(OBJLIST_CALLTREE) \
122+
$(OBJLIST_POSTLINK:.o=.c) $(OBJLIST_TRACEGEN:.o=.c)
121123

122124

123125
##### C files #####
@@ -142,6 +144,8 @@ bmp-script.o : bmp-script.c
142144

143145
bmp-support.o : bmp-support.c
144146

147+
calltree.o : calltree.c
148+
145149
cksum.o : cksum.c
146150

147151
crc32.o : crc32.c
@@ -226,6 +230,9 @@ bmtrace : $(OBJLIST_BMTRACE)
226230
bmscan : $(OBJLIST_BMSCAN)
227231
$(LNK) $(LFLAGS) -o$@ $^ -lbsd -lpthread
228232

233+
calltree : $(OBJLIST_CALLTREE)
234+
$(LNK) $(LFLAGS) -o$@ $^ -lbsd
235+
229236
elf-postlink : $(OBJLIST_POSTLINK)
230237
$(LNK) $(LFLAGS) -o$@ $^ -lbsd
231238

source/Makefile.mingw

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,21 @@ OBJLIST_BMTRACE = bmtrace.o bmcommon.o bmp-scan.o bmp-script.o bmp-support.o \
102102

103103
OBJLIST_BMSCAN = bmscan.o bmp-scan.o tcpip.o
104104

105+
OBJLIST_CALLTREE = calltree.o
106+
105107
OBJLIST_POSTLINK = elf-postlink.o elf.o strlcpy.o
106108

107109
OBJLIST_TRACEGEN = tracegen.o parsetsdl.o strlcpy.o
108110

109111

110-
project : bmdebug.exe bmflash.exe bmprofile.exe bmtrace.exe bmscan.exe elf-postlink.exe tracegen.exe
112+
project : bmdebug.exe bmflash.exe bmprofile.exe bmtrace.exe bmscan.exe \
113+
calltree.exe elf-postlink.exe tracegen.exe
111114

112115
depend :
113116
makedepend -b -fmakefile.dep $(OBJLIST_BMDEBUG:.o=.c) $(OBJLIST_BMFLASH:.o=.c) \
114-
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMTRACE:.o=.c) \
115-
$(OBJLIST_BMSCAN:.o=.c) $(OBJLIST_POSTLINK:.o=.c) \
116-
$(OBJLIST_TRACEGEN:.o=.c)
117+
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMSCAN:.o=.c) \
118+
$(OBJLIST_BMTRACE:.o=.c) $(OBJLIST_CALLTREE:.o=.c) \
119+
$(OBJLIST_POSTLINK:.o=.c) $(OBJLIST_TRACEGEN:.o=.c)
117120

118121

119122
##### C files #####
@@ -138,6 +141,8 @@ bmp-script.o : bmp-script.c
138141

139142
bmp-support.o : bmp-support.c
140143

144+
calltree.o : calltree.c
145+
141146
cksum.o : cksum.c
142147

143148
crc32.o : crc32.c
@@ -210,6 +215,8 @@ bmdebug.res : bmdebug.rc
210215

211216
bmflash.res : bmflash.rc
212217

218+
bmprofile.res : bmprofile.rc
219+
213220
bmtrace.res : bmtrace.rc
214221

215222

@@ -230,6 +237,9 @@ bmtrace.exe : $(OBJLIST_BMTRACE) bmtrace.res
230237
bmscan.exe : $(OBJLIST_BMSCAN)
231238
$(LNK) $(LFLAGS) -o$@ $^ -lws2_32
232239

240+
calltree.exe : $(OBJLIST_CALLTREE)
241+
$(LNK) $(LFLAGS) -o$@ $^
242+
233243
elf-postlink.exe : $(OBJLIST_POSTLINK)
234244
$(LNK) $(LFLAGS) -o$@ $^
235245

0 commit comments

Comments
 (0)