While learning assembly language from a book there is a listing showing some basic operations:
segment .data
a dq 176
b dq 4097
segment .text
global _start
_start:
mov rax, [a] ; Move a into rax.
add rax, [b] ; add b o rax.
xor rax, rax
ret
After assembling with "$yasm -f elf64 -g dwarf2 -l listing.lst listing.asm"
command and linking with "$ld -o listing listing.o"
I ran the program in gdb. There whenever I tried to print the value of a variable, gdb showed this error message:
(gdb) p a
'a' has unknown type; cast it to its declared type
Same for the other variable 'b'. However casting 'a' or 'b' for int worked:
(gdb) p (int)a
$11 = 176
(gdb) p (int)b
$12 = 4097
But isn't this supposed to work without casting? Why do I need to cast? What mistake I've made in my source file?
The expression can be any expression that is valid in the current context. The set variable command evaluates the specified expression. If the expression includes the assignment operator ( = ), the debugger evaluates that operator, as it does with all operators in expressions, and assigns the new value.
The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages). expr is an expression (in the source language).
It means that the type of that variable has been incompletely specified. For example: struct hatstand; struct hatstand *foo; GDB knows that foo is a pointer to a hatstand structure, but the members of that structure haven't been defined. Hence, "incomplete type".
You can cancel execution of a function call with the return command. If you give an expression argument, its value is used as the function's return value. When you use return , GDB discards the selected stack frame (and all frames within it).
Older GDB used to default to assuming that a symbol was an int
when it didn't have debug info describing the size / type.
This generally cause more confusion than the current behaviour, so it was changed. e.g. The value displayed in Kdbg is wrong -- NASM
But isn't this supposed to work without casting?
No. GDB tells you that it has no idea what type a
and b
are.
What mistake I've made in my source file?
You didn't make any mistakes, but you also didn't supply any debugging info that GDB could use.
You may have expected yasm -g dwarf2 ...
to do so, but it only creates minimal debug info describing the source, nothing else:
$ readelf -wi listing.o
Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0x37 (32-bit)
Version: 2
Abbrev Offset: 0x0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_stmt_list : 0x0
<10> DW_AT_low_pc : 0x0
<18> DW_AT_high_pc : 0x14
<20> DW_AT_name : listing.asm
<28> DW_AT_comp_dir : /tmp/
<2e> DW_AT_producer : yasm 1.3.0
<39> DW_AT_language : 32769 (MIPS assembler)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With