查找导致没有IDE的分割故障的位置

发布于 2025-01-28 22:12:42 字数 905 浏览 4 评论 0原文

我正在研究C ++的一个项目。它很大,由CMAKE创建。安装了所有依赖关系和自由时,它的构建很好。但是,当我运行它时,我会得到分割故障

这是事实:没有IDE,在VS代码中使用CMAKE运行此项目。我想知道是否可以在导致分割故障的代码中找到此位置。我知道此类事情有GDB调试器。我运行了几个命令,这是我得到的:

gdb build/studpark
...
Reading symbols from build/studpark...
(gdb) run
Starting program: /Users/admin/Downloads/StudPark-develop/build/studpark 
[New Thread 0x2503 of process 7316]
[New Thread 0x1903 of process 7316]
[New Thread 0x1a03 of process 7316]
warning: unhandled dyld version (17)

Thread 3 received signal SIGSEGV, Segmentation fault.
0x00007ff809bec6b2 in ?? ()

(gdb) backtrace
#0  0x00007ff809bec6b2 in ?? ()
#1  0x00007ff7bfeff510 in ?? ()
#2  0x0000000100002abe in main ()
Backtrace stopped: frame did not save the PC

问题是:是否可以在代码中跟踪并找到导致分割故障的代码中的确切位置?

编辑:我用这些标志编译我的项目:

set(cmake_cxx_flags“ -stdlib = libc ++ -g”)

我的平台是Mac OS。

I'm studying one project in C++. It's quite big, build is created with cmake. After installing all dependencies and libs it's the build is done fine. But when I run it, I get Segmentation fault.

Here is the thing: There is no IDE, running this project with cmake in VS Code. I wonder if it's possible to find this place in code which causes Segmentation fault. I know that there is GDB debugger for such things. I run several commands and here's what I get:

gdb build/studpark
...
Reading symbols from build/studpark...
(gdb) run
Starting program: /Users/admin/Downloads/StudPark-develop/build/studpark 
[New Thread 0x2503 of process 7316]
[New Thread 0x1903 of process 7316]
[New Thread 0x1a03 of process 7316]
warning: unhandled dyld version (17)

Thread 3 received signal SIGSEGV, Segmentation fault.
0x00007ff809bec6b2 in ?? ()

(gdb) backtrace
#0  0x00007ff809bec6b2 in ?? ()
#1  0x00007ff7bfeff510 in ?? ()
#2  0x0000000100002abe in main ()
Backtrace stopped: frame did not save the PC

The question is: Is it possible to trace and find exact place in code that causes segmentation fault?

EDIT: I compile my project with these flags:

set(CMAKE_CXX_FLAGS "-stdlib=libc++ -g")

My platform is Mac OS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-小熊_ 2025-02-04 22:12:42

我找到了一个解决方案的解决方案,这是我所做的:

  1. 安装了这些VS代码扩展名 - codelldb
  2. 添加了配置文件:运行/'添加配置...'
  3. 配置文件at at at< root_dit>/。vscode/。启动。JSON,看起来像这样:
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "launch",
      "name": "Debug",
      "program": "${workspaceFolder}/build/main",
      "args": [],
      "cwd": "${workspaceFolder}"
    }
  ]
}
  1. 在我的情况下,我只更改“ program”:“ $ {workspacefolder}/build/main/main”以显示我可执行文件的路径。

执行这些操作后,我能够以调试模式运行我的程序,并通过断点,帮助我检查项目并在代码中找到错误。

I've found a solution for my case and here's what I've done:

  1. Installed these VS Code Extensions - CodeLLDB
  2. Added Configuration File: Run/'Add Configuration...'
  3. The config file was at <root_dit>/.vscode/launch.json and looked like this:
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "launch",
      "name": "Debug",
      "program": "${workspaceFolder}/build/main",
      "args": [],
      "cwd": "${workspaceFolder}"
    }
  ]
}
  1. In my case I only changed "program": "${workspaceFolder}/build/main" to show path to my executable file.

After doing these actions I was able to run my program in Debug mode with breakpoints which helped me to examine project and find errors in code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文