[PATCH 1/1] lib, stackdepot: Add helper to print stack entries into buffer.

Vlastimil Babka vbabka at suse.cz
Mon Sep 13 08:51:12 UTC 2021


On 9/10/21 16:10, Imran Khan wrote:
> To print stack entries into a buffer, users of stackdepot,
> first get a list of stack entries using stack_depot_fetch
> and then print this list into a buffer using stack_trace_snprint.
> Provide a helper in stackdepot for this purpose.
> Also change above mentioned users to use this helper.
> 
> Signed-off-by: Imran Khan <imran.f.khan at oracle.com>
> Suggested-by: Vlastimil Babka <vbabka at suse.cz>

Acked-by: Vlastimil Babka <vbabka at suse.cz>

A comment below:

> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -214,6 +214,29 @@ static inline struct stack_record *find_stack(struct stack_record *bucket,
>  	return NULL;
>  }
>  
> +/**
> + * stack_depot_snprint - print stack entries from a depot into a buffer
> + *
> + * @handle:	Stack depot handle which was returned from
> + *		stack_depot_save().
> + * @buf:	Pointer to the print buffer
> + *
> + * @size:	Size of the print buffer
> + *
> + * @spaces:	Number of leading spaces to print
> + *
> + * Return:	Number of bytes printed.
> + */
> +int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,
> +		       int spaces)
> +{
> +	unsigned long *entries;
> +	unsigned int nr_entries;
> +
> +	nr_entries = stack_depot_fetch(handle, &entries);
> +	return stack_trace_snprint(buf, size, entries, nr_entries, 0);

stack_trace_snprint() has a WARN_ON(!entries).
So maybe we should not call it if nr_entries is 0 (because e.g. handle was
0) as the warnings are not useful in that case.


More information about the dri-devel mailing list