Анализировать значение с плавающей запятой в GDB - PullRequest
3 голосов
/ 22 апреля 2011

Пример кода:

int main()
{
        float x = 456.876;

        printf ("\nx = %f\n", x);

        return 0;
}

В GDB я выполнил этот код так:

Breakpoint 1, main () at sample_float.c:5   
5               float x = 456.876;   
(gdb) n    
7               printf ("\nx = %f\n", x);   
(gdb) p &x   
$1 = (float *) 0x7fffffffd9dc   
(gdb) x/4fb &x   
0x7fffffffd9dc: 33      112     -28     67   

Можно ли увидеть значение по адресу x, используя команду: x / fb как: 456.876?

Спасибо.

Ответы [ 3 ]

9 голосов
/ 22 апреля 2011

Возможно, я неправильно понимаю ваш вопрос, но вы можете просто сделать

p/f x

Или

x/f &x

Это то, что вы искали?

1 голос
/ 22 апреля 2011

согласен с приведенным выше ответом, но чтобы понять, почему вы получили результаты, которые вы сделали.

(gdb) x/4fb &x   
0x7fffffffd9dc: 33      112     -28     67 

из руководства по gdb

x/3uh 0x54320' is a request to display three halfwords (h) of memory, formatted as unsigned decimal integers ( u '), начиная с адреса 0x54320.

Таким образом, x / 4fb & x форматирует байт как число с плавающей точкой 4 раза. не 4 байта в виде числа с плавающей запятой.

0 голосов
/ 23 мая 2018

Вот ссылка на проверку памяти с использованием gdb

You can use the command x (for "examine") to examine memory in any of several formats, 
independently of your program's data types.

x/nfu addr
x addr
x
n, f, and u are all optional parameters that specify how much memory to display and how to format it; addr is an expression giving the address where you want to start displaying memory. If you use defaults for nfu, you need not type the slash `/'. Several commands set convenient defaults for addr.

n, the repeat count

The repeat count is a decimal integer; the default is 1. It specifies how much memory (counting by units u) to display.

f, the display format

The display format is one of the formats used by print, `s' (null-terminated string), or `i' (machine instruction). The default is `x' (hexadecimal) initially. 
The default changes each time you use either x or print.

 u, the unit size The unit size is any of
 b: Bytes.
 h: Halfwords (two bytes).
 w: Words (four bytes). This is the initial default.
 g: Giant words (eight bytes).
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...