4 On demand symbols can be enabled in LLDB for projects that generate debug info
5 for more than what is required by a normal debug session. Some build systems
6 enable debug information for all binaries and can end up producing many
7 gigabytes of debug information. This amount of debug information can greatly
8 increase debug session load times and can slow developer productivity when the
9 debug information isn't indexed. It can also cause expression evaluation to
10 be slow when types from all of the binaries have full debug info as each module
11 is queried for very common types, or global name lookups fail due to a mistyped
14 When should I consider enabling this feature?
15 ---------------------------------------------
17 Anyone that has a build system that produces debug information for many
18 binaries that are not all required when you want to focus on debugging a few of
19 the produced binaries. Some build systems enable debug info as a project wide
20 switch and the build system files that control how things are built are not
21 easy to modify to produce debug info for only a small subset of the files being
22 linked. If your debug session startup times are slow because of too much debug
23 info, this feature might help you be more productive during daily use.
25 How do I enable on demand symbols?
26 ----------------------------------
28 This feature is enabled using a LLDB setting:
33 (lldb) settings set symbols.load-on-demand true
35 Users can also put this command into their ~/.lldbinit file so it is always
38 How does this feature work?
39 ---------------------------
41 This feature works by selectively enabling debug information for modules that
42 the user focuses on. It is designed to be enabled and work without the user
43 having to set any other settings and will try and determine when to enable
44 debug info access from the modules automatically. All modules with debug info
45 start off with their debug information turned off for expensive name and type
46 lookups. The debug information for line tables are always left enabled to allow
47 users to reliably set breakpoints by file and line. As the user debugs their
48 target, some simple things can cause module to get its debug information
49 enabled (called hydration):
50 - Setting a file and line breakpoint
51 - Any PC from any stack frame that maps to a module
52 - Setting a breakpoint by function name
53 - Finding a global variable by name
55 Since most users set breakpoints by file and line, this is an easy way for
56 people to inform the debugger that they want focus on this module. Breakpoints
57 by file and line are always enabled when on demand symbols is being used. Line
58 tables in debug information are cheap to parse and breakpoints will be able to
59 be set in any module that has debug info. Setting breakpoints by file and line
60 acts as one of the primary ways to enable debug info for a module as it is
61 the most common way to stop your program at interesting areas of your code.
63 Once the user hits a breakpoint, or stops the program for any other reason,
64 like a crash, assertion or signal, the debugger will calculate the stack frames
65 for one or more threads. Any stack frames whose PC value is contained within
66 one of a module's sections will have its debug information enabled. This allows
67 us to enable debug information for the areas of code that the user is stopped
68 in and will allow only the important subset of modules to have their debug
71 On demand symbol loading tries to avoid indexing the names within the debug
72 information and makes a few tradeoffs to allow name matching of functions and
73 globals without having to always index all of the debug information.
74 Setting breakpoints by function name can work, but we try to avoid using
75 debug information by relying on the symbol tables from a module. Debug
76 information name indexing is one of the most expensive operations that we are
77 trying to avoid with the on demand symbol loading so this is one of the main
78 tradeoffs of this feature. When setting a breakpoint by function name, if the
79 symbol table contains a match, the debug information will be enabled for that
80 module and the query will be completed using the debug information. This does
81 mean that setting breakpoints on inline function names can fail for modules
82 that have debug info, but no matches in the symbol table since inlined
83 functions don't exist in symbol tables. When using on demand symbol loading it
84 is encouraged to not strip the symbol tables of local symbols as this will
85 allow users to set breakpoints on all concrete functions reliably. Stripped
86 symbol tables have their local symbols removed from the symbol table which
87 means that static functions and non exported function will not appear in the
88 symbol tables. This can cause breakpoint setting by function name to fail when
89 previously it wouldn't fail.
91 Global variable lookups rely on the same methodology as breakpoint setting by
92 function name: we use the symbol tables to find a match first if debug
93 information isn't enabled for a module. If we find a match in the symbol table
94 for a global variable lookup, we will enable debug information and complete
95 the query using the debug information. It is encouraged to not strip your
96 symbol tables with this features as static variables and other non exported
97 globals will not appear in the symbol table and can lead to matches not being
100 What other things might fail?
101 -----------------------------
103 The on demand symbol loading feature tries to limit expensive name lookups
104 within debug information. As such, some lookups by name might fail when they
105 wouldn't when this feature is not enabled:
106 - Setting breakpoints by function name for inlined functions
107 - Type lookups when the expression parser requests types by name
108 - Global variable lookups by name when the name of the variable is stripped
110 Setting breakpoints by function name can fail for inline function because this
111 information is only contained in the debug information. No symbols are created
112 for inlined functions unless there is a concrete copy of the inlined function
113 in that same module. As a result, we might not end up stopping at all inlined
114 functions when requested with this feature enabled. Setting file and line
115 breakpoints are a good way still use on demand symbol loading effectively
116 and still being able to stop at inline function invocations.
118 The expression parser often tries to lookup types by name when the user types
119 an expression. These are some of the most costly parts of expression evaluation
120 as the user can type something like "iterator" as part of their expression and
121 this can result in matches from all STL types in all modules. These kinds of
122 global type lookup queries can cause thousands of results to be found if debug
123 information is enabled. The way that most debug information is created these
124 days has the type information inlined into each module. Typically each module
125 will contain full type definitions in the debug info for any types that are
126 used in code. This means that when you type an expression when stopped, you
127 have debug information for all of the variables, arguments and global variables
128 in your current stack frame and we should be able to find type that are
129 important by using only the modules that have their debug information enabled.
131 The expression parser can also be asked to display global variables and they
132 can be looked up by name. For this feature to work reliably with on demand
133 symbol loading enabled, just don't strip your symbol tables and the expression
134 parser should have no problem finding your variables. Most global variables
135 that are exported will still be in your symbol table if it is stripped, but
136 static variables and non exported globals will not be.
138 Can I troubleshoot issues when I believe this feature is impeding my debugging?
139 -------------------------------------------------------------------------------
141 Logging has been added that can be enabled to help notify our engineers when
142 something is not producing results when this feature is enabled. This logging
143 can be enabled during a debug session and can be sent to the LLDB engineers
144 to help troubleshoot these situation. To enable logging, type the following
149 (lldb) log enable -f /tmp/ondemand.txt lldb on-demand
151 When the logging is enabled, we get full visibility into each query that would
152 have produced results if this feature were not enabled and will allow us to
153 troublshoot issues. Enabling this logging before an expression, setting a
154 breakpoint by name, or doing a type lookup can help us see the patterns that
155 cause failures and will help us improve this feature.