[Lldb-commits] Question about IRMemoryMap Malloc
    Kopec, Matt 
    matt.kopec at intel.com
       
    Wed Apr 24 14:02:24 PDT 2013
    
    
  
Hi Sean,
Can you explain what is being achieved with this line in IRMemoryMap::Malloc?
239    size_t          allocation_size = (size ? size : 1) + alignment - 1;  
If this is attempting size alignment, it's incorrect. It looks like additional bytes are being set for the allocation size for some reason? This is causing problems on Linux and some expressions are exhibiting strange behaviour, for instance:
Current executable set to 'a.out' (x86_64).
(lldb) b main
Breakpoint 1: where = a.out`main + 30 at main.cpp:14, address = 0x000000000040065e
(lldb) r
Process 21544 launched: '/home/mkopec1/dev/llvm/tools/lldb/test/expression_command/test/a.out' (x86_64)
Process 21544 stopped
* thread #1: tid = 0x5428, 0x000000000040065e a.out`main(argc=1, argv=0x00007fff914a0fe8) + 30 at main.cpp:14, stop reason = breakpoint 1.1
    frame #0: 0x000000000040065e a.out`main(argc=1, argv=0x00007fff914a0fe8) + 30 at main.cpp:14
   11  	
   12  	int main (int argc, char const *argv[])
   13  	{
-> 14  	    printf ("Hello world!\n");
   15  	    puts ("hello");
   16  	    // Please test many expressions while stopped at this line:
   17  	#if 0
(lldb) expression (int*)argv                                                                                                                                                                                         
(int *) $0 = 0x00007fff914a0fe8
(lldb) expression ((char**)environ)[0]                                                                                                                                                                               
(char *) $1 = 0x00007fff914a13b9 "SSH_AGENT_PID=1921"
(lldb) expression int i = 5; i                                                                                                                                                                                       
(int) $2 = 5
(lldb) expression $2 + 1                                                                                                                                                                                             
(int) $3 = 32531
(lldb)
The value of $3 is wrong. I did a little debugging and it looks like some allocated data is getting overwritten incorrectly during execution.  However, if I align the size requested in Malloc, it works fine on Linux. It just so happens this case I've tested, the sizes were already aligned.
Any thoughts?
Thanks,
Matt
    
    
More information about the lldb-commits
mailing list