Menu

Control flow graph of a cobol program

2023-07-18
2023-08-14
  • Sundar Raman P

    Sundar Raman P - 2023-07-18

    Support to obtain control flow graph of a cobol program at the abstraction of if-else to be able to extract business rules from old cobol codes in a structured way.

     
  • Simon Sobisch

    Simon Sobisch - 2023-07-18

    To get a "real" control flow you'd have to run the program with different input data and then check the result.

    To visualize the full possibilities you could try to import COBOL into Structorizer - note: it is mostly reasonable to do this "per section / logic block", not for programs with 140000 lines.

    If the possible program flow for paragraphs / sections is interesting you could use the program flow generation of https://sourceforge.net/projects/tp-cobol-debugg/ (I wouldn't suggest this for actual debugging any more) or in vscode using an extension like https://github.com/BroadcomMFD/cobol-control-flow (only works for COBOL which is compatible to IBM Enterprise COBOL).

    Extracting business rules is always hard to do, especially if the program is not very well structured, long, misses comments, ... and in any case there is no tool that really can does this for you, all tools only assist.
    Note: there are proprietary tools that may do better than the above, but in the end you always have to look at the code/imports and adjust those. I personally had the best results using Structorizer import, once for the program to get an idea of the general logic (only with smaller programs), then with hand-selecting the "interesting" parts and importing only those.

     
  • Sundar Raman P

    Sundar Raman P - 2023-08-14

    Thanks @sf-mensch for your valuable inputs. Structorizer seems to be helpful for a section as you mentioned but I want to start from a codebase level and generate the overall function call graph, then a static control flow graph (based on rules like if snippet, else snippet, perform snippet, call code snippet, etc. form the nodes of the graph). Broadcom's cobol control flow takes a very good first step in that direction (doing it based on perform statements). tp-cobol-debugg is written in COBOL, so can't be productionized.
    Wanted to ask if this static graph extraction based on "perform", "if-else" statements can be done through GnuCOBOL. I am currently exploring this resource: https://github.com/eclipse-che4z/che-che4z-lsp-for-cobol which seems to be open-source and useful for my requirement. Eager to hear your thoughts.

     
    • Simon Sobisch

      Simon Sobisch - 2023-08-14

      What do you mean with

      tp-cobol-debugg is written in COBOL, so can't be productionized.

      ?

      Wanted to ask if this static graph extraction based on "perform", "if-else" statements can be done through GnuCOBOL.

      Sure, it all depends on what the actual requirement is. The PERFORM (and/or GO TO) can be easily recognized from the cross-reference (-T listing -Xref, you can also drop unneeded parts in the listing - see the manual on that).
      In the past I've created shell scripts that used the listing and cross-reference to create "textual" flow graphs, including CALL, so that's definitely possible.

      Other than that, it would of course be possible to integrate a feature like that into cobc directly - but then again this would need a good spec, and someone that works on this.

       
  • Sundar Raman P

    Sundar Raman P - 2023-08-14

    Sorry, I read somewhere that tp-cobol-debug is written in COBOL but now on a rereading the official documentation, I relaized it's written in gnuCOBOL. So let me give that a try. Also thanks for the inputs on using gnucobol switches like "-T listing" to help accomplish what I want. I will have a look at it. Does tp-cobol-debug already implements someof it in it's animation? Can you also share the shell scripts which you have used to obtain all cross-references?

     
    • Simon Sobisch

      Simon Sobisch - 2023-08-14

      Those shell scripts were part of my last employment, so no, I don't have them any more.
      They definitely used something like -Tlisting -ftno-header -ftlines=0 -Xref to get a compile listing to then process with iterating over the CALLs (including checking for dynamic calls via the reference what content is written to the variable) and check the actual procedure cross-reference for which paragraphs were called from what place. The shell script used things like grep -C5 something-interesting but the if/else/when (especially the later can get huge) were not completely parsed (just checked for something specific like io-status, otherwise noted "conditional jump" without more details).

      For questions to TP-Debugger - please use its discussion board / mailing list / "social" media group(s) as I doesn't used that since quite a while. Ideally Federico could build a "specialized" version of his parser that only does the control flow reference...

       

Anonymous
Anonymous

Add attachments
Cancel