24
24
* SOFTWARE.
25
25
*/
26
26
27
- import { exec } from 'child_process' ;
27
+ import { spawnSync } from 'child_process' ;
28
28
import { platform , EOL } from 'os' ;
29
29
import { dirname , normalize , basename } from 'path' ;
30
30
@@ -78,42 +78,39 @@ export class SymbolTable {
78
78
}
79
79
80
80
public async loadSymbols ( ) : Promise < void > {
81
- try {
82
- const results = await this . execute ( ) ;
83
- const output = results . toString ( ) ;
84
- const lines = output . split ( EOL ) ;
85
- let currentFile : string | undefined = undefined ;
86
-
87
- for ( const line of lines ) {
88
- const match = line . match ( SYMBOL_REGEX ) ;
89
- if ( match ) {
90
- if ( match [ 7 ] === 'd' && match [ 8 ] === 'f' ) {
91
- currentFile = match [ 11 ] . trim ( ) ;
92
- }
93
- const type = TYPE_MAP [ match [ 8 ] ] ;
94
- const scope = SCOPE_MAP [ match [ 2 ] ] ;
95
- let name = match [ 11 ] . trim ( ) ;
96
- let hidden = false ;
97
-
98
- if ( name . startsWith ( '.hidden' ) ) {
99
- name = name . substring ( 7 ) . trim ( ) ;
100
- hidden = true ;
101
- }
102
-
103
- this . symbols . push ( {
104
- address : parseInt ( match [ 1 ] , 16 ) ,
105
- type : type ,
106
- scope : scope ,
107
- section : match [ 9 ] . trim ( ) ,
108
- length : parseInt ( match [ 10 ] , 16 ) ,
109
- name : name ,
110
- file : scope === SymbolScope . Local ? currentFile : undefined ,
111
- hidden : hidden
112
- } ) ;
81
+ const results = await this . execute ( ) ;
82
+ const output = results . toString ( ) ;
83
+ const lines = output . split ( EOL ) ;
84
+ let currentFile : string | undefined ;
85
+
86
+ for ( const line of lines ) {
87
+ const match = line . match ( SYMBOL_REGEX ) ;
88
+ if ( match ) {
89
+ if ( match [ 7 ] === 'd' && match [ 8 ] === 'f' ) {
90
+ currentFile = match [ 11 ] . trim ( ) ;
113
91
}
92
+ const type = TYPE_MAP [ match [ 8 ] ] ;
93
+ const scope = SCOPE_MAP [ match [ 2 ] ] ;
94
+ let name = match [ 11 ] . trim ( ) ;
95
+ let hidden = false ;
96
+
97
+ if ( name . startsWith ( '.hidden' ) ) {
98
+ name = name . substring ( 7 ) . trim ( ) ;
99
+ hidden = true ;
100
+ }
101
+
102
+ this . symbols . push ( {
103
+ address : parseInt ( match [ 1 ] , 16 ) ,
104
+ type : type ,
105
+ scope : scope ,
106
+ section : match [ 9 ] . trim ( ) ,
107
+ length : parseInt ( match [ 10 ] , 16 ) ,
108
+ name : name ,
109
+ file : scope === SymbolScope . Local ? currentFile : undefined ,
110
+ hidden : hidden
111
+ } ) ;
114
112
}
115
- // tslint:disable-next-line: no-empty
116
- } catch ( e ) { }
113
+ }
117
114
}
118
115
119
116
public getGlobalVariables ( ) : SymbolInformation [ ] {
@@ -131,20 +128,24 @@ export class SymbolTable {
131
128
132
129
private execute ( ) : Promise < string > {
133
130
return new Promise ( ( resolve , reject ) => {
134
- exec ( [
135
- this . objdump ,
136
- '--syms' ,
137
- `"${ this . program } "`
138
- ] . join ( ' ' ) , {
139
- cwd : dirname ( this . objdump ) ,
140
- windowsHide : true
141
- } , ( error : Error | null , stdout : string ) => {
131
+ try {
132
+ const { stdout, stderr } = spawnSync ( this . objdump , [
133
+ '--syms' ,
134
+ this . program
135
+ ] , {
136
+ cwd : dirname ( this . objdump ) ,
137
+ windowsHide : true
138
+ } ) ;
139
+
140
+ const error = stderr . toString ( 'utf8' ) ;
142
141
if ( error ) {
143
- return reject ( error ) ;
142
+ return reject ( new Error ( error ) ) ;
144
143
}
145
144
146
- return resolve ( stdout ) ;
147
- } ) ;
145
+ resolve ( stdout . toString ( 'utf8' ) ) ;
146
+ } catch ( error ) {
147
+ return reject ( new Error ( error ) ) ;
148
+ }
148
149
} ) ;
149
150
}
150
151
}
0 commit comments