@@ -205,7 +205,14 @@ impl Symbol {
205205 /// utf-8).
206206 /// * The raw bytes for the symbol name can be accessed.
207207 pub fn name ( & self ) -> Option < SymbolName < ' _ > > {
208- self . inner . name ( )
208+ self . name_raw ( ) . map ( |s| s. demangle ( ) )
209+ }
210+
211+ /// Returns the raw name of this function.
212+ ///
213+ /// This is similar to `name` but doesn't do any demangling.
214+ pub fn name_raw ( & self ) -> Option < RawSymbolName < ' _ > > {
215+ self . inner . name_raw ( )
209216 }
210217
211218 /// Returns the starting address of this function.
@@ -356,6 +363,42 @@ impl<'a> SymbolName<'a> {
356363 }
357364}
358365
366+ /// A wrapper around the raw, mangled, symbol name.
367+ pub struct RawSymbolName < ' a > {
368+ bytes : & ' a [ u8 ] ,
369+ }
370+ impl < ' a > RawSymbolName < ' a > {
371+ /// Creates a new raw symbol name from the raw underlying bytes.
372+ pub fn new ( bytes : & ' a [ u8 ] ) -> RawSymbolName < ' a > {
373+ RawSymbolName { bytes }
374+ }
375+
376+ /// Attempt to demangle the symbol name.
377+ pub fn demangle ( self ) -> SymbolName < ' a > {
378+ SymbolName :: new ( self . bytes )
379+ }
380+
381+ /// Returns the raw (mangled) symbol name as a `str` if the symbol is valid utf-8.
382+ pub fn as_str ( & self ) -> Option < & ' a str > {
383+ str:: from_utf8 ( self . bytes ) . ok ( )
384+ }
385+
386+ /// Returns the raw symbol name as a list of bytes
387+ pub fn as_bytes ( & self ) -> & ' a [ u8 ] {
388+ self . bytes
389+ }
390+ }
391+ impl < ' a > fmt:: Display for RawSymbolName < ' a > {
392+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
393+ format_symbol_name ( fmt:: Display :: fmt, self . bytes , f)
394+ }
395+ }
396+ impl < ' a > fmt:: Debug for RawSymbolName < ' a > {
397+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
398+ format_symbol_name ( fmt:: Debug :: fmt, self . bytes , f)
399+ }
400+ }
401+
359402fn format_symbol_name (
360403 fmt : fn ( & str , & mut fmt:: Formatter < ' _ > ) -> fmt:: Result ,
361404 mut bytes : & [ u8 ] ,
0 commit comments