On Tue, Apr 15, 2025, at 2:15 PM, Christian Hergert wrote:
> On 4/15/25 09:12, Serhei Makarov wrote:
>> Option 2: expose one function, treat file_name and fd as optional input
>> parameters.
>>
>> // normal use case
>> module_name = "/usr/lib/whatever.so"; /* name of module */
>> file_name = "/proc/PID/root/usr/lib/whatever.so"; /* actual location of
>> module */
>> dwfl_process_tracker_find_cached_elf (tracker, module_name, &file_name,
>> &elf, &fd);
>> /* Since file_name is specified, the dwfl_process_tracker
>> will access the module at file_name, and cache by
>> module_name + dev + ino. */
>
> What allocator owns `file_name`? Can they be const in both directions?
This probably shows my suggested API is unclear
since the input value of file_name is separate from the output value.
(The input value is a const string, owned by the caller, not retained by the
callee.
The output value is a newly allocated string.
Could be made to work, but will be too confusing to document.)
Would be better to add a separate arg. Thus, Option 3:
dwfl_process_tracker_find_cached_elf (tracker,
const char *module_name, /* -> /usr/lib/whatever.so */
const char *module_location, /* -> /proc/PID/root/usr/lib/whatever.so,
or could be NULL if module_name is the valid path */
Dwarf_Addr base,
char **file_name, /* OUTPUT, newly allocated string */
Elf **elfp, /* OUTPUT, elf struct, owned by elfutils */
int *fdp /* OUTPUT, fd, owned by elfutils */);
/* and the corresponding API to save a newly created Elf */
dwfl_process_tracker_cache_elf (tracker,
const char *module_name,
const char *file_name, /* -> /proc/PID/root/usr/lib/whatever.so */
Elf *elf, int fd);
> Is ownership of FD transferred to `dup()`d?
Not sure about the exact meaning of the question.
The relevant code is inside the sysprof_live_process_find_elf callback,
and the FD is returned to the caller of that callback, within Elfutils.
Elfutils handles the FD ownership, so
it should not necessary to duplicate the FD on the Sysprof side,
unless Sysprof wants to use the FD for its own purposes independently
of what Elfutils is doing with it.
--
All the best,
Serhei
http://serhei.io