Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Standalone Software Fault Injector

Hi Gonçalo

 

Well, what are you expecting your code to do and what does it actually do?

 

I see the following problems:

-          The method “mlac” receives a translation unit as argument for “node” (at least in the topmost call). Because that’s not an if-statement I guess, the modification-part is skipped completely. The subsequent calls are for the children. So, the method is crawling the AST recursively. I’d suggest you become familiar with the visitor pattern. But that’s a design issue, not a functional one.

-          When the method reaches an if-statement it removes the node through the ASTWriter (line 65). The modification store is then retrieved from the ASTRewrite with reflection (lines 68-71), ugly but should work. The modification store is printed, which will just be some the default object toString (lines 73-74). Lastly, you create an ASTWriter, set the modification store (with a method, which does not exist – so I guess you have added it and removed the final modifier of the field) and write the code of the previously removed node (lines 76 -79). The expected result would be to receive an empty string as code, because you are writing the node you’ve just removed above. I guess what you actually want, is to write the translation unit, using something like (“writer.write(node.getTranslationUnit())”) instead. This would result in the original code without the if-statement.

 

Does this help?

 

Regards

Thomas

 

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Gonçalo Pereira
Sent: Montag, 27. April 2015 17:58
To: CDT General developers list.
Subject: Re: [cdt-dev] Standalone Software Fault Injector

 

Thanks for the response Thomas.

 

I'm trying to do what you say, but I can't get the code with the modifications. You can review the lines 65 - 79 of anexed file?

 

Many many thanks Thomas!!!

 

 

2015-04-23 7:25 GMT+01:00 Corbat Thomas <tcorbat@xxxxxx>:

Hi Gonçalo

 

I guess you are creating the source code in printTree. The problem hereby is, that it is not possible to change the AST itself. In the ASTRewrite (which I guess is the type of r) just the descriptions of the modifications are collected. With that information the traversal path of the visitor is changed. If you afterwards visit the translation unit by yourself you will see it unchanged.

Yet, the source file you created the source code from should be changed if the “change” is valid.

 

Afaik, there is no convenient way of getting the source code in string form directly. This would be the job of the ASTWriter, which internally uses the ChangeGeneratorWriterVisitor, which in turn depends on an ASTModificationStore. The ASTRewrite uses an ASTModificationStore internally too and that’s the part knowing about the modification descriptions, but unfortunately it is not accessible from outside.

 

It’s not a neat solution, but you could go with reflection. Use the ASTRewrite to create the modification store, extract it by reflection. Create an ASTWriter for your AST, insert the extracted modification store into the ASTWriter, call write().

 

I hope this helps.

Regards

Thomas

 

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Gonçalo Pereira
Sent: Montag, 20. April 2015 18:02
To: CDT General developers list.
Subject: Re: [cdt-dev] Standalone Software Fault Injector

 

Thanks for the responde Thomas.

I have done it with one project, But I have problems with remove nodes from AST.

I do this:

 

r.remove(node, null);

Change change = r.rewriteAST();
change = change.perform(new NullProgressMonitor());
printTree(translationUnit, 1);

But when I Print the translationUnit, I have the same code that I have in begining.

What I'm doing wrong? Who I extract the code from rewriteAST?

Thanks in advance.
Gonçalo Silva Pereira

 

 

2015-04-20 8:01 GMT+01:00 Corbat Thomas <tcorbat@xxxxxx>:

Hi Gonçalo

 

At a glance I would say yes you have to create a project. The exception actually happens because you don’t have an originating translation unit for your AST, which you could set manually. But faking a translation unit might not be that simple. The ChangeFormatter will furthermore try to query the project of the translation unit for its formatter options.

 

In principle I see three options:

1.       Work with a project.

2.       Derive the ChangeGenerator and ASTWriting infrastructure (with your own implementation) to avoid the formatting or do it with default options.

3.       Try to create your own translation unit and cproject classes which just satisfy the required operations, which you could set as originating translation unit for your AST.

If possible I would follow the first option and I would really try to avoid the last two options.

 

I hope this helps!

Regards

Thomas

 

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Gonçalo Pereira
Sent: Freitag, 17. April 2015 15:28
To: CDT General developers list.
Subject: [cdt-dev] Standalone Software Fault Injector

 

Hello,

 

I'm trying to do an software to inject software faults in C programs, using CDT.

 

I have some .c files and read them with:

 

translationUnit = GPPLanguage.getDefault().getASTTranslationUnit(fileContent, info, emptyIncludes, null, opts, log);

 

But, when I try rewrite the AST Tree I get a NullPointException in ChangeFormatter.java:92:

 

// Calculate formatting changes for the regions after the refactoring changes.

                                   ICProject project = tu.getCProject();

 

What is my problem? 

What I'm doing wrong? 

I need to have a project with C files? Is mandatory?

 

Cheers

Gonçalo Silva Pereira


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev

 


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev

 


Back to the top