FD.io VPP  v16.06
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 #include <vppinfra/format.h>
16 #include <vlib/vlib.h>
17 
18 #include <vlib/threads.h>
19 
20 /* Functions to call from gdb */
21 
22 u32 vl(void *p)
23 {
24  return vec_len (p);
25 }
26 
27 uword pe (void *v)
28 {
29  return (pool_elts(v));
30 }
31 
32 int pifi (void *p, u32 index)
33 {
34  return pool_is_free_index (p, index);
35 }
36 
37 void debug_hex_bytes (u8 *s, u32 n)
38 {
39  fformat (stderr, "%U\n", format_hex_bytes, s, n);
40 }
41 
43 {
44  vlib_main_t * vm = vlib_get_main();
45  vlib_node_main_t * nm = &vm->node_main;
46  vlib_node_runtime_t * this_node_runtime;
47  vlib_next_frame_t * nf;
48  u32 first_nf_index;
49  u32 index;
50 
51  vec_foreach(this_node_runtime, nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL])
52  {
53  first_nf_index = this_node_runtime->next_frame_index;
54 
55  for (index = first_nf_index; index < first_nf_index +
56  this_node_runtime->n_next_nodes; index++)
57  {
58  vlib_node_runtime_t * owned_runtime;
59  nf = vec_elt_at_index (vm->node_main.next_frames, index);
60  if (nf->flags & VLIB_FRAME_OWNER)
61  {
62  owned_runtime = vec_elt_at_index (nm->nodes_by_type[0],
63  nf->node_runtime_index);
64  fformat(stderr,
65  "%s next index %d owns enqueue rights to %s\n",
66  nm->nodes[this_node_runtime->node_index]->name,
67  index - first_nf_index,
68  nm->nodes[owned_runtime->node_index]->name);
69  fformat (stderr, " nf index %d nf->frame_index %d\n",
70  nf - vm->node_main.next_frames,
71  nf->frame_index);
72  }
73  }
74  }
75 }
76 
78 {
79  vlib_main_t * vm = vlib_get_main();
80  vlib_node_main_t * nm = &vm->node_main;
81 
82  if (index > vec_len (nm->nodes))
83  {
84  fformat(stderr, "%d out of range, max %d\n", vec_len(nm->nodes));
85  return;
86  }
87 
88  fformat(stderr, "node runtime index %d name %s\n", index, nm->nodes[index]->name);
89 }
90 
91 
92 static clib_error_t *
94  unformat_input_t * input,
95  vlib_cli_command_t * cmd)
96 {
97  vlib_cli_output (vm, "vl(p) returns vec_len(p)");
98  vlib_cli_output (vm, "pe(p) returns pool_elts(p)");
99  vlib_cli_output (vm, "pifi(p, i) returns pool_is_free_index(p, i)");
100  vlib_cli_output (vm, "debug_hex_bytes (ptr, n_bytes) dumps n_bytes in hex");
101  vlib_cli_output (vm, "vlib_dump_frame_ownership() does what it says");
102  vlib_cli_output (vm, "vlib_runtime_index_to_node_name (index) prints NN");
103 
104  return 0;
105 }
106 
107 VLIB_CLI_COMMAND (show_gdb_funcs_command, static) = {
108  .path = "show gdb",
109  .short_help = "Describe functions which can be called from gdb",
110  .function = show_gdb_command_fn,
111 };
112 
113 /* Cafeteria plan, maybe you don't want these functions */
114 clib_error_t *
115 gdb_func_init (vlib_main_t * vm) { return 0; }
116 
void vlib_runtime_index_to_node_name(u32 index)
Definition: gdb_funcs.c:77
u32 next_frame_index
Definition: node.h:396
#define VLIB_FRAME_OWNER
Definition: node.h:332
void vlib_dump_frame_ownership(void)
Definition: gdb_funcs.c:42
always_inline vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
void debug_hex_bytes(u8 *s, u32 n)
Definition: gdb_funcs.c:37
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
vlib_node_t ** nodes
Definition: node.h:570
#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:79
always_inline uword pool_elts(void *v)
Definition: pool.h:97
vlib_node_runtime_t * nodes_by_type[VLIB_N_NODE_TYPE]
Definition: node.h:580
u32 frame_index
Definition: node.h:318
static clib_error_t * show_gdb_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gdb_funcs.c:93
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:538
u8 * name
Definition: node.h:187
#define pool_is_free_index(P, I)
Definition: pool.h:197
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
clib_error_t * gdb_func_init(vlib_main_t *vm)
Definition: gdb_funcs.c:115
unsigned int u32
Definition: types.h:88
int pifi(void *p, u32 index)
Definition: gdb_funcs.c:32
uword pe(void *v)
Definition: gdb_funcs.c:27
u64 uword
Definition: types.h:112
u32 vl(void *p)
Definition: gdb_funcs.c:22
#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:592
word fformat(FILE *f, char *fmt,...)
Definition: format.c:437
#define vec_foreach(var, vec)
Vector iterator.
u32 node_runtime_index
Definition: node.h:321
struct _unformat_input_t unformat_input_t