xref: /llvm-project/lldb/docs/use/troubleshooting.rst (revision 6a2552a1419d674033c8d2f8bfeeb981a70a2e67)
1edb874b2SJonas DevlieghereTroubleshooting
2edb874b2SJonas Devlieghere===============
3edb874b2SJonas Devlieghere
4edb874b2SJonas DevlieghereFile and Line Breakpoints Are Not Getting Hit
5edb874b2SJonas Devlieghere---------------------------------------------
6edb874b2SJonas Devlieghere
7edb874b2SJonas DevlieghereFirst you must make sure that your source files were compiled with debug
8edb874b2SJonas Devlieghereinformation. Typically this means passing -g to the compiler when compiling
9edb874b2SJonas Devlieghereyour source file.
10edb874b2SJonas Devlieghere
11edb874b2SJonas DevlieghereWhen setting breakpoints in implementation source files (.c, cpp, cxx, .m, .mm,
12edb874b2SJonas Devlieghereetc), LLDB by default will only search for compile units whose filename
13edb874b2SJonas Devliegherematches. If your code does tricky things like using #include to include source
14edb874b2SJonas Devliegherefiles:
15edb874b2SJonas Devlieghere
16edb874b2SJonas Devlieghere::
17edb874b2SJonas Devlieghere
18*59c954f7SShivam Gupta   $ cat foo.c
19edb874b2SJonas Devlieghere   #include "bar.c"
20edb874b2SJonas Devlieghere   #include "baz.c"
21edb874b2SJonas Devlieghere   ...
22edb874b2SJonas Devlieghere
23edb874b2SJonas DevlieghereThis will cause breakpoints in "bar.c" to be inlined into the compile unit for
24edb874b2SJonas Devlieghere"foo.c". If your code does this, or if your build system combines multiple
25edb874b2SJonas Devliegherefiles in some way such that breakpoints from one implementation file will be
26edb874b2SJonas Devliegherecompiled into another implementation file, you will need to tell LLDB to always
27edb874b2SJonas Devliegheresearch for inlined breakpoint locations by adding the following line to your
28edb874b2SJonas Devlieghere~/.lldbinit file:
29edb874b2SJonas Devlieghere
30edb874b2SJonas Devlieghere::
31edb874b2SJonas Devlieghere
32*59c954f7SShivam Gupta   $ echo "settings set target.inline-breakpoint-strategy always" >> ~/.lldbinit
33edb874b2SJonas Devlieghere
34edb874b2SJonas DevlieghereThis tells LLDB to always look in all compile units and search for breakpoint
35edb874b2SJonas Devliegherelocations by file and line even if the implementation file doesn't match.
36edb874b2SJonas DevlieghereSetting breakpoints in header files always searches all compile units because
37edb874b2SJonas Devlieghereinline functions are commonly defined in header files and often cause multiple
38edb874b2SJonas Devliegherebreakpoints to have source line information that matches many header file
39edb874b2SJonas Devliegherepaths.
40edb874b2SJonas Devlieghere
41edb874b2SJonas DevlieghereIf you set a file and line breakpoint using a full path to the source file,
4219ae9d01SAdrian Prantllike Xcode does when setting a breakpoint in its GUI on macOS when you click
43edb874b2SJonas Devliegherein the gutter of the source view, this path must match the full paths in the
44edb874b2SJonas Devliegheredebug information. If the paths mismatch, possibly due to passing in a resolved
45edb874b2SJonas Devliegheresource file path that doesn't match an unresolved path in the debug
46edb874b2SJonas Devlieghereinformation, this can cause breakpoints to not be resolved. Try setting
47edb874b2SJonas Devliegherebreakpoints using the file basename only.
48edb874b2SJonas Devlieghere
49edb874b2SJonas DevlieghereIf you are using an IDE and you move your project in your file system and build
50edb874b2SJonas Devlieghereagain, sometimes doing a clean then build will solve the issue.This will fix
51edb874b2SJonas Devliegherethe issue if some .o files didn't get rebuilt after the move as the .o files in
52edb874b2SJonas Devliegherethe build folder might still contain stale debug information with the old
53edb874b2SJonas Devliegheresource locations.
54edb874b2SJonas Devlieghere
55edb874b2SJonas DevlieghereHow Do I Check If I Have Debug Symbols?
56edb874b2SJonas Devlieghere---------------------------------------
57edb874b2SJonas Devlieghere
58edb874b2SJonas DevlieghereChecking if a module has any compile units (source files) is a good way to
59edb874b2SJonas Devliegherecheck if there is debug information in a module:
60edb874b2SJonas Devlieghere
61edb874b2SJonas Devlieghere::
62edb874b2SJonas Devlieghere
63edb874b2SJonas Devlieghere   (lldb) file /tmp/a.out
64edb874b2SJonas Devlieghere   (lldb) image list
65edb874b2SJonas Devlieghere   [  0] 71E5A649-8FEF-3887-9CED-D3EF8FC2FD6E 0x0000000100000000 /tmp/a.out
66edb874b2SJonas Devlieghere         /tmp/a.out.dSYM/Contents/Resources/DWARF/a.out
67edb874b2SJonas Devlieghere   [  1] 6900F2BA-DB48-3B78-B668-58FC0CF6BCB8 0x00007fff5fc00000 /usr/lib/dyld
68edb874b2SJonas Devlieghere   ....
69edb874b2SJonas Devlieghere   (lldb) script lldb.target.module['/tmp/a.out'].GetNumCompileUnits()
70edb874b2SJonas Devlieghere   1
71edb874b2SJonas Devlieghere   (lldb) script lldb.target.module['/usr/lib/dyld'].GetNumCompileUnits()
72edb874b2SJonas Devlieghere   0
73edb874b2SJonas Devlieghere
74edb874b2SJonas DevlieghereAbove we can see that "/tmp/a.out" does have a compile unit, and
75edb874b2SJonas Devlieghere"/usr/lib/dyld" does not.
76edb874b2SJonas Devlieghere
77edb874b2SJonas DevlieghereWe can also list the full paths to all compile units for a module using python:
78edb874b2SJonas Devlieghere
79edb874b2SJonas Devlieghere::
80edb874b2SJonas Devlieghere
81edb874b2SJonas Devlieghere   (lldb) script
82edb874b2SJonas Devlieghere   Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
83edb874b2SJonas Devlieghere   >>> m = lldb.target.module['a.out']
84edb874b2SJonas Devlieghere   >>> for i in range(m.GetNumCompileUnits()):
85edb874b2SJonas Devlieghere   ...   cu = m.GetCompileUnitAtIndex(i).file.fullpath
86edb874b2SJonas Devlieghere   /tmp/main.c
87edb874b2SJonas Devlieghere   /tmp/foo.c
88edb874b2SJonas Devlieghere   /tmp/bar.c
89edb874b2SJonas Devlieghere   >>>
90edb874b2SJonas Devlieghere
91edb874b2SJonas DevlieghereThis can help to show the actual full path to the source files. Sometimes IDEs
92edb874b2SJonas Devliegherewill set breakpoints by full paths where the path doesn't match the full path
93edb874b2SJonas Devliegherein the debug info and this can cause LLDB to not resolve breakpoints. You can
94edb874b2SJonas Devlieghereuse the breakpoint list command with the --verbose option to see the full paths
95edb874b2SJonas Devliegherefor any source file and line breakpoints that the IDE set using:
96edb874b2SJonas Devlieghere
97edb874b2SJonas Devlieghere::
98edb874b2SJonas Devlieghere
99edb874b2SJonas Devlieghere   (lldb) breakpoint list --verbose
100