Skip to content

* improvement: Adds statement-level LocalVariableTable debug scopes and metadata propagation - #1780

Draft
dkimitsa wants to merge 4 commits into
soot-oss:developfrom
dkimitsa:exp/local-variable-table
Draft

dkimitsa wants to merge 4 commits into
soot-oss:developfrom
dkimitsa:exp/local-variable-table

Conversation

@dkimitsa

@dkimitsa dkimitsa commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

depends on: #1777

What does this PR address? (Why)
This PR consist of 2 commits:

First:
Enables to specify extended analysis scopes to control optional analysis features.
In particular it allows to enable specific processing in AsmMethodSource (e.g., LocalVariableTable
debug info processing when required).

Second:
Adds statement-level LocalVariableTable debug scopes and metadata propagation to Jimple statements.
As Body is subject to transformations and optimizations this makes difficult to connect LVT debug information to the
final Jimple statements.
Many options were considered for observing Body transformations callbacks to monitor body changes and update LVT mapping
but this requires a lot of support in Delegates and is not error-prone.
Instead, propagation of LVT information withing Statement location information allows to have Local variable visibility for
each statement. Also existing Delegate implementation already supports location information adopting by Jimple changes that will also transfer/adopt LVT.

What are the main implementation details? (What, How)

  • functionality to be enabled with AnalysisExtendedScope.LocalVariableTable in AnalysisInputLocation.
  • Added immutable LocalVariableInfo (name, slotIndex, descriptor) and LocalVariableScope models in sootup.core.model.
  • Introduced LocalVariableStmtPositionInfo extending StmtPositionInfo to attach immutable variable scopes to statement positions without mutating existing position structures or breaking subclasses.
  • Updated StmtPositionInfo.withStmtPosition to allow polymorphic preservation of attached metadata when line numbers change.
  • Added LocalVariableTableLocals to parse LVT entries, track start/end labels, resolve overlapping slot scopes, and produce per-instruction LocalVariableScope snapshots.
  • Attached scopes to converted Jimple statements and exception identity statements.
  • Documented scope handling in docs/bodyinterceptors.md.
  • Added tests.

Compatibility note
it breaks binary compatibility due StmtPositionInfo being changed from Class to Interface

Checklist

Code style & guidelines

  • I ran the formatter: mvn com.spotify.fmt:fmt-maven-plugin:format
  • I added the necessary comments in the code
  • I provided meaningful tests for my proposed change
  • I updated documentation (if needed)

Self-review

  • I performed a self-review of my code
  • I added or updated tests where needed
  • I have successfully run tests with my changes locally
  • My branch is up to date with develop

Review

  • CI checks are green
  • I requested a review from a core contributor

…aLocal, and AsmMethodSource

**What does this PR address? (Why)**
Local objects lack a slot index information local was originated from. This information is crucial for downstream analyses and code generators that
need to map Jimple locals back to their original JVM stack frame slots. In particular used with Local packers/merging (analyses cannot distinguish
between real local variables and stack ones).

**What are the main implementation details? (What, How)**

- Local extended with `slotIndex` field, constructor, getters, and withers.
- Mirrored constructor, withers, and getters in `JavaLocal`.
- Added factory overloads in `Jimple` and `JavaJimple`.
- Preserved `equals` and `hashCode` semantics based on name/identity to maintain 100% backward compatibility with existing sets and maps.
- In `AsmMethodSource`: assigned `localIdx` (slot 0) to `thisLocal` for non-static methods, assigned `localIdx` to formal parameter locals.

**Checklist**

*Code style & guidelines*

- [x] I ran the formatter: `mvn com.spotify.fmt:fmt-maven-plugin:format`
- [x] I added the necessary comments in the code
- [x] I provided meaningful tests for my proposed change
- [ ] I updated documentation (if needed)

*Self-review*

- [x] I performed a self-review of my code
- [x] I added or updated tests where needed
- [x] I have successfully run tests with your changes locally
- [x] My branch is up to date with `develop`

*Review*

- [ ] CI checks are green
- [ ] I requested a review from a core contributor
…nputLocation

**What does this PR address? (Why)**
This enables to specify extended analysis scopes to control optional analysis features.
In particular it allows to enable specific processing in AsmMethodSource (e.g., LocalVariableTable
debug info processing when required).

**What are the main implementation details? (What, How)**
- Introduced `AnalysisExtendedScope` enum in `sootup.core.inputlocation`.
- Added default `getExtendedScope()` method to `AnalysisInputLocation` returning an empty set by default.
- Added constructor overloads and static factory methods accepting `Set<AnalysisExtendedScope>` in `PathBasedAnalysisInputLocation`, `ArchiveBasedAnalysisInputLocation`, `DirectoryBasedAnalysisInputLocation`, `JavaClassPathAnalysisInputLocation`, and `WarArchiveAnalysisInputLocation`.
- Extended scopes are stored as immutable `EnumSet` copies.
- Added unit test covering extended scope propagation in `PathBasedAnalysisInputLocationTest`.

**Checklist**

*Code style & guidelines*
- [x] I ran the formatter: `mvn com.spotify.fmt:fmt-maven-plugin:format`
- [x] I added the necessary comments in the code
- [x] I provided meaningful tests for my proposed change
- [ ] I updated documentation (if needed)

*Self-review*
- [x] I performed a self-review of my code
- [x] I added or updated tests where needed
- [x] I have successfully run tests with my changes locally
- [x] My branch is up to date with `develop`

*Review*
- [ ] CI checks are green
- [ ] I requested a review from a core contributor
…nd metadata propagation

**What does this PR address? (Why)**
Adds statement-level LocalVariableTable debug scopes and metadata propagation to Jimple statements.
As Body is subject to transformations and optimizations this makes difficult to connect LVT debug information to the
final Jimple statements.
Many options were considered for observing Body transformations callbacks to monitor body changes and update LVT mapping
but this requires a lot of support in Delegates and is not error-prone.
Instead, propagation of LVT information withing Statement location information allows to have Local variable visibility for
each statement. Also existing Delegate implementation already supports location information adopting by Jimple changes that
will also transfer/adopt LVT.

**What are the main implementation details? (What, How)**
- functionality to be enabled with `AnalysisExtendedScope.LocalVariableTable` in `AnalysisInputLocation`.
- Added immutable `LocalVariableInfo` (name, slotIndex, descriptor) and `LocalVariableScope` models in `sootup.core.model`.
- Introduced `LocalVariableStmtPositionInfo` extending `StmtPositionInfo` to attach immutable variable scopes to statement positions without mutating existing position structures or breaking subclasses.
- Updated `StmtPositionInfo.withStmtPosition` to allow polymorphic preservation of attached metadata when line numbers change.
- Added `LocalVariableTableLocals` to parse LVT entries, track start/end labels, resolve overlapping slot scopes, and produce per-instruction `LocalVariableScope` snapshots.
- Attached scopes to converted Jimple statements and exception identity statements.
- Documented scope handling in `docs/bodyinterceptors.md`.
- Added tests.

**Checklist**

*Code style & guidelines*
- [x] I ran the formatter: `mvn com.spotify.fmt:fmt-maven-plugin:format`
- [x] I added the necessary comments in the code
- [x] I provided meaningful tests for my proposed change
- [x] I updated documentation (if needed)

*Self-review*
- [x] I performed a self-review of my code
- [x] I added or updated tests where needed
- [x] I have successfully run tests with my changes locally
- [x] My branch is up to date with `develop`

*Review*
- [ ] CI checks are green
- [x] I requested a review from a core contributor

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant