[英]"Access violation writing location" using Visual Studio to debug cmake project for Windows ARM64
I'm trying to remotely debug a very simple CMake program on an Windows ARM64 machine from an X64 machine.我正在尝试从 X64 机器远程调试 Windows ARM64 机器上的一个非常简单的 CMake 程序。 I'm using Visual Studio 2019 and followed the instructions here .我正在使用 Visual Studio 2019 并按照此处的说明进行操作。
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:设置远程调试器后,当我在 Visual Studio 中运行程序时,会引发异常:
Exception thrown at 0x00007FF72B5730E8 in CMakeARM64.exe: 0xC0000005: Access violation writing location 0x00007FF72B574C38.在 CMakeARM64.exe 中的 0x00007FF72B5730E8 处引发异常:0xC0000005:访问冲突写入位置 0x00007FF72B574C38。
The debugger indicates that this happens on line 4 of the main.cpp file (hence at the beginning of main).调试器表明这发生在 main.cpp 文件的第 4 行(因此在 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我注意到的是 Visual Studio 将目标的可执行文件部署到
C:\Windows Default Deploy Directory\ARM64\CMakeARM64.exe C:\Windows 默认部署目录\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!"当我尝试从该目录中运行 ./CMakeArm64.exe 时,程序正确执行并且“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:当我点击“Go to Disassembly”时(下面的输出指的是写入位置为 0x00007FF770794C38 时),Visual Studio 显示:
// ...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
Windows on Arm supports X86 emulation on Windows 10 and additionally X64 emulation on Windows 11 versions. Windows on Arm 支持 Windows 10 上的 X86 仿真,另外还支持 Windows 11 版本上的 X64 仿真。 So its OK to run X64 and X86 assembly instructions, which is why the local exe runs.所以运行 X64 和 X86 汇编指令是可以的,这就是本地 exe 运行的原因。 However you will need the right remote debugger version to support the right instructions you are debugging.但是,您将需要正确的远程调试器版本来支持您正在调试的正确指令。 So if the app is X64 then install the Visual Studio 2019 X64 remote debugger client.因此,如果应用程序是 X64,则安装 Visual Studio 2019 X64 远程调试器客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.