Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libdrgn: prepare for libkdumpfile-0.5.5 #452

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions libdrgn/kdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,39 +299,36 @@ struct drgn_error *drgn_program_cache_kdump_threads(struct drgn_program *prog)
}

/*
* Note that in the following loop we never call kdump_attr_unref() on
* prstatus_ref, nor kdump_blob_unpin() on the prstatus blob that we get
* from libkdumpfile. Since drgn is completely read-only as a consumer
* of that library, we "leak" both the attribute reference and blob pin
* until kdump_free() is called which will clean up everything for us.
* Note that in the following loop we never call kdump_blob_unpin() on
* the prstatus blob that we get from libkdumpfile. Since drgn never
* modifies the PRSTATUS attributes (neither directly nor indirectly),
* we "leak" the blob pin until kdump_free() is called, which will
* clean up everything for us.
*/
for (i = 0; i < ncpus; i++) {
/* Enough for the longest possible PRSTATUS attribute name. */
kdump_attr_ref_t prstatus_ref;
kdump_attr_t prstatus_attr;
void *prstatus_data;
size_t prstatus_size;

#define FORMAT "cpu.%" PRIuFAST64 ".PRSTATUS"
/* Enough for the longest possible PRSTATUS attribute name. */
char attr_name[sizeof(FORMAT)
- sizeof("%" PRIuFAST64)
+ max_decimal_length(uint_fast64_t)
+ 1];
snprintf(attr_name, sizeof(attr_name), FORMAT, i);
#undef FORMAT
ks = kdump_attr_ref(prog->kdump_ctx, attr_name, &prstatus_ref);
if (ks != KDUMP_OK) {
return drgn_error_format(DRGN_ERROR_OTHER,
"kdump_attr_ref(%s): %s",
attr_name,
kdump_get_err(prog->kdump_ctx));
}

ks = kdump_attr_ref_get(prog->kdump_ctx, &prstatus_ref,
&prstatus_attr);
#if KDUMPFILE_VERSION >= KDUMPFILE_MKVER(0, 5, 5)
ks = kdump_get_typed_attr(prog->kdump_ctx, attr_name,
KDUMP_BLOB, &prstatus_attr.val);
#else
prstatus_attr.type = KDUMP_BLOB;
ks = kdump_get_typed_attr(prog->kdump_ctx, attr_name,
&prstatus_attr);
#endif
if (ks != KDUMP_OK) {
return drgn_error_format(DRGN_ERROR_OTHER,
"kdump_attr_ref_get(%s): %s",
"kdump_get_typed_attr(%s): %s",
attr_name,
kdump_get_err(prog->kdump_ctx));
}
Expand Down
Loading