当我尝试调试使用SDL2的代码时出现了问题。我正在使用GDB,出于某些原因无论我做什么,当我尝试在遇到断点后继续调试时程序突然崩溃。这只在调用任何SDL2方法时发生,否则,它可以正常工作。
这是脚本代码:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
printf("Could not initialize!");
return -1;
}
SDL_Window* win = SDL_CreateWindow("Hello, World!", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (win == nullptr) {
printf("Could not create window!");
SDL_Quit();
return -1;
}
bool quit = false;
SDL_Event e;
SDL_Surface* surface = SDL_GetWindowSurface(win);
SDL_FillRect(surface, nullptr, SDL_MapRGB(surface->format, 0xff, 0xff, 0xff));
while (!quit) {
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
quit = true;
}
}
int i = 0;
i++;
SDL_UpdateWindowSurface(win);
}
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
这是在断开点崩溃之前反汇编中的程序集。
0x7ffd4f9e9da0 sub $0xd8,%rsp
0x7ffd4f9e9da7 mov 0x1ad21a(%rip),%rax # 0x7ffd4fb96fc8
0x7ffd4f9e9dae xor %rsp,%rax
0x7ffd4f9e9db1 mov %rax,0xc0(%rsp)
0x7ffd4f9e9db9 andq $0x0,0x28(%rsp)
0x7ffd4f9e9dbf lea -0x26(%rip),%rax # 0x7ffd4f9e9da0 <RaiseException>
0x7ffd4f9e9dc6 and $0x1,%edx
0x7ffd4f9e9dc9 mov %ecx,0x20(%rsp)
0x7ffd4f9e9dcd mov %edx,0x24(%rsp)
0x7ffd4f9e9dd1 mov %rax,0x30(%rsp)
0x7ffd4f9e9dd6 test %r9,%r9
0x7ffd4f9e9dd9 je 0x7ffd4f9e9e20 <RaiseException+128>
0x7ffd4f9e9ddb mov $0xf,%eax
0x7ffd4f9e9de0 lea 0x40(%rsp),%rcx
0x7ffd4f9e9de5 cmp %eax,%r8d
0x7ffd4f9e9de8 mov %r9,%rdx
0x7ffd4f9e9deb cmova %eax,%r8d
0x7ffd4f9e9def mov %r8d,0x38(%rsp)
0x7ffd4f9e9df4 shl $0x3,%r8
0x7ffd4f9e9df8 callq 0x7ffd4fa07918 <SHExpandEnvironmentStringsA+312>
0x7ffd4f9e9dfd lea 0x20(%rsp),%rcx
0x7ffd4f9e9e02 callq *0xfc7d0(%rip) # 0x7ffd4fae65d8
0x7ffd4f9e9e08 mov 0xc0(%rsp),%rcx
0x7ffd4f9e9e10 xor %rsp,%rcx
0x7ffd4f9e9e13 callq 0x7ffd4fa04e90 <KERNELBASE!GetSystemWow64DirectoryA+128>
0x7ffd4f9e9e18 add $0xd8,%rsp
0x7ffd4f9e9e1f retq
0x7ffd4f9e9e20 andl $0x0,0x38(%rsp)
0x7ffd4f9e9e25 jmp 0x7ffd4f9e9dfd <RaiseException+93>
0x7ffd4f9e9e27 int3
0x7ffd4f9e9e28 int3
0x7ffd4f9e9e29 int3
0x7ffd4f9e9e2a int3
0x7ffd4f9e9e2b int3
0x7ffd4f9e9e2c int3
0x7ffd4f9e9e2d int3
0x7ffd4f9e9e2e int3
0x7ffd4f9e9e2f int3
我使用的是64位版本的TDM-GCC(包括调试器)和SDL2。