'Find place that causes segmentation fault without IDE

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex_Werben