赞
踩
打开VSCode,在项目目录下按下F5,VSCode就会在目录下生成.vscode配置文件夹,修改其中的launch.json为如下代码
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "gdb调试活动文件", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\build\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
注:修改其中的miDebuggerPath为自己系统中gdb的地址
void memory_dump(void *ptr, int len) {
int i;
printf("%p\n", ptr);
for (i = 0; i < len; i++) {
if (i % 8 == 0 && i != 0)
printf(" ");
if (i % 16 == 0 && i != 0)
printf("\n");
printf("%02x ", *((uint8_t *)ptr + i));
}
printf("\n");
}
并在需要访问内存的地方执行这段代码。
如下图所示:
创建CMakeLists.txt,内容如下:
cmake_minimum_required(VERSION 2.8)
project(array)
set(CMAKE_BUILD_TYPE "Debug")
add_executable(${PROJECT_NAME} array.cpp)
在终端中执行cmake:
cmake -S . -B ./build -G "MinGW Makefiles"
cmake --build ./build
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。