44
44
#define UNW_LOCAL_ONLY
45
45
#include <libunwind.h>
46
46
47
+ /*
48
+ * Convert `v` to ASCII hex characters. The bottom `n` nybbles (4-bits ie one
49
+ * hex digit) will be written, up to `buflen`. The buffer will not be
50
+ * null-terminated. Returns the number of digits written.
51
+ */
47
52
static size_t
48
- libspl_u64_to_hex_str (uint64_t v , size_t digits , char * buf , size_t buflen )
53
+ spl_bt_u64_to_hex_str (uint64_t v , size_t n , char * buf , size_t buflen )
49
54
{
50
55
static const char hexdigits [] = {
51
56
'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' ,
52
57
'8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f'
53
58
};
54
59
55
60
size_t pos = 0 ;
56
- boolean_t want = (digits == 0 );
61
+ boolean_t want = (n == 0 );
57
62
for (int i = 15 ; i >= 0 ; i -- ) {
58
63
const uint64_t d = v >> (i * 4 ) & 0xf ;
59
- if (!want && (d != 0 || digits > i ))
64
+ if (!want && (d != 0 || n > i ))
60
65
want = B_TRUE ;
61
66
if (want ) {
62
67
buf [pos ++ ] = hexdigits [d ];
@@ -88,14 +93,14 @@ libspl_backtrace(int fd)
88
93
for (n = 0 ; name [n ] != '\0' && name [n ] != '?' ; n ++ ) {}
89
94
if (n == 0 ) {
90
95
buf [0 ] = '?' ;
91
- n = libspl_u64_to_hex_str (regnum , 2 ,
96
+ n = spl_bt_u64_to_hex_str (regnum , 2 ,
92
97
& buf [1 ], sizeof (buf )- 1 ) + 1 ;
93
98
name = buf ;
94
99
}
95
100
spl_bt_write_n (fd , " " , 5 - MIN (n , 3 ));
96
101
spl_bt_write_n (fd , name , n );
97
102
spl_bt_write (fd , ": 0x" );
98
- n = libspl_u64_to_hex_str (v , 18 , buf , sizeof (buf ));
103
+ n = spl_bt_u64_to_hex_str (v , 18 , buf , sizeof (buf ));
99
104
spl_bt_write_n (fd , buf , n );
100
105
if (!(++ c % 3 ))
101
106
spl_bt_write (fd , "\n" );
@@ -108,22 +113,22 @@ libspl_backtrace(int fd)
108
113
while (unw_step (& cp ) > 0 ) {
109
114
unw_get_reg (& cp , UNW_REG_IP , & v );
110
115
spl_bt_write (fd , " [0x" );
111
- n = libspl_u64_to_hex_str (v , 18 , buf , sizeof (buf ));
116
+ n = spl_bt_u64_to_hex_str (v , 18 , buf , sizeof (buf ));
112
117
spl_bt_write_n (fd , buf , n );
113
118
spl_bt_write (fd , "] " );
114
119
unw_get_proc_name (& cp , buf , sizeof (buf ), & v );
115
120
for (n = 0 ; n < sizeof (buf ) && buf [n ] != '\0' ; n ++ ) {}
116
121
spl_bt_write_n (fd , buf , n );
117
122
spl_bt_write (fd , "+0x" );
118
- n = libspl_u64_to_hex_str (v , 2 , buf , sizeof (buf ));
123
+ n = spl_bt_u64_to_hex_str (v , 2 , buf , sizeof (buf ));
119
124
spl_bt_write_n (fd , buf , n );
120
125
#ifdef HAVE_LIBUNWIND_ELF
121
126
spl_bt_write (fd , " (in " );
122
127
unw_get_elf_filename (& cp , buf , sizeof (buf ), & v );
123
128
for (n = 0 ; n < sizeof (buf ) && buf [n ] != '\0' ; n ++ ) {}
124
129
spl_bt_write_n (fd , buf , n );
125
130
spl_bt_write (fd , " +0x" );
126
- n = libspl_u64_to_hex_str (v , 2 , buf , sizeof (buf ));
131
+ n = spl_bt_u64_to_hex_str (v , 2 , buf , sizeof (buf ));
127
132
spl_bt_write_n (fd , buf , n );
128
133
spl_bt_write (fd , ")" );
129
134
#endif
0 commit comments