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.
17 * @brief Host utility functions
19 #include <vppinfra/format.h>
20 #include <vlib/vlib.h>
22 #include <vlib/threads.h>
27 * @brief GDB callable function: vl - Return vector length of vector
29 * @param *p - void - address of vector
31 * @return length - u32
40 * @brief GDB callable function: pe - call pool_elts - number of elements in a pool
42 * @param *v - void - address of pool
44 * @return number - uword
49 return (pool_elts(v));
53 * @brief GDB callable function: pifi - call pool_is_free_index - is passed index free?
55 * @param *p - void - address of pool
61 int pifi (void *p, u32 index)
63 return pool_is_free_index (p, index);
67 * @brief GDB callable function: debug_hex_bytes - return formatted hex string
70 * @param n - u32 - number of bytes to format
73 void debug_hex_bytes (u8 *s, u32 n)
75 fformat (stderr, "%U\n", format_hex_bytes, s, n);
79 * @brief GDB callable function: vlib_dump_frame_ownership
82 void vlib_dump_frame_ownership (void)
84 vlib_main_t * vm = vlib_get_main();
85 vlib_node_main_t * nm = &vm->node_main;
86 vlib_node_runtime_t * this_node_runtime;
87 vlib_next_frame_t * nf;
91 vec_foreach(this_node_runtime, nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL])
93 first_nf_index = this_node_runtime->next_frame_index;
95 for (index = first_nf_index; index < first_nf_index +
96 this_node_runtime->n_next_nodes; index++)
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)
102 owned_runtime = vec_elt_at_index (nm->nodes_by_type[0],
103 nf->node_runtime_index);
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,
118 * @brief GDB callable function: vlib_runtime_index_to_node_name
120 * Takes node index and will return the node name.
124 void vlib_runtime_index_to_node_name (u32 index)
126 vlib_main_t * vm = vlib_get_main();
127 vlib_node_main_t * nm = &vm->node_main;
129 if (index > vec_len (nm->nodes))
131 fformat(stderr, "%d out of range, max %d\n", vec_len(nm->nodes));
135 fformat(stderr, "node runtime index %d name %s\n", index, nm->nodes[index]->name);
140 * @brief GDB callable function: show_gdb_command_fn - show gdb
142 * Shows list of functions for VPP available in GDB
144 * @return error - clib_error_t
146 static clib_error_t *
147 show_gdb_command_fn (vlib_main_t * vm,
148 unformat_input_t * input,
149 vlib_cli_command_t * cmd)
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");
161 VLIB_CLI_COMMAND (show_gdb_funcs_command, static) = {
163 .short_help = "Describe functions which can be called from gdb",
164 .function = show_gdb_command_fn,
167 /* Cafeteria plan, maybe you don't want these functions */
169 gdb_func_init (vlib_main_t * vm) { return 0; }
171 VLIB_INIT_FUNCTION (gdb_func_init);