Aman
Aman

Reputation: 1

Segmentation Fault Using LLDB

When I was debugging my .c file using lldb on terminal for Mac, I some how cannot find the location of the segmentation fault. I have debugged the code numerous of times and it is still producing the same error. Can someone help me on why I can find the location of segmentation fault. enter image description here

Upvotes: 0

Views: 1970

Answers (2)

Jason Molenda
Jason Molenda

Reputation: 15425

Use the bt command in lldb to see the call stack. You've called a libc function like scanf() and are most likely passing an invalid argument to it. When you see the call stack, you will see a stack frame with your own code on it, say it is frame #3. You can select that frame with f 3, and you can look at variables with the v command to understand what arguments were passed to the libc function that led to a crash.

Upvotes: 1

zhanga
zhanga

Reputation: 111

Without knowing what your code is doing, I would suggest using a tool like valgrind instead of just a normal debugger. It's designed to look for memory issues for lower-level languages like C/C++/FORTRAN. For example, it will tell you if you're trying to use an index that is too large for an array.

From the quick start guide, try valgrind --leak-check=yes myprog arg1 arg2

Upvotes: 0

Related Questions