178 {
179 fprintf(
stream,
"memory tracker debug (%zu bytes) at %p ",
size, addr);
180#if defined(MSAN_ON)
181 fprintf(
stream,
"[MSAN]: ")
182
183 for (
size_t i = 0; i <
size; i++) {
184 fprintf(
stream,
"\n%p: ", (
char*)addr + i);
185 if (__msan_test_shadow((char*)addr + i, 1) == -1) {
186 fprintf(
stream,
"U [%02x]", *((
unsigned char*)addr + i));
187 } else {
188 fprintf(
stream,
"I [%02x]", *((
unsigned char*)addr + i));
189 }
190 }
191#elif defined(ASAN_ON)
192
193 char* addr_start = (char*)addr;
194 char* addr_end = addr_start +
size;
195 char* granule_base = (char*)((uintptr_t)addr & ~0x7);
196 char* granule_end =
197 (
char*)(((uintptr_t)addr +
size + 7) & ~0x7);
198
199 fprintf(
stream,
"[ASAN]:");
201 "\ndisplaying each 8 byte grandule (asan tracks poisoning as 0-8 bytes from the end)");
204 for (size_t b = 0; b < 8; b++) {
205 fprintf(
stream,
" %lu ", b);
206 }
208 for (char* p = granule_base; p < granule_end; p += 8) {
209 fprintf(
stream,
"%p: ", p);
210 for (char* b = p; b < p + 8; b++) {
211 bool const poisoned = __asan_region_is_poisoned(b, 1);
212 bool const in_selected = (b >= addr_start && b < addr_end);
213 uint8_t value;
214 if (poisoned) {
215 __asan_unpoison_memory_region(b, 1);
216 value = *b;
217 __asan_poison_memory_region(b, 1);
218 } else {
219 value = *b;
220 }
221
222 char const status = poisoned ? 'P' : 'U';
223
224 if (in_selected) {
225 fprintf(
stream,
"[%c|%02x] ", status, value);
226 } else {
227 fprintf(
stream,
"|%c|%02x| ", status, value);
228 }
229 }
231 }
232#else
233 fprintf(
stream,
"[NO TRACKING]");
234 (void)addr;
236#endif
238}
static FILE * stream(SELF *self)
Opens a file for.