FD.io VPP  v17.04-9-g99c0734
Vector Packet Processing
gdb_funcs.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @file
17  * @brief Host utility functions
18  */
19 #include <vppinfra/format.h>
20 #include <vlib/vlib.h>
21 
22 #include <vlib/threads.h>
23 
24 
25 
26 /**
27  * @brief GDB callable function: vl - Return vector length of vector
28  *
29  * @param *p - void - address of vector
30  *
31  * @return length - u32
32  *
33  */
34 u32 vl(void *p)
35 {
36  return vec_len (p);
37 }
38 
39 /**
40  * @brief GDB callable function: pe - call pool_elts - number of elements in a pool
41  *
42  * @param *v - void - address of pool
43  *
44  * @return number - uword
45  *
46  */
47 uword pe (void *v)
48 {
49  return (pool_elts(v));
50 }
51 
52 /**
53  * @brief GDB callable function: pifi - call pool_is_free_index - is passed index free?
54  *
55  * @param *p - void - address of pool
56  * @param *index - u32
57  *
58  * @return 0|1 - int
59  *
60  */
61 int pifi (void *p, u32 index)
62 {
63  return pool_is_free_index (p, index);
64 }
65 
66 /**
67  * @brief GDB callable function: debug_hex_bytes - return formatted hex string
68  *
69  * @param *s - u8
70  * @param n - u32 - number of bytes to format
71  *
72  */
73 void debug_hex_bytes (u8 *s, u32 n)
74 {
75  fformat (stderr, "%U\n", format_hex_bytes, s, n);
76 }
77 
78 /**
79  * @brief GDB callable function: vlib_dump_frame_ownership
80  *
81  */
83 {
85  vlib_node_main_t * nm = &vm->node_main;
86  vlib_node_runtime_t * this_node_runtime;
87  vlib_next_frame_t * nf;
88  u32 first_nf_index;
89  u32 index;
90 
91  vec_foreach(this_node_runtime, nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL])
92  {
93  first_nf_index = this_node_runtime->next_frame_index;
94 
95  for (index = first_nf_index; index < first_nf_index +
96  this_node_runtime->n_next_nodes; index++)
97  {
98  vlib_node_runtime_t * owned_runtime;
99  nf = vec_elt_at_index (vm->node_main.next_frames, index);
100  if (nf->flags & VLIB_FRAME_OWNER)
101  {
102  owned_runtime = vec_elt_at_index (nm->nodes_by_type[0],
103  nf->node_runtime_index);
104  fformat(stderr,
105  "%s next index %d owns enqueue rights to %s\n",
106  nm->nodes[this_node_runtime->node_index]->name,
107  index - first_nf_index,
108  nm->nodes[owned_runtime->node_index]->name);
109  fformat (stderr, " nf index %d nf->frame_index %d\n",
110  nf - vm->node_main.next_frames,
111  nf->frame_index);
112  }
113  }
114  }
115 }
116 
117 /**
118  * @brief GDB callable function: vlib_runtime_index_to_node_name
119  *
120  * Takes node index and will return the node name.
121  *
122  * @param index - u32
123  */
125 {
127  vlib_node_main_t * nm = &vm->node_main;
128 
129  if (index > vec_len (nm->nodes))
130  {
131  fformat(stderr, "%d out of range, max %d\n", vec_len(nm->nodes));
132  return;
133  }
134 
135  fformat(stderr, "node runtime index %d name %s\n", index, nm->nodes[index]->name);
136 }
137 
138 
139 /**
140  * @brief GDB callable function: show_gdb_command_fn - show gdb
141  *
142  * Shows list of functions for VPP available in GDB
143  *
144  * @return error - clib_error_t
145  */
146 static clib_error_t *
148  unformat_input_t * input,
149  vlib_cli_command_t * cmd)
150 {
151  vlib_cli_output (vm, "vl(p) returns vec_len(p)");
152  vlib_cli_output (vm, "pe(p) returns pool_elts(p)");
153  vlib_cli_output (vm, "pifi(p, i) returns pool_is_free_index(p, i)");
154  vlib_cli_output (vm, "debug_hex_bytes (ptr, n_bytes) dumps n_bytes in hex");
155  vlib_cli_output (vm, "vlib_dump_frame_ownership() does what it says");
156  vlib_cli_output (vm, "vlib_runtime_index_to_node_name (index) prints NN");
157 
158  return 0;
159 }
160 
161 VLIB_CLI_COMMAND (show_gdb_funcs_command, static) = {
162  .path = "show gdb",
163  .short_help = "Describe functions which can be called from gdb",
164  .function = show_gdb_command_fn,
165 };
166 
167 /* Cafeteria plan, maybe you don't want these functions */
168 clib_error_t *
169 gdb_func_init (vlib_main_t * vm) { return 0; }
170 
void vlib_runtime_index_to_node_name(u32 index)
GDB callable function: vlib_runtime_index_to_node_name.
Definition: gdb_funcs.c:124
u32 next_frame_index
Start of next frames for this node.
Definition: node.h:433
#define VLIB_FRAME_OWNER
Definition: node.h:370
void vlib_dump_frame_ownership(void)
GDB callable function: vlib_dump_frame_ownership.
Definition: gdb_funcs.c:82
void debug_hex_bytes(u8 *s, u32 n)
GDB callable function: debug_hex_bytes - return formatted hex string.
Definition: gdb_funcs.c:73
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
vlib_node_t ** nodes
Definition: node.h:633
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:84
vlib_node_runtime_t * nodes_by_type[VLIB_N_NODE_TYPE]
Definition: node.h:643
u32 frame_index
Definition: node.h:356
static clib_error_t * show_gdb_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
GDB callable function: show_gdb_command_fn - show gdb.
Definition: gdb_funcs.c:147
#define v
Definition: acl.c:246
struct _unformat_input_t unformat_input_t
u32 node_index
Node index.
Definition: node.h:436
word fformat(FILE *f, char *fmt,...)
Definition: format.c:452
u8 * name
Definition: node.h:221
vlib_main_t * vm
Definition: buffer.c:276
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:238
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
clib_error_t * gdb_func_init(vlib_main_t *vm)
Definition: gdb_funcs.c:169
unsigned int u32
Definition: types.h:88
int pifi(void *p, u32 index)
GDB callable function: pifi - call pool_is_free_index - is passed index free?
Definition: gdb_funcs.c:61
uword pe(void *v)
GDB callable function: pe - call pool_elts - number of elements in a pool.
Definition: gdb_funcs.c:47
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u64 uword
Definition: types.h:112
u32 vl(void *p)
GDB callable function: vl - Return vector length of vector.
Definition: gdb_funcs.c:34
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
vlib_node_main_t node_main
Definition: main.h:115
vlib_next_frame_t * next_frames
Definition: node.h:655
#define vec_foreach(var, vec)
Vector iterator.
u32 node_runtime_index
Definition: node.h:359
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:577
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109