@@ -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' ) {
@@ -2098,13 +2114,17 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
20982114 }
20992115 }
21002116 if ( flasherCfg . otherCmds )
2101- cliArgs . push ( flasherCfg . otherCmds ) ;
2117+ utility . parseCliArgs ( flasherCfg . otherCmds )
2118+ . forEach ( s => cliArgs . push ( s ) )
21022119 if ( flasherCfg . speed ) {
21032120 cliArgs . push ( '-f' ) ;
21042121 cliArgs . push ( flasherCfg . speed ) ;
21052122 }
21062123 dbgCfg [ 'serverArgs' ] = cliArgs ;
2124+ // pyocd not support livewatch
2125+ dbgCfg [ 'liveWatch' ] [ 'enabled' ] = false ;
21072126 result . push ( dbgCfg ) ;
2127+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
21082128 }
21092129
21102130 else if ( flashertype == 'STLink' ) {
@@ -2145,6 +2165,7 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
21452165 dbgCfg [ 'stlinkPath' ] = gdbserverPath ;
21462166 dbgCfg [ 'stm32cubeprogrammer' ] = cubeProgramerPath ;
21472167 result . push ( dbgCfg ) ;
2168+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
21482169 }
21492170
21502171 else if ( flashertype == 'probe-rs' ) {
@@ -2181,6 +2202,7 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
21812202 }
21822203 }
21832204 result . push ( dbgCfg ) ;
2205+ result . push ( newAttachDebugCfg ( dbgCfg ) ) ;
21842206 }
21852207
21862208 // else if (flashertype == 'STVP') {
@@ -2218,13 +2240,13 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
22182240
22192241 // filter by debugType
22202242 if ( this . debuggerType )
2221- return result . filter ( cfg => cfg . type == this . debuggerType ) ;
2243+ result = result . filter ( cfg => cfg . type == this . debuggerType ) ;
22222244
22232245 return result ;
22242246 }
22252247}
22262248
2227- async function startDebugging ( ) {
2249+ async function startDebugging ( attach ?: boolean ) {
22282250
22292251 const prj = projectExplorer . getActiveProject ( ) ;
22302252 if ( ! prj ) {
@@ -2238,9 +2260,17 @@ async function startDebugging() {
22382260 index : 0
22392261 } ;
22402262
2241- const cfgs = await ( new ExternalDebugConfigProvider ( ) )
2242- . provideDebugConfigurations ( vscWorkspaceFolder ) ;
2243- if ( cfgs && cfgs . length > 0 ) {
2263+ const provider = new ExternalDebugConfigProvider ( ) ;
2264+ let cfgs = await provider . provideDebugConfigurations ( vscWorkspaceFolder ) ;
2265+ if ( ! cfgs )
2266+ return ;
2267+
2268+ if ( attach )
2269+ cfgs = cfgs . filter ( cfg => cfg . request === 'attach' ) ;
2270+ else
2271+ cfgs = cfgs . filter ( cfg => cfg . request === 'launch' ) ;
2272+
2273+ if ( cfgs . length > 0 ) {
22442274 let cfg = cfgs [ 0 ] ;
22452275 if ( cfgs . length > 1 ) {
22462276 const val = await vscode . window . showQuickPick ( cfgs . map ( e => e . name ) , {
0 commit comments