db_pprint: Properly handle complex pointer types
Some checks are pending
Cross-build Kernel / ${{ matrix.target_arch }} ${{ matrix.os }} (${{ matrix.compiler }}) (clang-14, /usr/lib/llvm-14/bin, ubuntu-22.04, bmake libarchive-dev clang-14 lld-14, arm64, aarch64) (push) Waiting to run
Cross-build Kernel / ${{ matrix.target_arch }} ${{ matrix.os }} (${{ matrix.compiler }}) (clang-14, /usr/lib/llvm-14/bin, ubuntu-22.04, bmake libarchive-dev clang-14 lld-14, amd64, amd64) (push) Waiting to run
Cross-build Kernel / ${{ matrix.target_arch }} ${{ matrix.os }} (${{ matrix.compiler }}) (clang-13, /opt/homebrew/opt/llvm@13/bin, macos-latest, bmake libarchive llvm@13, arm64, aarch64) (push) Waiting to run
Cross-build Kernel / ${{ matrix.target_arch }} ${{ matrix.os }} (${{ matrix.compiler }}) (clang-13, /opt/homebrew/opt/llvm@13/bin, macos-latest, bmake libarchive llvm@13, amd64, amd64) (push) Waiting to run
Cross-build Kernel / ${{ matrix.target_arch }} ${{ matrix.os }} (${{ matrix.compiler }}) (clang-12, /usr/lib/llvm-12/bin, ubuntu-20.04, bmake libarchive-dev clang-12 lld-12, arm64, aarch64) (push) Waiting to run
Cross-build Kernel / ${{ matrix.target_arch }} ${{ matrix.os }} (${{ matrix.compiler }}) (clang-12, /usr/lib/llvm-12/bin, ubuntu-20.04, bmake libarchive-dev clang-12 lld-12, amd64, amd64) (push) Waiting to run

The existing pretty-printing code fails to properly print complex
pointer types. This commit fixes this behaviour by traversing the
chain of CTF types until a base type is encountered.

Approved by: markj (mentor)
Fixes: c21bc6f3c2
This commit is contained in:
Bojan Novković 2024-07-21 18:51:22 +02:00
parent 82f5dfc121
commit 1cbd613f33

View file

@ -45,6 +45,7 @@ static void db_pprint_type(db_addr_t addr, struct ctf_type_v3 *type,
static u_int max_depth = DB_PPRINT_DEFAULT_DEPTH;
static struct db_ctf_sym_data sym_data;
static const char *asteriskstr = "*****";
/*
* Pretty-prints a CTF_INT type.
@ -248,9 +249,14 @@ db_pprint_ptr(db_addr_t addr, struct ctf_type_v3 *type, u_int depth)
const char *qual = "";
const char *name;
db_addr_t val;
uint32_t tid;
u_int kind;
int ptrcnt;
ref_type = db_ctf_typeid_to_type(&sym_data, type->ctt_type);
ptrcnt = 1;
tid = type->ctt_type;
again:
ref_type = db_ctf_typeid_to_type(&sym_data, tid);
kind = CTF_V3_INFO_KIND(ref_type->ctt_info);
switch (kind) {
case CTF_K_STRUCT:
@ -258,25 +264,41 @@ db_pprint_ptr(db_addr_t addr, struct ctf_type_v3 *type, u_int depth)
break;
case CTF_K_VOLATILE:
qual = "volatile ";
break;
tid = ref_type->ctt_type;
goto again;
case CTF_K_CONST:
qual = "const ";
break;
tid = ref_type->ctt_type;
goto again;
case CTF_K_RESTRICT:
qual = "restrict ";
tid = ref_type->ctt_type;
goto again;
case CTF_K_POINTER:
ptrcnt++;
tid = ref_type->ctt_type;
goto again;
case CTF_K_TYPEDEF:
tid = ref_type->ctt_type;
goto again;
default:
break;
}
val = db_get_value(addr, sizeof(db_addr_t), false);
if (depth < max_depth) {
ptrcnt = min(ptrcnt, strlen(asteriskstr));
val = (addr != 0) ? db_get_value(addr, sizeof(db_addr_t), false) : 0;
if (depth < max_depth && (val != 0)) {
/* Print contents of memory pointed to by this pointer. */
db_pprint_type(addr, ref_type, depth + 1);
db_pprint_type(val, ref_type, depth + 1);
} else {
name = db_ctf_stroff_to_str(&sym_data, ref_type->ctt_name);
db_indent = depth;
if (name != NULL)
db_printf("(%s%s *) 0x%lx", qual, name, (long)val);
db_printf("(%s%s %.*s) 0x%lx", qual, name, ptrcnt,
asteriskstr, (long)val);
else
db_printf("(%s *) 0x%lx", qual, (long)val);
db_printf("(%s %.*s) 0x%lx", qual, ptrcnt, asteriskstr,
(long)val);
}
}