Skip to content

Commit

Permalink
Book: added section on calltree analysis; a few clarifications in the…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
compuphase committed Oct 12, 2022
1 parent 335566e commit 1924b1f
Show file tree
Hide file tree
Showing 40 changed files with 1,402 additions and 485 deletions.
Binary file modified BlackMagicProbe.pdf
Binary file not shown.
Binary file modified doc/bmdebug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/bmflash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/bmprofile-top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/bmtrace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions examples/function_trace.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* Example functions for function enter/exit tracing via GCC instrumentation.
* It is based on SWO tracing, and should be used with the function_trace.tsdl
* file.
*
* Routines for initializing the micro-controller for TRACESWO are not included,
* as these are (in part) dependend on the particular micro-controller.
*
*
* Copyright 2022 CompuPhase
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

#include <stdint.h>

#if !defined ITM_TCR_ITMENA
#define ITM_TCR_ITMENA ITM_TCR_ITMENA_Msk
#endif

__attribute__((no_instrument_function))
void trace_xmit(int stream_id, const unsigned char *data, unsigned size)
{
if ((ITM->TCR & ITM_TCR_ITMENA) != 0UL && /* ITM tracing enabled */
(ITM->TER & (1 << channel)) != 0UL) /* ITM channel enabled */
{
/* collect and transmit bytes in packets of 4 bytes */
uint32_t value = 0, shift = 0;
while (size-- > 0) {
value |= (uint32_t)*data++ << shift;
shift += 8;
if (shift >= 32) {
/* in the waiting loop, use an empty statement and not __NOP();
although __NOP() is an inline function, it would still be
instrumented */
while (ITM->PORT[channel].u32 == 0UL)
{}
ITM->PORT[channel].u32 = value;
value = shift = 0;
}
}
/* transmit last collected bytes */
if (shift > 0) {
while (ITM->PORT[channel].u32 == 0UL)
{}
ITM->PORT[channel].u32 = value;
}
}
}

__attribute__((no_instrument_function))
void __cyg_profile_func_enter(void *this_fn, void *call_site)
{
(void)call_site;
trace_function_profile_enter((unsigned long)this_fn);
}
__attribute__((no_instrument_function))
void __cyg_profile_func_exit(void *this_fn, void *call_site)
{
(void)call_site;
trace_function_profile_exit((unsigned long)this_fn);
}

41 changes: 41 additions & 0 deletions examples/function_trace.tsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* TSDL file suitable for tracing function entries and exits.
*
* The source code must be compiled with GCC option -finstrument-functions.
* The code must also supply a function trace_xmit(), as explained in the
* book. An * important note is that trace_xmit() must be declared with
* __attribute__((no_instrument_function))
*/
trace {
major = 1;
minor = 8;
packet.header := struct {
uint16_t magic;
};
};

stream function_profile {
id = 31;
event.header := struct {
uint16_t id;
};
};

typealias integer {
size = 32;
signed = false;
base = symaddress;
} := code_address;

event function_profile::enter {
attribute = "no_instrument_function";
fields := struct {
code_address symbol;
};
};

event function_profile::exit {
attribute = "no_instrument_function";
fields := struct {
code_address symbol;
};
};
2 changes: 1 addition & 1 deletion examples/traceswo.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Implementation of functions to transmit data or strings over the TRACESWO
* wire of the ARM Cortex micro-controllers.
*
* These routines pack the bytes to * transmit into 32-bit words, in order to
* These routines pack the bytes to transmit into 32-bit words, in order to
* minimize overhead (each item that is transmitted over the TRACESWO pin is
* prefixed with a 1-byte header, so that when tranmitting single bytes, each
* byte has that 1-byte header overhead).
Expand Down
15 changes: 11 additions & 4 deletions source/Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ OBJLIST_BMTRACE = bmtrace.o bmcommon.o bmp-scan.o bmp-script.o bmp-support.o \

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

OBJLIST_CALLTREE = calltree.o

OBJLIST_POSTLINK = elf-postlink.o elf.o

OBJLIST_TRACEGEN = tracegen.o parsetsdl.o


project: bmdebug bmflash bmprofile bmtrace bmscan elf-postlink tracegen
project: bmdebug bmflash bmprofile bmscan bmtrace calltree elf-postlink tracegen

depend :
makedepend -b -fmakefile.dep $(OBJLIST_BMDEBUG:.o=.c) $(OBJLIST_BMFLASH:.o=.c) \
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMTRACE:.o=.c) \
$(OBJLIST_BMSCAN:.o=.c) $(OBJLIST_POSTLINK:.o=.c) \
$(OBJLIST_TRACEGEN:.o=.c)
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMSCAN:.o=.c) \
$(OBJLIST_BMTRACE:.o=.c) $(OBJLIST_CALLTREE) \
$(OBJLIST_POSTLINK:.o=.c) $(OBJLIST_TRACEGEN:.o=.c)


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

bmp-support.o : bmp-support.c

calltree.o : calltree.c

cksum.o : cksum.c

crc32.o : crc32.c
Expand Down Expand Up @@ -226,6 +230,9 @@ bmtrace : $(OBJLIST_BMTRACE)
bmscan : $(OBJLIST_BMSCAN)
$(LNK) $(LFLAGS) -o$@ $^ -lbsd -lpthread

calltree : $(OBJLIST_CALLTREE)
$(LNK) $(LFLAGS) -o$@ $^ -lbsd

elf-postlink : $(OBJLIST_POSTLINK)
$(LNK) $(LFLAGS) -o$@ $^ -lbsd

Expand Down
18 changes: 14 additions & 4 deletions source/Makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,21 @@ OBJLIST_BMTRACE = bmtrace.o bmcommon.o bmp-scan.o bmp-script.o bmp-support.o \

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

OBJLIST_CALLTREE = calltree.o

OBJLIST_POSTLINK = elf-postlink.o elf.o strlcpy.o

OBJLIST_TRACEGEN = tracegen.o parsetsdl.o strlcpy.o


project : bmdebug.exe bmflash.exe bmprofile.exe bmtrace.exe bmscan.exe elf-postlink.exe tracegen.exe
project : bmdebug.exe bmflash.exe bmprofile.exe bmtrace.exe bmscan.exe \
calltree.exe elf-postlink.exe tracegen.exe

depend :
makedepend -b -fmakefile.dep $(OBJLIST_BMDEBUG:.o=.c) $(OBJLIST_BMFLASH:.o=.c) \
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMTRACE:.o=.c) \
$(OBJLIST_BMSCAN:.o=.c) $(OBJLIST_POSTLINK:.o=.c) \
$(OBJLIST_TRACEGEN:.o=.c)
$(OBJLIST_BMPROFILE:.o=.c) $(OBJLIST_BMSCAN:.o=.c) \
$(OBJLIST_BMTRACE:.o=.c) $(OBJLIST_CALLTREE:.o=.c) \
$(OBJLIST_POSTLINK:.o=.c) $(OBJLIST_TRACEGEN:.o=.c)


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

bmp-support.o : bmp-support.c

calltree.o : calltree.c

cksum.o : cksum.c

crc32.o : crc32.c
Expand Down Expand Up @@ -210,6 +215,8 @@ bmdebug.res : bmdebug.rc

bmflash.res : bmflash.rc

bmprofile.res : bmprofile.rc

bmtrace.res : bmtrace.rc


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

calltree.exe : $(OBJLIST_CALLTREE)
$(LNK) $(LFLAGS) -o$@ $^

elf-postlink.exe : $(OBJLIST_POSTLINK)
$(LNK) $(LFLAGS) -o$@ $^

Expand Down
16 changes: 13 additions & 3 deletions source/Makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,20 @@ OBJLIST_BMTRACE = bmtrace.obj bmcommon.obj bmp-scan.obj bmp-script.obj bmp-suppo

OBJLIST_BMSCAN = bmscan.obj bmp-scan.obj tcpip.obj

OBJLIST_CALLTREE = calltree.obj

OBJLIST_POSTLINK = elf-postlink.obj elf.obj strlcpy.obj

OBJLIST_TRACEGEN = tracegen.obj parsetsdl.obj strlcpy.obj


project : bmdebug.exe bmflash.exe bmprofile.exe bmtrace.exe bmscan.exe elf-postlink.exe tracegen.exe
project : bmdebug.exe bmflash.exe bmprofile.exe bmtrace.exe bmscan.exe calltree.exe \
elf-postlink.exe tracegen.exe

depend :
makedepend -b -e -o.obj -fmakefile.dep $(OBJLIST_BMDEBUG:.obj=.c) $(OBJLIST_BMFLASH:.obj=.c) \
$(OBJLIST_BMPROFILE:.obj=.c) $(OBJLIST_BMTRACE:.obj=.c) \
$(OBJLIST_BMSCAN:.obj=.c) $(OBJLIST_POSTLINK:.obj=.c) \
$(OBJLIST_BMPROFILE:.obj=.c) $(OBJLIST_BMTRACE:.obj=.c) $(OBJLIST_BMSCAN:.obj=.c) \
$(OBJLIST_CALLTREE:.obj=.c) $(OBJLIST_POSTLINK:.obj=.c) \
$(OBJLIST_TRACEGEN:.obj=.c)


Expand All @@ -133,6 +136,8 @@ bmp-script.obj : bmp-script.c

bmp-support.obj : bmp-support.c

calltree.obj : calltree.c

cksum.obj : cksum.c

crc32.obj : crc32.c
Expand Down Expand Up @@ -204,6 +209,8 @@ bmdebug.res : bmdebug.rc

bmflash.res : bmflash.rc

bmprofile.res : bmprofile.rc

bmtrace.res : bmtrace.rc


Expand All @@ -224,6 +231,9 @@ bmtrace.exe : $(OBJLIST_BMTRACE) bmtrace.res
bmscan.exe : $(OBJLIST_BMSCAN)
$(LNK) $(LFLAGS_C) /OUT:$@ $** advapi32.lib wsock32.lib

calltree.exe : $(OBJLIST_CALLTREE)
$(LNK) $(LFLAGS_C) /OUT:$@ $**

elf-postlink.exe : $(OBJLIST_POSTLINK)
$(LNK) $(LFLAGS_C) /OUT:$@ $**

Expand Down
Loading

0 comments on commit 1924b1f

Please sign in to comment.