Skip to content
1 change: 0 additions & 1 deletion Code Samples/Fib/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"args": [],
Expand Down
72 changes: 28 additions & 44 deletions Code Samples/Fib/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@
{
"version": "2.0.0",
"tasks": []
}
```jsonc
{
"version": "2.0.0",
"tasks": []
}
```
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
// The explicit "build" task was removed because the sample now uses a direct g++ command
// (the Makefile was removed). If you prefer a build task, add one that runs the
// appropriate g++ command for your platform or call `build.cmd` on Windows.
"tasks": []
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
// The explicit "build" task was removed because the sample now uses a direct g++ command
// (the Makefile was removed). If you prefer a build task, add one that runs the
// appropriate g++ command for your platform or call `build.cmd` on Windows.
"tasks": []
}
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "${workspaceRoot}/build.cmd",
"args": [
"<Path/To/MinGW/Cygwin/Bin/Folder>", // Path to the bin folder containing g++ to compile
"fib.exe" // Output executable name
]
},
"linux": {
"command": "g++",
"args": [
"-g",
"*.cpp",
"-lpthread",
"--std=c++11",
"-o",
"fib.out"
]
},
"osx": {
"command": "g++",
"args": [
"-g",
"*.cpp",
"-lpthread",
"--std=c++11",
"-o",
"fib.out"
]
}
}
]
}
48 changes: 48 additions & 0 deletions Code Samples/Fib/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
# Fib

This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug.

## Building

Use one of the commands below to build the sample. The Makefile was removed and the sample is built with g++ directly.

```bash
# Linux / macOS
g++ -g *.cpp -std=c++11 -o fib.out

# Windows (MinGW)
g++ -g *.cpp -std=c++11 -o fib.exe
```

On Windows you can also run the included `build.cmd` if you prefer (it expects the path to a MinGW/Cygwin `bin` folder and an output name):

```powershell
.\build.cmd <Path\To\MinGW\Bin> fib.exe
```

After building, use the `launch.json` in this folder (or your own) to debug the produced binary.
```markdown
# Fib

This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug.

## Building

Use one of the commands below to build the sample. The Makefile was removed and the sample is built with g++ directly.

```bash
# Linux / macOS
g++ -g *.cpp -std=c++11 -o fib.out

# Windows (MinGW)
g++ -g *.cpp -std=c++11 -o fib.exe
```

On Windows you can also run the included `build.cmd` if you prefer (it expects the path to a MinGW/Cygwin `bin` folder and an output name):

```powershell
.\build.cmd <Path\To\MinGW\Bin> fib.exe
```

After building, use the `launch.json` in this folder (or your own) to debug the produced binary.
```
# Fib

This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug.
3 changes: 2 additions & 1 deletion Code Samples/Fib/build.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@@ -1,2 +0,0 @@
SET PATH=%PATH%;%1
g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2
g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2
21 changes: 10 additions & 11 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4770,15 +4770,8 @@
"attach": {
"type": "object",
"default": {},
"required": [
"program"
],
"required": [],
"properties": {
"program": {
"type": "string",
"description": "%c_cpp.debuggers.program.description%",
"default": "${workspaceRoot}/a.out"
},
"targetArchitecture": {
"type": "string",
"description": "%c_cpp.debuggers.targetArchitecture.description%",
Expand Down Expand Up @@ -4824,6 +4817,10 @@
"description": "%c_cpp.debuggers.useExtendedRemote.description%",
"default": false
},
"program": {
"type": "string",
"markdownDescription": "%c_cpp.debuggers.program.attach.markdownDescription%"
},
"processId": {
"markdownDescription": "%c_cpp.debuggers.processId.anyOf.markdownDescription%",
"anyOf": [
Expand Down Expand Up @@ -5789,15 +5786,17 @@
"attach": {
"type": "object",
"default": {},
"required": [
"processId"
],
"required": [],
"properties": {
"symbolSearchPath": {
"type": "string",
"description": "%c_cpp.debuggers.symbolSearchPath.description%",
"default": ""
},
"program": {
"type": "string",
"markdownDescription": "%c_cpp.debuggers.program.attach.markdownDescription%"
},
"processId": {
"markdownDescription": "%c_cpp.debuggers.processId.anyOf.markdownDescription%",
"anyOf": [
Expand Down
8 changes: 7 additions & 1 deletion Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,13 @@
"{Locked=\"`${command:pickProcess}`\"}"
]
},
"c_cpp.debuggers.symbolSearchPath.description": "Semicolon separated list of directories to use to search for symbol (that is, pdb) files. Example: \"c:\\dir1;c:\\dir2\".",
"c_cpp.debuggers.program.attach.markdownDescription": {
"message": "Optional full path to program executable. When specified, the debugger will search for a running process matching this executable name and attach to it. If multiple processes match, a selection prompt will be shown. Use either `program` or `processId`, not both.",
"comment": [
"{Locked=\"`program`\"} {Locked=\"`processId`\"}"
]
},
"c_cpp.debuggers.symbolSearchPath.description": "Semicolon separated list of directories to use to search for .so files. Example: \"c:\\dir1;c:\\dir2\".",
"c_cpp.debuggers.dumpPath.description": "Optional full path to a dump file for the specified program. Example: \"c:\\temp\\app.dmp\". Defaults to null.",
"c_cpp.debuggers.enableDebugHeap.description": "If false, the process will be launched with debug heap disabled. This sets the environment variable '_NO_DEBUG_HEAP' to '1'.",
"c_cpp.debuggers.symbolLoadInfo.description": "Explicit control of symbol loading.",
Expand Down
68 changes: 62 additions & 6 deletions Extension/src/Debugger/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PlatformInformation } from '../platform';
import { rsync, scp, ssh } from '../SSH/commands';
import * as Telemetry from '../telemetry';
import { AttachItemsProvider, AttachPicker, RemoteAttachPicker } from './attachToProcess';
import { AttachItem, showQuickPick } from './attachQuickPick';
import { ConfigMenu, ConfigMode, ConfigSource, CppDebugConfiguration, DebuggerEvent, DebuggerType, DebugType, IConfiguration, IConfigurationSnippet, isDebugLaunchStr, MIConfigurations, PipeTransportConfigurations, TaskStatus, WindowsConfigurations, WSLConfigurations } from './configurations';
import { NativeAttachItemsProviderFactory } from './nativeAttach';
import { Environment, ParsedEnvironmentFile } from './ParsedEnvironmentFile';
Expand Down Expand Up @@ -354,13 +355,24 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
// Pick process if process id is empty
if (config.request === "attach" && !config.processId) {
let processId: string | undefined;
if (config.pipeTransport || config.useExtendedRemote) {
const remoteAttachPicker: RemoteAttachPicker = new RemoteAttachPicker();
processId = await remoteAttachPicker.ShowAttachEntries(config);

// If program is specified, try to find matching process by name
if (config.program) {
processId = await this.findProcessByProgramName(config.program, config, token);
if (!processId) {
void logger.getOutputChannelLogger().showErrorMessage(`No running process found matching "${config.program}".`);
return undefined;
}
} else {
const attachItemsProvider: AttachItemsProvider = NativeAttachItemsProviderFactory.Get();
const attacher: AttachPicker = new AttachPicker(attachItemsProvider);
processId = await attacher.ShowAttachEntries(token);
// Show process picker if no program specified
if (config.pipeTransport || config.useExtendedRemote) {
const remoteAttachPicker: RemoteAttachPicker = new RemoteAttachPicker();
processId = await remoteAttachPicker.ShowAttachEntries(config);
} else {
const attachItemsProvider: AttachItemsProvider = NativeAttachItemsProviderFactory.Get();
const attacher: AttachPicker = new AttachPicker(attachItemsProvider);
processId = await attacher.ShowAttachEntries(token);
}
}

if (processId) {
Expand Down Expand Up @@ -1157,6 +1169,50 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
}
return true;
}

private async findProcessByProgramName(
programPath: string,
config: CppDebugConfiguration,
token?: vscode.CancellationToken
): Promise<string | undefined> {
const programBaseName: string = path.basename(programPath);
let processes: AttachItem[];

// Get process list using the same logic as interactive attach
if (config.pipeTransport || config.useExtendedRemote) {
// For remote attach, we need to use RemoteAttachPicker's methods
void logger.getOutputChannelLogger().showErrorMessage(
"Finding process by program name is not yet supported for remote attach. Please use processId instead."
);
return undefined;
} else {
const attachItemsProvider: AttachItemsProvider = NativeAttachItemsProviderFactory.Get();
processes = await attachItemsProvider.getAttachItems(token);
}

// Find processes matching the program name
const matchingProcesses: AttachItem[] = processes.filter(p => {
const processName: string = p.label.toLowerCase();
const targetName: string = programBaseName.toLowerCase();
// Match if the process name exactly matches or starts with the target name
return processName === targetName || processName.startsWith(targetName);
});

if (matchingProcesses.length === 0) {
return undefined;
} else if (matchingProcesses.length === 1) {
void logger.getOutputChannelLogger().appendLine(
`Found process "${matchingProcesses[0].label}" with PID ${matchingProcesses[0].id}`
);
return matchingProcesses[0].id;
} else {
// Multiple matches - let user choose
void logger.getOutputChannelLogger().appendLine(
`Multiple processes found matching "${programBaseName}". Please select one:`
);
return showQuickPick(() => Promise.resolve(matchingProcesses));
}
}
}

export interface IConfigurationAssetProvider {
Expand Down
1 change: 1 addition & 0 deletions MIEngine_Debug
Submodule MIEngine_Debug added at bc13df
Loading