user7140392
user7140392

Reputation:

Valgrind and GDB substitutes for Mac?

Newbie coder. Mainly work with use a text editor (sublime/atom) with the command line.Usually code in C but will be moving on to Java and Databases soon.

I want to start use Valgrind and GDB (the former i understand is good practice for detecting memory issues). However i understand that these are not available as standard tools on Mac's and alternatives such as LLDB exist.

Could someone suggest the alternative (if that is possible) e.g. LLDB for GDB; Explaining why this is appropriate?

Supplementary literature would be appreciated (I find online tutorials for GDB are widely available...but cant say the same for LLDB (from a dumbed down perspective of a beginner such as myself)).

Upvotes: 2

Views: 4279

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27110

valgrind is a great tool, but it's good to have a variety of such tools on hand, so...

Xcode ships with a tool called ASAN (address sanitizer) which does many of the same memory analysis techniques that valgrind does. That's easiest to use if you build your project with Xcode. Then you just edit the Run scheme (Product->Scheme->Edit Scheme, then choose Run) choose the Diagnostics tab and turn on ASAN. If you run in Xcode, when an error is triggered, it will show you the relevant stacks (the original alloc plus the two free's for a double free, etc...)

If you are building outside Xcode, here's a link to the ASAN documentation:

http://clang.llvm.org/docs/AddressSanitizer.html

Upvotes: 1

Related Questions