Skip to content

Debugging C with Clang compiler and LLDB on MacOS

Prepare llvm

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


#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);


clang -g test.c -o test

Debug with lldb

lldb test

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

  1. License under CC BY-NC 4.0
  2. Copyright issue feedback, 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