<div dir="ltr">The overall idea makes sense, especially if there is a real interest from gdb/lldb users. <div>So far __asan_describe_address was the only thing that anyone requested, but we could be proactive too.</div><div>
Please send patches as usual, with tests (compiler-rt/test/asan/TestCases), and preferably in small chunks. </div><div><br></div><div>--kcc </div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 10, 2014 at 6:28 AM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Should probably involve the LLDB developers as well here.</div><div class="gmail_extra"><br><br><div class="gmail_quote">
<div><div class="h5">On Wed, Jul 9, 2014 at 6:13 PM, Kuba Břečka <span dir="ltr"><<a href="mailto:kuba.brecka@gmail.com" target="_blank">kuba.brecka@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">Hi,</span></font></div>
<div>
<font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">I would like to improve the debugging experience for ASan. The idea is to have a couple of useful commands in LLDB (probably implemented as Python scripts) that could help the user when they are debugging an ASan-enabled binary. We already have some debugging API (asan_interface.h):</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Print the description of addr (useful when debugging in gdb).</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    void __asan_describe_address(void *addr);</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">What I'd like to have is a few more API on the ASan/compiler-rt side to query various information that ASan can provide, both about an error report and about general addresses, something like:</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from a debugger to get information about an error.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // If an error has been (or is beign) reported, returns the pc, bp, sp,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // address, access type, access type and bug description, and the return</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // value of the function is 1. If no error occurred yet, returns 0.</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_report_data(void **pc, void **bp, void **sp, void **addr,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">                               int *is_write, size_t *access_size,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">                               char **bug_description);</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Address/memory type from ASan's point of view.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    typedef enum {</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_UNKNOWN,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_SHADOW_LOW,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_SHADOW_GAP,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_SHADOW_HIGH,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_GLOBAL,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_STACK,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_HEAP,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    } asan_address_type;</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get information about a pointer.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Return one of the __ADDRESS_TYPE_* enum values. If global or stack, tries</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // to also return the variable name, address and size. If heap, tries to</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // return the chunk address and size.</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_address_type(void *addr, char **region_name,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">                                void **region_address, size_t *region_size);</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br>



</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get the allocation stack trace</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // and thread ID for a heap address. Returns 1 on success, 0 on error.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_alloc_stack(void *addr, void **trace, size_t *frame_count,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">                               void **top_frame_bp, int *thread_id);</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get the free stack trace</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // and thread ID for a heap address. Returns 1 on success, 0 on error.</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_free_stack(void *addr, void **trace, size_t *frame_count,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">                              void **top_frame_bp, int *thread_id);</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br>



</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get the current shadow memory</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // mapping.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    void __asan_get_shadow_mapping(size_t *shadow_scale, size_t *shadow_offset);</span></font></div><div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">Hi,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">I would like to improve the debugging experience for ASan. The idea is to have a couple of useful commands in LLDB (probably implemented as Python scripts) that could help the user when they are debugging an ASan-enabled binary. We already have some debugging API (asan_interface.h):</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Print the description of addr (useful when debugging in gdb).</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    void __asan_describe_address(void *addr);</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">What I'd like to have is a few more API to query various information that ASan can provide, both about an error report and about general addresses, something like:</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from a debugger to get information about an error.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // If an error has been (or is being) reported, returns the pc, bp, sp,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // address, access type, access type and bug description, and the return</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // value of the function is 1. If no error occurred yet, returns 0.</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_report_data(void **pc, void **bp, void **sp, void **addr,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">                               int *is_write, size_t *access_size,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">                               char **bug_description);</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Address/memory type from ASan's point of view.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    typedef enum {</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_UNKNOWN,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_SHADOW_LOW,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_SHADOW_GAP,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_SHADOW_HIGH,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_GLOBAL,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_STACK,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">      __ADDRESS_TYPE_HEAP,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    } asan_address_type;</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get information about a pointer.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Return one of the __ADDRESS_TYPE_* enum values. If global or stack, tries</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // to also return the variable name, address and size. If heap, tries to</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // return the chunk address and size.</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_address_type(void *addr, char **region_name,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">                                void **region_address, size_t *region_size);</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br>



</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get the allocation stack trace</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // and thread ID for a heap address. Returns 1 on success, 0 on error.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_alloc_stack(void *addr, void **trace, size_t *frame_count,</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">                               void **top_frame_bp, int *thread_id);</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br></span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get the free stack trace</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // and thread ID for a heap address. Returns 1 on success, 0 on error.</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    int __asan_get_free_stack(void *addr, void **trace, size_t *frame_count,</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">                              void **top_frame_bp, int *thread_id);</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px"><br>



</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // Useful for calling from the debugger to get the current shadow memory</span></font></div><div><font color="#000000" face="Helvetica"><span style="font-size:12px">    // mapping.</span></font></div>



<div><font color="#000000" face="Helvetica"><span style="font-size:12px">    void __asan_get_shadow_mapping(size_t *shadow_scale, size_t *shadow_offset);</span></font></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">



<br></div></div></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">The information that this API would provide is currently only available in the textual form in ASan reports. Having an API to provide it would enable implementation of various tools/script for LLDB and GDB.</div>

<span><font color="#888888">
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Kuba</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">


<br></div></font></span></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
<br></blockquote></div><br></div>