Question

When I output a SSE register using print I get the expected result:

(gdb) p $xmm0
$1 = {
    v4_float = {0, 0, 0, 0}, 
    v2_double = {0, 0}, 
    v16_int8 = {0 <repeats 16 times>}, 
    v8_int16 = {0, 0, 0, 0, 0, 0, 0, 0}, 
    v4_int32 = {0, 0, 0, 0}, 
    v2_int64 = {0, 0}, 
    uint128 = 0
}

However, if I use info registers $xmm0 everything is in hexadecimal:

(gdb) i r $xmm0
xmm0           {
    v4_float = {0x0, 0x0, 0x0, 0x0}, 
    v2_double = {0x0, 0x0}, 
    v16_int8 = {0x0 <repeats 16 times>}, 
    v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
    v4_int32 = {0x0, 0x0, 0x0, 0x0}, 
    v2_int64 = {0x0, 0x0}, 
    uint128 = 0x00000000000000000000000000000000
}

Is there any way to get the same output as I get from print?

EDIT: Maybe an unrelated question, but how do I interpret the values of v4_float? An example:

(gdb) i r $xmm0
xmm0           {
    v4_float = {0x1, 0x0, 0x0, 0x0}, 
    v2_double = {0x0, 0x0}, 
    v16_int8 = {0x0, 0x0, 0xa0, 0x3f, 0x0 <repeats 12 times>}, 
    v8_int16 = {0x0, 0x3fa0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
    v4_int32 = {0x3fa00000, 0x0, 0x0, 0x0}, 
    v2_int64 = {0x3fa00000, 0x0}, 
    uint128 = 0x0000000000000000000000003fa00000
}

Shouldn't v4_float[0] and v4_int32[0] both be 0x3fa00000 (1.25f)? If I use print I correctly get v4_float = {1.25, 0, 0, 0}. So why is v4_float[0] = 0x1 when using info registers?

Was it helpful?

Solution

Is there any way to get the same output as I get from print?, No

However I did some study on this so wanted to post it here for the reference in future. Following is the information about command "info all-registers and about the special registers.

Some machines have special registers whose contents can be interpreted in several different ways. For example, modern x86-based machines have SSE and MMX registers that can hold several values packed together in several different formats.

The info registers command shows the canonical names. For example, on the SPARC,info registers displays the processor status register as $psr but you can also refer to it as $ps; and on x86-based machines $ps is an alias for the eflags register. gdb always considers the contents of an ordinary register as an integer when the register is examined in this way.

It looks like that there is limitation of gdb when displaying the registers(due to various reasons like different types of machine and other reason).We should also remember that register is not a simple variable of your program rather it is special and unique for a program and it looks like hexadecimal is the natural format for displaying these registers. However wherever possible gdb would display the contents of general purpose registers value in both format. Just to illustrate it consider the following output:

//We can see that gdb is displaying the registers in both format(hex and decimal)
//and in some cases hex and hex format.
(gdb) info r
rax            0x7ffff7dd6568   140737351869800
rbx            0x0  0
rcx            0x400620 4195872
rdx            0x7fffffffe218   140737488347672
rsi            0x7fffffffe208   140737488347656
rdi            0x1  1
rbp            0x7fffffffe120   0x7fffffffe120
rsp            0x7fffffffe070   0x7fffffffe070
r8             0x4006b0 4196016
.............................
ds             0x0  0
es             0x0  0
fs             0x0  0
gs             0x0  0
//gdb would interpret the registers in the normal variable types. However if 
// we want to display it in decimal rather in hex format. 
(gdb) p $rsp
$24 = (void *) 0x7fffffffe070
(gdb) p/d $rsp
$25 = 140737488347248

There is another important setting which can change the default base for the numeric display.

set output-radix base

Set the default base for numeric display. Supported choices for base are decimal 8, 10, or 16. base must itself be specified either unambiguously or using the current input radix.

This can be used to change the default display of the normal variable/numbers inside GDB. However these setting also does not change the default view of registers(when using info register). However when we display it using print command, it changes its default from decimal to hex for normal variables as well registers. Just to illustrate it consider that we have one local variable(result).

(gdb) show output-radix 10
Default output radix for printing of values is 10.
(gdb) p ii
$26 = (int *) 0x400369
(gdb) p result
$27 = 0
(gdb) info r $xmm0
xmm0           {
  v4_float = {0x0, 0x0, 0x0, 0x0}, 
  v2_double = {0x0, 0x0}, 
  v16_int8 = {0xff, 0x0 <repeats 15 times>}, 
  v8_int16 = {0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
  v4_int32 = {0xff, 0x0, 0x0, 0x0}, 
  v2_int64 = {0xff, 0x0}, 
  uint128 = 0x000000000000000000000000000000ff
}
(gdb) p $xmm0
$28 = {
  v4_float = {3.57331108e-43, 0, 0, 0}, 
  v2_double = {1.2598673968951787e-321, 0}, 
  v16_int8 = {-1, 0 <repeats 15 times>}, 
  v8_int16 = {255, 0, 0, 0, 0, 0, 0, 0}, 
  v4_int32 = {255, 0, 0, 0}, 
  v2_int64 = {255, 0}, 
  uint128 = 255
}
(gdb) set output-radix 16
Output radix now set to decimal 16, hex 10, octal 20.
(gdb) p result
$29 = 0x0
(gdb) info r $xmm0
xmm0           {
  v4_float = {0x0, 0x0, 0x0, 0x0}, 
  v2_double = {0x0, 0x0}, 
  v16_int8 = {0xff, 0x0 <repeats 15 times>}, 
  v8_int16 = {0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
  v4_int32 = {0xff, 0x0, 0x0, 0x0}, 
  v2_int64 = {0xff, 0x0}, 
  uint128 = 0x000000000000000000000000000000ff
}
(gdb) p $xmm0
$30 = {
  v4_float = {3.57331108e-43, 0, 0, 0}, 
  v2_double = {1.2598673968951787e-321, 0}, 
  v16_int8 = {0xff, 0x0 <repeats 15 times>}, 
  v8_int16 = {0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
  v4_int32 = {0xff, 0x0, 0x0, 0x0}, 
  v2_int64 = {0xff, 0x0}, 
  uint128 = 0x000000000000000000000000000000ff
}

So it look like, there is no way to change the format while using the info register command. However if we want to display the register using print command, its default format can be changed as GDB does consider registers as normal registers and hence display it in different format. Hence we should use the both type of commands for displaying the registers under different circumstances in our debugging session.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top