Set debugger from at&t to intel [closed]
Emily Wong
I want to set my assembly debugger from at&t to intel in gcc. I'm currently on ubuntu 18.0. How can i do this?
21 Answer
GCC assembler output in intel syntax
Assuming you use gcc you have a flag called -masm=dialect
From the manual of gcc:
-masm=dialect Output assembly instructions using selected dialect. Also affects which dialect is used for basic "asm" and extended "asm". Supported choices (in dialect order) are att or intel. The default is att. Darwin does not support intel.To get a intel syntax you have to compile with
gcc -S -masm=intel adder.cHere I have a small example:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{ int a = atoi(argv[1]), b = atoi(argv[2]); int sum=0; sum = a+b; printf("%d + %d = %d\n", a, b, sum); return 0; }Save this as adder.c and compile it
gcc adder.c -o adder and test the program with
./adder 1 4The output should be
1 + 4 = 5Now make an intel asm file with
gcc -S -masm=intel adder.cHere the first lines of adder.s
.file "adder.c" .intel_syntax noprefix .text .section .rodata
.LC0: .string "%d + %d = %d\n" .text .globl main .type main, @function
main:
.LFB5: .cfi_startproc push rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 mov rbp, rsp .cfi_def_cfa_register 6 sub rsp, 32 mov DWORD PTR -20[rbp], edi mov QWORD PTR -32[rbp], rsi mov rax, QWORD PTR -32[rbp] add rax, 8 mov rax, QWORD PTR [rax]Using intel syntax in GDB
Now compile the last example with debug option:
gcc -g adder.c -o adderOpen gnu debugger
gdb -q --args ./adder 3 5 and set the flavor
set disassembly-flavor intelset a break at main
b mainand run the program
rIf you type now
disassembleyou will get the code in intel style:
(gdb) disassemble
Dump of assembler code for function main: 0x000055555555468a <+0>: push rbp 0x000055555555468b <+1>: mov rbp,rsp 0x000055555555468e <+4>: sub rsp,0x20 0x0000555555554692 <+8>: mov DWORD PTR [rbp-0x14],edi 0x0000555555554695 <+11>: mov QWORD PTR [rbp-0x20],rsi
=> 0x0000555555554699 <+15>: mov rax,QWORD PTR [rbp-0x20] 0x000055555555469d <+19>: add rax,0x8 0x00005555555546a1 <+23>: mov rax,QWORD PTR [rax]To set your flavor back you have to change it back to at&t style:
set disassembly-flavor attTo permanently get intel syntax in your gdb, type the following in your shell:
echo "set disassembly-flavor intel" >> ~/.gdbinit
This will set the property to your .gdbinit file. To change simply edit this file.