<div dir="ltr">Should probably involve the LLDB developers as well here.</div><div class="gmail_extra"><br><br><div class="gmail_quote">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>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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 class="HOEnZb"><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>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">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>