brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.4 KiB · da19705 Raw
156 lines · plain
1On Demand Symbols2=================3 4On demand symbols can be enabled in LLDB for projects that generate debug info5for more than what is required by a normal debug session. Some build systems6enable debug information for all binaries and can end up producing many7gigabytes of debug information. This amount of debug information can greatly8increase debug session load times and can slow developer productivity when the9debug information isn't indexed. It can also cause expression evaluation to10be slow when types from all of the binaries have full debug info as each module11is queried for very common types, or global name lookups fail due to a mistyped12expression.13 14When should I consider enabling this feature?15---------------------------------------------16 17Anyone that has a build system that produces debug information for many18binaries that are not all required when you want to focus on debugging a few of19the produced binaries. Some build systems enable debug info as a project wide20switch and the build system files that control how things are built are not21easy to modify to produce debug info for only a small subset of the files being22linked. If your debug session startup times are slow because of too much debug23info, this feature might help you be more productive during daily use.24 25How do I enable on demand symbols?26----------------------------------27 28This feature is enabled using a LLDB setting:29 30 31::32 33   (lldb) settings set symbols.load-on-demand true34 35Users can also put this command into their ~/.lldbinit file so it is always36enabled.37 38How does this feature work?39---------------------------40 41This feature works by selectively enabling debug information for modules that42the user focuses on. It is designed to be enabled and work without the user43having to set any other settings and will try and determine when to enable44debug info access from the modules automatically. All modules with debug info45start off with their debug information turned off for expensive name and type46lookups. The debug information for line tables are always left enabled to allow47users to reliably set breakpoints by file and line. As the user debugs their48target, some simple things can cause module to get its debug information49enabled (called hydration):50- Setting a file and line breakpoint51- Any PC from any stack frame that maps to a module52- Setting a breakpoint by function name53- Finding a global variable by name54 55Since most users set breakpoints by file and line, this is an easy way for56people to inform the debugger that they want focus on this module. Breakpoints57by file and line are always enabled when on demand symbols is being used. Line58tables in debug information are cheap to parse and breakpoints will be able to59be set in any module that has debug info. Setting breakpoints by file and line60acts as one of the primary ways to enable debug info for a module as it is61the most common way to stop your program at interesting areas of your code.62 63Once the user hits a breakpoint, or stops the program for any other reason,64like a crash, assertion or signal, the debugger will calculate the stack frames65for one or more threads. Any stack frames whose PC value is contained within66one of a module's sections will have its debug information enabled. This allows67us to enable debug information for the areas of code that the user is stopped68in and will allow only the important subset of modules to have their debug69information enabled.70 71On demand symbol loading tries to avoid indexing the names within the debug72information and makes a few tradeoffs to allow name matching of functions and73globals without having to always index all of the debug information.74Setting breakpoints by function name can work, but we try to avoid using75debug information by relying on the symbol tables from a module. Debug76information name indexing is one of the most expensive operations that we are77trying to avoid with the on demand symbol loading so this is one of the main78tradeoffs of this feature. When setting a breakpoint by function name, if the79symbol table contains a match, the debug information will be enabled for that80module and the query will be completed using the debug information. This does81mean that setting breakpoints on inline function names can fail for modules82that have debug info, but no matches in the symbol table since inlined83functions don't exist in symbol tables. When using on demand symbol loading it84is encouraged to not strip the symbol tables of local symbols as this will85allow users to set breakpoints on all concrete functions reliably. Stripped86symbol tables have their local symbols removed from the symbol table which87means that static functions and non exported function will not appear in the88symbol tables. This can cause breakpoint setting by function name to fail when89previously it wouldn't fail.90 91Global variable lookups rely on the same methodology as breakpoint setting by92function name: we use the symbol tables to find a match first if debug93information isn't enabled for a module. If we find a match in the symbol table94for a global variable lookup, we will enable debug information and complete95the query using the debug information. It is encouraged to not strip your96symbol tables with this features as static variables and other non exported97globals will not appear in the symbol table and can lead to matches not being98found.99 100What other things might fail?101-----------------------------102 103The on demand symbol loading feature tries to limit expensive name lookups104within debug information. As such, some lookups by name might fail when they105wouldn't when this feature is not enabled:106- Setting breakpoints by function name for inlined functions107- Type lookups when the expression parser requests types by name108- Global variable lookups by name when the name of the variable is stripped109 110Setting breakpoints by function name can fail for inline function because this111information is only contained in the debug information. No symbols are created112for inlined functions unless there is a concrete copy of the inlined function113in that same module. As a result, we might not end up stopping at all inlined114functions when requested with this feature enabled. Setting file and line115breakpoints are a good way still use on demand symbol loading effectively116and still being able to stop at inline function invocations.117 118The expression parser often tries to lookup types by name when the user types119an expression. These are some of the most costly parts of expression evaluation120as the user can type something like "iterator" as part of their expression and121this can result in matches from all STL types in all modules. These kinds of122global type lookup queries can cause thousands of results to be found if debug123information is enabled. The way that most debug information is created these124days has the type information inlined into each module. Typically each module125will contain full type definitions in the debug info for any types that are126used in code. This means that when you type an expression when stopped, you127have debug information for all of the variables, arguments and global variables128in your current stack frame and we should be able to find type that are129important by using only the modules that have their debug information enabled.130 131The expression parser can also be asked to display global variables and they132can be looked up by name. For this feature to work reliably with on demand133symbol loading enabled, just don't strip your symbol tables and the expression134parser should have no problem finding your variables. Most global variables135that are exported will still be in your symbol table if it is stripped, but136static variables and non exported globals will not be.137 138Can I troubleshoot issues when I believe this feature is impeding my debugging?139-------------------------------------------------------------------------------140 141Logging has been added that can be enabled to help notify our engineers when142something is not producing results when this feature is enabled. This logging143can be enabled during a debug session and can be sent to the LLDB engineers144to help troubleshoot these situation. To enable logging, type the following145command:146 147::148 149   (lldb) log enable -f /tmp/ondemand.txt lldb on-demand150 151When the logging is enabled, we get full visibility into each query that would152have produced results if this feature were not enabled and will allow us to153troublshoot issues. Enabling this logging before an expression, setting a154breakpoint by name, or doing a type lookup can help us see the patterns that155cause failures and will help us improve this feature.156