Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | */ |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 15 | /** |
| 16 | * @file |
| 17 | * @brief Host utility functions |
| 18 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 19 | #include <vppinfra/format.h> |
| 20 | #include <vlib/vlib.h> |
| 21 | |
| 22 | #include <vlib/threads.h> |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 23 | #include <vnet/vnet.h> |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 24 | #include <vppinfra/format.h> |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 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 | */ |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 34 | u32 |
| 35 | vl (void *p) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | { |
| 37 | return vec_len (p); |
| 38 | } |
| 39 | |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 40 | /** |
Dave Barach | a690fdb | 2020-01-21 12:34:55 -0500 | [diff] [blame] | 41 | * @brief GDB callable function: pvh - Return vector header of vector |
| 42 | * |
| 43 | * @param *p - void - address of vector |
| 44 | * |
| 45 | * @return vh - vec_header_t, the vector header |
| 46 | * |
| 47 | */ |
| 48 | vec_header_t * |
| 49 | pvh (void *p) |
| 50 | { |
| 51 | return _vec_find (p); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /** |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 56 | * @brief GDB callable function: pe - call pool_elts - number of elements in a pool |
| 57 | * |
| 58 | * @param *v - void - address of pool |
| 59 | * |
| 60 | * @return number - uword |
| 61 | * |
| 62 | */ |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 63 | uword |
| 64 | pe (void *v) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 66 | return (pool_elts (v)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 69 | /** |
Christian Hopps | b71653e | 2020-07-13 11:57:27 -0400 | [diff] [blame] | 70 | * @brief GDB callable function: ph - call pool_header - get pool header. |
| 71 | * |
| 72 | * @param *p - void - address of pool |
| 73 | * |
| 74 | * @return pool_header_t |
| 75 | * |
| 76 | */ |
| 77 | pool_header_t * |
| 78 | ph (void *p) |
| 79 | { |
| 80 | return pool_header (p); |
| 81 | } |
| 82 | |
| 83 | /** |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 84 | * @brief GDB callable function: pifi - call pool_is_free_index - is passed index free? |
| 85 | * |
| 86 | * @param *p - void - address of pool |
| 87 | * @param *index - u32 |
| 88 | * |
| 89 | * @return 0|1 - int |
| 90 | * |
| 91 | */ |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 92 | int |
| 93 | pifi (void *p, u32 index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | { |
| 95 | return pool_is_free_index (p, index); |
| 96 | } |
| 97 | |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 98 | /** |
| 99 | * @brief GDB callable function: debug_hex_bytes - return formatted hex string |
| 100 | * |
| 101 | * @param *s - u8 |
| 102 | * @param n - u32 - number of bytes to format |
| 103 | * |
| 104 | */ |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 105 | void |
| 106 | debug_hex_bytes (u8 * s, u32 n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | { |
| 108 | fformat (stderr, "%U\n", format_hex_bytes, s, n); |
| 109 | } |
| 110 | |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 111 | /** |
| 112 | * @brief GDB callable function: vlib_dump_frame_ownership |
| 113 | * |
| 114 | */ |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 115 | void |
| 116 | vlib_dump_frame_ownership (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 117 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 118 | vlib_main_t *vm = vlib_get_main (); |
| 119 | vlib_node_main_t *nm = &vm->node_main; |
| 120 | vlib_node_runtime_t *this_node_runtime; |
| 121 | vlib_next_frame_t *nf; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | u32 first_nf_index; |
| 123 | u32 index; |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 124 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 125 | vec_foreach (this_node_runtime, nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]) |
| 126 | { |
| 127 | first_nf_index = this_node_runtime->next_frame_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 128 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 129 | for (index = first_nf_index; index < first_nf_index + |
| 130 | this_node_runtime->n_next_nodes; index++) |
| 131 | { |
| 132 | vlib_node_runtime_t *owned_runtime; |
| 133 | nf = vec_elt_at_index (vm->node_main.next_frames, index); |
| 134 | if (nf->flags & VLIB_FRAME_OWNER) |
| 135 | { |
| 136 | owned_runtime = vec_elt_at_index (nm->nodes_by_type[0], |
| 137 | nf->node_runtime_index); |
| 138 | fformat (stderr, |
| 139 | "%s next index %d owns enqueue rights to %s\n", |
| 140 | nm->nodes[this_node_runtime->node_index]->name, |
| 141 | index - first_nf_index, |
| 142 | nm->nodes[owned_runtime->node_index]->name); |
Andreas Schultz | 58b2eb1 | 2019-07-15 15:40:56 +0200 | [diff] [blame] | 143 | fformat (stderr, " nf index %d nf->frame %p\n", |
| 144 | nf - vm->node_main.next_frames, nf->frame); |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 150 | /** |
| 151 | * @brief GDB callable function: vlib_runtime_index_to_node_name |
| 152 | * |
| 153 | * Takes node index and will return the node name. |
| 154 | * |
| 155 | * @param index - u32 |
| 156 | */ |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 157 | void |
| 158 | vlib_runtime_index_to_node_name (u32 index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 160 | vlib_main_t *vm = vlib_get_main (); |
| 161 | vlib_node_main_t *nm = &vm->node_main; |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 162 | |
Eyal Bari | cd30774 | 2018-07-22 12:45:15 +0300 | [diff] [blame] | 163 | if (index >= vec_len (nm->nodes)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 165 | fformat (stderr, "%d out of range, max %d\n", vec_len (nm->nodes)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | return; |
| 167 | } |
| 168 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 169 | fformat (stderr, "node runtime index %d name %s\n", index, |
| 170 | nm->nodes[index]->name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 171 | } |
| 172 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 173 | void |
| 174 | gdb_show_errors (int verbose) |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 175 | { |
| 176 | extern vlib_cli_command_t vlib_cli_show_errors; |
| 177 | unformat_input_t input; |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 178 | vlib_main_t *vm = vlib_get_main (); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 179 | |
| 180 | if (verbose == 0) |
| 181 | unformat_init_string (&input, "verbose 0", 9); |
| 182 | else if (verbose == 1) |
| 183 | unformat_init_string (&input, "verbose 1", 9); |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 184 | else |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 185 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 186 | fformat (stderr, "verbose not 0 or 1\n"); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 187 | return; |
| 188 | } |
| 189 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 190 | vlib_cli_show_errors.function (vm, &input, 0 /* cmd */ ); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 191 | unformat_free (&input); |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 192 | } |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 193 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 194 | void |
| 195 | gdb_show_session (int verbose) |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 196 | { |
| 197 | extern vlib_cli_command_t vlib_cli_show_session_command; |
| 198 | unformat_input_t input; |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 199 | vlib_main_t *vm = vlib_get_main (); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 200 | |
| 201 | if (verbose == 0) |
| 202 | unformat_init_string (&input, "verbose 0", 9); |
| 203 | else if (verbose == 1) |
| 204 | unformat_init_string (&input, "verbose 1", 9); |
| 205 | else if (verbose == 2) |
| 206 | unformat_init_string (&input, "verbose 2", 9); |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 207 | else |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 208 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 209 | fformat (stderr, "verbose not 0 - 2\n"); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 210 | return; |
| 211 | } |
| 212 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 213 | vlib_cli_show_session_command.function (vm, &input, 0 /* cmd */ ); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 214 | unformat_free (&input); |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 215 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 216 | |
Kingwel Xie | 3543908 | 2019-03-05 05:06:48 -0500 | [diff] [blame] | 217 | static int |
| 218 | trace_cmp (void *a1, void *a2) |
| 219 | { |
| 220 | vlib_trace_header_t **t1 = a1; |
| 221 | vlib_trace_header_t **t2 = a2; |
| 222 | i64 dt = t1[0]->time - t2[0]->time; |
| 223 | return dt < 0 ? -1 : (dt > 0 ? +1 : 0); |
| 224 | } |
| 225 | |
| 226 | void |
| 227 | gdb_show_traces () |
| 228 | { |
| 229 | vlib_trace_main_t *tm; |
| 230 | vlib_trace_header_t **h, **traces; |
| 231 | u32 i, index = 0; |
| 232 | char *fmt; |
| 233 | u8 *s = 0; |
| 234 | u32 max; |
| 235 | |
| 236 | /* By default display only this many traces. */ |
| 237 | max = 50; |
| 238 | |
| 239 | /* Get active traces from pool. */ |
| 240 | |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 241 | foreach_vlib_main () |
| 242 | { |
| 243 | fmt = "------------------- Start of thread %d %s -------------------\n"; |
| 244 | s = format (s, fmt, index, vlib_worker_threads[index].name); |
Kingwel Xie | 3543908 | 2019-03-05 05:06:48 -0500 | [diff] [blame] | 245 | |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 246 | tm = &this_vlib_main->trace_main; |
Kingwel Xie | 3543908 | 2019-03-05 05:06:48 -0500 | [diff] [blame] | 247 | |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 248 | trace_apply_filter (this_vlib_main); |
Kingwel Xie | 3543908 | 2019-03-05 05:06:48 -0500 | [diff] [blame] | 249 | |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 250 | traces = 0; |
| 251 | pool_foreach (h, tm->trace_buffer_pool) |
| 252 | { |
| 253 | vec_add1 (traces, h[0]); |
| 254 | } |
| 255 | |
| 256 | if (vec_len (traces) == 0) |
| 257 | { |
| 258 | s = format (s, "No packets in trace buffer\n"); |
| 259 | goto done; |
| 260 | } |
| 261 | |
| 262 | /* Sort them by increasing time. */ |
| 263 | vec_sort_with_function (traces, trace_cmp); |
| 264 | |
| 265 | for (i = 0; i < vec_len (traces); i++) |
| 266 | { |
| 267 | if (i == max) |
| 268 | { |
| 269 | fformat (stderr, |
| 270 | "Limiting display to %d packets." |
| 271 | " To display more specify max.", |
| 272 | max); |
| 273 | goto done; |
| 274 | } |
| 275 | |
| 276 | s = format (s, "Packet %d\n%U\n\n", i + 1, format_vlib_trace, |
| 277 | vlib_get_first_main (), traces[i]); |
| 278 | } |
| 279 | |
| 280 | done: |
| 281 | vec_free (traces); |
| 282 | |
| 283 | index++; |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 284 | } |
Kingwel Xie | 3543908 | 2019-03-05 05:06:48 -0500 | [diff] [blame] | 285 | |
Kingwel Xie | 3543908 | 2019-03-05 05:06:48 -0500 | [diff] [blame] | 286 | fformat (stderr, "%v", s); |
| 287 | vec_free (s); |
| 288 | } |
| 289 | |
Keith Burns (alagalah) | 07203af | 2016-08-25 13:37:37 -0700 | [diff] [blame] | 290 | /** |
| 291 | * @brief GDB callable function: show_gdb_command_fn - show gdb |
| 292 | * |
| 293 | * Shows list of functions for VPP available in GDB |
| 294 | * |
| 295 | * @return error - clib_error_t |
| 296 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 297 | static clib_error_t * |
| 298 | show_gdb_command_fn (vlib_main_t * vm, |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 299 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 300 | { |
| 301 | vlib_cli_output (vm, "vl(p) returns vec_len(p)"); |
Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 302 | vlib_cli_output (vm, "vb(b) returns vnet_buffer(b) [opaque]"); |
| 303 | vlib_cli_output (vm, "vb2(b) returns vnet_buffer2(b) [opaque2]"); |
Benoît Ganne | 2b65f9c | 2019-11-21 16:53:31 +0100 | [diff] [blame] | 304 | vlib_cli_output (vm, "vbi(b) returns b index"); |
Christian Hopps | b71653e | 2020-07-13 11:57:27 -0400 | [diff] [blame] | 305 | vlib_cli_output (vm, |
| 306 | "vgb(bi) returns vlib_get_buffer(vlib_get_main(), bi)"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | vlib_cli_output (vm, "pe(p) returns pool_elts(p)"); |
Christian Hopps | b71653e | 2020-07-13 11:57:27 -0400 | [diff] [blame] | 308 | vlib_cli_output (vm, "ph(p) returns pool_header(p)"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 309 | vlib_cli_output (vm, "pifi(p, i) returns pool_is_free_index(p, i)"); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 310 | vlib_cli_output (vm, "gdb_show_errors(0|1) dumps error counters"); |
| 311 | vlib_cli_output (vm, "gdb_show_session dumps session counters"); |
Kingwel Xie | 3543908 | 2019-03-05 05:06:48 -0500 | [diff] [blame] | 312 | vlib_cli_output (vm, "gdb_show_traces() dumps buffer traces"); |
Benoît Ganne | 2b65f9c | 2019-11-21 16:53:31 +0100 | [diff] [blame] | 313 | vlib_cli_output (vm, "gdb_validate_buffer(b) check vlib_buffer b sanity"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 314 | vlib_cli_output (vm, "debug_hex_bytes (ptr, n_bytes) dumps n_bytes in hex"); |
| 315 | vlib_cli_output (vm, "vlib_dump_frame_ownership() does what it says"); |
| 316 | vlib_cli_output (vm, "vlib_runtime_index_to_node_name (index) prints NN"); |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 321 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | VLIB_CLI_COMMAND (show_gdb_funcs_command, static) = { |
| 323 | .path = "show gdb", |
| 324 | .short_help = "Describe functions which can be called from gdb", |
| 325 | .function = show_gdb_command_fn, |
| 326 | }; |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 327 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 328 | |
Christian Hopps | b71653e | 2020-07-13 11:57:27 -0400 | [diff] [blame] | 329 | vlib_buffer_t * |
| 330 | vgb (u32 bi) |
| 331 | { |
| 332 | return vlib_get_buffer (vlib_get_main (), bi); |
| 333 | } |
| 334 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 335 | vnet_buffer_opaque_t * |
| 336 | vb (void *vb_arg) |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 337 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 338 | vlib_buffer_t *b = (vlib_buffer_t *) vb_arg; |
| 339 | vnet_buffer_opaque_t *rv; |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 340 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 341 | rv = vnet_buffer (b); |
| 342 | |
| 343 | return rv; |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 344 | } |
| 345 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 346 | vnet_buffer_opaque2_t * |
| 347 | vb2 (void *vb_arg) |
Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 348 | { |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 349 | vlib_buffer_t *b = (vlib_buffer_t *) vb_arg; |
| 350 | vnet_buffer_opaque2_t *rv; |
Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 351 | |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 352 | rv = vnet_buffer2 (b); |
| 353 | |
| 354 | return rv; |
Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Benoît Ganne | 2b65f9c | 2019-11-21 16:53:31 +0100 | [diff] [blame] | 357 | u32 |
| 358 | vbi (vlib_buffer_t * b) |
| 359 | { |
| 360 | vlib_main_t *vm = vlib_get_main (); |
| 361 | vlib_buffer_main_t *bm = vm->buffer_main; |
| 362 | u32 bi = pointer_to_uword (b) - bm->buffer_mem_start; |
| 363 | bi >>= CLIB_LOG2_CACHE_LINE_BYTES; |
| 364 | return bi; |
| 365 | } |
| 366 | |
| 367 | int |
| 368 | gdb_validate_buffer (vlib_buffer_t * b) |
| 369 | { |
| 370 | vlib_main_t *vm = vlib_get_main (); |
| 371 | u32 bi = vbi (b); |
| 372 | u8 *s = |
| 373 | vlib_validate_buffers (vm, &bi, 0, 1, VLIB_BUFFER_KNOWN_ALLOCATED, 1); |
| 374 | if (s) |
| 375 | { |
| 376 | fformat (stderr, "gdb_validate_buffer(): %v", s); |
| 377 | return -1; |
| 378 | } |
| 379 | fformat (stderr, "gdb_validate_buffer(): no error found\n"); |
| 380 | return 0; |
| 381 | } |
Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 382 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | /* Cafeteria plan, maybe you don't want these functions */ |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 384 | clib_error_t * |
| 385 | gdb_func_init (vlib_main_t * vm) |
| 386 | { |
| 387 | return 0; |
| 388 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 389 | |
| 390 | VLIB_INIT_FUNCTION (gdb_func_init); |
sharath reddy | 1b0c983 | 2017-11-29 20:08:11 +0530 | [diff] [blame] | 391 | |
| 392 | /* |
| 393 | * fd.io coding-style-patch-verification: ON |
| 394 | * |
| 395 | * Local Variables: |
| 396 | * eval: (c-set-style "gnu") |
| 397 | * End: |
| 398 | */ |