CDB de base: CDB varie-t-elle à la manière dont il note la portée?
Question
Si je compile:
int *a;
void main(void)
{
*a = 1;
}
puis démontez le principal dans CDB I Obtenir:
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
SO * A est symbolisé par pointresProject! a.Tout bon.
Cependant, si je déclare le pointeur dans la principale:
void main(void)
{
int *a;
a = 1;
}
Je vois que A est juste un décalage du pointeur de la pile (je crois), plutôt que la structure lisible à l'homme que je m'attendais (comme, dire pointersProject! Main! 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
Ceci est probablement autant de choses sur ma compréhension de ce que le compilateur fait comme autre chose que: Quelqu'un peut-il expliquer pourquoi la notation pour un n'est pas ce que j'attends?
(Ceci inspiré par la Musing en regardant X64 Windows Débogage: Fondations pratiques de Dmitry Vostokov).
La solution
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.