Skip to content

Commit

Permalink
[cppdbg] Support new sourceFileMap schema (#6319)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
WardenGnaw authored Oct 22, 2020
1 parent 7779eb0 commit 839eefa
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 31 deletions.
90 changes: 80 additions & 10 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1455,11 +1455,46 @@
"default": false
},
"sourceFileMap": {
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
"anyOf": [
{
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
},
{
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%",
"type": "object",
"default": {
"<source-path>": {
"editorPath": "",
"useForBreakpoints": true
}
},
"properties": {
"<source-path>": {
"type": "object",
"default": {
"editorPath": "",
"useForBreakpoints": true
},
"properties": {
"editorPath": {
"type": "string",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description%",
"default": ""
},
"useForBreakpoints": {
"type": "boolean",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.useForBreakpoints.description%",
"default": true
}
}
}
}
}
]
},
"logging": {
"description": "%c_cpp.debuggers.logging.description%",
Expand Down Expand Up @@ -1648,11 +1683,46 @@
"default": false
},
"sourceFileMap": {
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
"anyOf": [
{
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
},
{
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%",
"type": "object",
"default": {
"<source-path>": {
"editorPath": "",
"useForBreakpoints": true
}
},
"properties": {
"<source-path>": {
"type": "object",
"default": {
"editorPath": "",
"useForBreakpoints": true
},
"properties": {
"editorPath": {
"type": "string",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description%",
"default": ""
},
"useForBreakpoints": {
"type": "boolean",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.useForBreakpoints.description%",
"default": true
}
}
}
}
}
]
},
"logging": {
"description": "%c_cpp.debuggers.logging.description%",
Expand Down
5 changes: 4 additions & 1 deletion Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,8 @@
"c_cpp.taskDefinitions.args.description": "Additional arguments to pass to the compiler or compilation script",
"c_cpp.taskDefinitions.options.description": "Additional command options",
"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.",
"c_cpp.taskDefinitions.detail.description": "Additional details of the task"
"c_cpp.taskDefinitions.detail.description": "Additional details of the task",
"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.",
"c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description": "The path to the source tree the editor will use.",
"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."
}
31 changes: 21 additions & 10 deletions Extension/src/Debugger/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,24 +344,35 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider {
let message: string = "";
const sourceFileMapTarget: string = config.sourceFileMap[sourceFileMapSource];

// TODO: pass config.environment as 'additionalEnvironment' to resolveVariables when it is { key: value } instead of { "key": key, "value": value }
const newSourceFileMapSource: string = util.resolveVariables(sourceFileMapSource, undefined);
const newSourceFileMapTarget: string = util.resolveVariables(sourceFileMapTarget, undefined);

let source: string = sourceFileMapSource;
let target: string = sourceFileMapTarget;
let target: string | object = sourceFileMapTarget;

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

if (sourceFileMapTarget !== newSourceFileMapTarget) {
// Add a space if source was changed, else just tab the target message.
message += (message ? ' ' : '\t');
message += localize("replacing.targetpath", "Replacing {0} '{1}' with '{2}'.", "targetPath", sourceFileMapTarget, newSourceFileMapTarget);
target = newSourceFileMapTarget;
if (util.isString(sourceFileMapTarget)) {
const newSourceFileMapTarget: string = util.resolveVariables(sourceFileMapTarget, undefined);
if (sourceFileMapTarget !== newSourceFileMapTarget) {
// Add a space if source was changed, else just tab the target message.
message += (message ? ' ' : '\t');
message += localize("replacing.targetpath", "Replacing {0} '{1}' with '{2}'.", "targetPath", sourceFileMapTarget, newSourceFileMapTarget);
target = newSourceFileMapTarget;
}
} else if (util.isObject(sourceFileMapTarget)) {
const newSourceFileMapTarget: {"editorPath": string; "useForBreakpoints": boolean } = sourceFileMapTarget;
newSourceFileMapTarget["editorPath"] = util.resolveVariables(sourceFileMapTarget["editorPath"], undefined);

if (sourceFileMapTarget !== newSourceFileMapTarget) {
// Add a space if source was changed, else just tab the target message.
message += (message ? ' ' : '\t');
message += localize("replacing.editorPath", "Replacing {0} '{1}' with '{2}'.", "editorPath", sourceFileMapTarget, newSourceFileMapTarget["editorPath"]);
target = newSourceFileMapTarget;
}
}

if (message) {
Expand Down
4 changes: 4 additions & 0 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export function isBoolean(input: any): input is boolean {
return typeof(input) === "boolean";
}

export function isObject(input: any): input is object {
return typeof(input) === "object";
}

export function isArray(input: any): input is any[] {
return input instanceof Array;
}
Expand Down
9 changes: 9 additions & 0 deletions Extension/tools/GenerateOptionsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ function replaceReferences(definitions: any, objects: any): any {
objects[key] = refReplace(definitions, objects[key]);
}

// Handle 'anyOf' with references
if (objects[key].hasOwnProperty('anyOf')) {
for (const index in objects[key].anyOf) {
if (objects[key].anyOf[index].hasOwnProperty('$ref')) {
objects[key].anyOf[index] = refReplace(definitions, objects[key].anyOf[index]);
}
}
}

// Recursively replace references if this object has properties.
if (objects[key].hasOwnProperty('type') && objects[key].type === 'object' && objects[key].properties !== null) {
objects[key].properties = replaceReferences(definitions, objects[key].properties);
Expand Down
67 changes: 57 additions & 10 deletions Extension/tools/OptionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,37 @@
}
}
},
"SourceFileMapEntry": {
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%",
"default": {
"<source-path>": {
"editorPath": "",
"useForBreakpoints": true
}
},
"properties": {
"<source-path>": {
"type": "object",
"default": {
"editorPath": "",
"useForBreakpoints": true
},
"properties": {
"editorPath": {
"type": "string",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.editorPath.description%",
"default": "<editor-path>"
},
"useForBreakpoints": {
"type": "boolean",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.useForBreakpoints.description%",
"default": true
}
}
}
}
},
"CppdbgLaunchOptions": {
"type": "object",
"default": {},
Expand Down Expand Up @@ -304,11 +335,19 @@
"default": false
},
"sourceFileMap": {
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
"anyOf": [
{
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
},
{
"$ref": "#/definitions/SourceFileMapEntry",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%"
}
]
},
"logging": {
"$ref": "#/definitions/Logging",
Expand Down Expand Up @@ -402,11 +441,19 @@
"default": false
},
"sourceFileMap": {
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
"anyOf": [
{
"type": "object",
"description": "%c_cpp.debuggers.sourceFileMap.description%",
"default": {
"<source-path>": "<target-path>"
}
},
{
"$ref": "#/definitions/SourceFileMapEntry",
"description": "%c_cpp.debuggers.sourceFileMap.sourceFileMapEntry.description%"
}
]
},
"logging": {
"$ref": "#/definitions/Logging",
Expand Down

0 comments on commit 839eefa

Please sign in to comment.