Skip to content

Debugging C with Clang compiler and LLDB on MacOS


Debugging is an important part of software development, which helps developers identify and fix errors in their code. Clang is an open-source C compiler that is used by many developers on macOS. In this blog post, we will discuss how to use Clang and LLDB (the debugger that comes with Clang) to debug C programs 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