talloc_ctx_vty.c File Reference

Osmocom talloc context introspection via VTY. More...

`#include <stdio.h>`
`#include <regex.h>`
`#include <string.h>`
`#include <talloc.h>`
`#include <osmocom/vty/command.h>`
`#include <osmocom/vty/vty.h>`

## Data Structures

struct | walk_cb_params

## Macros

#define | BASE_CMD_STR "show talloc-context (application|all) (full|brief|DEPTH)"
#define | BASE_CMD_DESCR

## Enumerations

enum | walk_filter_type { WALK_FILTER_NONE = 0 , WALK_FILTER_REGEXP , WALK_FILTER_TREE }

## Functions

static void | talloc_ctx_walk_cb (const void *chunk, int depth, int max_depth, int is_ref, void *data)
| Print a talloc memory hierarchy to the given VTY. More...
static void | talloc_ctx_walk (const char *ctx, const char *depth, struct walk_cb_params *params)
| Parse talloc context and depth values from a VTY command. More...
| DEFUN (show_talloc_ctx, show_talloc_ctx_cmd, BASE_CMD_STR, BASE_CMD_DESCR)
| DEFUN (show_talloc_ctx_filter, show_talloc_ctx_filter_cmd, BASE_CMD_STR " filter REGEXP", BASE_CMD_DESCR "Filter chunks using regular expression\n" "Regular expression\n")
| DEFUN (show_talloc_ctx_tree, show_talloc_ctx_tree_cmd, BASE_CMD_STR " tree ADDRESS", BASE_CMD_DESCR "Display only a specific memory chunk\n" "Chunk address (e.g. 0xdeadbeef)\n")
void | osmo_talloc_vty_add_cmds (void)
| Install VTY commands for talloc context introspection. More...

## Variables

void * | tall_vty_ctx
struct host | host

## Detailed Description

Osmocom talloc context introspection via VTY.

## Macro Definition Documentation

## BASE_CMD_DESCR

#define BASE_CMD_DESCR

Value:
SHOW_STR "Show talloc memory hierarchy\n" \
"Application's context\n" \
"All contexts, if NULL-context tracking is enabled\n" \
"Display a full talloc memory hierarchy\n" \
"Display a brief talloc memory hierarchy\n" \
"Specify required maximal depth value\n"
SHOW_STR
#define SHOW_STR
Definition: command.h:313

## BASE_CMD_STR

#define BASE_CMD_STR "show talloc-context (application|all) (full|brief|DEPTH)"

## Enumeration Type Documentation

## walk_filter_type

enum walk_filter_type

Enumerator
WALK_FILTER_NONE |
WALK_FILTER_REGEXP |
WALK_FILTER_TREE |

## Function Documentation

## DEFUN() [1/3]

DEFUN | ( | show_talloc_ctx | ,
|  | show_talloc_ctx_cmd | ,
|  | BASE_CMD_STR | ,
|  | BASE_CMD_DESCR |
| ) |  |

References argv, CMD_SUCCESS, walk_cb_params::filter, talloc_ctx_walk(), walk_cb_params::vty, vty, and WALK_FILTER_NONE.

## DEFUN() [2/3]

DEFUN | ( | show_talloc_ctx_filter | ,
|  | show_talloc_ctx_filter_cmd | ,
|  | BASE_CMD_STR " filter REGEXP" | ,
|  | BASE_CMD_DESCR "Filter chunks using regular expression\n" "Regular expression\n" |
| ) |  |

References argv, CMD_SUCCESS, CMD_WARNING, walk_cb_params::filter, walk_cb_params::regexp, talloc_ctx_walk(), walk_cb_params::vty, vty, VTY_NEWLINE, vty_out(), and WALK_FILTER_REGEXP.

## DEFUN() [3/3]

DEFUN | ( | show_talloc_ctx_tree | ,
|  | show_talloc_ctx_tree_cmd | ,
|  | BASE_CMD_STR " tree ADDRESS" | ,
|  | BASE_CMD_DESCR "Display only a specific memory chunk\n" "Chunk address (e.g. 0xdeadbeef)\n" |
| ) |  |

References argv, walk_cb_params::chunk_ptr, CMD_SUCCESS, CMD_WARNING, walk_cb_params::filter, talloc_ctx_walk(), walk_cb_params::vty, vty, VTY_NEWLINE, vty_out(), and WALK_FILTER_TREE.

## osmo_talloc_vty_add_cmds()

void osmo_talloc_vty_add_cmds | ( | void |  | ) |

Install VTY commands for talloc context introspection.

This installs a set of VTY commands for introspection of a talloc context. Call this once from your application if you want to support those commands.

## talloc_ctx_walk()

static void talloc_ctx_walk | ( | const char * | ctx,
|  | const char * | depth,
|  | struct walk_cb_params * | params
| ) |  |

static

Parse talloc context and depth values from a VTY command.

Parameters

  ctx | The context to be printed (a string from argv)
  depth | The report depth (a string from argv)
  params | The walk_cb_params struct instance

References host::app_info, depth, vty_app_info::tall_ctx, and talloc_ctx_walk_cb().

Referenced by DEFUN().

## talloc_ctx_walk_cb()

static void talloc_ctx_walk_cb | ( | const void * | chunk,
|  | int | depth,
|  | int | max_depth,
|  | int | is_ref,
|  | void * | data
| ) |  |

static

Print a talloc memory hierarchy to the given VTY.

To be called by the talloc_report_depth_cb(). If one of supported filters is specified, then only satisfying memory trees would be printed.

Parameters

  chunk | The talloc chunk to be printed
  depth | Current depth value
  max_depth | Maximal depth of report (negative means full)
  is_ref | Is this chunk a reference?
  data | The walk_cb_params struct instance

A filter is being bypassed while current depth value is higher than the 'depth_pass', i.e. the callback does processing the child memory chunks. As soon as this condition becomes false, we need to 'enable' a filter, and resume the processing other chunks.

As soon as a filter passes any chunk, all the memory tree starting from one would be printed. To do that, we need to temporary 'disable' a filter for child chunks (current_depth > depth_pass).

References walk_cb_params::chunk_ptr, data, depth, walk_cb_params::depth_pass, walk_cb_params::filter, walk_cb_params::regexp, walk_cb_params::vty, VTY_NEWLINE, vty_out(), WALK_FILTER_REGEXP, and WALK_FILTER_TREE.

Referenced by talloc_ctx_walk().