For example, consider the following Linux freestanding true
program with an useless my_longs
variable for illustrative purposes:
main.S
.section .rodata
my_longs: .quad 0x12, 0x34
.text
.global _start
_start:
asm_main_after_prologue:
mov $60, %rax
mov $0, %rdi
syscall
which you can assemble and run with:
as -o main.o main.S
ld -o main.out main.o
gdb main.out
Then start the program with:
starti
Now, to see the value of my_longs
, I have to type the annoying (long[2])
part:
p/x (long[2])my_longs
Is there any way to tell GDB the type of my_longs
on by adding some extra annotation to my assembly program?
When writing a C program:
main_c.c
long my_longs[] = {0x12, 0x34};
int main(void) {
return 0;
}
compiled with:
gcc -O0 -ggdb3 -save-temps -o main_c.out main_c.c
I can see the symbols directly with;
p/x my_longs
presumably due to the DWARF debug information GCC added.
When I had a look at the generated assembly, the only references I could find to my_longs
were:
.Ltext0:
.comm my_longs,16,16
.Ldebug_info0:
.long .LASF351
.quad my_longs
.LASF351:
.string "my_longs"
so I'm not sure where the type information is being stored.
I know that this question may come down basically to: how are types encoded in DWARF, and is it practical to manually encode that information. I intend to study DWARF a bit later on if this keeps on bothering me.