CDB básico: ¿CDB varía cómo notifica el alcance?
Pregunta
Si compile:
int *a;
void main(void)
{
*a = 1;
}
y luego desmonte la principal en el CDB, obtengo:
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á simbolizado por PointersProject! a.Todo bien.
Sin embargo, si declaro el puntero dentro de Main:
void main(void)
{
int *a;
a = 1;
}
Veo que A es solo un desplazamiento del puntero de la pila (creo), en lugar de la estructura legible por el hombre que espero (como, decir PointersProject! 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
Esto es probablemente tanto sobre mi comprensión de lo que el compilador ha hecho como cualquier otra cosa, pero ¿alguien puede explicar por qué la notación de A no es lo que espero?
(Esto se inspira en Mensing mientras mira la depuración de Windows X64: Fundaciones prácticas de Dmitry Vostokov).
Solución
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.