@@ -187,7 +187,7 @@ func (fc *FileCache) Line(filename string, line int) ([]byte, error) {
187
187
// If filter is non-nil, the disassembly only includes functions with names matching filter.
188
188
// If printCode is true, the disassembly includs corresponding source lines.
189
189
// The disassembly only includes functions that overlap the range [start, end).
190
- func (d * Disasm ) Print (w io.Writer , filter * regexp.Regexp , start , end uint64 , printCode bool ) {
190
+ func (d * Disasm ) Print (w io.Writer , filter * regexp.Regexp , start , end uint64 , printCode bool , gnuAsm bool ) {
191
191
if start < d .textStart {
192
192
start = d .textStart
193
193
}
@@ -229,7 +229,7 @@ func (d *Disasm) Print(w io.Writer, filter *regexp.Regexp, start, end uint64, pr
229
229
var lastFile string
230
230
var lastLine int
231
231
232
- d .Decode (symStart , symEnd , relocs , func (pc , size uint64 , file string , line int , text string ) {
232
+ d .Decode (symStart , symEnd , relocs , gnuAsm , func (pc , size uint64 , file string , line int , text string ) {
233
233
i := pc - d .textStart
234
234
235
235
if printCode {
@@ -266,7 +266,7 @@ func (d *Disasm) Print(w io.Writer, filter *regexp.Regexp, start, end uint64, pr
266
266
}
267
267
268
268
// Decode disassembles the text segment range [start, end), calling f for each instruction.
269
- func (d * Disasm ) Decode (start , end uint64 , relocs []Reloc , f func (pc , size uint64 , file string , line int , text string )) {
269
+ func (d * Disasm ) Decode (start , end uint64 , relocs []Reloc , gnuAsm bool , f func (pc , size uint64 , file string , line int , text string )) {
270
270
if start < d .textStart {
271
271
start = d .textStart
272
272
}
@@ -277,7 +277,7 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6
277
277
lookup := d .lookup
278
278
for pc := start ; pc < end ; {
279
279
i := pc - d .textStart
280
- text , size := d .disasm (code [i :], pc , lookup , d .byteOrder )
280
+ text , size := d .disasm (code [i :], pc , lookup , d .byteOrder , gnuAsm )
281
281
file , line , _ := d .pcln .PCToLine (pc )
282
282
sep := "\t "
283
283
for len (relocs ) > 0 && relocs [0 ].Addr < i + uint64 (size ) {
@@ -291,25 +291,29 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6
291
291
}
292
292
293
293
type lookupFunc = func (addr uint64 ) (sym string , base uint64 )
294
- type disasmFunc func (code []byte , pc uint64 , lookup lookupFunc , ord binary.ByteOrder ) (text string , size int )
294
+ type disasmFunc func (code []byte , pc uint64 , lookup lookupFunc , ord binary.ByteOrder , _ bool ) (text string , size int )
295
295
296
- func disasm_386 (code []byte , pc uint64 , lookup lookupFunc , _ binary.ByteOrder ) (string , int ) {
297
- return disasm_x86 (code , pc , lookup , 32 )
296
+ func disasm_386 (code []byte , pc uint64 , lookup lookupFunc , _ binary.ByteOrder , gnuAsm bool ) (string , int ) {
297
+ return disasm_x86 (code , pc , lookup , 32 , gnuAsm )
298
298
}
299
299
300
- func disasm_amd64 (code []byte , pc uint64 , lookup lookupFunc , _ binary.ByteOrder ) (string , int ) {
301
- return disasm_x86 (code , pc , lookup , 64 )
300
+ func disasm_amd64 (code []byte , pc uint64 , lookup lookupFunc , _ binary.ByteOrder , gnuAsm bool ) (string , int ) {
301
+ return disasm_x86 (code , pc , lookup , 64 , gnuAsm )
302
302
}
303
303
304
- func disasm_x86 (code []byte , pc uint64 , lookup lookupFunc , arch int ) (string , int ) {
304
+ func disasm_x86 (code []byte , pc uint64 , lookup lookupFunc , arch int , gnuAsm bool ) (string , int ) {
305
305
inst , err := x86asm .Decode (code , arch )
306
306
var text string
307
307
size := inst .Len
308
308
if err != nil || size == 0 || inst .Op == 0 {
309
309
size = 1
310
310
text = "?"
311
311
} else {
312
- text = x86asm .GoSyntax (inst , pc , lookup )
312
+ if gnuAsm {
313
+ text = fmt .Sprintf ("%-36s // %s" , x86asm .GoSyntax (inst , pc , lookup ), x86asm .GNUSyntax (inst , pc , nil ))
314
+ } else {
315
+ text = x86asm .GoSyntax (inst , pc , lookup )
316
+ }
313
317
}
314
318
return text , size
315
319
}
@@ -334,39 +338,47 @@ func (r textReader) ReadAt(data []byte, off int64) (n int, err error) {
334
338
return
335
339
}
336
340
337
- func disasm_arm (code []byte , pc uint64 , lookup lookupFunc , _ binary.ByteOrder ) (string , int ) {
341
+ func disasm_arm (code []byte , pc uint64 , lookup lookupFunc , _ binary.ByteOrder , gnuAsm bool ) (string , int ) {
338
342
inst , err := armasm .Decode (code , armasm .ModeARM )
339
343
var text string
340
344
size := inst .Len
341
345
if err != nil || size == 0 || inst .Op == 0 {
342
346
size = 4
343
347
text = "?"
348
+ } else if gnuAsm {
349
+ text = fmt .Sprintf ("%-36s // %s" , armasm .GoSyntax (inst , pc , lookup , textReader {code , pc }), armasm .GNUSyntax (inst ))
344
350
} else {
345
351
text = armasm .GoSyntax (inst , pc , lookup , textReader {code , pc })
346
352
}
347
353
return text , size
348
354
}
349
355
350
- func disasm_arm64 (code []byte , pc uint64 , lookup lookupFunc , byteOrder binary.ByteOrder ) (string , int ) {
356
+ func disasm_arm64 (code []byte , pc uint64 , lookup lookupFunc , byteOrder binary.ByteOrder , gnuAsm bool ) (string , int ) {
351
357
inst , err := arm64asm .Decode (code )
352
358
var text string
353
359
if err != nil || inst .Op == 0 {
354
360
text = "?"
361
+ } else if gnuAsm {
362
+ text = fmt .Sprintf ("%-36s // %s" , arm64asm .GoSyntax (inst , pc , lookup , textReader {code , pc }), arm64asm .GNUSyntax (inst ))
355
363
} else {
356
364
text = arm64asm .GoSyntax (inst , pc , lookup , textReader {code , pc })
357
365
}
358
366
return text , 4
359
367
}
360
368
361
- func disasm_ppc64 (code []byte , pc uint64 , lookup lookupFunc , byteOrder binary.ByteOrder ) (string , int ) {
369
+ func disasm_ppc64 (code []byte , pc uint64 , lookup lookupFunc , byteOrder binary.ByteOrder , gnuAsm bool ) (string , int ) {
362
370
inst , err := ppc64asm .Decode (code , byteOrder )
363
371
var text string
364
372
size := inst .Len
365
373
if err != nil || size == 0 {
366
374
size = 4
367
375
text = "?"
368
376
} else {
369
- text = ppc64asm .GoSyntax (inst , pc , lookup )
377
+ if gnuAsm {
378
+ text = fmt .Sprintf ("%-36s // %s" , ppc64asm .GoSyntax (inst , pc , lookup ), ppc64asm .GNUSyntax (inst , pc ))
379
+ } else {
380
+ text = ppc64asm .GoSyntax (inst , pc , lookup )
381
+ }
370
382
}
371
383
return text , size
372
384
}
0 commit comments