drgn/libdrgn/linux_kernel_object_find.inc.strswitch
Omar Sandoval 18a8f69ad8 libdrgn: linux_kernel: add object finder for jiffies
We have a lot of examples that use jiffies, but they stopped working
long ago on x86-64 (since Linux kernel commit d8ad6d39c35d ("x86_64: Fix
jiffies ODR violation") (in v5.8 and backported to stable releases)) and
never worked on other architectures. This is because jiffies is defined
in the Linux kernel's linker script. #277 proposed updating the examples
to use jiffies_64, but I would guess that most kernel developers are
familiar with jiffies and many have never seen jiffies_64. jiffies is
also a nicer name to type in live demos. Let's add a case to the Linux
kernel object finder to get the jiffies variable.

Reported-by: Martin Liska <mliska@suse.cz>
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-22 11:15:37 -08:00

40 lines
1.1 KiB
Plaintext

// Copyright (c) Meta Platforms, Inc. and affiliates.
// SPDX-License-Identifier: LGPL-2.1-or-later
struct drgn_error *linux_kernel_object_find(const char *name, size_t name_len,
const char *filename,
enum drgn_find_object_flags flags,
void *arg, struct drgn_object *ret)
{
struct drgn_program *prog = arg;
if (!filename) {
@memswitch (name, name_len)@
@case "PAGE_SHIFT"@
if (flags & DRGN_FIND_OBJECT_CONSTANT)
return linux_kernel_get_page_shift(prog, ret);
break;
@case "PAGE_SIZE"@
if (flags & DRGN_FIND_OBJECT_CONSTANT)
return linux_kernel_get_page_size(prog, ret);
break;
@case "PAGE_MASK"@
if (flags & DRGN_FIND_OBJECT_CONSTANT)
return linux_kernel_get_page_mask(prog, ret);
break;
@case "UTS_RELEASE"@
if (flags & DRGN_FIND_OBJECT_CONSTANT)
return linux_kernel_get_uts_release(prog, ret);
break;
@case "jiffies"@
if (flags & DRGN_FIND_OBJECT_VARIABLE)
return linux_kernel_get_jiffies(prog, ret);
break;
@case "vmemmap"@
if (flags & DRGN_FIND_OBJECT_CONSTANT)
return linux_kernel_get_vmemmap(prog, ret);
break;
@endswitch@
}
return &drgn_not_found;
}