Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Apr 2022 01:25:26 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: bd36c568070b - stable/13 - rtld: extract printer for a single traced object into a helper
Message-ID:  <202204080125.2381PQuR095141@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=bd36c568070b7c3794f964e9315d2c41ff3f5c15

commit bd36c568070b7c3794f964e9315d2c41ff3f5c15
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-03-30 20:46:21 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-04-08 01:25:17 +0000

    rtld: extract printer for a single traced object into a helper
    
    (cherry picked from commit 24d0c9c1f565bab6e97ec629f223e85b18bc700a)
---
 libexec/rtld-elf/rtld.c | 118 ++++++++++++++++++++++++------------------------
 1 file changed, 58 insertions(+), 60 deletions(-)

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index f0263ec487d4..a73dc5e5d350 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -4981,11 +4981,66 @@ trace_calc_fmts(const char **main_local, const char **fmt1, const char **fmt2)
 		*fmt2 = "\t%o (%x)\n";
 }
 
+static void
+trace_print_obj(Obj_Entry *obj, const char *name, const char *path,
+    const char *main_local, const char *fmt1, const char *fmt2)
+{
+	const char *fmt;
+	int c;
+
+	fmt = strncmp(name, "lib", 3) == 0 ? fmt1 : fmt2;	/* XXX bogus */
+	while ((c = *fmt++) != '\0') {
+		switch (c) {
+		default:
+			rtld_putchar(c);
+			continue;
+		case '\\':
+			switch (c = *fmt) {
+			case '\0':
+				continue;
+			case 'n':
+				rtld_putchar('\n');
+				break;
+			case 't':
+				rtld_putchar('\t');
+				break;
+			}
+			break;
+		case '%':
+			switch (c = *fmt) {
+			case '\0':
+				continue;
+			case '%':
+			default:
+				rtld_putchar(c);
+				break;
+			case 'A':
+				rtld_putstr(main_local);
+				break;
+			case 'a':
+				rtld_putstr(obj_main->path);
+				break;
+			case 'o':
+				rtld_putstr(name);
+				break;
+			case 'p':
+				rtld_putstr(path);
+				break;
+			case 'x':
+				rtld_printf("%p", obj != NULL ?
+				    obj->mapbase : NULL);
+				break;
+			}
+			break;
+		}
+		++fmt;
+	}
+}
+
 static void
 trace_loaded_objects(Obj_Entry *obj)
 {
-    const char *fmt1, *fmt2, *fmt, *main_local, *list_containers;
-    int c;
+    const char *fmt1, *fmt2, *main_local, *list_containers;
 
     trace_calc_fmts(&main_local, &fmt1, &fmt2);
     list_containers = ld_get_env_var(LD_TRACE_LOADED_OBJECTS_ALL);
@@ -4993,7 +5048,6 @@ trace_loaded_objects(Obj_Entry *obj)
     for (; obj != NULL; obj = TAILQ_NEXT(obj, next)) {
 	Needed_Entry *needed;
 	const char *name, *path;
-	bool is_lib;
 
 	if (obj->marker)
 	    continue;
@@ -5009,63 +5063,7 @@ trace_loaded_objects(Obj_Entry *obj)
 		path = "not found";
 
 	    name = obj->strtab + needed->name;
-	    is_lib = strncmp(name, "lib", 3) == 0;	/* XXX - bogus */
-
-	    fmt = is_lib ? fmt1 : fmt2;
-	    while ((c = *fmt++) != '\0') {
-		switch (c) {
-		default:
-		    rtld_putchar(c);
-		    continue;
-		case '\\':
-		    switch (c = *fmt) {
-		    case '\0':
-			continue;
-		    case 'n':
-			rtld_putchar('\n');
-			break;
-		    case 't':
-			rtld_putchar('\t');
-			break;
-		    }
-		    break;
-		case '%':
-		    switch (c = *fmt) {
-		    case '\0':
-			continue;
-		    case '%':
-		    default:
-			rtld_putchar(c);
-			break;
-		    case 'A':
-			rtld_putstr(main_local);
-			break;
-		    case 'a':
-			rtld_putstr(obj_main->path);
-			break;
-		    case 'o':
-			rtld_putstr(name);
-			break;
-#if 0
-		    case 'm':
-			rtld_printf("%d", sodp->sod_major);
-			break;
-		    case 'n':
-			rtld_printf("%d", sodp->sod_minor);
-			break;
-#endif
-		    case 'p':
-			rtld_putstr(path);
-			break;
-		    case 'x':
-			rtld_printf("%p", needed->obj ? needed->obj->mapbase :
-			  0);
-			break;
-		    }
-		    break;
-		}
-		++fmt;
-	    }
+	    trace_print_obj(obj, name, path, main_local, fmt1, fmt2);
 	}
     }
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202204080125.2381PQuR095141>