I'm trying to remotely debug a very simple CMake program on an Windows ARM64 machine from an X64 machine. I'm using Visual Studio 2019 and followed the instructions here.
The program has the following structure:
# CMakeLists.txt
cmake_minimum_required (VERSION 3.8)
project ("CMakeARM64")
add_executable (CMakeARM64 "main.cpp")
// main.cpp
#include <iostream>
int main()
{ // exception thrown on this line
std::cout << "Hello World!" << std::endl;
return 0;
}
// CMakeSettings.json
{
"configurations": [
{
"name": "arm64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_arm64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
}
]
}
After setting up the remote debugger, when I run the program in Visual Studio an exception is thrown:
Exception thrown at 0x00007FF72B5730E8 in CMakeARM64.exe: 0xC0000005: Access violation writing location 0x00007FF72B574C38.
The debugger indicates that this happens on line 4 of the main.cpp file (hence at the beginning of main). I don't know how to investigate the reason of the crash further.
What I've noticed is that Visual Studio deploys the executable of the target to
C:\Windows Default Deploy Directory\ARM64\CMakeARM64.exe
on the target machine. When I try to run ./CMakeArm64.exe from within that directory, the program executes correctly and "Hello World!" is printed on the terminal.
Any clue on what might be going on here?
When I click on "Go to Disassembly" (the output below refers to when the writing location was 0x00007FF770794C38), Visual Studio shows this:
// ...other instructions
00007FF7707930CE add byte ptr [rax],al
00007FF7707930D0 add byte ptr [rax],al
00007FF7707930D2 add byte ptr [rax],al
00007FF7707930D4 add byte ptr [rax],al
00007FF7707930D6 add byte ptr [rax],al
00007FF7707930D8 add byte ptr [rax],al
00007FF7707930DA add byte ptr [rax],al
00007FF7707930DC add byte ptr [rax],al
00007FF7707930DE add byte ptr [rax],al
00007FF7707930E0 add byte ptr [rax],al
00007FF7707930E2 add byte ptr [rax],al
00007FF7707930E4 add byte ptr [rax],al
00007FF7707930E6 add byte ptr [rax],al
--- C:\Users\user\source\repos\CMakeARM64\main.cpp ----------------------------
#include <iostream>
int main()
{
00007FF7707930E8 std // exceptions seems be triggered here
00007FF7707930E9 jnp __gsfailure+1340h (07FF7707930A8h)
00007FF7707930EB test eax,0A90157F4h
00007FF7707930F0 not byte ptr [rbx]
00007FF7707930F2 add cl,bh
00007FF7707930F4 std
00007FF7707930F5 add eax,dword ptr [rax]
00007FF7707930F7 xchg eax,ecx
std::cout << "Hello World!" << std::endl;
00007FF7707930F8 add byte ptr [rax],al
00007FF7707930FB mov al,1
00007FF7707930FD ?? ??????
std::cout << "Hello World!" << std::endl;
00007FF7707930FE xor byte ptr [rcx-2FFFFF98h],dl
00007FF770793104 add cl,al
00007FF770793106 stc
00007FF770793108 jmp main+19h (07FF770793101h)
00007FF77079310A call qword ptr [rdi-2F000018h]
00007FF770793110 add ecx,esi
00007FF770793112 add byte ptr [rcx-2FFFFF98h],dl
00007FF770793118 or byte ptr [rbp+100F940h],cl
00007FF77079311E ?? ??????
00007FF77079311F ?? ??????
return 0;
//...other instructions