Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a4e7eb4

Browse files
authored
Debugger now allows generic selection of sub-configurations (#2435)
* debug: extend hotfix for trailing dash '-' to all toolchains * Added additional_config selector for debug configuration * Added docs
1 parent 4bf81fd commit a4e7eb4

File tree

5 files changed

+163
-4
lines changed

5 files changed

+163
-4
lines changed

‎commands/debug/debug_info.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
133133
for k, v := range toolProperties.SubTree("debug").AsMap() {
134134
debugProperties.Set(k, toolProperties.ExpandPropsInString(v))
135135
}
136+
if debugAdditionalConfig, ok := toolProperties.GetOk("debug.additional_config"); ok {
137+
debugAdditionalConfig = toolProperties.ExpandPropsInString(debugAdditionalConfig)
138+
for k, v := range toolProperties.SubTree(debugAdditionalConfig).AsMap() {
139+
debugProperties.Set(k, toolProperties.ExpandPropsInString(v))
140+
}
141+
}
136142

137143
if !debugProperties.ContainsKey("executable") {
138144
return nil, &arduino.FailedDebugError{Message: tr("Debugging not supported for board %s", req.GetFqbn())}
@@ -169,12 +175,10 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
169175
}
170176
}
171177

178+
toolchainPrefix := debugProperties.Get("toolchain.prefix")
172179
// HOTFIX: for samd (and maybe some other platforms). We should keep this for a reasonable
173180
// amount of time to allow seamless platforms update.
174-
toolchainPrefix := debugProperties.Get("toolchain.prefix")
175-
if toolchainPrefix == "arm-none-eabi-" {
176-
toolchainPrefix = "arm-none-eabi"
177-
}
181+
toolchainPrefix = strings.TrimSuffix(toolchainPrefix, "-")
178182

179183
customConfigs := map[string]string{}
180184
if cortexDebugProps := debugProperties.SubTree("cortex-debug.custom"); cortexDebugProps.Size() > 0 {

‎docs/platform-specification.md‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,74 @@ will result in the following JSON:
14521452
}
14531453
```
14541454

1455+
### Additional debugger config selection via `debug.additional_config` directive.
1456+
1457+
It is possible to use any sub-tree of the platform configuration to override the debugger configuration using the
1458+
directive `debug.additional_config=CONFIG_PREFIX`. This rule will use the configuration under `CONFIG_PREFIX.*` to
1459+
override the current `debug.*` config.
1460+
1461+
This change allows a more convenient rationalization and selection of the configs to apply to the debugger. For example,
1462+
we could factor common parts of a configuration in the platform.txt file:
1463+
1464+
```
1465+
# CONFIG 1
1466+
debug-overrides.esp32.cortex-debug.custom.name=Arduino on ESP32
1467+
debug-overrides.esp32.cortex-debug.custom.request=attach
1468+
debug-overrides.esp32.cortex-debug.custom.postAttachCommands.0=set remote hardware-watchpoint-limit 2
1469+
debug-overrides.esp32.cortex-debug.custom.postAttachCommands.1=monitor reset halt
1470+
debug-overrides.esp32.cortex-debug.custom.postAttachCommands.2=monitor gdb_sync
1471+
debug-overrides.esp32.cortex-debug.custom.postAttachCommands.3=thb setup
1472+
debug-overrides.esp32.cortex-debug.custom.postAttachCommands.4=c
1473+
debug-overrides.esp32.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
1474+
debug-overrides.esp32.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync
1475+
debug-overrides.esp32.cortex-debug.custom.overrideRestartCommands.2=thb setup
1476+
debug-overrides.esp32.cortex-debug.custom.overrideRestartCommands.3=c
1477+
1478+
# CONFIG 2
1479+
debug-overrides.esp32s2.cortex-debug.custom.name=Arduino on ESP32-S2
1480+
debug-overrides.esp32s2.cortex-debug.custom.request=attach
1481+
debug-overrides.esp32s2.cortex-debug.custom.postAttachCommands.0=set remote hardware-watchpoint-limit 2
1482+
debug-overrides.esp32s2.cortex-debug.custom.postAttachCommands.1=monitor reset halt
1483+
debug-overrides.esp32s2.cortex-debug.custom.postAttachCommands.2=monitor gdb_sync
1484+
debug-overrides.esp32s2.cortex-debug.custom.postAttachCommands.3=thb setup
1485+
debug-overrides.esp32s2.cortex-debug.custom.postAttachCommands.4=c
1486+
debug-overrides.esp32s2.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
1487+
debug-overrides.esp32s2.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync
1488+
debug-overrides.esp32s2.cortex-debug.custom.overrideRestartCommands.2=thb setup
1489+
debug-overrides.esp32s2.cortex-debug.custom.overrideRestartCommands.3=c
1490+
```
1491+
1492+
and choose which one to use depending on the board in the boards.txt file:
1493+
1494+
```
1495+
myboard.name=My Board with esp32
1496+
myboard.debug.additional_config=debug-overrides.esp32
1497+
1498+
anotherboard.name=My Board with esp32s2
1499+
anotherboard.debug.additional_config=debug-overrides.esp32s2
1500+
...
1501+
```
1502+
1503+
Another possibility is to compose the configuration using another variable present in the board configuration, for
1504+
example if in the `platform.txt` we add:
1505+
1506+
```
1507+
debug.additional_config=debug-overrides.{build.mcu}
1508+
```
1509+
1510+
we may use the `build.mcu` value as a "selector" for the board-specific debug configuration that is overlapped to the
1511+
global debug configuration:
1512+
1513+
```
1514+
myboard.name=My Board with esp32
1515+
myboard.build.mcu=esp32
1516+
...
1517+
1518+
anotherboard.name=My Board with esp32s2
1519+
anotherboard.build.mcu=esp32s2
1520+
...
1521+
```
1522+
14551523
### Optimization level for debugging
14561524

14571525
The compiler optimization level that is appropriate for normal usage will often not provide a good experience while

‎internal/integrationtest/debug/debug_test.go‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,62 @@ func testAllDebugInformation(t *testing.T, env *integrationtest.Environment, cli
272272
}`)
273273
}
274274

275+
{
276+
// Mixing programmer and additional_config
277+
jsonDebugOut, _, err := cli.Run("debug", "-b", "my:samd:my3", "-P", "my_cold_ice", sketchPath.String(), "--info", "--format", "json")
278+
require.NoError(t, err)
279+
debugOut := requirejson.Parse(t, jsonDebugOut)
280+
debugOut.MustContain(`
281+
{
282+
"toolchain": "gcc",
283+
"toolchain_path": "gcc-path",
284+
"toolchain_prefix": "gcc-prefix",
285+
"server": "openocd",
286+
"server_path": "openocd-path",
287+
"server_configuration": {
288+
"path": "openocd-path",
289+
"scripts_dir": "openocd-scripts-dir",
290+
"scripts": [
291+
"cold_ice_script"
292+
]
293+
},
294+
"custom_configs": {
295+
"cortex-debug": {
296+
"test1": "true"
297+
}
298+
},
299+
"svd_file": "test1.svd",
300+
"programmer": "my_cold_ice"
301+
}`)
302+
}
303+
304+
{
305+
// Mixing programmer and additional_config selected by another variable
306+
jsonDebugOut, _, err := cli.Run("debug", "-b", "my:samd:my4", "-P", "my_cold_ice", sketchPath.String(), "--info", "--format", "json")
307+
require.NoError(t, err)
308+
debugOut := requirejson.Parse(t, jsonDebugOut)
309+
debugOut.MustContain(`
310+
{
311+
"toolchain": "gcc",
312+
"toolchain_path": "gcc-path",
313+
"toolchain_prefix": "gcc-prefix",
314+
"server": "openocd",
315+
"server_path": "openocd-path",
316+
"server_configuration": {
317+
"path": "openocd-path",
318+
"scripts_dir": "openocd-scripts-dir",
319+
"scripts": [
320+
"cold_ice_script"
321+
]
322+
},
323+
"custom_configs": {
324+
"cortex-debug": {
325+
"test2": "true"
326+
}
327+
},
328+
"svd_file": "test2.svd",
329+
"programmer": "my_cold_ice"
330+
}`)
331+
}
275332
}
276333
}

‎internal/integrationtest/debug/testdata/hardware/my/samd/boards.txt‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,28 @@ my2.debug.server.openocd.path=openocd-path
8787
my2.debug.server.openocd.scripts_dir=openocd-scripts-dir
8888
my2.debug.server.openocd.script=single-script
8989
my2.debug.svd_file=svd-file
90+
91+
my3.name=My third Cool Board
92+
my3.build.core=arduino:arduino
93+
my3.build.variant=arduino:mkr1000
94+
my3.debug.toolchain.path=gcc-path
95+
my3.debug.toolchain.prefix=gcc-prefix
96+
my3.debug.server.openocd.path=openocd-path
97+
my3.debug.server.openocd.scripts_dir=openocd-scripts-dir
98+
my3.debug.server.openocd.script=single-script
99+
# this one will be overwritten by additional_config
100+
my3.debug.svd_file=svd-file
101+
my3.debug.additional_config=build.debug.config.test1
102+
103+
my4.name=My fourth Cool Board
104+
my4.build.core=arduino:arduino
105+
my4.build.variant=arduino:mkr1000
106+
my4.debug.toolchain.path=gcc-path
107+
my4.debug.toolchain.prefix=gcc-prefix
108+
my4.debug.server.openocd.path=openocd-path
109+
my4.debug.server.openocd.scripts_dir=openocd-scripts-dir
110+
my4.debug.server.openocd.script=single-script
111+
my4.build.mcu=test2
112+
# this one will be overwritten by additional_config
113+
my4.debug.svd_file=svd-file
114+
my4.debug.additional_config=build.debug.config.{build.mcu}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build.debug.config.test1.svd_file=test1.svd
2+
build.debug.config.test1.cortex-debug.custom.test1=true
3+
4+
build.debug.config.test2.svd_file=test2.svd
5+
build.debug.config.test2.cortex-debug.custom.test2=true

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /