ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
system.c File Reference

🍎 macOS system utilities and backtrace symbol resolution More...

Go to the source code of this file.

Functions

int get_binary_file_address_offsets (const void *addr, platform_binary_match_t *matches, int max_matches)
 Get binary that contains address on macOS via dyld.
 

Detailed Description

🍎 macOS system utilities and backtrace symbol resolution

Definition in file macos/system.c.

Function Documentation

◆ get_binary_file_address_offsets()

int get_binary_file_address_offsets ( const void *  addr,
platform_binary_match_t *  matches,
int  max_matches 
)

Get binary that contains address on macOS via dyld.

Iterates through dyld-loaded images to find which one contains the given runtime address. Returns the file offset within that image, which is passed to llvm-symbolizer for symbol resolution.

Parameters
addrRuntime address from backtrace
matchesOutput array for matches (path, offset, is_project_lib)
max_matchesMaximum number of matches to store
Returns
Number of matches found (0, 1, or rarely 2)

Definition at line 54 of file macos/system.c.

54 {
55 int count = 0;
56 uintptr_t addr_int = (uintptr_t)addr;
57
58 uint32_t image_count = _dyld_image_count();
59 for (uint32_t i = 0; i < image_count && count < max_matches; i++) {
60 const char *image_name = _dyld_get_image_name(i);
61 const struct mach_header_64 *header = (const struct mach_header_64 *)_dyld_get_image_header(i);
62 intptr_t slide = _dyld_get_image_vmaddr_slide(i);
63
64 if (!header || !image_name) {
65 continue;
66 }
67
68 // Calculate image size from mach header
69 uint64_t image_size = get_image_size_from_header(header);
70 if (image_size == 0) {
71 continue;
72 }
73
74 // Base address is header address + slide
75 uintptr_t base = (uintptr_t)header + slide;
76 uintptr_t end = base + image_size;
77
78 // Check if address falls within this image
79 if (addr_int >= base && addr_int < end) {
80 strncpy(matches[count].path, image_name, PLATFORM_MAX_PATH_LENGTH - 1);
81 matches[count].path[PLATFORM_MAX_PATH_LENGTH - 1] = '\0';
82 matches[count].file_offset = addr_int - base;
83
84#ifndef NDEBUG
85 log_debug("[macOS dyld] addr=%p matches %s (offset=%lx, base=%p, slide=%ld)", addr, image_name,
86 matches[count].file_offset, (void *)base, slide);
87#endif
88 count++;
89 }
90 }
91
92 return count;
93}
#define PLATFORM_MAX_PATH_LENGTH
Definition system.c:64

References PLATFORM_MAX_PATH_LENGTH.