Базовый CDB: CDB варьируется, как это отмечает охват?

StackOverflow https://stackoverflow.com/questions/6048602

  •  15-11-2019
  •  | 
  •  

Вопрос

Если я компилируюсь:

int *a;

void main(void)
{
    *a = 1;
}
.

, а затем разбирать основные в CDB i Get:

pointersproject!main:
00000001`3fd51010 mov     rax,qword ptr [pointersproject!a (00000001`3fd632f0)]
00000001`3fd51017 mov     dword ptr [rax],1
00000001`3fd5101d xor     eax,eax
00000001`3fd5101f ret    
.

Так что * a символизируется указаниемProject! a.Все хорошо.

Однако, если я объявляю указателя в главном:

void main(void)
{
    int *a;
    a = 1;
}
.

Я вижу, что это просто смещение от указателя стека (я верю), скорее, а затем читаемая структура, которую я ожидаю (например, сказать PointersProject! GAIL! A):

pointersproject!main:
00000001`3fd51010 sub     rsp,18h
00000001`3fd51014 mov     rax,qword ptr [rsp]
00000001`3fd51018 mov     dword ptr [rax],1
00000001`3fd5101e xor     eax,eax
00000001`3fd51020 add     rsp,18h
00000001`3fd51024 ret
.

Это, вероятно, так много о моем понимании того, что компилятор сделан как что-то еще, но: может кто-нибудь объяснить, почему обозначение для не то, что я ожидаю?

(это вдохновлено размышлением, глядя на отладку X64 Windows: практические основы Дмитрия Востоков).

Это было полезно?

Решение

When a variable is defined inside a function, it is an automatic variable unless explicitly declared static. Such variables only live during the execution of the function and are normally allocated in the stack, thus they are deallocated when the function exits. The change you see in the complied code is not due to the change in scope but to the change from static to automatic variable. If you make a static, it will not be allocated in the stack, even if its scope is the function main.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top