mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 01:51:00 +03:00
libspl/backtrace: rename and document hex conversion function
Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes #16653
This commit is contained in:
parent
c7e47b3d9a
commit
2596a75306
@ -44,8 +44,13 @@
|
|||||||
#define UNW_LOCAL_ONLY
|
#define UNW_LOCAL_ONLY
|
||||||
#include <libunwind.h>
|
#include <libunwind.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert `v` to ASCII hex characters. The bottom `n` nybbles (4-bits ie one
|
||||||
|
* hex digit) will be written, up to `buflen`. The buffer will not be
|
||||||
|
* null-terminated. Returns the number of digits written.
|
||||||
|
*/
|
||||||
static size_t
|
static size_t
|
||||||
libspl_u64_to_hex_str(uint64_t v, size_t digits, char *buf, size_t buflen)
|
spl_bt_u64_to_hex_str(uint64_t v, size_t n, char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
static const char hexdigits[] = {
|
static const char hexdigits[] = {
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
@ -53,10 +58,10 @@ libspl_u64_to_hex_str(uint64_t v, size_t digits, char *buf, size_t buflen)
|
|||||||
};
|
};
|
||||||
|
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
boolean_t want = (digits == 0);
|
boolean_t want = (n == 0);
|
||||||
for (int i = 15; i >= 0; i--) {
|
for (int i = 15; i >= 0; i--) {
|
||||||
const uint64_t d = v >> (i * 4) & 0xf;
|
const uint64_t d = v >> (i * 4) & 0xf;
|
||||||
if (!want && (d != 0 || digits > i))
|
if (!want && (d != 0 || n > i))
|
||||||
want = B_TRUE;
|
want = B_TRUE;
|
||||||
if (want) {
|
if (want) {
|
||||||
buf[pos++] = hexdigits[d];
|
buf[pos++] = hexdigits[d];
|
||||||
@ -88,14 +93,14 @@ libspl_backtrace(int fd)
|
|||||||
for (n = 0; name[n] != '\0' && name[n] != '?'; n++) {}
|
for (n = 0; name[n] != '\0' && name[n] != '?'; n++) {}
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
buf[0] = '?';
|
buf[0] = '?';
|
||||||
n = libspl_u64_to_hex_str(regnum, 2,
|
n = spl_bt_u64_to_hex_str(regnum, 2,
|
||||||
&buf[1], sizeof (buf)-1) + 1;
|
&buf[1], sizeof (buf)-1) + 1;
|
||||||
name = buf;
|
name = buf;
|
||||||
}
|
}
|
||||||
spl_bt_write_n(fd, " ", 5-MIN(n, 3));
|
spl_bt_write_n(fd, " ", 5-MIN(n, 3));
|
||||||
spl_bt_write_n(fd, name, n);
|
spl_bt_write_n(fd, name, n);
|
||||||
spl_bt_write(fd, ": 0x");
|
spl_bt_write(fd, ": 0x");
|
||||||
n = libspl_u64_to_hex_str(v, 18, buf, sizeof (buf));
|
n = spl_bt_u64_to_hex_str(v, 18, buf, sizeof (buf));
|
||||||
spl_bt_write_n(fd, buf, n);
|
spl_bt_write_n(fd, buf, n);
|
||||||
if (!(++c % 3))
|
if (!(++c % 3))
|
||||||
spl_bt_write(fd, "\n");
|
spl_bt_write(fd, "\n");
|
||||||
@ -108,14 +113,14 @@ libspl_backtrace(int fd)
|
|||||||
while (unw_step(&cp) > 0) {
|
while (unw_step(&cp) > 0) {
|
||||||
unw_get_reg(&cp, UNW_REG_IP, &v);
|
unw_get_reg(&cp, UNW_REG_IP, &v);
|
||||||
spl_bt_write(fd, " [0x");
|
spl_bt_write(fd, " [0x");
|
||||||
n = libspl_u64_to_hex_str(v, 18, buf, sizeof (buf));
|
n = spl_bt_u64_to_hex_str(v, 18, buf, sizeof (buf));
|
||||||
spl_bt_write_n(fd, buf, n);
|
spl_bt_write_n(fd, buf, n);
|
||||||
spl_bt_write(fd, "] ");
|
spl_bt_write(fd, "] ");
|
||||||
unw_get_proc_name(&cp, buf, sizeof (buf), &v);
|
unw_get_proc_name(&cp, buf, sizeof (buf), &v);
|
||||||
for (n = 0; n < sizeof (buf) && buf[n] != '\0'; n++) {}
|
for (n = 0; n < sizeof (buf) && buf[n] != '\0'; n++) {}
|
||||||
spl_bt_write_n(fd, buf, n);
|
spl_bt_write_n(fd, buf, n);
|
||||||
spl_bt_write(fd, "+0x");
|
spl_bt_write(fd, "+0x");
|
||||||
n = libspl_u64_to_hex_str(v, 2, buf, sizeof (buf));
|
n = spl_bt_u64_to_hex_str(v, 2, buf, sizeof (buf));
|
||||||
spl_bt_write_n(fd, buf, n);
|
spl_bt_write_n(fd, buf, n);
|
||||||
#ifdef HAVE_LIBUNWIND_ELF
|
#ifdef HAVE_LIBUNWIND_ELF
|
||||||
spl_bt_write(fd, " (in ");
|
spl_bt_write(fd, " (in ");
|
||||||
@ -123,7 +128,7 @@ libspl_backtrace(int fd)
|
|||||||
for (n = 0; n < sizeof (buf) && buf[n] != '\0'; n++) {}
|
for (n = 0; n < sizeof (buf) && buf[n] != '\0'; n++) {}
|
||||||
spl_bt_write_n(fd, buf, n);
|
spl_bt_write_n(fd, buf, n);
|
||||||
spl_bt_write(fd, " +0x");
|
spl_bt_write(fd, " +0x");
|
||||||
n = libspl_u64_to_hex_str(v, 2, buf, sizeof (buf));
|
n = spl_bt_u64_to_hex_str(v, 2, buf, sizeof (buf));
|
||||||
spl_bt_write_n(fd, buf, n);
|
spl_bt_write_n(fd, buf, n);
|
||||||
spl_bt_write(fd, ")");
|
spl_bt_write(fd, ")");
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user