Armin Ronacher
Armin Ronacher

Reputation: 32533

LLDB: Execute a python callback after target create to inject symbols

I'm trying to execute a python function after target create so I can iterate over all modules of the target, download missing symbols from the internet (based on GetUUIDString) and then override the GetSymbolFileSpec() directory and path to what I downloaded.

Unfortunately I cannot figure out how to actually get a function invoked at the right time so that the program did not execute yet, the target is created and lldb.target.modules is populated and lets me modify the symbols.

Is there some documentation on how to hook into this? I am aware that there is a theoretical way to fetch symbols on demand via a shell script however that is only implemented on macos and not other platforms.

Upvotes: 1

Views: 315

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27110

You probably don't want to do this on target create since there's no guarantee that a target will know all the libraries that will load into it before it actually runs. And plus, you probably also want to handle libraries that are dynamically loaded as the program runs. The real place to do this is on Module add (which is where the hook for DebugSymbols happens in lldb.)

It looks like Linux and Windows don't have the notion of a call-out to some agent to pull in debug symbols. They do look in /usr/local/debug for pre-cached symbols, but there's no mechanism to have a call-out like with dsymForUUID.

If you're up for a little lldb hacking, it would be pretty straightforward to add such a callout. Just make a setting that takes the name of a program. That program would takes as input a UUID, and returns as output the file name for the debug info. Then you could have lldb run this in the same place where lldb currently calls LocateMacOSXFilesUsingDebugSymbols (in LocateSymbols.cpp).

Perhaps a simpler way to do this would be to add a target stop-hook that calls some python based command you've written that looks at the module list and fetches debug information for any new libraries that have shown up. If you want to use this for debugging running programs, you only care that the symbols get added before control returns to the user. So a stop hook would be an appropriate place to do this.

Upvotes: 0

Related Questions