C++ operator 'new' causing lpc2138 to abort

Comments

4 comments

  • Avatar
    Jon Elliott

    Check that you've allocated enough heap to store the object.

    See http://rowley.zendesk.com/entries/46159-change-the-heap-size-of-my-application for a description of how you specify the heap size.

    0
    Comment actions Permalink
  • Avatar
    Michael Woods

    I have increased the heap size to 8kB, which is much more than enough, but it is still not working.

     

    I have stepped throught the assembly code to where it looks like it enters an infinite loop. The infinite loop appears to start inside the <malloc> subroutine that is in the assembly code, and I am able to step throught the code until the instruction

     

    ldr r3, [r0, #+0x004] //is called

     

    here is the entire malloc subroutine in assembly code;

    <malloc>:
           E52DE004   str lr, [sp, #-0x004]!
           E1A02000   mov r2, r0
           E59F30B4   ldr r3, [pc, #+0x0B4]
           E5930000   ldr r0, [r3]
           E3500000   cmp r0, #0x00000000
           0A000027   beq 0x00001AAC
           E2823013   add r3, r2, #0x00000013
           E3C3100F   bic r1, r3, #0x0000000F
           E5903004   ldr r3, [r0, #+0x004]   <---- infinite loop appears to start here
           E1510003   cmp r1, r3
           11A02000   movne r2, r0
           13A0E000   movne lr, #0x00000000
           13E0C000   mvnne r12, #0x00000000
           1A00000D   bne 0x00001A64
           EA000006   b 0x00001A4C
           E5903004   ldr r3, [r0, #+0x004]
           E1510003   cmp r1, r3
           1A000008   bne 0x00001A60
           E3520000   cmp r2, #0x00000000
           15903000   ldrne r3, [r0]
           15823000   strne r3, [r2]
           1A000002   bne 0x00001A58
           E5902000   ldr r2, [r0]
           E59F3060   ldr r3, [pc, #+0x060]
           E5832000   str r2, [r3]
           E4801004   str r1, [r0], #+0x004
           EA000013   b 0x00001AB0
           E1A02000   mov r2, r0
           E1510003   cmp r1, r3
           2A000002   bcs 0x00001A78
           E15C0003   cmp r12, r3
           81A0E002   movhi lr, r2
           81A0C003   movhi r12, r3
           E5920000   ldr r0, [r2]
           E3500000   cmp r0, #0x00000000
           1AFFFFEA   bne 0x00001A30
           E35E0000   cmp lr, #0x00000000
           0A000007   beq 0x00001AAC
           E59E3004   ldr r3, [lr, #+0x004]
           E0613003   rsb r3, r1, r3
           E58E3004   str r3, [lr, #+0x004]
           E061300C   rsb r3, r1, r12
           E083200E   add r2, r3, lr
           E783100E   str r1, [r3, +lr]
           E2820004   add r0, r2, #0x00000004
           EA000000   b 0x00001AB0
           E3A00000   mov r0, #0x00000000
           E49DE004   ldr lr, [sp], #+0x004
           E12FFF1E   bx lr
           4000003C   andmi r0, r0, r12, lsr r0

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    Suggest that the heap's been corrupted if malloc() doesn't work, it the first descriptor for it has not been set up correctly from the startup code, or that the heap section isn't correctly aligned to a word boundary.

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    The source code of malloc is provide in the $(StuioDir)/source directory add it to your project if you think there is a problem with it.

    0
    Comment actions Permalink

Please sign in to leave a comment.