[DTrace-devel] [PATCH] doc: Add rudimentary documentation for using [u]stack as a value

Kris Van Hees kris.van.hees at oracle.com
Mon Oct 13 19:15:37 UTC 2025


On Thu, Oct 09, 2025 at 11:33:37PM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at 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 at oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

> ---
>  doc/userguide/reference/function_stack.md  | 21 ++++++++++++++---
>  doc/userguide/reference/function_ustack.md | 27 +++++++++++++++++++---
>  2 files changed, 42 insertions(+), 6 deletions(-)
> 
> diff --git a/doc/userguide/reference/function_stack.md b/doc/userguide/reference/function_stack.md
> index a92c61a0f..d172dd017 100644
> --- a/doc/userguide/reference/function_stack.md
> +++ b/doc/userguide/reference/function_stack.md
> @@ -2,17 +2,25 @@
>  # stack
>  
>  Records a stack trace to the buffer.
> +Alternatively, returns a `dt_stack_t` value that can be stored in a variable.
>  
>  ```
> -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.
> +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.
>  
> -The `stack` function, having a non-`void` return value, can also be used as the key to an aggregation.
> +The `stack` function can also be used as the key to an aggregation.
> +
> +Or, its value may be used as a value to a variable.
>  
>  ## How to use stack to obtain a kernel stack trace for a particular probe
>  
> +In this example, `stack()` is an action that prints the kernel stack.
> +
>  ```
>  fbt::ksys_write:entry
>  {
> @@ -22,5 +30,12 @@ fbt::ksys_write:entry
>  
>  ```
>  
> +Alternatively, here `stack()` is used to assign to a variable and print later using `%k` conversion.
> +
> +```
> +        v = stack(3);
> +        printf("%k", v);
> +```
> +
>  **Parent topic:**[DTrace Function Reference](../reference/dtrace_functions.md)
>  
> diff --git a/doc/userguide/reference/function_ustack.md b/doc/userguide/reference/function_ustack.md
> index be9436f82..01d282c7f 100644
> --- a/doc/userguide/reference/function_ustack.md
> +++ b/doc/userguide/reference/function_ustack.md
> @@ -2,14 +2,29 @@
>  # ustack
>  
>  Records a user stack trace to the directed buffer.
> +Alternatively, returns a `dt_stack_t` value that can be stored in a variable.
>  
>  ```
> -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.
> +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.
>  
> -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.
> +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.
> +
> +The `ustack` function can also be used as the key to an aggregation.
> +
> +Or, its value may be used as a value to a variable.
>  
>  ## How to use ustack to trace a stack with no address-to-symbol translation
>  
> @@ -35,7 +50,13 @@ Mon 20 Feb 17:38:15 GMT 2023
>                0x7f6d63fc2e65
>  ```
>  
> +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);
> +```
>  
>  **Parent topic:**[DTrace Function Reference](../reference/dtrace_functions.md)
>  
> -- 
> 2.47.3
> 



More information about the DTrace-devel mailing list