@@ -133,6 +133,10 @@ export async function activate(context: vscode.ExtensionContext) {
133133 startDebugging ( )
134134 . catch ( err => GlobalEvent . emit ( 'error' , err ) ) ;
135135 } ) ) ;
136+ subscriptions . push ( vscode . commands . registerCommand ( 'eide.debug.start.attach' , ( ) => {
137+ startDebugging ( true )
138+ . catch ( err => GlobalEvent . emit ( 'error' , err ) ) ;
139+ } ) ) ;
136140
137141 // internal command
138142 // TODO
@@ -1911,7 +1915,7 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
19111915 provideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined ,
19121916 token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration [ ] > {
19131917
1914- const result : vscode . DebugConfiguration [ ] = [ ] ;
1918+ let result : vscode . DebugConfiguration [ ] = [ ] ;
19151919
19161920 if ( ! folder )
19171921 return result ;
@@ -2034,6 +2038,16 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
20342038 return dbgCfg ;
20352039 } ;
20362040
2041+ const newAttachDebugCfg = ( cfgtocopy : any ) => {
2042+ const nCfg = JSON . parse ( JSON . stringify ( cfgtocopy ) ) ;
2043+ nCfg [ 'name' ] += '(attach)' ;
2044+ nCfg [ 'request' ] = 'attach' ;
2045+ if ( nCfg [ 'type' ] === 'cortex-debug' ) {
2046+ nCfg [ 'runToEntryPoint' ] = undefined ;
2047+ }
2048+ return nCfg ;
2049+ } ;
2050+
20372051 const fmtOpenocdCfgPath = ( type : 'interface' | 'target' , path : string ) => {
20382052 let cfgpath = path . startsWith ( '${workspaceFolder}/' )
20392053 ? path . replace ( '${workspaceFolder}/' , '' )
@@ -2066,6 +2080,7 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
20662080 dbgCfg [ 'serialNumber' ] = m [ 1 ] ;
20672081 }
20682082 result . push ( dbgCfg ) ;
2083+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
20692084 }
20702085
20712086 else if ( flashertype == 'OpenOCD' ) {
@@ -2081,6 +2096,7 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
20812096 dbgCfg [ 'configFiles' ] = ocdCfgs ;
20822097 dbgCfg [ 'serverpath' ] = settingManager . getOpenOCDExePath ( ) ;
20832098 result . push ( dbgCfg ) ;
2099+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
20842100 }
20852101
20862102 else if ( flashertype == 'pyOCD' ) {
@@ -2104,7 +2120,10 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
21042120 cliArgs . push ( flasherCfg . speed ) ;
21052121 }
21062122 dbgCfg [ 'serverArgs' ] = cliArgs ;
2123+ // pyocd not support livewatch
2124+ dbgCfg [ 'liveWatch' ] [ 'enabled' ] = false ;
21072125 result . push ( dbgCfg ) ;
2126+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
21082127 }
21092128
21102129 else if ( flashertype == 'STLink' ) {
@@ -2145,6 +2164,7 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
21452164 dbgCfg [ 'stlinkPath' ] = gdbserverPath ;
21462165 dbgCfg [ 'stm32cubeprogrammer' ] = cubeProgramerPath ;
21472166 result . push ( dbgCfg ) ;
2167+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
21482168 }
21492169
21502170 else if ( flashertype == 'probe-rs' ) {
@@ -2181,6 +2201,7 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
21812201 }
21822202 }
21832203 result . push ( dbgCfg ) ;
2204+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
21842205 }
21852206
21862207 // else if (flashertype == 'STVP') {
@@ -2218,13 +2239,13 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
22182239
22192240 // filter by debugType
22202241 if ( this . debuggerType )
2221- return result . filter ( cfg => cfg . type == this . debuggerType ) ;
2242+ result = result . filter ( cfg => cfg . type == this . debuggerType ) ;
22222243
22232244 return result ;
22242245 }
22252246}
22262247
2227- async function startDebugging ( ) {
2248+ async function startDebugging ( attach ?: boolean ) {
22282249
22292250 const prj = projectExplorer . getActiveProject ( ) ;
22302251 if ( ! prj ) {
@@ -2238,8 +2259,10 @@ async function startDebugging() {
22382259 index : 0
22392260 } ;
22402261
2241- const cfgs = await ( new ExternalDebugConfigProvider ( ) )
2242- . provideDebugConfigurations ( vscWorkspaceFolder ) ;
2262+ const provider = new ExternalDebugConfigProvider ( ) ;
2263+ let cfgs = await provider . provideDebugConfigurations ( vscWorkspaceFolder ) ;
2264+ if ( cfgs && attach )
2265+ cfgs = cfgs . filter ( cfg => cfg . request === 'attach' ) ;
22432266 if ( cfgs && cfgs . length > 0 ) {
22442267 let cfg = cfgs [ 0 ] ;
22452268 if ( cfgs . length > 1 ) {
0 commit comments