Skip to content

Commit 839eefa

Browse files
authored
[cppdbg] Support new sourceFileMap schema (#6319)
* [cppdbg] Support new sourceFileMap schema For cppdbg, sourceFileMap can be used for binding breakpoints. If keeping with the old format "<source-path>":"<target-path>", it will always be used for breakpoints. If you use the new: "<compile-path>" : { "editorPath": "<target-path>", "useForBreakpoints": true } The sourceMap will only be used for frame enumeration. * Fix linter issues * Addressing PR comments
1 parent 7779eb0 commit 839eefa

File tree

6 files changed

+175
-31
lines changed

6 files changed

+175
-31
lines changed

Extension/package.json

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,11 +1455,46 @@
14551455
"default": false
14561456
},
14571457
"sourceFileMap": {
1458-
"type": "object",
1459-
"description": "%c_cpp.debuggers.sourceFileMap.description%",
1460-
"default": {
1461-
"<source-path>": "<target-path>"
1462-
}
1458+
"anyOf": [
1459+
{
1460+
"type": "object",
1461+
"description": "%c_cpp.debuggers.sourceFileMap.description%",
1462+
"default": {
1463+
"<source-path>": "<target-path>"
1464+
}
1465+
},
1466+
{
1467+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%",
1468+
"type": "object",
1469+
"default": {
1470+
"<source-path>": {
1471+
"editorPath": "",
1472+
"useForBreakpoints": true
1473+
}
1474+
},
1475+
"properties": {
1476+
"<source-path>": {
1477+
"type": "object",
1478+
"default": {
1479+
"editorPath": "",
1480+
"useForBreakpoints": true
1481+
},
1482+
"properties": {
1483+
"editorPath": {
1484+
"type": "string",
1485+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description%",
1486+
"default": ""
1487+
},
1488+
"useForBreakpoints": {
1489+
"type": "boolean",
1490+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.useForBreakpoints.description%",
1491+
"default": true
1492+
}
1493+
}
1494+
}
1495+
}
1496+
}
1497+
]
14631498
},
14641499
"logging": {
14651500
"description": "%c_cpp.debuggers.logging.description%",
@@ -1648,11 +1683,46 @@
16481683
"default": false
16491684
},
16501685
"sourceFileMap": {
1651-
"type": "object",
1652-
"description": "%c_cpp.debuggers.sourceFileMap.description%",
1653-
"default": {
1654-
"<source-path>": "<target-path>"
1655-
}
1686+
"anyOf": [
1687+
{
1688+
"type": "object",
1689+
"description": "%c_cpp.debuggers.sourceFileMap.description%",
1690+
"default": {
1691+
"<source-path>": "<target-path>"
1692+
}
1693+
},
1694+
{
1695+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%",
1696+
"type": "object",
1697+
"default": {
1698+
"<source-path>": {
1699+
"editorPath": "",
1700+
"useForBreakpoints": true
1701+
}
1702+
},
1703+
"properties": {
1704+
"<source-path>": {
1705+
"type": "object",
1706+
"default": {
1707+
"editorPath": "",
1708+
"useForBreakpoints": true
1709+
},
1710+
"properties": {
1711+
"editorPath": {
1712+
"type": "string",
1713+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description%",
1714+
"default": ""
1715+
},
1716+
"useForBreakpoints": {
1717+
"type": "boolean",
1718+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.useForBreakpoints.description%",
1719+
"default": true
1720+
}
1721+
}
1722+
}
1723+
}
1724+
}
1725+
]
16561726
},
16571727
"logging": {
16581728
"description": "%c_cpp.debuggers.logging.description%",

Extension/package.nls.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,8 @@
227227
"c_cpp.taskDefinitions.args.description": "Additional arguments to pass to the compiler or compilation script",
228228
"c_cpp.taskDefinitions.options.description": "Additional command options",
229229
"c_cpp.taskDefinitions.options.cwd.description": "The current working directory of the executed program or script. If omitted Code's current workspace root is used.",
230-
"c_cpp.taskDefinitions.detail.description": "Additional details of the task"
230+
"c_cpp.taskDefinitions.detail.description": "Additional details of the task",
231+
"c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description": "Current and compile-time paths to the same source trees. Files found under the EditorPath are mapped to the CompileTimePath path for breakpoint matching and mapped from CompileTimePath to EditorPath when displaying stacktrace locations.",
232+
"c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description": "The path to the source tree the editor will use.",
233+
"c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.useForBreakpoints.description": "False if this entry is only used for stack frame location mapping. True if this entry should also be used when specifying breakpoint locations."
231234
}

Extension/src/Debugger/configurationProvider.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,35 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider {
344344
let message: string = "";
345345
const sourceFileMapTarget: string = config.sourceFileMap[sourceFileMapSource];
346346

347-
// TODO: pass config.environment as 'additionalEnvironment' to resolveVariables when it is { key: value } instead of { "key": key, "value": value }
348-
const newSourceFileMapSource: string = util.resolveVariables(sourceFileMapSource, undefined);
349-
const newSourceFileMapTarget: string = util.resolveVariables(sourceFileMapTarget, undefined);
350-
351347
let source: string = sourceFileMapSource;
352-
let target: string = sourceFileMapTarget;
348+
let target: string | object = sourceFileMapTarget;
353349

350+
// TODO: pass config.environment as 'additionalEnvironment' to resolveVariables when it is { key: value } instead of { "key": key, "value": value }
351+
const newSourceFileMapSource: string = util.resolveVariables(sourceFileMapSource, undefined);
354352
if (sourceFileMapSource !== newSourceFileMapSource) {
355353
message = "\t" + localize("replacing.sourcepath", "Replacing {0} '{1}' with '{2}'.", "sourcePath", sourceFileMapSource, newSourceFileMapSource);
356354
delete config.sourceFileMap[sourceFileMapSource];
357355
source = newSourceFileMapSource;
358356
}
359357

360-
if (sourceFileMapTarget !== newSourceFileMapTarget) {
361-
// Add a space if source was changed, else just tab the target message.
362-
message += (message ? ' ' : '\t');
363-
message += localize("replacing.targetpath", "Replacing {0} '{1}' with '{2}'.", "targetPath", sourceFileMapTarget, newSourceFileMapTarget);
364-
target = newSourceFileMapTarget;
358+
if (util.isString(sourceFileMapTarget)) {
359+
const newSourceFileMapTarget: string = util.resolveVariables(sourceFileMapTarget, undefined);
360+
if (sourceFileMapTarget !== newSourceFileMapTarget) {
361+
// Add a space if source was changed, else just tab the target message.
362+
message += (message ? ' ' : '\t');
363+
message += localize("replacing.targetpath", "Replacing {0} '{1}' with '{2}'.", "targetPath", sourceFileMapTarget, newSourceFileMapTarget);
364+
target = newSourceFileMapTarget;
365+
}
366+
} else if (util.isObject(sourceFileMapTarget)) {
367+
const newSourceFileMapTarget: {"editorPath": string; "useForBreakpoints": boolean } = sourceFileMapTarget;
368+
newSourceFileMapTarget["editorPath"] = util.resolveVariables(sourceFileMapTarget["editorPath"], undefined);
369+
370+
if (sourceFileMapTarget !== newSourceFileMapTarget) {
371+
// Add a space if source was changed, else just tab the target message.
372+
message += (message ? ' ' : '\t');
373+
message += localize("replacing.editorPath", "Replacing {0} '{1}' with '{2}'.", "editorPath", sourceFileMapTarget, newSourceFileMapTarget["editorPath"]);
374+
target = newSourceFileMapTarget;
375+
}
365376
}
366377

367378
if (message) {

Extension/src/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ export function isBoolean(input: any): input is boolean {
262262
return typeof(input) === "boolean";
263263
}
264264

265+
export function isObject(input: any): input is object {
266+
return typeof(input) === "object";
267+
}
268+
265269
export function isArray(input: any): input is any[] {
266270
return input instanceof Array;
267271
}

Extension/tools/GenerateOptionsSchema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ function replaceReferences(definitions: any, objects: any): any {
8080
objects[key] = refReplace(definitions, objects[key]);
8181
}
8282

83+
// Handle 'anyOf' with references
84+
if (objects[key].hasOwnProperty('anyOf')) {
85+
for (const index in objects[key].anyOf) {
86+
if (objects[key].anyOf[index].hasOwnProperty('$ref')) {
87+
objects[key].anyOf[index] = refReplace(definitions, objects[key].anyOf[index]);
88+
}
89+
}
90+
}
91+
8392
// Recursively replace references if this object has properties.
8493
if (objects[key].hasOwnProperty('type') && objects[key].type === 'object' && objects[key].properties !== null) {
8594
objects[key].properties = replaceReferences(definitions, objects[key].properties);

Extension/tools/OptionsSchema.json

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@
145145
}
146146
}
147147
},
148+
"SourceFileMapEntry": {
149+
"type": "object",
150+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%",
151+
"default": {
152+
"<source-path>": {
153+
"editorPath": "",
154+
"useForBreakpoints": true
155+
}
156+
},
157+
"properties": {
158+
"<source-path>": {
159+
"type": "object",
160+
"default": {
161+
"editorPath": "",
162+
"useForBreakpoints": true
163+
},
164+
"properties": {
165+
"editorPath": {
166+
"type": "string",
167+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description%",
168+
"default": "<editor-path>"
169+
},
170+
"useForBreakpoints": {
171+
"type": "boolean",
172+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.useForBreakpoints.description%",
173+
"default": true
174+
}
175+
}
176+
}
177+
}
178+
},
148179
"CppdbgLaunchOptions": {
149180
"type": "object",
150181
"default": {},
@@ -304,11 +335,19 @@
304335
"default": false
305336
},
306337
"sourceFileMap": {
307-
"type": "object",
308-
"description": "%c_cpp.debuggers.sourceFileMap.description%",
309-
"default": {
310-
"<source-path>": "<target-path>"
311-
}
338+
"anyOf": [
339+
{
340+
"type": "object",
341+
"description": "%c_cpp.debuggers.sourceFileMap.description%",
342+
"default": {
343+
"<source-path>": "<target-path>"
344+
}
345+
},
346+
{
347+
"$ref": "#/definitions/SourceFileMapEntry",
348+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%"
349+
}
350+
]
312351
},
313352
"logging": {
314353
"$ref": "#/definitions/Logging",
@@ -402,11 +441,19 @@
402441
"default": false
403442
},
404443
"sourceFileMap": {
405-
"type": "object",
406-
"description": "%c_cpp.debuggers.sourceFileMap.description%",
407-
"default": {
408-
"<source-path>": "<target-path>"
409-
}
444+
"anyOf": [
445+
{
446+
"type": "object",
447+
"description": "%c_cpp.debuggers.sourceFileMap.description%",
448+
"default": {
449+
"<source-path>": "<target-path>"
450+
}
451+
},
452+
{
453+
"$ref": "#/definitions/SourceFileMapEntry",
454+
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%"
455+
}
456+
]
410457
},
411458
"logging": {
412459
"$ref": "#/definitions/Logging",

0 commit comments

Comments
 (0)