Skip to content

Commit 313b3c0

Browse files
authoredAug 4, 2022
Add debug support for build.opt (#8637)
Add support to have different build option comment blocks for debug and production builds. Updated example esp8266/HwdtStackDump to use build.opt
1 parent ee7ac2f commit 313b3c0

File tree

5 files changed

+132
-4
lines changed

5 files changed

+132
-4
lines changed
 

‎cores/esp8266/hwdt_app_entry.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@
180180
* tool performing hardware reset and exiting, then the serial monitor
181181
* re-engaging. This is not an issue that needs to be addressed here.
182182
*/
183-
#define DEBUG_ESP_HWDT_PRINT_GREETING
183+
#ifndef DEBUG_ESP_HWDT_PRINT_GREETING
184+
#define DEBUG_ESP_HWDT_PRINT_GREETING (1)
185+
#endif
184186

185187

186188
/*
@@ -995,7 +997,7 @@ STATIC void IRAM_MAYBE handle_hwdt(void) {
995997
}
996998
#endif
997999

998-
#if defined(DEBUG_ESP_HWDT_PRINT_GREETING)
1000+
#if DEBUG_ESP_HWDT_PRINT_GREETING
9991001
ETS_PRINTF("\n\nHardware WDT Stack Dump - enabled\n\n");
10001002
#else
10011003
ETS_PRINTF("\n\n");

‎doc/faq/a06-global-build-options.rst

+66
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,72 @@ Global ``.h`` file: ``LowWatermark.ino.globals.h``
9292
9393
#endif
9494
95+
Separate production and debug build options
96+
===========================================
97+
98+
If your production and debug build option requirements are different,
99+
adding ``mkbuildoptglobals.extra_flags={build.debug_port}`` to
100+
``platform.local.txt`` will create separate build option groups for
101+
debugging and production. For the production build option group, the “C”
102+
block comment starts with ``/*@create-file:build.opt@``, as previously
103+
defined. For the debugging group, the new “C” block comment starts with
104+
``/*@create-file:build.opt:debug@``. You make your group selection
105+
through “Arduino->Tools->Debug port” by selecting or disabling the
106+
“Debug port.”
107+
108+
Options common to both debug and production builds must be included in
109+
both groups. Neither of the groups is required. You may also omit either
110+
or both.
111+
112+
Reminder with this change, any old “sketch” with only a “C” block
113+
comment starting with ``/*@create-file:build.opt@`` would not use a
114+
``build.opt`` file for the debug case. Update old sketches as needed.
115+
116+
Updated Global ``.h`` file: ``LowWatermark.ino.globals.h``
117+
118+
.. code:: cpp
119+
120+
/*@create-file:build.opt:debug@
121+
// Debug build options
122+
-DMYTITLE1="\"Running on \""
123+
-DUMM_STATS_FULL=1
124+
125+
//-fanalyzer
126+
127+
// Removing the optimization for "sibling and tail recursive calls" may fill
128+
// in some gaps in the stack decoder report. Preserves the stack frames
129+
// created at each level as you call down to the next.
130+
-fno-optimize-sibling-calls
131+
*/
132+
133+
/*@create-file:build.opt@
134+
// Production build options
135+
-DMYTITLE1="\"Running on \""
136+
-DUMM_STATS_FULL=1
137+
-O3
138+
*/
139+
140+
#ifndef LOWWATERMARK_INO_GLOBALS_H
141+
#define LOWWATERMARK_INO_GLOBALS_H
142+
143+
#if defined(__cplusplus)
144+
#define MYTITLE2 "Empty"
145+
#endif
146+
147+
#if !defined(__cplusplus) && !defined(__ASSEMBLER__)
148+
#define MYTITLE2 "Full"
149+
#endif
150+
151+
#ifdef DEBUG_ESP_PORT
152+
// Global Debug defines
153+
// ...
154+
#else
155+
// Global Production defines
156+
// ...
157+
#endif
158+
159+
#endif
160+
95161
Aggressively cache compiled core
96162
================================
97163

‎libraries/esp8266/examples/HwdtStackDump/HwdtStackDump.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,27 @@ extern "C" {
4747
////////////////////////////////////////////////////////////////////
4848

4949
void setup(void) {
50-
WiFi.persistent(false); // w/o this a flash write occurs at every boot
51-
WiFi.mode(WIFI_OFF);
5250
Serial.begin(115200);
5351
delay(20); // This delay helps when using the 'Modified Serial monitor' otherwise it is not needed.
5452
Serial.println();
5553
Serial.println();
5654
Serial.println(F("The Hardware Watchdog Timer Demo is starting ..."));
5755
Serial.println();
5856

57+
#ifdef DEMO_THUNK
5958
// This allows us to test dumping a BearSSL stack after HWDT.
6059
stack_thunk_add_ref();
6160
thunk_ets_uart_printf("Using Thunk Stack to print this line.\n\n");
61+
#endif
6262

63+
#ifdef DEMO_WIFI
6364
// We don't need this for this example; however, starting WiFi uses a little
6465
// more of the SYS stack.
6566
WiFi.mode(WIFI_STA);
6667
WiFi.begin(ssid, password);
6768
Serial.println(F("A WiFi connection attempt has been started."));
6869
Serial.println();
70+
#endif
6971

7072
// #define DEMO_NOEXTRA4K
7173
#ifdef DEMO_NOEXTRA4K
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*@create-file:build.opt:debug@
2+
// For this block to work, you must have
3+
// `mkbuildoptglobals.extra_flags={build.debug_port}` in `platform.local.txt`
4+
// Or move contents to the block with the signature "@create-file:build.opt@"
5+
6+
7+
// Removing the optimization for "sibling and tail recursive calls" will clear
8+
// up some gaps in the stack decoder report. Preserves stack frames created at
9+
// each level as you call down to the next.
10+
-fno-optimize-sibling-calls
11+
12+
13+
// Adds a pointer toward the end of the stack frame that points to the beginning
14+
// of the stack frame. The stack dump will annotate the line where it occurs
15+
// with a `<` mark.
16+
-fno-omit-frame-pointer
17+
18+
19+
// Options for HWDT Stack Dump (hwdt_app_entry.cpp)
20+
21+
// Alter the UART serial speed used for printing the Hardware WDT reset stack
22+
// dump. Without this option on an HWDT reset, the existing default speed of
23+
// 115200 bps will be used. If you are using this default speed, you can skip
24+
// this option. Note this option only changes the speed while the stack dump is
25+
// printing. Prior settings are restored.
26+
// -DDEBUG_ESP_HWDT_UART_SPEED=19200
27+
// -DDEBUG_ESP_HWDT_UART_SPEED=74880
28+
// -DDEBUG_ESP_HWDT_UART_SPEED=115200
29+
// -DDEBUG_ESP_HWDT_UART_SPEED=230400
30+
31+
// HWDT Stack Dump defaults to print a simple introduction to let you know the
32+
// tool is active and in the build. At power-on, this may not be viewable on
33+
// some devices. Use the DEBUG_ESP_HWDT_UART_SPEED option above to improve.
34+
// Or uncomment line below to turn off greeting
35+
// -DDEBUG_ESP_HWDT_PRINT_GREETING=0
36+
37+
// Demos
38+
-DDEMO_THUNK=1
39+
// -DDEMO_NOEXTRA4K=1
40+
-DDEMO_WIFI=1
41+
*/
42+
43+
/*@create-file:build.opt@
44+
// -fno-optimize-sibling-calls
45+
// -fno-omit-frame-pointer
46+
47+
// Demos
48+
-DDEMO_THUNK=1
49+
// -DDEMO_NOEXTRA4K=1
50+
-DDEMO_WIFI=1
51+
*/

‎tools/mkbuildoptglobals.py

+7
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ def parse_args():
680680
parser.add_argument('source_globals_h_fqfn', help="Source FQFN Sketch.ino.globals.h")
681681
parser.add_argument('commonhfile_fqfn', help="Core Source FQFN CommonHFile.h")
682682
parser.add_argument('--debug', action='store_true', required=False, default=False)
683+
parser.add_argument('-DDEBUG_ESP_PORT', nargs='?', action='store', const="", default="", help='Add mkbuildoptglobals.extra_flags={build.debug_port} to platform.local.txt')
683684
parser.add_argument('--ci', action='store_true', required=False, default=False)
684685
group = parser.add_mutually_exclusive_group(required=False)
685686
group.add_argument('--cache_core', action='store_true', default=None, help='Assume a "compiler.cache_core" value of true')
@@ -721,6 +722,12 @@ def main():
721722
print_dbg(f"globals_name: {globals_name}")
722723
print_dbg(f"build_path_core: {build_path_core}")
723724
print_dbg(f"globals_h_fqfn: {globals_h_fqfn}")
725+
print_dbg(f"DDEBUG_ESP_PORT: {args.DDEBUG_ESP_PORT}")
726+
727+
if len(args.DDEBUG_ESP_PORT):
728+
build_opt_signature = build_opt_signature[:-1] + ":debug@"
729+
730+
print_dbg(f"build_opt_signature: {build_opt_signature}")
724731

725732
if args.ci:
726733
# Requires CommonHFile.h to never be checked in.

0 commit comments

Comments
 (0)
Please sign in to comment.