Skip to content

Commit 31cd6ab

Browse files
committed
BMDebug: more logging around loading source files.
1 parent 498b053 commit 31cd6ab

File tree

9 files changed

+55
-43
lines changed

9 files changed

+55
-43
lines changed

‎README.md‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Embedded Debugging with the Black Magic Probe
22
<img src="https://github.com/compuphase/Black-Magic-Probe-Book/blob/master/doc/blackmagicprobe-book.jpg" alt="Book cover" width="400" align="right">
3-
This guide covers setting up and using the <a href="https://github.com/blackmagic-debug/blackmagic/">Black Magic Probe</a>. The Black Magic Probe is a low cost JTAG/SWD probe for ARM Cortex micro-controllers. A distinguishing feature of the Black Magic Probe is that it embeds a GDB server. As a result, the
3+
This guide covers setting up and using the <a href="https://github.com/blackmagic-debug/blackmagic/">Black Magic Probe</a>. The Black Magic Probe is a low cost JTAG/SWD probe for ARM Cortex micro-controllers. A distinguishing feature of the Black Magic Probe is that it embeds a GDB server. As a result, the
44
libbsd-dev
55
libfontconfig-dev
66
libgtk-3-dev
@@ -80,12 +80,5 @@ To generate the `.res` files, use MingW's `windres` function as follows:
8080
```
8181
windres -O coff -J rc -i file.rc -o file.res
8282
```
83-
84-
You'll also need to install fontconfig with:
85-
86-
```
87-
pacman -S mingw-w64-x86_64-fontconfig
88-
```
89-
9083
### Windows with Visual C/C++
9184
The makefile for Visual C/C++ (`Makefile.msvc`) uses Microsoft's `nmake`, which is a bare-bones `make` clone.

‎source/bmdebug.c‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ static bool sourcefile_disassemble(const char *path, const SOURCEFILE *source, A
15291529
* OS-specific format). This parameter may be NULL (in which
15301530
* case the path is assumed the same as the base name).
15311531
*/
1532-
static void sources_add(int srcindex, const char *filename, const char *filepath)
1532+
static bool sources_add(int srcindex, const char *filename, const char *filepath, bool debugmode)
15331533
{
15341534
assert(filename != NULL);
15351535

@@ -1557,7 +1557,9 @@ static void sources_add(int srcindex, const char *filename, const char *filepath
15571557
src->srcindex[src->srccount] = srcindex;
15581558
src->srccount += 1;
15591559
}
1560-
return;
1560+
if (debugmode)
1561+
printf("exists, mapped to index %d\n", src->srcindex[0]);
1562+
return true;
15611563
}
15621564
}
15631565
}
@@ -1590,12 +1592,18 @@ static void sources_add(int srcindex, const char *filename, const char *filepath
15901592
/* load the source file */
15911593
const char *path = (newsrc->path != NULL) ? newsrc->path : newsrc->basename;
15921594
FILE *fp = fopen(path, "rt");
1593-
if (fp != NULL) {
1594-
sourcefile_load(fp, &newsrc->root);
1595-
fclose(fp);
1596-
/* get it's timestamp too */
1597-
newsrc->timestamp = file_timestamp(path);
1595+
if (fp == NULL) {
1596+
if (debugmode)
1597+
printf("file open failed, error %d\n", errno);
1598+
return false;
15981599
}
1600+
sourcefile_load(fp, &newsrc->root);
1601+
fclose(fp);
1602+
if (debugmode)
1603+
printf("loaded\n");
1604+
/* get it's timestamp too */
1605+
newsrc->timestamp = file_timestamp(path);
1606+
return true;
15991607
}
16001608

16011609
/** sources_clear() removes all source files from the sources lists, and
@@ -1625,7 +1633,7 @@ static void sources_clear(bool free_sym)
16251633
}
16261634
}
16271635

1628-
static void sources_parse(const char *gdbresult)
1636+
static bool sources_parse(const char *gdbresult, bool debugmode)
16291637
{
16301638
const char *head = gdbresult;
16311639
if (*head == '^')
@@ -1635,7 +1643,7 @@ static void sources_parse(const char *gdbresult)
16351643
if (*head == ',')
16361644
head++;
16371645
if (strncmp(head, "files=", 6) != 0)
1638-
return;
1646+
return false;
16391647

16401648
int fileidx = 0;
16411649
assert(head[6] == '[');
@@ -1683,13 +1691,16 @@ static void sources_parse(const char *gdbresult)
16831691
const char *basename;
16841692
for (basename = name + strlen(name) - 1; basename > name && *(basename -1 ) != '/' && *(basename -1 ) != '\\'; basename--)
16851693
{}
1686-
sources_add(fileidx, basename, path);
1694+
if (debugmode)
1695+
printf("SRC: %d: %s [%s] ", fileidx, basename, path);
1696+
sources_add(fileidx, basename, path, debugmode);
16871697
fileidx++;
16881698
head = sep + 1;
16891699
assert(*head == ',' || *head == ']');
16901700
if (*head == ',')
1691-
head++;
1701+
head++;
16921702
}
1703+
return true;
16931704
}
16941705

16951706
/** file_timestamp() returns the latest modification time of a file, which may
@@ -3546,6 +3557,10 @@ static void source_widget(struct nk_context *ctx, const char *id, float rowheigh
35463557
if (lines == 0) {
35473558
nk_layout_row_dynamic(ctx, rowheight, 1);
35483559
nk_label(ctx, "NO SOURCE", NK_TEXT_CENTERED);
3560+
const char *basename = source_getname(source_cursorfile);
3561+
char msg[250];
3562+
sprintf(msg, "[%d] %s", source_cursorfile, (basename != NULL) ? basename : "unknown");
3563+
nk_label(ctx, msg, NK_TEXT_CENTERED);
35493564
}
35503565
nk_group_end(ctx);
35513566
if (maxlen > 0)
@@ -7097,7 +7112,7 @@ static void handle_stateaction(APPSTATE *state, const enum nk_collapse_states ta
70977112
MARKSTATE(state);
70987113
} else if (gdbmi_isresult() != NULL) {
70997114
if (strncmp(gdbmi_isresult(), "done,", 5) == 0) {
7100-
sources_parse(gdbmi_isresult() + 5); /* + 5 to skip "done" and comma */
7115+
sources_parse(gdbmi_isresult() + 5, state->debugmode); /* + 5 to skip "done" and comma */
71017116
state->sourcefiles = sources_getnames(&state->sourcefiles_count); /* create array with names for the dropdown */
71027117
state->warn_source_tstamps = !elf_up_to_date(state->ELFfile); /* check timestamps of sources against elf file */
71037118
MOVESTATE(state, STATE_MEMACCESS_1);

‎source/bmflash.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ static void version(void)
670670
freopen("CONOUT$", "wb", stdout);
671671
freopen("CONOUT$", "wb", stderr);
672672
}
673-
printf("Fortify: [%d] %s\n", type, str);
674673
# endif
674+
printf("Fortify: [%d] %s\n", type, str);
675675
}
676676
#endif
677677

‎source/bmprofile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static void version(void)
164164
freopen("CONOUT$", "wb", stdout);
165165
freopen("CONOUT$", "wb", stderr);
166166
}
167-
printf("Fortify: [%d] %s\n", type, str);
168167
# endif
168+
printf("Fortify: [%d] %s\n", type, str);
169169
}
170170
#endif
171171

‎source/bmserial.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ static void version(void)
146146
freopen("CONOUT$", "wb", stdout);
147147
freopen("CONOUT$", "wb", stderr);
148148
}
149-
printf("Fortify: [%d] %s\n", type, str);
150149
# endif
150+
printf("Fortify: [%d] %s\n", type, str);
151151
}
152152
#endif
153153

‎source/bmtrace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ static void version(void)
190190
freopen("CONOUT$", "wb", stdout);
191191
freopen("CONOUT$", "wb", stderr);
192192
}
193-
printf("Fortify: [%d] %s\n", type, str);
194193
# endif
194+
printf("Fortify: [%d] %s\n", type, str);
195195
}
196196
#endif
197197

‎source/nuklear.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12762,9 +12762,9 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
1276212762
combo->label_normal = table[NK_COLOR_TEXT];
1276312763
combo->label_hover = table[NK_COLOR_TEXT];
1276412764
combo->label_active = table[NK_COLOR_TEXT];
12765-
combo->sym_normal = NK_SYMBOL_TRIANGLE_DOWN; /* NK_SYMBOL_TRIANGLE_DOWN_SMALL */
12766-
combo->sym_hover = NK_SYMBOL_TRIANGLE_DOWN; /* NK_SYMBOL_TRIANGLE_DOWN_SMALL */
12767-
combo->sym_active = NK_SYMBOL_TRIANGLE_DOWN; /* NK_SYMBOL_TRIANGLE_DOWN_SMALL */
12765+
combo->sym_normal = NK_SYMBOL_TRIANGLE_DOWN_SMALL;
12766+
combo->sym_hover = NK_SYMBOL_TRIANGLE_DOWN_SMALL;
12767+
combo->sym_active = NK_SYMBOL_TRIANGLE_DOWN_SMALL;
1276812768
combo->content_padding = nk_vec2(4,4);
1276912769
combo->button_padding = nk_vec2(0,4);
1277012770
combo->spacing = nk_vec2(4,0);
@@ -18080,8 +18080,10 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
1808018080
} else {
1808118081
/* circles: make the bounding box rectangular */
1808218082
content = nk_square_rect(content);
18083-
if (type == NK_SYMBOL_CIRCLE_SOLID_SMALL || type == NK_SYMBOL_CIRCLE_OUTLINE_SMALL)
18084-
content = nk_shrink_rect(content, 3);
18083+
if (type == NK_SYMBOL_CIRCLE_SOLID_SMALL || type == NK_SYMBOL_CIRCLE_OUTLINE_SMALL) {
18084+
content = nk_shrink_rect(content, content.w * 0.3f);
18085+
content.y += content.h * 0.3f;
18086+
}
1808518087
nk_fill_circle(out, content, foreground);
1808618088
if (type == NK_SYMBOL_CIRCLE_OUTLINE)
1808718089
nk_fill_circle(out, nk_shrink_rect(content, 1), background);
@@ -18097,10 +18099,12 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
1809718099
heading = (type == NK_SYMBOL_TRIANGLE_RIGHT) ? NK_RIGHT :
1809818100
(type == NK_SYMBOL_TRIANGLE_LEFT) ? NK_LEFT:
1809918101
(type == NK_SYMBOL_TRIANGLE_UP) ? NK_UP: NK_DOWN;
18100-
if (type == NK_SYMBOL_TRIANGLE_DOWN_SMALL)
18101-
nk_triangle_from_direction(points, content, 3, 3, heading);
18102-
else
18102+
if (type == NK_SYMBOL_TRIANGLE_DOWN_SMALL) {
18103+
float sz = NK_MIN(content.w, content.h);
18104+
nk_triangle_from_direction(points, content, sz * 0.1f, sz * 0.1f, heading);
18105+
} else {
1810318106
nk_triangle_from_direction(points, content, 0, 0, heading);
18107+
}
1810418108
nk_fill_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y,
1810518109
points[2].x, points[2].y, foreground);
1810618110
} break;

‎source/nuklear.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ enum nk_symbol_type {
533533
NK_SYMBOL_PLUS,
534534
NK_SYMBOL_MINUS,
535535
NK_SYMBOL_TRIPLE_DOT,
536-
NK_SYMBOL_TRIANGLE_DOWN_SMALL,
537-
NK_SYMBOL_CIRCLE_SOLID_SMALL,
538-
NK_SYMBOL_CIRCLE_OUTLINE_SMALL,
536+
NK_SYMBOL_TRIANGLE_DOWN_SMALL, /* 20% smaller (10% margin around symbol) */
537+
NK_SYMBOL_CIRCLE_SOLID_SMALL, /* 60% smaller */
538+
NK_SYMBOL_CIRCLE_OUTLINE_SMALL, /* 60% smaller */
539539
NK_SYMBOL_LINK,
540540
NK_SYMBOL_LINK_ALT,
541541
NK_SYMBOL_MAX

‎source/svnrev.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
* (https://www.compuphase.com/svnrev.htm).
33
* You should not modify it manually, as it may be re-generated.
44
*
5-
* $Revision: 6901$
6-
* $Date: 2023-02-23$
5+
* $Revision: 6902M$
6+
* $Date: 2023-02-24$
77
*/
88

99
#ifndef _SVNREV_H_
1010
#define _SVNREV_H_
1111

12-
#define SVNREV_NUM 6901
13-
#define SVNREV_STR "1.2.6901"
14-
#define SVNREV_RCS "$Revision: 6901 $"
15-
#define SVNREV_DATE "2023-02-23"
16-
#define SVNREV_STAMP 20230223L
17-
#define SVNREV_MODIFIED 0
12+
#define SVNREV_NUM 6902
13+
#define SVNREV_STR "1.2.6902M"
14+
#define SVNREV_RCS "$Revision: 6902M $"
15+
#define SVNREV_DATE "2023-02-24"
16+
#define SVNREV_STAMP 20230224L
17+
#define SVNREV_MODIFIED 1
1818

1919
#endif /* _SVNREV_H_ */

0 commit comments

Comments
 (0)