llvm / llvm/llvm-project

LLDB formatters are global between targets (and debugger instances)

Open
#176,760 2 comments 1 reaction 0 assignees View on GitHub
lldb
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Currently type summaries/synthetic providers are global (shared between targets, and even debugger instances). But a type with the same name might be implemented differently between two targets. We should make the format management target-specific.

Below is an example:

Consider this C++ program:
```
struct Foo {};

int main() {
Foo f;
__builtin_debugtrap();
}
```
Compiled as `clang++ -g main.cpp -o ~/a.out` on macOS.

Then in LLDB (which owns a single debugger instance):
```
$ lldb -o "target create a.out" -o run -o "target create a.out" -o run
...
(lldb) target select 0

(lldb) type summary add -x Foo --summary-string 'Test Summary'

(lldb) v f
(Foo) f = Test Summary

(lldb) target select 1

(lldb) v f
(Foo) f = Test Summary
```

Note how adding the summary in only one of the targets has an effect on the summary for the other target too.

To observe how they are global even between debugger instances, run the following (e.g., on macOS run `xcrun python3 debuggers.py`):
```
import lldb
import os

def get_new_debugger():
dbg = lldb.SBDebugger.Create()
dbg.SetAsync(False)
target = dbg.CreateTarget("~/a.out")
assert target
process = target.LaunchSimple(None, None, os.getcwd())
assert process
assert process.GetState() == lldb.eStateStopped
th = process.GetSelectedThread()
assert th

frame = th.GetSelectedFrame()
assert frame.name == "main"

return dbg, frame

d1, f1 = get_new_debugger()

d1.HandleCommand("type summary add -x Foo --summary-string 'Test Summary'")
assert f1.FindVariable("f").GetSummary() == "Test Summary"

d2, f2 = get_new_debugger()
assert f2.FindVariable("f").GetSummary() == "Test Summary"

lldb.SBDebugger.Destroy(d1)
lldb.SBDebugger.Destroy(d2)
```

Note how we only added a type summary for `Foo` in one of the debugger instances, but it still applied to the other instance.

Contributor guide

Open the contributing guide

Research direction

Start with LLDB’s type-summary and synthetic-provider format-management path, then reproduce the target and debugger-instance examples in the issue. Trace how each target and SBDebugger obtains its format state; done means a summary added to one target or debugger instance no longer affects another, while both examples still run as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.