Re: Debug single COBOL paragraph (327 Views)
Reply
Occasional Advisor
Posts: 6
Registered: ‎02-01-2006
Message 1 of 8 (327 Views)

Debug single COBOL paragraph

Hi,

I'm trying to determine if it is possible to execute a single arbitrary COBOL paragraph from within the debugger. The scenario I have in mind is:

(1) Start program under debugger control and get to main entry point.
(2) Deposit required values into variables.
(3) Execute the paragraph under test.
(4) Examine contents of variables to see what happened.

The attachment contains a simple test program and the results of some experiments. My initial conclusion is that this might not be a good idea... but I'd really like to be proved wrong!

Environment is:

Compaq COBOL V2.8-1286
OpenVMS V7.3-2
Alpha

cheers
andrew
Honored Contributor
Posts: 6,591
Registered: ‎05-19-2003
Message 2 of 8 (327 Views)

Re: Debug single COBOL paragraph

Those cobol labels are not like call entry points. No go.

And I think that between the first go to the program entry, and the first executable line (11), there are some setups, so you needs at least an step/line.

Check the .lis file from $cob /list/mach/debu/noopt.
Warning: not for the those that get dizy quickly.

I think you are stuck woth the classic:
1) set brea `label`
2) go
3) deposit...
4) go or step further

fwiw,
Hein.

Honored Contributor
Posts: 496
Registered: ‎08-07-2003
Message 3 of 8 (327 Views)

Re: Debug single COBOL paragraph

From your results it looks like you have achieved "paragraph drop-through".
Maybe the break/return has disrupted the return mechanism, as it is a small program why don't you include a SET TRACE?
I would suggest adding spurious paragraphs between the 3 executable paragraphs like

TwoLevelsDown.
DISPLAY ">>>>>>>> Now in TwoLevelsDown."
PERFORM ThreeLevelsDown.
DISPLAY ">>>>>>>> Back in TwoLevelsDown.".

Limbo1.
DISPLAY "In limbo1 - where next".

OneLevelDown.
DISPLAY ">>>> Now in OneLevelDown"
PERFORM TwoLevelsDown
DISPLAY ">>>> Back in OneLevelDown".

Limbo2.
DISPLAY "In limbo2 - where next".


Make sure you compile with /noopt or it will remove unreferenced code.
On alphas I have always regarded the line numbers displayed by the debugger as an estimate.
Phil
Honored Contributor
Posts: 4,536
Registered: ‎12-17-2003
Message 4 of 8 (327 Views)

Re: Debug single COBOL paragraph

Andrew,

sorry, no help from me on this one, but I noticed it is your first entry, so:

WELCOME to the VMS forum!

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Occasional Advisor
Posts: 6
Registered: ‎02-01-2006
Message 5 of 8 (327 Views)

Re: Debug single COBOL paragraph

All,

Thanks for your suggestions so far. I'd already looked at the assembly listing, I'd expected the paragraphs to be invoked with a JSB (or whatever on Alpha) and exited with RSB (ditto) like it used to be on VAX a long long time ago... nope, looked like unconditional branch instructions to me. This probably explains some of the behaviour.

I think the suggestion to use STEP to execute the paragraph is probably the way to go if I can just get to the start of it in a clean way first!

The dream is to be able to use the debugger as a universal test harness for unit testing parts of typical monolithic Cobol programs.

cheers
andrew
Honored Contributor
Posts: 3,002
Registered: ‎07-31-2003
Message 6 of 8 (327 Views)

Re: Debug single COBOL paragraph

Andrew,

There many ways to force DEBUG to stop exactly where you want it, and/or easily build debug harnesses.

STEP/BRANCH may do what you want already. It will stop at any branch instruction. Here's an example:

DBG> step/branch
In TopLevel. Starting to run program
>>>> Now in OneLevelDown
>>>>>>>> Now in TwoLevelsDown.
>>>>>>>>>>>> Now in ThreeLevelsDown
stepped to PERFORMFORMAT1\%LINE 30+52: JMP R31,(R0)
30: DISPLAY ">>>>>>>>>>>> Now in ThreeLevelsDown".
DBG> step/branch
>>>>>>>> Back in TwoLevelsDown.
stepped to PERFORMFORMAT1\%LINE 20+48: JMP R31,(R0)
20: DISPLAY ">>>>>>>> Back in TwoLevelsDown.".
DBG> step/branch
>>>> Back in OneLevelDown
stepped to PERFORMFORMAT1\%LINE 26+56: JMP R31,(R0)
26: DISPLAY ">>>> Back in OneLevelDown".
DBG> step/branch
Back in TopLevel.
%DEBUG-I-EXITSTATUS, is '%SYSTEM-S-NORMAL, normal successful completion'


Another option is to use COBOL CONTINUE statements to give you lines that you can set break points at. Just put one as the first and one as the last line in your code.

You could also declare a variable, say DEBUG-LEVEL which you increment at the top of each paragraph and decrement at the bottom. That way the single DEBUG command:

DBG> SET WATCH DEBUG-LEVEL

will stop at the top and bottom of every paragraph, but you could also be more selective:

DBG> SET WATCH DEBUG-LEVEL WHEN(DEBUG-LEVEL > 2)

This will only stop at depths greater than 2 (I'm not 100% certain of the conditional syntax used for COBOL programs - it may be "GREATER THAN")

Explore the DEBUG commands. SET BREAK and SET WATCH have LOTS of options and optional clauses. If you can think of a way of debugging code, the DEBUG engineers are probably ahead of you, and have provided it already!

More complex... try writing each paragraph as an independent program. You can then CALL the program from DEBUG. See attachment. Here's an example run.


OpenVMS Alpha Debug64 Version V7.2-01R

%DEBUG-I-INITIAL, Language: COBOL, Module: PERFORMFORMAT1
%DEBUG-I-NOTATMAIN, Type GO to reach MAIN program

DBG> Go
break at routine PERFORMFORMAT1
2: PROGRAM-ID. PerformFormat1.
DBG> CALL LevelOne
>>>> Now in OneLevelDown
>>>>>>>> Now in TwoLevelsDown.
>>>>>>>>>>>> Now in ThreeLevelsDown
>>>>>>>> Back in TwoLevelsDown.
>>>> Back in OneLevelDown
value returned is 1
DBG> CALL LevelThree
>>>>>>>>>>>> Now in ThreeLevelsDown
value returned is 1
DBG> CALL LevelTwo
>>>>>>>> Now in TwoLevelsDown.
>>>>>>>>>>>> Now in ThreeLevelsDown
>>>>>>>> Back in TwoLevelsDown.
value returned is 1
DBG> Exit

A crucible of informative mistakes
Occasional Advisor
Posts: 6
Registered: ‎02-01-2006
Message 7 of 8 (327 Views)

Re: Debug single COBOL paragraph

John,

Thanks for your detailed and thoughtful response. A few comments if I may...

(1) STEP/BRANCH is something I had not thought of and it certainly appears to work in this simple case. It might get a little confusing where EVALUATE (switch) statements are involved in the body of a paragraph, I suspect the compiler might start generating a few branch instructions here as well. There will probably be other cases where branch instructions are generated that are not involved in the entry/exit of a paragraph. This would lead to confusion.

(2) The CONTINUE statement. Tried that, seemed to get optimized out of existence even when /DEBUG/NOOPT specified. At least SET BREAK %LINE couldn't find it.

(3) DEBUG-LEVEL. This will work and I will include it in my discussions with the developers.

(4) Refactoring. This is absolutely the correct way to go. However the reluctance of developers to touch a large complicated piece of code that might succesfully implement some bizarre legislative requirement cannot be underestimated. If it works there is no desire to fix it! Hence the attempt to test fragments of the code in-situ.

My current, less than optimal 'solution', is to insert code at the end of the module along the lines of:

DBGMYPARA.
PERFORM MYPARA.
CALL LIB$SIGNAL USING BY VALUE SS$_DEBUG.

This gives me the ability to execute each paragraph normally with instructions like:

DBG> GO DBGMYPARA

The SS$_DEBUG gets control back to the debugger in a 'graceful' way. It doesn't rely on knowledge of the code generated by the compiler and the additional lines could be added by a simple automated editing procedure.

To all those who responded. Thank you.

cheers
andrew
Occasional Advisor
Posts: 6
Registered: ‎02-01-2006
Message 8 of 8 (327 Views)

Re: Debug single COBOL paragraph

Thread now closed
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.