@@ -2,22 +2,24 @@ import assert from 'assert';
2
2
import * as vscode from 'vscode' ;
3
3
import { adaExtState } from './extension' ;
4
4
import { AdaMain , getAdaMains , getProjectFile } from './helpers' ;
5
+ import { BUILD_PROJECT_TASK_NAME , getBuildTaskName } from './taskProviders' ;
5
6
6
7
/**
7
8
* Ada Configuration for a debug session
8
9
*/
9
10
interface AdaConfig extends vscode . DebugConfiguration {
10
11
MIMode : string ;
11
12
program : string ;
12
- cwd : string ;
13
- targetArchitecture : string ;
14
- stopAtEntry : boolean ;
15
- args : string [ ] ;
16
- setupCommands : {
13
+ cwd ? : string ;
14
+ targetArchitecture ? : string ;
15
+ stopAtEntry ? : boolean ;
16
+ args ? : string [ ] ;
17
+ setupCommands ? : {
17
18
description : string ;
18
19
text : string ;
19
20
ignoreFailures : boolean ;
20
21
} [ ] ;
22
+ processId ?: string ;
21
23
}
22
24
23
25
/**
@@ -53,9 +55,9 @@ export function initializeDebugging(ctx: vscode.ExtensionContext) {
53
55
) : Promise < vscode . DebugConfiguration [ ] > {
54
56
const quickpick = await createQuickPickItems ( 'Build & Debug' ) ;
55
57
56
- const configs : vscode . DebugConfiguration [ ] = quickpick . map ( ( i ) => {
58
+ const configs : AdaConfig [ ] = quickpick . flatMap ( ( i ) => {
57
59
assert ( i . adaMain ) ;
58
- return initializeConfig ( i . adaMain . execFullPath , i . adaMain . mainRelPath ( ) ) ;
60
+ return [ initializeConfig ( i . adaMain ) , createAttachConfig ( i . adaMain ) ] ;
59
61
} ) ;
60
62
61
63
return configs ;
@@ -89,27 +91,23 @@ export function initializeDebugging(ctx: vscode.ExtensionContext) {
89
91
* 'program' parameter.
90
92
* @returns an AdaConfig
91
93
*/
92
- function initializeConfig ( program ?: string , main ?: string , name ?: string ) : AdaConfig {
94
+ function initializeConfig ( main : AdaMain , name ?: string ) : AdaConfig {
93
95
// TODO it would be nice if this and the package.json configuration snippet
94
96
// were the same.
95
97
const config : AdaConfig = {
96
98
type : 'cppdbg' ,
97
- name :
98
- name ??
99
- ( main
100
- ? `Ada: Debug main - ${ main } `
101
- : program
102
- ? `Ada: Debug executable - ${ program . replace ( '${workspaceFolder}/' , '' ) } `
103
- : 'Ada: Debugger Launch' ) ,
99
+ name : name ?? ( main ? `Ada: Debug main - ${ main . mainRelPath ( ) } ` : 'Ada: Debugger Launch' ) ,
104
100
request : 'launch' ,
105
101
targetArchitecture : process . arch ,
106
102
cwd : '${workspaceFolder}' ,
107
- program : program ?? '${workspaceFolder}/${command:ada.getOrAskForProgram}' ,
103
+ program : main
104
+ ? `\${workspaceFolder}/${ main . execRelPath ( ) } `
105
+ : '${workspaceFolder}/${command:ada.getOrAskForProgram}' ,
108
106
stopAtEntry : false ,
109
107
externalConsole : false ,
110
108
args : [ ] ,
111
109
MIMode : 'gdb' ,
112
- preLaunchTask : 'ada: Build current project' ,
110
+ preLaunchTask : main ? getBuildTaskName ( main ) : BUILD_PROJECT_TASK_NAME ,
113
111
setupCommands : setupCmd ,
114
112
} ;
115
113
@@ -155,12 +153,7 @@ export class AdaDebugConfigProvider implements vscode.DebugConfigurationProvider
155
153
const item = quickpick [ i ] ;
156
154
if ( item != generateAll ) {
157
155
assert ( item . adaMain ) ;
158
- configs . push (
159
- initializeConfig (
160
- `\${workspaceFolder}/${ item . adaMain . execRelPath ( ) } ` ,
161
- item . adaMain . mainRelPath ( )
162
- )
163
- ) ;
156
+ configs . push ( initializeConfig ( item . adaMain ) ) ;
164
157
}
165
158
}
166
159
} else if ( selectedProgram ) {
@@ -169,10 +162,7 @@ export class AdaDebugConfigProvider implements vscode.DebugConfigurationProvider
169
162
// The cppdbg debug configuration exepects the executable to be
170
163
// a full path rather than a path relative to the specified
171
164
// cwd. That is why we include ${workspaceFolder}.
172
- const configuration = initializeConfig (
173
- `\${workspaceFolder}/${ selectedProgram . adaMain . execRelPath ( ) } ` ,
174
- selectedProgram . label
175
- ) ;
165
+ const configuration = initializeConfig ( selectedProgram . adaMain ) ;
176
166
configs . push ( configuration ) ;
177
167
} else {
178
168
return Promise . reject ( 'Cancelled' ) ;
@@ -212,10 +202,10 @@ export class AdaDebugConfigProvider implements vscode.DebugConfigurationProvider
212
202
// configuration on the fly.
213
203
return debugConfiguration ;
214
204
} else {
215
- const exec = await getOrAskForProgram ( ) ;
205
+ const main = await getOrAskForProgram ( ) ;
216
206
217
- if ( exec ) {
218
- return initializeConfig ( `\${workspaceFolder}/ ${ exec } ` ) ;
207
+ if ( main ) {
208
+ return initializeConfig ( main ) ;
219
209
}
220
210
}
221
211
@@ -308,31 +298,29 @@ async function assertProjectHasMains(mains?: AdaMain[]) {
308
298
* matches one of the mains, the corresponding executable is returned.
309
299
*
310
300
* Otherwise, the list of mains is offered to the user as a QuickPicker to
311
- * choose a main file. The executable corresponding to the selected main
312
- * file is returned.
313
- *
314
- * Note that paths are returned relative to the workspace.
301
+ * choose a main file. The object corresponding to the selected main file is
302
+ * returned.
315
303
*
316
304
* @param mains - a list of AdaMains if available at the caller site, otherwise
317
305
* it is computed by the call.
318
- * @returns the path of the executable to debug *relative to the workspace*,
319
- * or *undefined* if no selection was made.
306
+ * @returns the object representing the selected main, or *undefined* if no
307
+ * selection was made.
320
308
*/
321
- export async function getOrAskForProgram ( mains ?: AdaMain [ ] ) : Promise < string | undefined > {
309
+ export async function getOrAskForProgram ( mains ?: AdaMain [ ] ) : Promise < AdaMain | undefined > {
322
310
// Compute list of mains if not provided by the caller
323
311
mains = mains ?? ( await getAdaMains ( ) ) ;
324
312
325
313
await assertProjectHasMains ( mains ) ;
326
314
327
- if ( mains . length == 1 ) return mains [ 0 ] . execRelPath ( ) ;
315
+ if ( mains . length == 1 ) return mains [ 0 ] ;
328
316
329
317
// Check if the current file matches one of the mains of the project. If
330
318
// so, use it.
331
319
const currentFile = vscode . window . activeTextEditor ?. document . uri . path ;
332
320
if ( currentFile != undefined ) {
333
321
const adaMain = await getAdaMainForSourceFile ( currentFile , mains ) ;
334
322
if ( adaMain ) {
335
- return adaMain . execRelPath ( ) ;
323
+ return adaMain ;
336
324
}
337
325
}
338
326
@@ -343,7 +331,7 @@ export async function getOrAskForProgram(mains?: AdaMain[]): Promise<string | un
343
331
placeHolder : 'Select a main file to debug' ,
344
332
} ) ;
345
333
if ( selectedProgram ) {
346
- return selectedProgram . adaMain ?. execRelPath ( ) ;
334
+ return selectedProgram . adaMain ;
347
335
}
348
336
349
337
return undefined ;
@@ -366,3 +354,15 @@ async function getAdaMainForSourceFile(
366
354
367
355
return mains . find ( ( val ) => srcPath == val . mainFullPath ) ;
368
356
}
357
+
358
+ function createAttachConfig ( adaMain : AdaMain ) : AdaConfig {
359
+ return {
360
+ name : `Ada: Attach debugger to running process - ${ adaMain . mainRelPath ( ) } ` ,
361
+ type : 'cppdbg' ,
362
+ request : 'attach' ,
363
+ program : `\${workspaceFolder}/${ adaMain . execRelPath ( ) } ` ,
364
+ processId : '${command:pickProcess}' ,
365
+ MIMode : 'gdb' ,
366
+ preLaunchTask : adaMain ? getBuildTaskName ( adaMain ) : BUILD_PROJECT_TASK_NAME ,
367
+ } ;
368
+ }
0 commit comments