Error 3 : Dynamic Memory Allocation - 2024.1 English

Vitis Tutorials: Embedded Software (XD260)

Document ID
XD260
Release Date
2024-06-19
Version
2024.1 English

Enable the _ERROR6_ macro in the application source file linux_test_application.c and disable _ERROR3_ and _ERROR5_ as shown below.

//#define _ERROR3_
//#define _ERROR5_
#define _ERROR6_

The goal of dynamic memory allocation debugging is to understand memory management.

  1. Under FLOW, highlight the linux_test_app, and Build.

  2. Under FLOW, highlight the linux_test_app, and Debug to launch a Launch Configuration.

  3. Select, the Target Connection; either physical_zcu102, or qemu_zcu102 and the Work Directory to /home/petalinux`

../../../../_images/launch_config1.PNG

  1. The code stops at the program entry.

  2. Use debugging techniques such as the Variables view, step over, breakpoints, and so on to identify the incorrect memory assignment.

  3. Place a breakpoint at the following lines.

    *ptr = i + 1;
    ptr++;
    
  4. Click Resume and let the tool stop at the breakpoint.

  5. Open Variables view to check the ptr value. Observe that a value is not correctly assigned to a pointer.

  6. Comment out the following code lines:

    #ifdef _ERROR6_
    ................
    ................
    ................
    //ptr = i + 1;
    //ptr++;
    ................
    
  7. Uncomment the following line of code to make the appropriate pointer assignment.

    #ifdef _ERROR6_
    ................
    ................
    ................
    ................
    ptr[i] = i + 1;
    ................
    
  8. Rebuild the application.

  9. Relaunch the Launch Configuration

  10. Observe the output.