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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vppinfra/format.h>
16 #include <vlib/vlib.h>
18 #include <vlib/threads.h>
20 /* Functions to call from gdb */
29 return (pool_elts(v));
32 int pifi (void *p, u32 index)
34 return pool_is_free_index (p, index);
37 void debug_hex_bytes (u8 *s, u32 n)
39 fformat (stderr, "%U\n", format_hex_bytes, s, n);
42 void vlib_dump_frame_ownership (void)
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;
51 vec_foreach(this_node_runtime, nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL])
53 first_nf_index = this_node_runtime->next_frame_index;
55 for (index = first_nf_index; index < first_nf_index +
56 this_node_runtime->n_next_nodes; index++)
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)
62 owned_runtime = vec_elt_at_index (nm->nodes_by_type[0],
63 nf->node_runtime_index);
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,
77 void vlib_runtime_index_to_node_name (u32 index)
79 vlib_main_t * vm = vlib_get_main();
80 vlib_node_main_t * nm = &vm->node_main;
82 if (index > vec_len (nm->nodes))
84 fformat(stderr, "%d out of range, max %d\n", vec_len(nm->nodes));
88 fformat(stderr, "node runtime index %d name %s\n", index, nm->nodes[index]->name);
93 show_gdb_command_fn (vlib_main_t * vm,
94 unformat_input_t * input,
95 vlib_cli_command_t * cmd)
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");
107 VLIB_CLI_COMMAND (show_gdb_funcs_command, static) = {
109 .short_help = "Describe functions which can be called from gdb",
110 .function = show_gdb_command_fn,
113 /* Cafeteria plan, maybe you don't want these functions */
115 gdb_func_init (vlib_main_t * vm) { return 0; }
117 VLIB_INIT_FUNCTION (gdb_func_init);