MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / elf_user_dump

Function elf_user_dump

components/lwp/lwp_elf.c:101–138  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

99 * @param len Length of the memory region to dump.
100 */
101static 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.

Callers 2

elf_file_mmapFunction · 0.85
elf_load_segmentFunction · 0.85

Calls 5

rt_kprintfFunction · 0.85
rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
lwp_data_getFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected