<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 15, 2019, at 05:57, Vangelis Tsiatsianas via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><font face="SFProText-Medium" class="">[ This question has already been asked in </font><font face="FiraCode-Medium" class=""><span class="">lldb-dev</span></font><font face="SFProText-Medium" class=""> (see attached emails), however it was suggested that I should forward the question to </font><font face="FiraCode-Medium" class=""><span class="">llvm-dev</span></font><font face="SFProText-Medium" class="">, since it is more relevant to MC Disassembler than LLDB. ]</font></font><div class=""><font class=""><span style="caret-color: rgb(0, 0, 0);" class=""><br class=""></span></font></div><div class=""><font class=""><span style="caret-color: rgb(0, 0, 0);" class=""><br class=""></span></font><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class="">Hello,</font></div><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><br class="">I am looking for a way to track memory stores and save both the old and the new value of the memory location being modified using LLDB, as described below:</font></div><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""><b class="">1.</b> Recognize the instructions that <b class="">definitely</b> access memory before they execute, based on their opcode.<br class=""></font></div></div></div></div></blockquote><div><br class=""></div><div>I'm only aware of API's that report the possibility of storing. For example, MCInstrDesc::mayStore(). Whether an instruction with mayStore() actually does store is target specific and can depend on the exact inputs or the state of the processor or memory at the time. For example, an atomic store might depend on the value of memory or a physical register at the time it executes.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><b class="">2.</b> Tell whether each operand is a register or a memory location.<br class=""></font></div></div></div></div></blockquote><div><br class=""></div><div>MCOperandInfo::OperandType can sometimes tell you this but not all targets use it accurately (many get away with OPERAND_UNKNOWN most of the time) so I don't know how useful that will be.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><b class="">3.</b> If itβs a memory location, check whether it is a load or store destination.<br class=""></font></div></div></div></div></blockquote><div><br class=""></div><div>This is target specific and depends on the opcode. As far as I know the MC layer doesn't have API's to determine this. The MIR had some of this information in the MachineMemoryOperand but that information didn't know which operand(s) were involved and is discarded when lowering to the MC layer.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><b class="">4.</b> In case it is a store destination, fetch and save current value from memory.<br class=""></font></div></div></div></div></blockquote><div><br class=""></div><div>The MC layer doesn't know how the address is calculated so it can't tell LLDB which location to fetch. You'd need to implement something that knew how each instruction calculates the address.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><b class="">5.</b> Execute instruction.<br class=""></font></div></div></div></div></blockquote><div><br class=""></div><div>LLDB would presumably handle this bit by single-stepping.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><b class="">6.</b> Fetch and save new value from memory.</font></div></div></div></div></blockquote>This is the same as for 4.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class="">However, I was not able to find a cross-architecture API that covers all of the conditions above and more specifically <font face="FiraCode-Medium" class=""><span class="">Instruction::DoesStore()</span></font> and <font face="FiraCode-Medium" class=""><span class="">Operand::IsStoreDestination()</span></font>.</font></div><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><br class="">Last but not least, I should notice that the target is executed in single-step mode, so I do have control right before and after the execution of every instruction.</font></div><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><br class="">Thank you very much, in advance! π</font></div><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></font></div><div class=""><font style="background-color: rgba(255, 255, 255, 0);" class=""><br class="">β Vangelis</font></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class="">Begin forwarded message:<br class=""><blockquote type="cite" class=""></blockquote><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;"><b class="">From: </b></span><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;">Vangelis Tsiatsianas</span><br class=""><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;"><b class="">Subject: </b></span><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;"><b class="">Re: Identifying instructions that definitely access memory</b></span><br class=""><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;"><b class="">Date: </b></span><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;">5 November 2019 - 14:43:29 EET</span><br class=""><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;"><b class="">To: </b></span><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;">via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>></span><br class=""><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>Hello,<br class=""><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>I decided to try once more with a follow-up email, since my previous one got no responses (I hope itβs not considered rude to send more than one message in a row for a particular question).<br class=""><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>To sum up and clarify my previous question, what I need is a way to track memory stores and save both the old and the new value of the memory location being modified.<br class=""><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>My thinking so far:<br class=""><b class="">1.</b> Recognize the instructions that definitely access memory before they execute, based on their opcode.<br class=""><b class="">2.</b> Tell whether each operand is a register or a memory location.<br class=""><b class="">3.</b> If itβs a memory location, check whether it is a load or store destination.<br class=""><b class="">4.</b> In case it is a store destination, fetch and save current value from memory.<br class=""><b class="">5.</b> Execute instruction.<br class=""><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><b class="">6.</b> Fetch and save new value from memory.<br class=""></div></div></div><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>However, I was not able to find a cross-architecture API that covers all of the conditions above and more specifically <font face="FiraCode-Regular" class=""><span class="">Instruction::DoesStore()</span></font> and <font face="FiraCode-Regular" class=""><span class="">Operand::IsStoreDestination()</span></font>.<br class=""><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>Last but not least, I should notice that the target is executed in single-step mode, so I do have control right before and after the execution of every instruction.<br class=""><font color="#00c8fa" class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>Thanks, again, in advance! π<br class=""><font color="#00c8fa" class=""><br class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font>β Vangelis<br class=""><font color="#00c8fa" class=""><br class=""><span style="caret-color: rgb(0, 200, 250);" class=""><br class=""></span></font><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><div class="">On 21 Oct 2019, at 08:54, Vangelis Tsiatsianas wrote:<br class=""><blockquote type="cite" class=""></blockquote><font color="#57d977" class=""><span style="caret-color: rgb(87, 217, 119);" class=""><br class=""></span></font>Hello,<br class=""><font color="#57d977" class=""><span style="caret-color: rgb(87, 217, 119);" class=""><br class=""></span></font>I am looking for a way to identify loads, stores and any other kind of instruction that <b class="">definitely</b> perform memory access and extract the address operand(s), however I was not able to find a cross-architecture API. The closest I stumbled upon are "<font face="FiraCode-Regular" class=""><span class="">MCInstrDesc::mayLoad()</span></font>" and "<font face="FiraCode-Regular" class=""><span class="">MCInstrDesc::mayStore()</span></font>", but I understand that their results are just a hint, so I would then need to examine the instruction name or opcode in order to find out whether itβs actually a load or store and which operand(s) is (are) memory address(es) and also do so for each architecture separately, which I would really like to avoid.<br class=""><font color="#57d977" class=""><span style="caret-color: rgb(87, 217, 119);" class=""><br class=""></span></font>Is there a way to identify such instructions either by examining them through the disassembler (e.g. "<font face="FiraCode-Regular" class=""><span class="">DoesLoad()</span></font>" | "<font face="FiraCode-Regular" class=""><span class="">DoesStore()</span></font>") before they execute or right after they perform any kind of memory access?<br class=""><font color="#57d977" class=""><span style="caret-color: rgb(87, 217, 119);" class=""><br class=""></span></font>Thank you very much, in advance! π<br class=""><font color="#57d977" class=""><br class=""><span style="caret-color: rgb(87, 217, 119);" class=""><br class=""></span></font>β Vangelis<br class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div></div></div></div></div></div></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>