Resolving a dynamic call site inside its own program
Read first: Value sets and dynamic calls
PROGA has three dynamic XCTLs. Two take their names from PROGA's own literals, so the walk over PROGA alone finds their targets, with no doubt attached. The third copies its name out of the commarea, so its value set is empty and carries inbound-linkage: a caller decides.
Each site's answer is the value set of its operand where the site runs, found by a forward reaching-definitions walk. Terms are in the COBOL/CICS primer.
The example
PROGA's sites are on lines 24, 27 and 30, each handing over its 100-byte commarea.
flowchart LR
S24["PROGA line 24
XCTL WS-FIRST-PGM"] --> B["PROGB"]
S27["PROGA line 27
XCTL WS-MENU-PGM"] --> B
S27 --> C["PROGC"]
S30["PROGA line 30
XCTL WS-NEXT-PGM"] -.->|"a caller decides"| U["?"]
Solid arrows end at programs found inside PROGA; the dashed one has no known end yet. That is the whole answer for this example:
The lines that matter: each site's operand, and every write to it. LK-NEXT is commarea bytes [0, 8).
* PROGA
01 WS-FIRST-PGM PIC X(8) VALUE 'PROGB'.
01 WS-MENU-PGM PIC X(8).
01 WS-NEXT-PGM PIC X(8).
IF WS-FLAG = 'Y'
MOVE 'PROGB' TO WS-MENU-PGM
ELSE
MOVE 'PROGC' TO WS-MENU-PGM
END-IF.
MOVE LK-NEXT TO WS-NEXT-PGM.
* line 24, WHEN '1'
EXEC CICS XCTL PROGRAM(WS-FIRST-PGM)
COMMAREA(DFHCOMMAREA) END-EXEC
* line 27, WHEN '2'
EXEC CICS XCTL PROGRAM(WS-MENU-PGM)
COMMAREA(DFHCOMMAREA) END-EXEC
* line 30, WHEN OTHER
EXEC CICS XCTL PROGRAM(WS-NEXT-PGM)
COMMAREA(DFHCOMMAREA) END-EXEC
Full listing (PROGA; line numbers count from its first line)
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGA.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-FIRST-PGM PIC X(8) VALUE 'PROGB'.
01 WS-MENU-PGM PIC X(8).
01 WS-NEXT-PGM PIC X(8).
01 WS-FLAG PIC X.
01 WS-MODE PIC X.
LINKAGE SECTION.
01 DFHCOMMAREA.
05 LK-NEXT PIC X(8).
05 LK-REST PIC X(92).
PROCEDURE DIVISION.
MAIN-PARA.
IF WS-FLAG = 'Y'
MOVE 'PROGB' TO WS-MENU-PGM
ELSE
MOVE 'PROGC' TO WS-MENU-PGM
END-IF.
MOVE LK-NEXT TO WS-NEXT-PGM.
EVALUATE WS-MODE
WHEN '1'
EXEC CICS XCTL PROGRAM(WS-FIRST-PGM)
COMMAREA(DFHCOMMAREA) END-EXEC
WHEN '2'
EXEC CICS XCTL PROGRAM(WS-MENU-PGM)
COMMAREA(DFHCOMMAREA) END-EXEC
WHEN OTHER
EXEC CICS XCTL PROGRAM(WS-NEXT-PGM)
COMMAREA(DFHCOMMAREA) END-EXEC
END-EVALUATE.
In cobble's node names the three sites are MAIN-PARA/2.when.0.0, MAIN-PARA/2.when.1.0 and MAIN-PARA/2.when.2.0. The operands are WS-FIRST-PGM@working_storage[0:8], WS-MENU-PGM@working_storage[8:16] and WS-NEXT-PGM@working_storage[16:24].
Step by step
One walk over PROGA carries the set of every field at once; the tables follow the three sites' operands. Each row is the set arriving at that node, which is what the walk reports for a site. Values are shown as stored: PIC X(8) pads 'PROGB' with three spaces, written ␣. The program has no loop, so the worklist visits each node once, in order.
One forward walk over PROGA (7 steps)
-
Entry. Each operand starts at what the program holds before any statement runs. WS-FIRST-PGM is covered by a
VALUE, so it starts at that literal. The other two have noVALUE: uninitialised. An operand in LINKAGE would start as inbound-linkage.operand arriving WS-FIRST-PGM {'PROGB␣␣␣'} WS-MENU-PGM {} + uninitialised WS-NEXT-PGM {} + uninitialised -
IF WS-FLAG = 'Y'writes nothing. Both arms start from the same sets.operand arriving at each arm WS-FIRST-PGM {'PROGB␣␣␣'} WS-MENU-PGM {} + uninitialised WS-NEXT-PGM {} + uninitialised -
Each arm moves a literal into all eight bytes of WS-MENU-PGM. The write is exact, not weak, and covers the whole operand: it replaces. The then arm leaves {'PROGB␣␣␣'}, the else arm {'PROGC␣␣␣'}. The uninitialised doubt is gone on both: the write killed it.
operand leaving then leaving else WS-FIRST-PGM {'PROGB␣␣␣'} {'PROGB␣␣␣'} WS-MENU-PGM {'PROGB␣␣␣'} {'PROGC␣␣␣'} WS-NEXT-PGM {} + uninitialised {} + uninitialised -
The arms meet at
MOVE LK-NEXT TO WS-NEXT-PGM(MAIN-PARA/1), so its arriving set is the union of both. Then the move: it is exact and covers all of WS-NEXT-PGM, so it replaces, as in step 3, though it stores no literal. The uninitialised doubt is gone, and WS-NEXT-PGM takes what its source holds: LK-NEXT is in LINKAGE, so that is {} + inbound-linkage.operand arriving leaving WS-FIRST-PGM {'PROGB␣␣␣'} {'PROGB␣␣␣'} WS-MENU-PGM {'PROGB␣␣␣', 'PROGC␣␣␣'} {'PROGB␣␣␣', 'PROGC␣␣␣'} WS-NEXT-PGM {} + uninitialised {} + inbound-linkage -
Line 24:
XCTL PROGRAM(WS-FIRST-PGM). Its operand arrives with {'PROGB␣␣␣'} and no doubt. Trimmed, that spells PROGB. Resolved to PROGB. The XCTL never returns. Its one write in PROGA is to the commarea it hands over, DFHCOMMAREA bytes [0, 100), which none of the three operands lies in, so it changes none of the three sets.line 24 → PROGB -
Line 27:
XCTL PROGRAM(WS-MENU-PGM). Arrives with {'PROGB␣␣␣', 'PROGC␣␣␣'} and no doubt. Resolved to PROGB and PROGC.line 24 → PROGBline 27 → PROGB, PROGC -
Line 30:
XCTL PROGRAM(WS-NEXT-PGM). Arrives with {} + inbound-linkage. No candidates, so the site is unresolved, and its reason says why: a caller supplies the name. The site goes to the cross-program walk later.line 24 → PROGBline 27 → PROGB, PROGCline 30 unresolved: inbound-linkage
Why literals settle it
Steps 3 and 4 of the walk decided line 27. Here is the part of PROGA's graph they covered, with the set of WS-MENU-PGM, line 27's operand, on each edge:
flowchart TD
E["entry"] -->|"{} + uninitialised"| I["line 16
IF WS-FLAG = 'Y'"]
I -->|then| T["line 17
MOVE 'PROGB'"]
I -->|else| F["line 19
MOVE 'PROGC'"]
T -->|"{'PROGB␣␣␣'}"| J["line 21
MOVE LK-NEXT TO WS-NEXT-PGM"]
F -->|"{'PROGC␣␣␣'}"| J
J -->|"{'PROGB␣␣␣', 'PROGC␣␣␣'}"| V["line 22
EVALUATE WS-MODE"]
V --> S24["line 24 site"]
V --> S27["line 27 site
PROGB, PROGC"]
V --> S30["line 30 site"]
In step 3 each arm writes all eight bytes exactly, so it replaces what arrived, the uninitialised doubt included. In step 4 the arms meet at line 21, so the set is their union; line 21 writes WS-NEXT-PGM, not WS-MENU-PGM. Every value reaching line 27 is a literal this program wrote, so its set is complete.
That is the whole test. If every value reaching a site is a literal this program wrote, the site's answer is complete here. If the name came from linkage, a callee or a file, this program alone cannot see it: the set carries a reason, and the site goes to the cross-program walk.
Where this shows up in reverse engineering
On a large CICS corpus (about 3,800 programs and 19,000 jumps), the dynamic targets came in three shapes, and PROGA has one of each; the line numbers are those of the full listing.
| shape | in PROGA | site | needs other programs? |
|---|---|---|---|
| a literal VALUE, never written | WS-FIRST-PGM ... VALUE 'PROGB' (line 5) | line 24 | no |
| a MOVE 'LITERAL' on each branch | MOVE 'PROGB' / MOVE 'PROGC' TO WS-MENU-PGM (lines 17, 19) | line 27 | no |
| a name read out of DFHCOMMAREA | MOVE LK-NEXT TO WS-NEXT-PGM (line 21) | line 30 | yes |
Only the third row, about 5% of the corpus's sites, needs the cross-program walk: a caller put the next program's name in the commarea. That walk is the subject of answering every walk once and bounding walks by crossings.
The rule
= the VALUE bytes covering o, if a VALUE covers it
= uninitialised, otherwise
in(entry) = initial(o); in(n) = ⋃ out(p) for every predecessor p
out(n) = in(n) after each write w at n:
w misses o's bytes → unchanged
w is exact and covers o → w's values and reasons, sliced to o
(whatever w holds; uninitialised goes too)
w may land anywhere over o (a computed subscript or offset),
or is a statement cobble does not model
→ in(n) joined with w's values and reasons
w overwrites only part of o → no values; not-a-literal,
plus uninitialised while a byte of o has had no exact write
(inbound-linkage instead, if o is in LINKAGE)
candidates(site) = program names among values(in(site))
complete(site) ⇔ reasons(in(site)) = ∅
Each line has already run in the walk. initial(o) is step 1: WS-FIRST-PGM starts at its VALUE, the other two at uninitialised. in(n) as a union is step 4, where the arms meet at line 21. The exact-and-covers line is steps 3 and 4: in step 4 it removes WS-NEXT-PGM's uninitialised and leaves the inbound-linkage of its LINKAGE source, which is why line 30's set carries inbound-linkage. The last two write lines are not used by PROGA.
What goes wrong
Each case is a one-site program, run through cobble-dataflow-fixpoint; the chips are the candidates and reasons of its targets.jsonl row.
- A path with no write. No
ELSE, so on one path nothing writes the operand. The literal is found, and the gap is marked:IF WS-FLAG = 'Y' MOVE 'PROGB' TO WS-PGM END-IF.candidates: PROGBreasons: uninitialised - Conditions are not evaluated. A literal on a branch that never runs still counts. Nothing writes
WS-NEVER, yetPROGCis a candidate. Loose, not wrong:01 WS-PGM PIC X(8) VALUE 'PROGB'. 01 WS-NEVER PIC X VALUE 'N'. ... IF WS-NEVER = 'Y' MOVE 'PROGC' TO WS-PGM END-IF.candidates: PROGB, PROGCreasons: none - The walk starts at the program's entry. A
CALLed batch subprogram keeps its working storage between calls. Below, the site runs before theMOVE, so the walk sees only uninitialised; on a second call,WS-PGMalready holds'PROGB'from the first. The reason says the set may be short, but the candidate is missed:CALL WS-PGM USING DFHCOMMAREA. MOVE 'PROGB' TO WS-PGM. GOBACK.candidates: nonereasons: uninitialised
Two cases that look hard are not. A copy of a literal through another field (MOVE 'PROGB' TO WS-OTHER, MOVE WS-OTHER TO WS-PGM) gives PROGB with no reasons, because the value set travels with the bytes. A table of names read with a computed subscript (XCTL PROGRAM(WS-PGMS(WS-I)) over 'PROGB' and 'PROGC') gives both, with no reasons.
In cobble
The resolution is part of cobble-dataflow-fixpoint: every dynamic site's operand gets its value set where the site runs, and the run writes one targets.jsonl row per site. For PROGA:
{"caller": "PROGA", "node": "MAIN-PARA/2.when.0.0", "kind": "program",
"transfer": "CICS_XCTL", "expression": "WS-FIRST-PGM",
"candidates": ["PROGB"], "reasons": [], "dropped": []}
{"caller": "PROGA", "node": "MAIN-PARA/2.when.1.0", "kind": "program",
"transfer": "CICS_XCTL", "expression": "WS-MENU-PGM",
"candidates": ["PROGB", "PROGC"], "reasons": [], "dropped": []}
{"caller": "PROGA", "node": "MAIN-PARA/2.when.2.0", "kind": "program",
"transfer": "CICS_XCTL", "expression": "WS-NEXT-PGM",
"candidates": [], "reasons": ["inbound-linkage"], "dropped": []}
kind says the values must name a program; dropped lists values set aside because they cannot be a program name, such as a field of spaces.
The commands, with the bridge environment sourced and a corpus config listing PROGA:
cobble-parse-corpus --config corpus.toml cobble-extents --asg-dir asg --out extents.jsonl cobble-dataflow-fixpoint --asg-dir asg --extents extents.jsonl --out-dir fixpoint --all
cobble-dataflow-combine then takes every site whose reasons say a caller or callee decides, and walks across programs for it. Next: sweeps.