From: Olivier Houchard Date: Wed, 28 Oct 2026 17:51:06 +0000 (+0100) Subject: CLEANUP: sym: factor out the short object name extraction X-Git-Tag: v3.5-dev11~94 X-Git-Url: https://git.kaiwu.me/$%7BISSUES%7D/static/gitweb.js?a=commitdiff_plain;h=030ae75ff87b302a646f014751b70f33ad0ae6b0;p=haproxy.git CLEANUP: sym: factor out the short object name extraction dump_sym_lookup() and resolve_dso_name() both keep the part of an object's path between the last '/' and the first following '.'. Introduce append_obj_name() for it and use it in both places. --- diff --git a/src/sym.c b/src/sym.c index 11c601ff6..a3fe65d48 100644 --- a/src/sym.c +++ b/src/sym.c @@ -1609,6 +1609,19 @@ void *get_sym_next_addr(const char *name) #endif /* elf & linux & dl */ +static void append_obj_name(struct buffer *buf, const char *file) +{ + const char *fn = file, *q; + + q = strrchr(fn, '/'); + if (q) + fn = q + 1; + q = strchr(fn, '.'); + if (!q) + q = fn + strlen(fn); + chunk_appendf(buf, "%.*s", (int)(long)(q - fn), fn); +} + /* appends "[obj:]sym[+off[/size]]" for the symbol found for ; the * object prefix (between last '/' and first following '.') is omitted for the * executable or when is zero. @@ -1617,15 +1630,8 @@ static void dump_sym_lookup(struct buffer *buf, const struct sym_lookup *sl, const void *addr, int with_obj) { if (with_obj && !sl->is_exe && sl->file) { - const char *fn = sl->file, *q; - - q = strrchr(fn, '/'); - if (q) - fn = q + 1; - q = strchr(fn, '.'); - if (!q) - q = fn + strlen(fn); - chunk_appendf(buf, "%.*s:", (int)(long)(q - fn), fn); + append_obj_name(buf, sl->file); + chunk_appendf(buf, ":"); } chunk_appendf(buf, "%s", sl->name); @@ -1851,7 +1857,6 @@ const void *resolve_dso_name(struct buffer *buf, const char *pfx, const void *ad #if (defined(__ELF__) && !defined(__linux__)) || defined(USE_DL) Dl_info dli; size_t size; - const char *fname, *p; /* Now let's try to be smarter */ if (!dladdr_and_size(addr, &dli, &size)) @@ -1862,15 +1867,7 @@ const void *resolve_dso_name(struct buffer *buf, const char *pfx, const void *ad pfx = NULL; } - /* keep the part between '/' and '.' */ - fname = dli.dli_fname; - p = strrchr(fname, '/'); - if (p++) - fname = p; - p = strchr(fname, '.'); - if (!p) - p = fname + strlen(fname); - chunk_appendf(buf, "%.*s", (int)(long)(p - fname), fname); + append_obj_name(buf, dli.dli_fname); return addr; unknown: #endif /* __ELF__ && !__linux__ || USE_DL */