From: Kris Van Hees <kris.van.hees@oracle.com>
To: eugene.loh@oracle.com
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH v3] doc: Add rudimentary documentation for using [u]stack as a value
Date: Thu, 23 Oct 2025 21:47:38 -0400 [thread overview]
Message-ID: <aPrauoas4Qcopakh@oracle.com> (raw)
In-Reply-To: <20251023231500.25228-1-eugene.loh@oracle.com>
On Thu, Oct 23, 2025 at 07:15:00PM -0400, eugene.loh@oracle.com wrote:
> From: Eugene Loh <eugene.loh@oracle.com>
>
> While we are at it, break up some of the super long source lines for
> future maintainability of these files.
>
> Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
> doc/userguide/reference/function_stack.md | 26 +++++++++++---
> doc/userguide/reference/function_ustack.md | 41 +++++++++++++++++-----
> 2 files changed, 54 insertions(+), 13 deletions(-)
>
> diff --git a/doc/userguide/reference/function_stack.md b/doc/userguide/reference/function_stack.md
> index a92c61a0f..903d3f090 100644
> --- a/doc/userguide/reference/function_stack.md
> +++ b/doc/userguide/reference/function_stack.md
> @@ -1,17 +1,33 @@
>
> # stack
>
> -Records a stack trace to the buffer.
> +Retrieves the kernel call stack.
>
> ```
> -stack stack([uint32_t *frames*])
> +dt_stack_t stack([uint32_t *frames*])
> ```
>
> -The `stack` function records a kernel stack trace to the directed buffer. The function includes an option to specify the number of frames deep to record from the kernel stack. If no value is specified, the number of stack frames recorded is the number that's specified by the `stackframes` runtime option. The `dtrace` command reports frames, either up to the root frame or until the specified limit has been reached, whichever comes first.
> +Returns a `dt_stack_t` value that can be stored in a variable,
> +including an associative array element,
> +or used as a key to an aggregation or associative array.
>
> -The `stack` function, having a non-`void` return value, can also be used as the key to an aggregation.
> +When `stack();` appears alone, as a singular action,
> +it records a stack trace to the output buffer.
>
> -## How to use stack to obtain a kernel stack trace for a particular probe
> +One can optionally specify a number of frames.
> +If no value is specified, the number specified by the `stackframes` runtime option is used.
> +Frames are included either up to the root frame or until the specified limit has been reached, whichever comes first.
> +
> +## How to use stack
> +
> +Here `stack()` is used to assign to a variable and print later using `%k` conversion.
> +
> +```
> + v = stack(3);
> + printf("%k", v);
> +```
> +
> +In this example, `stack()` is an action that prints the kernel stack.
>
> ```
> fbt::ksys_write:entry
> diff --git a/doc/userguide/reference/function_ustack.md b/doc/userguide/reference/function_ustack.md
> index be9436f82..2ab6afe3b 100644
> --- a/doc/userguide/reference/function_ustack.md
> +++ b/doc/userguide/reference/function_ustack.md
> @@ -1,17 +1,44 @@
>
> # ustack
>
> -Records a user stack trace to the directed buffer.
> +Retrieves the call stack in user space.
>
> ```
> -stack ustack([uint32_t *nframes*, uint32_t *strsize*])
> +dt_stack_t ustack([uint32_t *nframes*, uint32_t *strsize*])
> ```
>
> -The `ustack` function records a user stack trace to the directed buffer. The user stack is, at most, *nframes* in depth. If *nframes* isn't specified, the number of stack frames recorded is the number specified by the `ustackframes` option. While `ustack` can determine the address of the calling frames when the probe fires, the stack frames aren't translated into symbols until the `ustack` function is processed at user level by the DTrace utility. If *strsize* is specified and is non zero, `ustack` allocates the specified amount of string space and then uses it to perform address-to-symbol translation directly from the kernel. Such direct user symbol translation is used only with stacktrace helpers that support this usage with DTrace. If such frames can't be translated, the frames appear only as hexadecimal addresses.
> +Returns a `dt_stack_t` value that can be stored in a variable,
> +including an associative array element,
> +or used as a key to an aggregation or associative array.
>
> -The `ustack` symbol translation occurs after the stack data is recorded. Therefore, the corresponding user process might exit before symbol translation can be performed, making stack frame translation impossible. If the user process exits before symbol translation is performed, `dtrace` outputs a warning message, followed by the hexadecimal stack frames.
> +When `ustack();` appears alone, as a singular action,
> +it records a user stack trace to the output buffer.
>
> -## How to use ustack to trace a stack with no address-to-symbol translation
> +One can optionally specify a number of frames.
> +If no value is specified, the number specified by the `ustackframes` runtime option is used.
> +Frames are included either up to the root frame or until the specified limit has been reached, whichever comes first.
> +
> +Stack frames aren't translated into symbols until the `ustack` function is processed at user level by the DTrace utility.
> +
> +**Note**: Historically, if *strsize* was specified and non zero,
> +`ustack` would allocate the specified amount of string space and then use it to perform address-to-symbol translation directly from the kernel.
> +Such direct user symbol translation was used only with stacktrace helpers that supported this usage with DTrace.
> +If such frames could not be translated, the frames would appear only as hexadecimal addresses.
> +Currently, *strsize* is ignored.
> +
> +The `ustack` symbol translation occurs after the stack data is recorded.
> +Therefore, the corresponding user process might exit before symbol translation can be performed, making stack frame translation impossible.
> +If the user process exits before symbol translation is performed, `dtrace` outputs a warning message, followed by the hexadecimal stack frames.
> +
> +## How to use ustack
> +
> +This example shows a D clause that stores the user stack to a global variable,
> +then later print it with a `%k` conversion:
> +
> +```
> + v = ustack(3);
> + printf("%k", v);
> +```
>
> The example shows how to use `ustack` to trace the stack for an `openat` system call by the `date` command.
>
> @@ -19,7 +46,7 @@ The example shows how to use `ustack` to trace the stack for an `openat` system
> sudo dtrace -qn syscall::openat:entry'/pid == $target/{ustack();}' -c 'date'
> ```
>
> -Generates output similar to the following:
> +This generates output similar to the following:
>
> ```
> CPU ID FUNCTION:NAME
> @@ -35,7 +62,5 @@ Mon 20 Feb 17:38:15 GMT 2023
> 0x7f6d63fc2e65
> ```
>
> -
> -
> **Parent topic:**[DTrace Function Reference](../reference/dtrace_functions.md)
>
> --
> 2.47.3
>
prev parent reply other threads:[~2025-10-24 1:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-23 23:15 [PATCH v3] doc: Add rudimentary documentation for using [u]stack as a value eugene.loh
2025-10-24 1:47 ` Kris Van Hees [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aPrauoas4Qcopakh@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=eugene.loh@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox