diff --git a/Code Samples/Fib/.vscode/launch.json b/Code Samples/Fib/.vscode/launch.json index 301f8c5f2..b1349d1a4 100644 --- a/Code Samples/Fib/.vscode/launch.json +++ b/Code Samples/Fib/.vscode/launch.json @@ -3,7 +3,6 @@ "configurations": [ { "name": "(gdb) Launch", - "preLaunchTask": "build", "type": "cppdbg", "request": "launch", "args": [], diff --git a/Code Samples/Fib/.vscode/tasks.json b/Code Samples/Fib/.vscode/tasks.json index 104a10aad..49c3004f1 100644 --- a/Code Samples/Fib/.vscode/tasks.json +++ b/Code Samples/Fib/.vscode/tasks.json @@ -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 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" - ] - } - } - ] } diff --git a/Code Samples/Fib/README.md b/Code Samples/Fib/README.md index 6402c911b..a9f9eb045 100644 --- a/Code Samples/Fib/README.md +++ b/Code Samples/Fib/README.md @@ -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 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 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. \ No newline at end of file diff --git a/Code Samples/Fib/build.cmd b/Code Samples/Fib/build.cmd index 821c62747..8b78dafa9 100644 --- a/Code Samples/Fib/build.cmd +++ b/Code Samples/Fib/build.cmd @@ -1,2 +1,3 @@ +@@ -1,2 +0,0 @@ SET PATH=%PATH%;%1 -g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 \ No newline at end of file +g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 diff --git a/Extension/package.json b/Extension/package.json index 82df4bbae..8e9b96758 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -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%", @@ -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": [ @@ -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": [ diff --git a/Extension/package.nls.json b/Extension/package.nls.json index ab888087b..1299838e1 100644 --- a/Extension/package.nls.json +++ b/Extension/package.nls.json @@ -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.", diff --git a/Extension/src/Debugger/configurationProvider.ts b/Extension/src/Debugger/configurationProvider.ts index 559011251..70b1773c9 100644 --- a/Extension/src/Debugger/configurationProvider.ts +++ b/Extension/src/Debugger/configurationProvider.ts @@ -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'; @@ -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) { @@ -1324,4 +1336,48 @@ export class ConfigurationSnippetProvider implements vscode.CompletionItemProvid return Promise.resolve(new vscode.CompletionList(items, true)); } + + private async findProcessByProgramName( + programPath: string, + config: CppDebugConfiguration, + token?: vscode.CancellationToken + ): Promise { + 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)); + } + } } diff --git a/MIEngine_Debug b/MIEngine_Debug new file mode 160000 index 000000000..bc13df50d --- /dev/null +++ b/MIEngine_Debug @@ -0,0 +1 @@ +Subproject commit bc13df50d03df838843dbbc1ca15639d8ae42801