<div dir="ltr">Hi, Andres,<div><br></div><div>If I understand correctly, you need to first traverse the module, function, bbs and then detect the instructions that you want to modify. You can use the getOpcode() or getOpcodeName() to detect the instruction that you want to modify. Then you need to know which operand you want to modify. You can use getOperand(i) to get the ith operand of one instruction, and then use setOperand(i, new_value) to set the new operand. You can see the examples from the links in your email.</div><div><br></div><div>But all these are done in IR level. In the assembly, these instructions could be deleted/modified/optimized.</div><div><br></div><div>Regards,</div><div><br></div><div>Xiangyang</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-12-10 0:06 GMT-05:00 Andres Torres Garcia via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div dir="ltr">


<div dir="ltr"><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)">Hi,</p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><br></p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)">I want to use LLVM to make a dynamic fault injection. My primary goal is to modify the value of a particular register in a particular instruction  and do, for example, bit flipping on that register.</p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><br></p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)">I've studying some tutorials and codes about LLVM but I'm still not sure how to begin with. I know that I need to program a LLVM pass that iterates over blocks and check which instruction modify to later check which operand in that instruction modify. Is that the correct?</p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><br></p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)">I've seen some examples but all of them seem very complicated (a lot of code) to understand for a beginner like me. I wonder if there is an easier example to understand or if you can provide me with one to start with.</p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><br></p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)">Thank you very much for your help!</p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><br></p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)">Best,</p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><br></p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)">Examples that I haven't understood:</p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><a href="https://github.com/aperson40/FlipIt/blob/master/src/pass/faults.cpp" target="_blank">https://github.com/aperson40/FlipIt/blob/master/src/pass/faults.cpp</a></p><p style="margin-bottom:1em;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px;background-color:rgb(255,255,255)"><a href="https://github.com/uswick/sight/blob/bd07a3c8592cf073366c76961479f25be1f8d83d/widgets/kulfi/faultInj/faults.cpp" target="_blank">https://github.com/uswick/sight/blob/bd07a3c8592cf073366c76961479f25be1f8d83d/widgets/kulfi/faultInj/faults.cpp</a></p></div>
                                          </div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>