简体   繁体   English

GDB 是否检查命令反转字节?

[英]Does the GDB examine command reverse bytes?

Does gdb reverse the order of bytes when printing out multiple word chunks (4 bytes)?打印出多个字块(4 个字节)时,gdb 是否颠倒了字节顺序? If so, then why?如果是这样,那为什么? Does this have anything to do with how programs read memory?这与程序如何读取内存有关吗?

Here is an example code to demonstrate what I mean by reverse the order这是一个示例代码,用于演示我所说的颠倒顺序

// test.c
#include <stdio.h>

int main(int argc, char *argv[])
{
  int large = 33825;              // 1000 0100 0010 0001
  int zero = 0;                   // 0000 0000 0000 0000
  int ten = 10;                   // 0000 0000 0000 1010
  printf("GDB test program\n");
  return 0;
}

Compile & run program with gdb:使用 gdb 编译和运行程序:

$ gcc -z execstack -g -fno-stack-protector test.c -o test
$ gdb test
(gdb) break 9
Breakpoint 1 at 0x8048441: file test.c, line 9.
(gdb) run
Breakpoint 1, main (argc=1, argv=0xbfffeff4) at test.c:9
9     return 0;

(gdb) # get the address of the ten variable (which has the smallest memory address location)
(gdb) print &ten 
$2 = (int *) 0xbfffef34

(gdb) # print the first byte of the ten variable
(gdb) x /1tb 0xbfffef34
0xbfffef34: 0000 1010

(gdb) # print the entire memory (4 bytes) allocated for the ten variable (0xbfffef34 - 0xbfffef38)
(gdb) x /1tw 0xbfffef34
0xbfffef34: 0000 0000 0000 0000 0000 0000 0000 1010
(gdb) # Why is "0000 0000" the first octet instead of "0000 1010"
(gdb) # It seems like the print order of the bytes are reversed


(gdb) # Another example
(gdb) # print the entire memory (4 bytes) allocated for the large variable (0xbfffef3c - 0xbfffef3f)
(gdb) x /1tw 0xbfffef3c
0xbfffef3c: 0000 0000 0000 0000 1000 0100 0010 0001

(gdb) x /1tb 0xbfffef3c
0xbfffef3c: 0010 0001

(gdb) x /1tb 0xbfffef3d
0xbfffef3d: 1000 0100

(gdb) x /1tb 0xbfffef3e
0xbfffef3e: 0000 0000

(gdb) x /1tb 0xbfffef3f
0xbfffef3f: 0000 0000

When I print the entire variable, it reads how I would normally read binary (most significant octet on the left)当我打印整个变量时,它读取我通常如何读取二进制(左侧最重要的八位字节)

When I print the first octet of the same variable it displays the least significant octet.当我打印同一个变量的第一个八位字节时,它显示最不重要的八位字节。

Is GDB rearranging the order of the octets to make it more readable? GDB 是否重新排列八位字节的顺序以使其更具可读性? Does this have anything to do with how the computer reads memory?这与计算机如何读取内存有关系吗?

print prints the variables as a human would expect them to be printed (as integers). print以人类期望的方式打印变量(作为整数)。

examine prints them as bytes in memory without modifying them to compensate for the endianness that the computer uses. examine它们作为内存中的字节打印,而不修改它们以补偿计算机使用的字节序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM