<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="">Thank you for your thorough and timely response, Pavel! 🙂<div class=""><br class=""></div><div class="">Your suggestions might actually cover completely what I am attempting to achieve. </div><div class=""><br class=""></div><div class="">Unfortunately, I am not able to disclose the exact reason I need it, but I want to track all heap writes, in order to detect modifications in the heap and save both the old and the newly written value.</div><div class=""><br class=""></div><div class="">For now, this translates to tracking common x86 assembly instructions (<font face="FiraCode-Regular" class=""><span style="font-style: normal;" class="">mov{l, w, d, q}</span></font>) for a single thread ―supporting more “exotic” instructions like SIMD, multiple architectures or threads is not currently a goal.</div><div class=""><br class=""></div><div class="">Another method could also be an <span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">LLVM</span> instrumentation <span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">pass,</span> however I would like to avoid recompiling and modifying the binary, thus I focus on LLDB, even if I end up missing a few writes that way.</div><div class=""><br class=""></div><div class="">I was initially looking for a more complete, cross-platform solution (see: <a href="http://lists.llvm.org/pipermail/llvm-dev/2019-November/136876.html" class="">http://lists.llvm.org/pipermail/llvm-dev/2019-November/136876.html</a>), but the solution proved to be too time consuming for the timeframe I have available for my master’s (ending in March).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">― Vangelis</div><div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 7 Feb 2020, at 01:20, Pavel Labath <<a href="mailto:labath@google.com" class="">labath@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">In general, getting this kind of information is pretty hard, so lldb does not offer you an out-of-the-box solution for it, but it does give you tools which you can use to approximate that.<div class=""><br class=""></div><div class="">If I wanted to do something like this, the first thing I'd try to do is run "image lookup -a 0xaddr". If this doesn't return anything then the address does not correspond to any known module. This rules out code, global variables, and similar. Then you can run through all of the threads and do a "memory region $SP", which will give you bounds of the memory allocation around the stack pointer. If your address is in one of these ranges, then it's a stack address. Otherwise, it's probably heap (though you can never be 100% sure of that).</div><div class=""><br class=""></div><div class="">However, it's not fully clear to me what it is that you're trying to do here. Maybe if you explain the higher level problem that you're trying to solve, we can come up with a better solution.</div><div class=""><br class=""></div><div class="">pl</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 6 Feb 2020 at 07:40, Vangelis Tsiatsianas via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi everyone,<br class="">
<br class="">
I am looking for a way to tell whether a memory address belongs to the heap or not.<br class="">
<br class="">
In other words, I would like to make sure that the address does not reside within any stack frame (even if the stack of the thread has been allocated in the heap) and that it’s not a global variable or instruction.<br class="">
<br class="">
Checking whether it is a valid or correctly allocated address or a memory-mapped file or register is not a goal, so accessing it in order to decide, at the risk of causing a segmentation fault, is an accepted solution.<br class="">
<br class="">
I have been thinking of manually checking the address against the boundaries of each active stack frame, the start and end of the instruction segment and the locations of all global variables.<br class="">
<br class="">
However, I would like to ask where there are better ways to approach this problem in LLDB.<br class="">
<br class="">
Thank you very much, advance! 🙂<br class="">
<br class="">
<br class="">
― Vangelis<br class="">
<br class="">
_______________________________________________<br class="">
lldb-dev mailing list<br class="">
<a href="mailto:lldb-dev@lists.llvm.org" target="_blank" class="">lldb-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>