This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to debug through malloc function?

Hi All,

I am using EFM32GG11 cpu and have problem with malloc function. It crashes on the first call.

I have specified stack and heap areas in the scatter file.

I would like to debug through malloc function. I am using the standart C library linked to my keil MDK 5 project,

How could i build c runtime and link it to my project?

Thanks,

Parents
  • What the plumbing looks like

    From .MAP
        HEAP                                     0x20002c50   Section     8192  startup_stm32l432xx.o(HEAP)
    
    ...
    
        __microlib_freelist                      0x20000004   Data           4  mvars.o(.data)
        __microlib_freelist_initialised          0x20000008   Data           4  mvars.o(.data)
    
    ...
        __heap_base                              0x20002c50   Data           0  startup_stm32l432xx.o(HEAP)
        __heap_limit                             0x20004c50   Data           0  startup_stm32l432xx.o(HEAP)
        __initial_sp                             0x20005450   Data           0  startup_stm32l432xx.o(STACK)
    
    FromELF Listing
    
        i.malloc
        malloc
            0x08006f2c:    b5f0        ..      PUSH     {r4-r7,lr}
            0x08006f2e:    300b        .0      ADDS     r0,r0,#0xb
            0x08006f30:    4d15        .M      LDR      r5,[pc,#84] ; [0x8006f88] = 0x20000008
            0x08006f32:    f0200107     ...    BIC      r1,r0,#7
            0x08006f36:    2400        .$      MOVS     r4,#0
            0x08006f38:    4a14        .J      LDR      r2,[pc,#80] ; [0x8006f8c] = 0x20000004
            0x08006f3a:    e00f        ..      B        0x8006f5c ; malloc + 48
            0x08006f3c:    6803        .h      LDR      r3,[r0,#0]
            0x08006f3e:    428b        .B      CMP      r3,r1
            0x08006f40:    d30b        ..      BCC      0x8006f5a ; malloc + 46
            0x08006f42:    428b        .B      CMP      r3,r1
            0x08006f44:    d905        ..      BLS      0x8006f52 ; malloc + 38
            0x08006f46:    1a5e        ^.      SUBS     r6,r3,r1
            0x08006f48:    1843        C.      ADDS     r3,r0,r1
            0x08006f4a:    6847        Gh      LDR      r7,[r0,#4]
            0x08006f4c:    e9c36700    ...g    STRD     r6,r7,[r3,#0]
            0x08006f50:    e000        ..      B        0x8006f54 ; malloc + 40
            0x08006f52:    6843        Ch      LDR      r3,[r0,#4]
            0x08006f54:    6013        .`      STR      r3,[r2,#0]
            0x08006f56:    c002        ..      STM      r0!,{r1}
            0x08006f58:    e004        ..      B        0x8006f64 ; malloc + 56
            0x08006f5a:    1d02        ..      ADDS     r2,r0,#4
            0x08006f5c:    6810        .h      LDR      r0,[r2,#0]
            0x08006f5e:    2800        .(      CMP      r0,#0
            0x08006f60:    d1ec        ..      BNE      0x8006f3c ; malloc + 16
            0x08006f62:    4620         F      MOV      r0,r4
            0x08006f64:    2800        .(      CMP      r0,#0
            0x08006f66:    d102        ..      BNE      0x8006f6e ; malloc + 66
            0x08006f68:    6828        (h      LDR      r0,[r5,#0]
            0x08006f6a:    b108        ..      CBZ      r0,0x8006f70 ; malloc + 68
            0x08006f6c:    2000        .       MOVS     r0,#0
            0x08006f6e:    bdf0        ..      POP      {r4-r7,pc}
            0x08006f70:    4a06        .J      LDR      r2,[pc,#24] ; [0x8006f8c] = 0x20000004
            0x08006f72:    4807        .H      LDR      r0,[pc,#28] ; [0x8006f90] = 0x20002c54
            0x08006f74:    6010        .`      STR      r0,[r2,#0]
            0x08006f76:    4a07        .J      LDR      r2,[pc,#28] ; [0x8006f94] = 0x20004c50
            0x08006f78:    1a12        ..      SUBS     r2,r2,r0
            0x08006f7a:    f0220207    "...    BIC      r2,r2,#7
            0x08006f7e:    e9c02400    ...$    STRD     r2,r4,[r0,#0]
            0x08006f82:    2001        .       MOVS     r0,#1
            0x08006f84:    6028        (`      STR      r0,[r5,#0]
            0x08006f86:    e7d7        ..      B        0x8006f38 ; malloc + 12
        $d
            0x08006f88:    20000008    ...     DCD    536870920 __microlib_freelist_initialised
            0x08006f8c:    20000004    ...     DCD    536870916 __microlib_freelist
            0x08006f90:    20002c54    T,.     DCD    536882260 __heapbase + 4
            0x08006f94:    20004c50    PL.     DCD    536890448 __heaplimit
        $t
    

Reply
  • What the plumbing looks like

    From .MAP
        HEAP                                     0x20002c50   Section     8192  startup_stm32l432xx.o(HEAP)
    
    ...
    
        __microlib_freelist                      0x20000004   Data           4  mvars.o(.data)
        __microlib_freelist_initialised          0x20000008   Data           4  mvars.o(.data)
    
    ...
        __heap_base                              0x20002c50   Data           0  startup_stm32l432xx.o(HEAP)
        __heap_limit                             0x20004c50   Data           0  startup_stm32l432xx.o(HEAP)
        __initial_sp                             0x20005450   Data           0  startup_stm32l432xx.o(STACK)
    
    FromELF Listing
    
        i.malloc
        malloc
            0x08006f2c:    b5f0        ..      PUSH     {r4-r7,lr}
            0x08006f2e:    300b        .0      ADDS     r0,r0,#0xb
            0x08006f30:    4d15        .M      LDR      r5,[pc,#84] ; [0x8006f88] = 0x20000008
            0x08006f32:    f0200107     ...    BIC      r1,r0,#7
            0x08006f36:    2400        .$      MOVS     r4,#0
            0x08006f38:    4a14        .J      LDR      r2,[pc,#80] ; [0x8006f8c] = 0x20000004
            0x08006f3a:    e00f        ..      B        0x8006f5c ; malloc + 48
            0x08006f3c:    6803        .h      LDR      r3,[r0,#0]
            0x08006f3e:    428b        .B      CMP      r3,r1
            0x08006f40:    d30b        ..      BCC      0x8006f5a ; malloc + 46
            0x08006f42:    428b        .B      CMP      r3,r1
            0x08006f44:    d905        ..      BLS      0x8006f52 ; malloc + 38
            0x08006f46:    1a5e        ^.      SUBS     r6,r3,r1
            0x08006f48:    1843        C.      ADDS     r3,r0,r1
            0x08006f4a:    6847        Gh      LDR      r7,[r0,#4]
            0x08006f4c:    e9c36700    ...g    STRD     r6,r7,[r3,#0]
            0x08006f50:    e000        ..      B        0x8006f54 ; malloc + 40
            0x08006f52:    6843        Ch      LDR      r3,[r0,#4]
            0x08006f54:    6013        .`      STR      r3,[r2,#0]
            0x08006f56:    c002        ..      STM      r0!,{r1}
            0x08006f58:    e004        ..      B        0x8006f64 ; malloc + 56
            0x08006f5a:    1d02        ..      ADDS     r2,r0,#4
            0x08006f5c:    6810        .h      LDR      r0,[r2,#0]
            0x08006f5e:    2800        .(      CMP      r0,#0
            0x08006f60:    d1ec        ..      BNE      0x8006f3c ; malloc + 16
            0x08006f62:    4620         F      MOV      r0,r4
            0x08006f64:    2800        .(      CMP      r0,#0
            0x08006f66:    d102        ..      BNE      0x8006f6e ; malloc + 66
            0x08006f68:    6828        (h      LDR      r0,[r5,#0]
            0x08006f6a:    b108        ..      CBZ      r0,0x8006f70 ; malloc + 68
            0x08006f6c:    2000        .       MOVS     r0,#0
            0x08006f6e:    bdf0        ..      POP      {r4-r7,pc}
            0x08006f70:    4a06        .J      LDR      r2,[pc,#24] ; [0x8006f8c] = 0x20000004
            0x08006f72:    4807        .H      LDR      r0,[pc,#28] ; [0x8006f90] = 0x20002c54
            0x08006f74:    6010        .`      STR      r0,[r2,#0]
            0x08006f76:    4a07        .J      LDR      r2,[pc,#28] ; [0x8006f94] = 0x20004c50
            0x08006f78:    1a12        ..      SUBS     r2,r2,r0
            0x08006f7a:    f0220207    "...    BIC      r2,r2,#7
            0x08006f7e:    e9c02400    ...$    STRD     r2,r4,[r0,#0]
            0x08006f82:    2001        .       MOVS     r0,#1
            0x08006f84:    6028        (`      STR      r0,[r5,#0]
            0x08006f86:    e7d7        ..      B        0x8006f38 ; malloc + 12
        $d
            0x08006f88:    20000008    ...     DCD    536870920 __microlib_freelist_initialised
            0x08006f8c:    20000004    ...     DCD    536870916 __microlib_freelist
            0x08006f90:    20002c54    T,.     DCD    536882260 __heapbase + 4
            0x08006f94:    20004c50    PL.     DCD    536890448 __heaplimit
        $t
    

Children
No data