@@ -9,142 +9,145 @@ import * as util from "../common/util";
9
9
import { DeviceContext } from "../deviceContext" ;
10
10
11
11
export class DebuggerManager {
12
- private _usbDetector ;
13
- private _debugServerPath : string ;
14
- private _miDebuggerPath : string ;
15
- private _debuggerMappings : any = { } ;
16
- private _debuggerBoardMappings : any = { } ;
17
- constructor (
18
- private _extensionRoot : string ,
19
- private _arduinoSettings : IArduinoSettings ,
20
- private _boardManager : BoardManager ) {
21
- }
12
+ private _usbDetector ;
13
+ private _debugServerPath : string ;
14
+ private _miDebuggerPath : string ;
15
+ private _debuggerMappings : any = { } ;
16
+ private _debuggerBoardMappings : any = { } ;
17
+ constructor (
18
+ private _extensionRoot : string ,
19
+ private _arduinoSettings : IArduinoSettings ,
20
+ private _boardManager : BoardManager ) {
21
+ }
22
22
23
- public initialize ( ) {
24
- const debugFileContent = fs . readFileSync ( path . join ( this . _extensionRoot , "misc" , "debuggerUsbMapping.json" ) , "utf8" ) ;
25
- const usbFileContent = fs . readFileSync ( path . join ( this . _extensionRoot , "misc" , "usbmapping.json" ) , "utf8" ) ;
23
+ public initialize ( ) {
24
+ const debugFileContent = fs . readFileSync ( path . join ( this . _extensionRoot , "misc" , "debuggerUsbMapping.json" ) , "utf8" ) ;
25
+ const usbFileContent = fs . readFileSync ( path . join ( this . _extensionRoot , "misc" , "usbmapping.json" ) , "utf8" ) ;
26
26
27
- for ( const _debugger of JSON . parse ( debugFileContent ) ) {
28
- if ( Array . isArray ( _debugger . pid ) ) {
29
- for ( const pid of _debugger . pid ) {
30
- this . _debuggerMappings [ `${ pid } %${ _debugger . vid } ` ] = { ..._debugger , pid, vid : _debugger . vid } ;
27
+ for ( const _debugger of JSON . parse ( debugFileContent ) ) {
28
+ if ( Array . isArray ( _debugger . pid ) ) {
29
+ for ( const pid of _debugger . pid ) {
30
+ this . _debuggerMappings [ `${ pid } %${ _debugger . vid } ` ] = { ..._debugger , pid, vid : _debugger . vid } ;
31
+ }
32
+ } else {
33
+ this . _debuggerMappings [ `${ _debugger . pid } %${ _debugger . vid } ` ] = { ..._debugger , pid : _debugger . pid , vid : _debugger . vid } ;
34
+ }
31
35
}
32
- } else {
33
- this . _debuggerMappings [ `${ _debugger . pid } %${ _debugger . vid } ` ] = { ..._debugger , pid : _debugger . pid , vid : _debugger . vid } ;
34
- }
35
- }
36
- for ( const config of JSON . parse ( usbFileContent ) ) {
37
- for ( const board of config . boards ) {
38
- if ( board . interface || board . target ) {
39
- this . _debuggerBoardMappings [ [ board . package , board . architecture , board . id ] . join ( ":" ) ] = board ;
36
+ for ( const config of JSON . parse ( usbFileContent ) ) {
37
+ for ( const board of config . boards ) {
38
+ if ( board . interface || board . target ) {
39
+ this . _debuggerBoardMappings [ [ board . package , board . architecture , board . id ] . join ( ":" ) ] = board ;
40
+ }
41
+ }
42
+ }
43
+ this . _usbDetector = require ( "../../../vendor/node-usb-native" ) . detector ;
44
+ this . _debugServerPath = platform . findFile ( platform . getExecutableFileName ( "openocd" ) ,
45
+ path . join ( this . _arduinoSettings . packagePath , "packages" ) ) ;
46
+ if ( ! util . fileExistsSync ( this . _debugServerPath ) ) {
47
+ this . _debugServerPath = "" ;
48
+ }
49
+
50
+ this . _miDebuggerPath = platform . findFile ( platform . getExecutableFileName ( "arm-none-eabi-gdb" ) ,
51
+ path . join ( this . _arduinoSettings . packagePath , "packages" ) ) ;
52
+ if ( ! util . fileExistsSync ( this . _miDebuggerPath ) ) {
53
+ this . _miDebuggerPath = "" ;
40
54
}
41
- }
42
- }
43
- this . _usbDetector = require ( "../../../vendor/node-usb-native" ) . detector ;
44
- this . _debugServerPath = platform . findFile ( platform . getExecutableFileName ( "openocd" ) ,
45
- path . join ( this . _arduinoSettings . packagePath , "packages" ) ) ;
46
- if ( ! util . fileExistsSync ( this . _debugServerPath ) ) {
47
- this . _debugServerPath = "" ;
48
55
}
49
56
50
- this . _miDebuggerPath = platform . findFile ( platform . getExecutableFileName ( "arm-none-eabi-gdb" ) ,
51
- path . join ( this . _arduinoSettings . packagePath , "packages" ) ) ;
52
- if ( ! util . fileExistsSync ( this . _miDebuggerPath ) ) {
53
- this . _miDebuggerPath = "" ;
57
+ public get miDebuggerPath ( ) : string {
58
+ return this . _miDebuggerPath ;
54
59
}
55
- }
56
60
57
- public get miDebuggerPath ( ) : string {
58
- return this . _miDebuggerPath ;
59
- }
61
+ public get debugServerPath ( ) : string {
62
+ return this . _debugServerPath ;
63
+ }
60
64
61
- public get debugServerPath ( ) : string {
62
- return this . _debugServerPath ;
63
- }
65
+ public async listDebuggers ( ) : Promise < any [ ] > {
66
+ const usbDeviceList = await this . _usbDetector . find ( ) ;
67
+ const keys = [ ] ;
68
+ const results = [ ] ;
69
+ usbDeviceList . forEach ( ( device ) => {
70
+ if ( device . vendorId && device . productId ) {
71
+ /* tslint:disable:max-line-length*/
72
+ const key = util . convertToHex ( device . productId , 4 ) + "%" + util . convertToHex ( device . vendorId , 4 ) ;
73
+ const relatedDebugger = this . _debuggerMappings [ key ] ;
74
+ if ( relatedDebugger && keys . indexOf ( key ) < 0 ) {
75
+ keys . push ( key ) ;
76
+ results . push ( relatedDebugger ) ;
77
+ }
78
+ }
79
+ } ) ;
80
+ return results ;
81
+ }
64
82
65
- public async listDebuggers ( ) : Promise < any [ ] > {
66
- const usbDeviceList = await this . _usbDetector . find ( ) ;
67
- const keys = [ ] ;
68
- const results = [ ] ;
69
- usbDeviceList . forEach ( ( device ) => {
70
- if ( device . vendorId && device . productId ) {
71
- /* tslint:disable:max-line-length*/
72
- const key = util . convertToHex ( device . productId , 4 ) + "%" + util . convertToHex ( device . vendorId , 4 ) ;
73
- const relatedDebugger = this . _debuggerMappings [ key ] ;
74
- if ( relatedDebugger && keys . indexOf ( key ) < 0 ) {
75
- keys . push ( key ) ;
76
- results . push ( relatedDebugger ) ;
83
+ public async resolveOpenOcdOptions ( config ) : Promise < string > {
84
+ const board = this . _boardManager . currentBoard . key ;
85
+ const debugConfig = this . _debuggerBoardMappings [ board ] ;
86
+ const dc = DeviceContext . getInstance ( ) ;
87
+ const debuggerConfigured : string = dc . debugger_ ;
88
+ if ( ! debugConfig ) {
89
+ throw new Error ( `Debug for board ${ this . _boardManager . currentBoard . name } is not supported by now.` ) ;
90
+ }
91
+ let resolvedDebugger ;
92
+ const debuggers = await this . listDebuggers ( ) ;
93
+ if ( ! debuggers . length ) {
94
+ throw new Error ( `No supported debuggers are connected.` ) ;
95
+ }
96
+ // rule 1: if this board has debuggers, use its own debugger
97
+ if ( debugConfig . interface ) {
98
+ resolvedDebugger = debuggers . find ( ( _debugger ) => {
99
+ return _debugger . short_name === debugConfig . interface || _debugger . config_file === debugConfig . interface ;
100
+ } ) ;
101
+ if ( ! resolvedDebugger ) {
102
+ throw new Error ( `Debug port for board ${ this . _boardManager . currentBoard . name } is not connected.` ) ;
103
+ }
104
+ }
105
+ // rule 2: if there is only one debugger, use the only debugger
106
+ if ( ! resolvedDebugger && ! debuggerConfigured && debuggers . length === 1 ) {
107
+ resolvedDebugger = debuggers [ 0 ] ;
77
108
}
78
- }
79
- } ) ;
80
- return results ;
81
- }
82
-
83
- public async resolveOpenOcdOptions ( config ) : Promise < string > {
84
- const board = this . _boardManager . currentBoard . key ;
85
- const debugConfig = this . _debuggerBoardMappings [ board ] ;
86
- const dc = DeviceContext . getInstance ( ) ;
87
- const debuggerConfigured : string = dc . debugger_ ;
88
- if ( ! debugConfig ) {
89
- throw new Error ( `Debug for board ${ this . _boardManager . currentBoard . name } is not supported by now.` ) ;
90
- }
91
- let resolvedDebugger ;
92
- const debuggers = await this . listDebuggers ( ) ;
93
- if ( ! debuggers . length ) {
94
- throw new Error ( `No supported debuggers are connected.` ) ;
95
- }
96
- // rule 1: if this board has debuggers, use its own debugger
97
- if ( debugConfig . interface ) {
98
- resolvedDebugger = debuggers . find ( ( _debugger ) => {
99
- return _debugger . short_name === debugConfig . interface || _debugger . config_file === debugConfig . interface ;
100
- } ) ;
101
- if ( ! resolvedDebugger ) {
102
- throw new Error ( `Debug port for board ${ this . _boardManager . currentBoard . name } is not connected.` ) ;
103
- }
104
- }
105
- // rule 2: if there is only one debugger, use the only debugger
106
- if ( ! resolvedDebugger && ! debuggerConfigured && debuggers . length === 1 ) {
107
- resolvedDebugger = debuggers [ 0 ] ;
108
- }
109
109
110
- // rule 3: if there is any configuration about debugger, use this configuration
111
- if ( ! resolvedDebugger && debuggerConfigured ) {
112
- resolvedDebugger = debuggers . find ( ( _debugger ) => {
113
- return _debugger . short_name === debuggerConfigured || _debugger . config_file === debuggerConfigured ;
114
- } ) ;
115
- }
116
- if ( ! resolvedDebugger ) {
117
- const chosen = await vscode . window . showQuickPick ( < vscode . QuickPickItem [ ] > debuggers . map ( ( l ) : vscode . QuickPickItem => {
118
- return {
119
- description : `(0x${ l . vid } :0x${ l . pid } )` ,
120
- label : l . name ,
121
- } ;
122
- } ) . sort ( ( a , b ) : number => {
123
- return a . label === b . label ? 0 : ( a . label > b . label ? 1 : - 1 ) ;
124
- } ) , { placeHolder : "Select a debugger" } ) ;
125
- if ( chosen && chosen . label ) {
126
- resolvedDebugger = debuggers . find ( ( _debugger ) => _debugger . name === chosen . label ) ;
127
- if ( resolvedDebugger ) {
128
- dc . debugger_ = resolvedDebugger . config_file ;
110
+ // rule 3: if there is any configuration about debugger, use this configuration
111
+ if ( ! resolvedDebugger && debuggerConfigured ) {
112
+ resolvedDebugger = debuggers . find ( ( _debugger ) => {
113
+ return _debugger . short_name === debuggerConfigured || _debugger . config_file === debuggerConfigured ;
114
+ } ) ;
115
+ }
116
+ if ( ! resolvedDebugger ) {
117
+ const chosen = await vscode . window . showQuickPick ( < vscode . QuickPickItem [ ] > debuggers . map ( ( l ) : vscode . QuickPickItem => {
118
+ return {
119
+ description : `(0x${ l . vid } :0x${ l . pid } )` ,
120
+ label : l . name ,
121
+ } ;
122
+ } ) . sort ( ( a , b ) : number => {
123
+ return a . label === b . label ? 0 : ( a . label > b . label ? 1 : - 1 ) ;
124
+ } ) , { placeHolder : "Select a debugger" } ) ;
125
+ if ( chosen && chosen . label ) {
126
+ resolvedDebugger = debuggers . find ( ( _debugger ) => _debugger . name === chosen . label ) ;
127
+ if ( resolvedDebugger ) {
128
+ dc . debugger_ = resolvedDebugger . config_file ;
129
+ }
130
+ }
131
+ if ( ! resolvedDebugger ) {
132
+ return "" ;
133
+ }
129
134
}
130
- }
131
- if ( ! resolvedDebugger ) {
132
- return "" ;
133
- }
134
- }
135
135
136
- const debugServerPath = config . debugServerPath ;
137
- let scriptsFolder = path . join ( path . dirname ( debugServerPath ) , "../scripts/" ) ;
138
- if ( ! util . directoryExistsSync ( scriptsFolder ) ) {
139
- scriptsFolder = path . join ( path . dirname ( debugServerPath ) , "../share/openocd/scripts/" ) ;
140
- }
141
- if ( ! util . directoryExistsSync ( scriptsFolder ) ) {
142
- throw new Error ( "Cannot find scripts folder from openocd." ) ;
143
- }
144
- if ( resolvedDebugger . config_file . includes ( "jlink" ) ) {
145
- // only swd is supported now
146
- return `-s ${ scriptsFolder } -f interface/${ resolvedDebugger . config_file } -c "transport select swd" -f target/${ debugConfig . target } ` ;
136
+ const debugServerPath = config . debugServerPath ;
137
+ let scriptsFolder = path . join ( path . dirname ( debugServerPath ) , "../scripts/" ) ;
138
+ if ( ! util . directoryExistsSync ( scriptsFolder ) ) {
139
+ scriptsFolder = path . join ( path . dirname ( debugServerPath ) , "../share/openocd/scripts/" ) ;
140
+ }
141
+ if ( ! util . directoryExistsSync ( scriptsFolder ) ) {
142
+ throw new Error ( "Cannot find scripts folder from openocd." ) ;
143
+ }
144
+ // TODO: need to config gdb port other than hard-coded 3333
145
+ if ( resolvedDebugger . config_file . includes ( "jlink" ) ) {
146
+ // only swd is supported now
147
+ /* tslint:disable:max-line-length*/
148
+ return `-s ${ scriptsFolder } -f interface/${ resolvedDebugger . config_file } -c "transport select swd" -f target/${ debugConfig . target } -c "telnet_port disabled" -c "tcl_port disabled"` ;
149
+ }
150
+ /* tslint:disable:max-line-length*/
151
+ return `-s ${ scriptsFolder } -f interface/${ resolvedDebugger . config_file } -f target/${ debugConfig . target } -c "telnet_port disabled" -c "tcl_port disabled"` ;
147
152
}
148
- return `-s ${ scriptsFolder } -f interface/${ resolvedDebugger . config_file } -f target/${ debugConfig . target } ` ;
149
- }
150
153
}
0 commit comments