* @brief Dump the contents of a user-space memory region for debugging. * * This function reads and prints the contents of a specified user-space memory region * in hexadecimal format. It is primarily used for debugging ELF loading and execution. * * @param lwp Pointer to the Light Weight Process (LWP) structure. * @param va Virtual address of the memory region to dump. * @param len Length
| 99 | * @param len Length of the memory region to dump. |
| 100 | */ |
| 101 | static void elf_user_dump(struct rt_lwp *lwp, void *va, size_t len) |
| 102 | { |
| 103 | #ifdef ELF_DEBUG_DUMP |
| 104 | uint8_t *k_va; |
| 105 | int ret; |
| 106 | |
| 107 | if (len < 16) |
| 108 | len = 16; |
| 109 | rt_kprintf("\r\n"); |
| 110 | rt_kprintf("%s : user va : %p, len : 0x%x(%d)\n", __func__, va, len, len); |
| 111 | k_va = rt_malloc(len); |
| 112 | if (k_va == RT_NULL) |
| 113 | { |
| 114 | rt_kprintf("%s : malloc failed\n", __func__); |
| 115 | return; |
| 116 | } |
| 117 | rt_memset(k_va, 0, len); |
| 118 | |
| 119 | ret = lwp_data_get(lwp, k_va, va, len); |
| 120 | if (ret != len) |
| 121 | { |
| 122 | rt_kprintf("%s : lwp_get_from_user failed, ret = %d\n", __func__, ret); |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | rt_kprintf("%s : k_va : %p\n", __func__, k_va); |
| 127 | |
| 128 | for (size_t i = 0; i < len; i += 16) |
| 129 | { |
| 130 | rt_kprintf(" %02x %02x %02x %02x %02x %02x %02x %02x ", k_va[i], k_va[i+1], k_va[i+2], k_va[i+3], |
| 131 | k_va[i+4], k_va[i+5], k_va[i+6], k_va[i+7]); |
| 132 | rt_kprintf(" %02x %02x %02x %02x %02x %02x %02x %02x \n", k_va[i+8], k_va[i+9], k_va[i+10], k_va[i+11], |
| 133 | k_va[i+12], k_va[i+13], k_va[i+14], k_va[i+15]); |
| 134 | } |
| 135 | rt_kprintf("\r\n"); |
| 136 | rt_free(k_va); |
| 137 | #endif |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @brief Generate a random offset for ELF loading. |
no test coverage detected