Search code examples
cgccgdblldb

Why gcc -g doesn't work with multiple files


To debug my C code I compile it with the -g flag and use lldb to see where my seg fault is for example.
I use the -g flag so the output of lldb is in C not Assembly.
but now I have a multiple files project and lldb shows only Assembly even tho I'm using the -g flag, it's like the -g flag applies only to one file.
Example:

gcc -g example.c
lldb a.out
>run
   I get c code here
gcc -g example1.c example2.c main.c
lldb a.out
>run
   I get assembly code here

Can anyone tell me what I'm I missing here?
and how can I get c code in lldb.

Thanks in advance.


Solution

  • When you just run the program you shouldn't be getting code at all.

    You will be getting code if the program stops running. Then you need to look at the call stack to make sure you're actually in your own code.

    If you're in library code then it will likely not have source available and you'll get assembler code. Go up the call-stack until you reach your own code.