Reputation: 59
I just started learning about assembly language in Kali Linux in VMware. I have a Ryzen 5 CPU. In the below code snippet, I have a few things I don't understand.
lea rax, [rip ± 0xeb3]
at <main + 17>? I understand what lea
does, but what is the meaning of ±?(gdb) list
1 #include<stdio.h>
2
3 int main(){
4 int i;
5 for(i = 0 ; i < 10 ; i++){
6 printf("Hello World!\n");
7 }
8 return 0;
9 }
(gdb) disassemble main
Dump of assembler code for function main:
0x0000000000001139 <+0>: push rbp
0x000000000000113a <+1>: mov rbp,rsp
0x000000000000113d <+4>: sub rsp,0x10
0x0000000000001141 <+8>: mov DWORD PTR [rbp-0x4],0x0
0x0000000000001148 <+15>: jmp 0x115d <main+36>
0x000000000000114a <+17>: lea rax,[rip±0xeb3] # 0x2004
0x0000000000001151 <+24>: mov rdi,rax
0x0000000000001154 <+27>: call 0x1030 <puts@plt>
0x0000000000001159 <+32>: add DWORD PTR [rbp-0x4],0x1
0x000000000000115d <+36>: cmp DWORD PTR [rbp-0x4],0x9
0x0000000000001161 <+40>: jle 0x114a <main+17>
0x0000000000001163 <+42>: mov eax,0x0
0x0000000000001168 <+47>: leave
0x0000000000001169 <+48>: ret
End of assembler dump.
(gdb)
Edit:
gdb -v
GNU gdb (Debian 12.1-3) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Upvotes: 5
Views: 440
Reputation: 44066
It's not a plus-minus (±, Unicode point 0x00b1), it's an underlined plus.
If you copy-paste it, you get only a plus (+).
GDB 12.1 uses Python to colorize each line of its disassembler output. Specifically, it uses the Pygments packages, which, at the current version 2.11.2, handle x64 code badly, here's a test case:
from pygments import formatters, lexers, highlight
def colorize_disasm(content, gdbarch):
# Don't want any errors.
try:
lexer = lexers.get_lexer_by_name("asm")
formatter = formatters.TerminalFormatter()
return highlight(content, lexer, formatter).rstrip().encode()
except:
return None
print(colorize_disasm("lea [rip+0x211] #test", None).decode())
The (yet to be released) next version uses an entirely different coloring code, where each disassembler function can introduce style markers in its output and the disassemble command (see gdb/disassemble.c
) translates those markers into terminal escapes.
Upvotes: 4