1

A posted a question a while back on how to add custom LLDB type summaries into Xcode. I found out that we can do so by loading a Python script.

However, I want to know if there's a way to load multiple Python files? I work with many different projects, so I want to have 1 summaries files for the general types that are used in all my projects, and 1 summaries files for project-specific types.


~/MyGenericSummaries.py

import lldb

def __lldb_init_module(debugger, dictionary):
    debugger.HandleCommand('type summary add --summary-string "these are words" MyGenericClass');

~/MyProjectSummaries.py

import lldb

def __lldb_init_module(debugger, dictionary):
    debugger.HandleCommand('type summary add --summary-string "these are more words" MyProjectClass');

~/.lldbinit

command script import ~/MyGenericSummaries.py
command script import ~/MyProjectSummaries.py

This never loads the type summary of MyProjectSummaries.py -- LLDB just tells me

error: module importing failed: module already imported

Is it possible to keep the generic summaries and project summaries in seperate files? This would really help, because I have some type names that clash amongst different projects, so I'd rather split these off.

Many thanks :)

Community
  • 1
  • 1
OLL
  • 655
  • 5
  • 20

2 Answers2

3

Ok I got it... With a bit of Python magic:


~/MyGenericSummaries.py

import lldb

def doLoad(debugger, dictionary):
    debugger.HandleCommand('type summary add --summary-string "these are words" MyGenericClass');

def __lldb_init_module(debugger, dictionary):
    doLoad(debugger, dictionary);

~/MyProjectSummaries.py

import lldb
from MyGenericSummaries import doLoad

def __lldb_init_module(debugger, dictionary):
    doLoad(debugger, dictionary);
    debugger.HandleCommand('type summary add --summary-string "these are more words" MyProjectClass');

~/.lldbinit

command script import ~/MyProjectSummaries.py

The only downside is that I'll need to tweak .lldbinit and restart Xcode everytime I switch project, but that's something I can live with.

OLL
  • 655
  • 5
  • 20
2

I'm not clear why the original code did not work. From what you've quoted, I expect that to work.

You can certainly command script import multiple Python files in your ~/.lldbinit file - I do that all the time. From the error message, it looks like you had a command script import ~/MyProjectSummaries.py in your ~/.lldbinit already. Be careful to look for a ~/.lldbinit-Xcode which is also sourced when Xcode is run (or ~/.lldbinit-lldb if the command line lldb is being used. The general form is ~/.lldbinit-DRIVER_NAME for whatever lldb is being used. This feature is useful if you want to enable certain settings only when the lldb library is being used inside Xcode, for instance.)

You may want to put your type summary entries in per-project groups. If you do type summary list you will see that the built-in summaries are already grouped into categories like libcxx, VectorTypes, CoreGraphics, etc. These groups of summaries can be enabled or disabled with type category enable|disable|list|delete.

Command line lldb will also read a .lldbinit in the current working directory where it is run - although this doesn't help the Xcode case. For what you're doing, you really want a Project-specific lldbinit file. If you had these type summaries added in your ~/.lldbinit file, the project-specific lldbinit might just enable/disable the correct type summaries for this project. But there's no feature like this in Xcode right now.

Jason Molenda
  • 14,835
  • 1
  • 59
  • 61