Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Building control flow graph for C/C++ code using CDT

Thank you Ridhi for reporting back your findings.

The ValueFactory error sounds like something that should be fixed in CDT. If you can report* it with how to test the change in https://github.com/eclipse-cdt/cdt/issues/new that would be great.

Thanks
Jonah

* cdt-dev'ers - the transition to GitHub is now in progress, official announcement due soon now that I have sufficient permissions. In the meantime please excuse our transitory state.

~~~
Jonah Graham
Kichwa Coders
www.kichwacoders.com


On Thu, 4 Aug 2022 at 03:10, Ridhi Jain <ridhij@xxxxxxxxxxx> wrote:
Thanks, Jonah! 
I had already figured it out.

For anyone else facing a similar issue, here's how I did it:

Get the function declaration for which you want to get the CFG and try these statements.

IASTFunctionDefinition decl = (IASTFunctionDefinition) ast.getDeclarations()[j];
CxxControlFlowGraph graph = new ControlFlowGraphBuilder().build((IASTFunctionDefinition) decl);

You will most likely get the error that  ControlFlowGraphBuilder could not find the class ValueFactory. So you go to the source code for org.eclipse.cdt.codan.cxx.internal.model.cfg.ControlFlowGraphBuilder.java and comment the dependency on ValueFactory. Create a new jar file and include it. This works well if you do not need the information about whether or not a node is a constant. You may write a method to do so explicitly as well. 

The other workaround could be to find the ValueFactory.java and rebuild your jar with it.
 

On Wed, Aug 3, 2022 at 11:04 PM Jonah Graham <jonah@xxxxxxxxxxxxxxxx> wrote:
Hi Ridhi,

I don't have a specific answer for you - but you can look in this direction.

Eclipse CDT includes a feature called Codan (Code analysis) that does use/make (not sure which) CFGs to do some of that analysis. There is an example plug-in called org.eclipse.cdt.codan.ui.cfgview which includes a view to visualize the CFG called ControlFlowGraphView that you can look at to see how it gets the CFG and apply that to your own work.

This archived content on the Wiki may be useful too: https://wiki.eclipse.org/CDT/Archive/designs/StaticAnalysis

HTH,
Jonah


~~~
Jonah Graham
Kichwa Coders
www.kichwacoders.com


On Tue, 26 Jul 2022 at 01:33, Ridhi Jain <ridhij@xxxxxxxxxxx> wrote:
Hi

I want to build a control flow graph of a C/C++ code snippet. I can get the IASTTranslationUnit and can also visit each node in the AST.  However, I could not find any code to generate a CFG for the same code. Can you please help?

Apologies if you have received multiple copies of this question.

--
Thanks 
Ridhi 
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev


--
Thanks 
Ridhi 
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev

Back to the top