Skip to content

Debugging C with Clang compiler and LLDB on MacOS

Prepare llvm

brew install llvm --with-clang --with-asan

Example

#include <stdio.h>

  int main()
  {
    int x = 1;
    int y = 5;
    char *name = "Bob";

    x += 1;
    x += y; 
    printf("Name is %s\n", name);
    printf("Number x is %d\n", x);
  }

Compile

clang -g test.c -o test

Debug with lldb

lldb test

b 10
b main
run
br list
br del 1
p x
expr x = 5
  • f Display current line
  • bt Using backtrace

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App