]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Fix display of function names in debug
authorDavid Mulder <dmulder@samba.org>
Thu, 22 Aug 2024 21:23:15 +0000 (15:23 -0600)
committerDavid Mulder <dmulder@samba.org>
Wed, 23 Oct 2024 14:21:34 +0000 (14:21 +0000)
Rust adds some odd `{{closure}}` bits to the
function name that need to be removed, otherwise
the debug is unreadable.

Signed-off-by: David Mulder <dmulder@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
rust/dbg/src/lib.rs

index 55447ba85f0435485b72efa9ccc9a55e76dd2e79..2104cdb0d1c0e5ff5fb8602a761984812dd29c3a 100644 (file)
@@ -88,10 +88,15 @@ macro_rules! function {
         }
         let name = type_name_of(f);
 
-        match &name[..name.len() - 3].rfind(':') {
-            Some(pos) => &name[pos + 1..name.len() - 3],
-            None => &name[..name.len() - 3],
-        }
+        let base_name = match name.rfind("::") {
+            Some(pos) => &name[..pos],
+            None => name,
+        };
+        let parts: Vec<&str> = base_name
+            .split("::")
+            .filter(|&p| p != "{{closure}}")
+            .collect();
+        parts.join("::")
     }};
 }
 
@@ -103,7 +108,7 @@ macro_rules! DBG_PREFIX {
             let location_cstr = chelps::wrap_string(&location);
             let function = $crate::function!();
             let function_msg = format!("{}: ", function);
-            let function_cstr = chelps::wrap_string(function);
+            let function_cstr = chelps::wrap_string(&function);
             let function_msg_cstr = chelps::wrap_string(&function_msg);
             let msg = format!($($arg),*);
             let msg_cstr = chelps::wrap_string(&msg);