Problem
LLDB currently does not support fetching source files from arbitrary source servers due to security concerns and debuginfod support for fetching source files is yet to be integrated. Users currently need to ensure the source file state matches with the debugging process built source state inorder to resolve the source files correctly and hit breakpoints during debugging.
Proposal
I’d like to propose a new feature to address this problem which is similar to python callback for custom module resolution.
A Python callback for Platform
CallResolveSourceFileCallbackIfSet.
This new feature has negligible performance impact when not used.
When it is used, this Python callback will work as the implementation for getting source files from stack frame in LineEntry.cpp - ApplyFileMappings. The callback takes build id of module, original source file resolved by LLDB as input args and populates resolved source file spec. The method’s signature is as follows:
void CallResolveSourceFileCallbackIfSet(const char* build_id, const FileSpec& original_source_file_spec, FileSpec &resolved_source_file_spec, bool *did_create_ptr);
If the callback fails, or something goes wrong, CallResolveSourceFileCallbackIfSet
fallbacks to continue to use the LLDB implementation for getting source files. If the callback succeeds to return a source file path, CallResolveSourceFileCallbackIfSet
will use it in the same way with the LLDB implementation.
This will unblock users to write their own source file caching system for LLDB and allows fetching from arbitrary source servers. Since the python callback is called from userland, LLDB does not need to deal with authentication from different source servers and not worry about security concerns exposing source code.
Users will be able to use a new SBPlatform
API to set the callback function.
Performance benefits
Currently, we are checking out an entire repo and/or checking out the source code commit corresponding to the built process even if we want to resolve a few source files for debugging. In my scenario, checking out the repo takes close to 10 minutes. This can be an overkill whereas fetching of source files on a pay-per-play basis should be very fast where fetching each file takes 1-2 seconds.
Draft Implementation