@@ -178,22 +178,16 @@ export const getInstructions = async (
178
178
if ( result . length === 0 ) {
179
179
// If cannot retrieve more instructions, break the loop, go to catch
180
180
// and fill the remaining instructions with empty instruction information
181
- throw new Error ( 'Cannot retrieve more instructions!' ) ;
181
+ break ;
182
182
}
183
183
pushToList ( result ) ;
184
184
}
185
185
} catch ( e ) {
186
- // Fill with empty instructions in case of memory error.
187
- const lastMemoryAddress =
188
- list . length === 0
189
- ? memoryReference
190
- : list [ isReverseFetch ? 0 : list . length - 1 ] . address ;
191
- const emptyInstuctions = getEmptyInstructions (
192
- lastMemoryAddress ,
193
- remainingLength ( ) ,
194
- 2
195
- ) ;
196
- pushToList ( emptyInstuctions ) ;
186
+ // If error occured in the first iteration and no items can be read
187
+ // throw the original error, otherwise continue and fill the empty instructions.
188
+ if ( list . length === 0 ) {
189
+ throw e ;
190
+ }
197
191
}
198
192
199
193
if ( absLength < list . length ) {
@@ -206,5 +200,23 @@ export const getInstructions = async (
206
200
}
207
201
}
208
202
203
+ // Fill with empty instructions in case couldn't read desired length
204
+ if ( absLength > list . length ) {
205
+ if ( list . length === 0 ) {
206
+ // In case of memory read error, where no instructions read before you cannot be sure about the memory offsets
207
+ // Avoid sending empty instructions, which is overriding the previous disassembled instructions in the VSCode
208
+ // Instead, send error message and fail the request.
209
+ throw new Error ( `Cannot retrieve instructions!` ) ;
210
+ }
211
+ const lastMemoryAddress =
212
+ list [ isReverseFetch ? 0 : list . length - 1 ] . address ;
213
+ const emptyInstuctions = getEmptyInstructions (
214
+ lastMemoryAddress ,
215
+ absLength - list . length ,
216
+ Math . sign ( length ) * 2
217
+ ) ;
218
+ pushToList ( emptyInstuctions ) ;
219
+ }
220
+
209
221
return list ;
210
222
} ;
0 commit comments