<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="">Hello Daniel,<div class=""><br class=""></div><div class="">Thank you very much for your insightful answer!<br class=""><div class=""><br class=""></div><div class="">Unfortunately, the situation regarding <b class="">1 - 4</b> seems worse (regarding what Iβm looking for) than I expected.</div><div class=""><br class=""></div><div class="">It would be really nice if the target backends provided at least the information currently available (e.g. <font face="FiraCode-Medium" class=""><span style="font-style: normal;" class="">MCOperandInfo::OperandType</span></font>), since it would be helpful for gaining more insights about machine code and thus allowing for more kinds of new features and plugins, e.g., by tracking and analyzing memory accesses.</div><div class=""><br class=""></div><div class="">Is there any chance you (or anyone on the list) are aware of a disassembly library that provides such information either for at least x86 or ARM (64-bit for both platforms)? π</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">β Vangelis</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 18 Nov 2019, at 23:40, Daniel Sanders <<a href="mailto:daniel_l_sanders@apple.com" class="">daniel_l_sanders@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="caret-color: rgb(0, 0, 0); font-family: SFProText-Regular; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="Apple-interchange-newline"><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=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><font class="" style="background-color: rgba(255, 255, 255, 0);"><font face="SFProText-Medium" class="">[ This question has already been asked in<span class="Apple-converted-space"> </span></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<span class="Apple-converted-space"> </span></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 class="" style="caret-color: rgb(0, 0, 0);"><br class=""></span></font></div><div class=""><font class=""><span class="" style="caret-color: rgb(0, 0, 0);"><br class=""></span></font><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);">Hello,</font></div><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><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 class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""><b class="">1.</b><span class="Apple-converted-space"> </span>Recognize the instructions that<span class="Apple-converted-space"> </span><b class="">definitely</b><span class="Apple-converted-space"> </span>access memory before they execute, based on their opcode.<br class=""></font></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><b class="">2.</b><span class="Apple-converted-space"> </span>Tell whether each operand is a register or a memory location.<br class=""></font></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><b class="">3.</b><span class="Apple-converted-space"> </span>If itβs a memory location, check whether it is a load or store destination.<br class=""></font></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><b class="">4.</b><span class="Apple-converted-space"> </span>In case it is a store destination, fetch and save current value from memory.<br class=""></font></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><b class="">5.</b><span class="Apple-converted-space"> </span>Execute instruction.<br class=""></font></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">LLDB would presumably handle this bit by single-stepping.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><b class="">6.</b><span class="Apple-converted-space"> </span>Fetch and save new value from memory.</font></div></div></div></div></blockquote>This is the same as for 4.</div><div style="caret-color: rgb(0, 0, 0); font-family: SFProText-Regular; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);">However, I was not able to find a cross-architecture API that covers all of the conditions above and more specifically<span class="Apple-converted-space"> </span><font face="FiraCode-Medium" class=""><span class="">Instruction::DoesStore()</span></font><span class="Apple-converted-space"> </span>and<span class="Apple-converted-space"> </span><font face="FiraCode-Medium" class=""><span class="">Operand::IsStoreDestination()</span></font>.</font></div><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><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 class="" style="background-color: rgba(255, 255, 255, 0);"><br class="">Thank you very much, in advance! π</font></div><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></font></div><div class=""><font class="" style="background-color: rgba(255, 255, 255, 0);"><br class="">β Vangelis</font></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class="">Begin forwarded message:<br class=""><blockquote type="cite" class=""></blockquote><font color="#00c8fa" class=""><span class="" style="caret-color: rgb(0, 200, 250);"><br class=""></span></font><span class="" style="font-family: -webkit-system-font, "Helvetica Neue", Helvetica, sans-serif;"><b class="">From:<span class="Apple-converted-space"> </span></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:<span class="Apple-converted-space"> </span></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:<span class="Apple-converted-space"> </span></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:<span class="Apple-converted-space"> </span></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 class="" style="caret-color: rgb(0, 200, 250);"><br class=""></span></font>Hello,<br class=""><font color="#00c8fa" class=""><span class="" style="caret-color: rgb(0, 200, 250);"><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 class="" style="caret-color: rgb(0, 200, 250);"><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 class="" style="caret-color: rgb(0, 200, 250);"><br class=""></span></font>My thinking so far:<br class=""><b class="">1.</b><span class="Apple-converted-space"> </span>Recognize the instructions that definitely access memory before they execute, based on their opcode.<br class=""><b class="">2.</b><span class="Apple-converted-space"> </span>Tell whether each operand is a register or a memory location.<br class=""><b class="">3.</b><span class="Apple-converted-space"> </span>If itβs a memory location, check whether it is a load or store destination.<br class=""><b class="">4.</b><span class="Apple-converted-space"> </span>In case it is a store destination, fetch and save current value from memory.<br class=""><b class="">5.</b><span class="Apple-converted-space"> </span>Execute instruction.<br class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><b class="">6.</b><span class="Apple-converted-space"> </span>Fetch and save new value from memory.<br class=""></div></div></div><font color="#00c8fa" class=""><span class="" style="caret-color: rgb(0, 200, 250);"><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 class="" style="caret-color: rgb(0, 200, 250);"><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 class="" style="caret-color: rgb(0, 200, 250);"><br class=""></span></font>Thanks, again, in advance! π<br class=""><font color="#00c8fa" class=""><br class=""><span class="" style="caret-color: rgb(0, 200, 250);"><br class=""></span></font>β Vangelis<br class=""><font color="#00c8fa" class=""><br class=""><span class="" style="caret-color: rgb(0, 200, 250);"><br class=""></span></font><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><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 class="" style="caret-color: rgb(87, 217, 119);"><br class=""></span></font>Hello,<br class=""><font color="#57d977" class=""><span class="" style="caret-color: rgb(87, 217, 119);"><br class=""></span></font>I am looking for a way to identify loads, stores and any other kind of instruction that<span class="Apple-converted-space"> </span><b class="">definitely</b><span class="Apple-converted-space"> </span>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 class="" style="caret-color: rgb(87, 217, 119);"><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 class="" style="caret-color: rgb(87, 217, 119);"><br class=""></span></font>Thank you very much, in advance! π<br class=""><font color="#57d977" class=""><br class=""><span class="" style="caret-color: rgb(87, 217, 119);"><br class=""></span></font>β Vangelis<br class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><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=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div></div></blockquote></div><br class=""></div></div></body></html>