OLD | NEW |
(Empty) | |
| 1 /* Generic static probe support for GDB. |
| 2 |
| 3 Copyright (C) 2012 Free Software Foundation, Inc. |
| 4 |
| 5 This file is part of GDB. |
| 6 |
| 7 This program is free software; you can redistribute it and/or modify |
| 8 it under the terms of the GNU General Public License as published by |
| 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. |
| 11 |
| 12 This program is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. |
| 16 |
| 17 You should have received a copy of the GNU General Public License |
| 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 |
| 20 #include "defs.h" |
| 21 #include "probe.h" |
| 22 #include "command.h" |
| 23 #include "cli/cli-cmds.h" |
| 24 #include "cli/cli-utils.h" |
| 25 #include "objfiles.h" |
| 26 #include "symtab.h" |
| 27 #include "progspace.h" |
| 28 #include "filenames.h" |
| 29 #include "exceptions.h" |
| 30 #include "linespec.h" |
| 31 #include "gdb_regex.h" |
| 32 #include "frame.h" |
| 33 #include "arch-utils.h" |
| 34 #include <ctype.h> |
| 35 |
| 36 |
| 37 |
| 38 /* See definition in probe.h. */ |
| 39 |
| 40 struct symtabs_and_lines |
| 41 parse_probes (char **argptr, struct linespec_result *canonical) |
| 42 { |
| 43 char *arg_start, *arg_end, *arg; |
| 44 char *objfile_name = NULL, *provider = NULL, *name, *p; |
| 45 struct cleanup *cleanup; |
| 46 struct symtabs_and_lines result; |
| 47 struct objfile *objfile; |
| 48 struct program_space *pspace; |
| 49 const struct probe_ops *probe_ops; |
| 50 const char *cs; |
| 51 |
| 52 result.sals = NULL; |
| 53 result.nelts = 0; |
| 54 |
| 55 arg_start = *argptr; |
| 56 |
| 57 cs = *argptr; |
| 58 probe_ops = probe_linespec_to_ops (&cs); |
| 59 gdb_assert (probe_ops != NULL); |
| 60 |
| 61 arg = (char *) cs; |
| 62 arg = skip_spaces (arg); |
| 63 if (!*arg) |
| 64 error (_("argument to `%s' missing"), arg_start); |
| 65 |
| 66 arg_end = skip_to_space (arg); |
| 67 |
| 68 /* We make a copy here so we can write over parts with impunity. */ |
| 69 arg = savestring (arg, arg_end - arg); |
| 70 cleanup = make_cleanup (xfree, arg); |
| 71 |
| 72 /* Extract each word from the argument, separated by ":"s. */ |
| 73 p = strchr (arg, ':'); |
| 74 if (p == NULL) |
| 75 { |
| 76 /* This is `-p name'. */ |
| 77 name = arg; |
| 78 } |
| 79 else |
| 80 { |
| 81 char *hold = p + 1; |
| 82 |
| 83 *p = '\0'; |
| 84 p = strchr (hold, ':'); |
| 85 if (p == NULL) |
| 86 { |
| 87 /* This is `-p provider:name'. */ |
| 88 provider = arg; |
| 89 name = hold; |
| 90 } |
| 91 else |
| 92 { |
| 93 /* This is `-p objfile:provider:name'. */ |
| 94 *p = '\0'; |
| 95 objfile_name = arg; |
| 96 provider = hold; |
| 97 name = p + 1; |
| 98 } |
| 99 } |
| 100 |
| 101 if (*name == '\0') |
| 102 error (_("no probe name specified")); |
| 103 if (provider && *provider == '\0') |
| 104 error (_("invalid provider name")); |
| 105 if (objfile_name && *objfile_name == '\0') |
| 106 error (_("invalid objfile name")); |
| 107 |
| 108 ALL_PSPACES (pspace) |
| 109 ALL_PSPACE_OBJFILES (pspace, objfile) |
| 110 { |
| 111 VEC (probe_p) *probes; |
| 112 struct probe *probe; |
| 113 int ix; |
| 114 |
| 115 if (!objfile->sf || !objfile->sf->sym_probe_fns) |
| 116 continue; |
| 117 |
| 118 if (objfile_name |
| 119 && FILENAME_CMP (objfile->name, objfile_name) != 0 |
| 120 && FILENAME_CMP (lbasename (objfile->name), objfile_name) != 0) |
| 121 continue; |
| 122 |
| 123 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); |
| 124 |
| 125 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) |
| 126 { |
| 127 struct symtab_and_line *sal; |
| 128 |
| 129 if (probe_ops != &probe_ops_any && probe->pops != probe_ops) |
| 130 continue; |
| 131 |
| 132 if (provider && strcmp (probe->provider, provider) != 0) |
| 133 continue; |
| 134 |
| 135 if (strcmp (probe->name, name) != 0) |
| 136 continue; |
| 137 |
| 138 ++result.nelts; |
| 139 result.sals = xrealloc (result.sals, |
| 140 result.nelts |
| 141 * sizeof (struct symtab_and_line)); |
| 142 sal = &result.sals[result.nelts - 1]; |
| 143 |
| 144 init_sal (sal); |
| 145 |
| 146 sal->pc = probe->address; |
| 147 sal->explicit_pc = 1; |
| 148 sal->section = find_pc_overlay (sal->pc); |
| 149 sal->pspace = pspace; |
| 150 sal->probe = probe; |
| 151 } |
| 152 } |
| 153 |
| 154 if (result.nelts == 0) |
| 155 { |
| 156 throw_error (NOT_FOUND_ERROR, |
| 157 _("No probe matching objfile=`%s', provider=`%s', name=`%s'")
, |
| 158 objfile_name ? objfile_name : _("<any>"), |
| 159 provider ? provider : _("<any>"), |
| 160 name); |
| 161 } |
| 162 |
| 163 if (canonical) |
| 164 { |
| 165 canonical->special_display = 1; |
| 166 canonical->pre_expanded = 1; |
| 167 canonical->addr_string = savestring (*argptr, arg_end - *argptr); |
| 168 } |
| 169 |
| 170 *argptr = arg_end; |
| 171 do_cleanups (cleanup); |
| 172 |
| 173 return result; |
| 174 } |
| 175 |
| 176 /* See definition in probe.h. */ |
| 177 |
| 178 VEC (probe_p) * |
| 179 find_probes_in_objfile (struct objfile *objfile, const char *provider, |
| 180 const char *name) |
| 181 { |
| 182 VEC (probe_p) *probes, *result = NULL; |
| 183 int ix; |
| 184 struct probe *probe; |
| 185 |
| 186 if (!objfile->sf || !objfile->sf->sym_probe_fns) |
| 187 return NULL; |
| 188 |
| 189 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); |
| 190 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) |
| 191 { |
| 192 if (strcmp (probe->provider, provider) != 0) |
| 193 continue; |
| 194 |
| 195 if (strcmp (probe->name, name) != 0) |
| 196 continue; |
| 197 |
| 198 VEC_safe_push (probe_p, result, probe); |
| 199 } |
| 200 |
| 201 return result; |
| 202 } |
| 203 |
| 204 /* See definition in probe.h. */ |
| 205 |
| 206 struct probe * |
| 207 find_probe_by_pc (CORE_ADDR pc, struct objfile **objfile_out) |
| 208 { |
| 209 struct objfile *objfile; |
| 210 |
| 211 ALL_OBJFILES (objfile) |
| 212 { |
| 213 VEC (probe_p) *probes; |
| 214 int ix; |
| 215 struct probe *probe; |
| 216 |
| 217 if (!objfile->sf || !objfile->sf->sym_probe_fns) |
| 218 continue; |
| 219 |
| 220 /* If this proves too inefficient, we can replace with a hash. */ |
| 221 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); |
| 222 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) |
| 223 if (probe->address == pc) |
| 224 { |
| 225 *objfile_out = objfile; |
| 226 return probe; |
| 227 } |
| 228 } |
| 229 |
| 230 return NULL; |
| 231 } |
| 232 |
| 233 |
| 234 |
| 235 /* A utility structure. A VEC of these is built when handling "info |
| 236 probes". */ |
| 237 |
| 238 struct probe_and_objfile |
| 239 { |
| 240 /* The probe. */ |
| 241 struct probe *probe; |
| 242 |
| 243 /* The probe's objfile. */ |
| 244 struct objfile *objfile; |
| 245 }; |
| 246 |
| 247 typedef struct probe_and_objfile probe_and_objfile_s; |
| 248 DEF_VEC_O (probe_and_objfile_s); |
| 249 |
| 250 /* A helper function for collect_probes that compiles a regexp and |
| 251 throws an exception on error. This installs a cleanup to free the |
| 252 resulting pattern on success. If RX is NULL, this does nothing. */ |
| 253 |
| 254 static void |
| 255 compile_rx_or_error (regex_t *pattern, const char *rx, const char *message) |
| 256 { |
| 257 int code; |
| 258 |
| 259 if (!rx) |
| 260 return; |
| 261 |
| 262 code = regcomp (pattern, rx, REG_NOSUB); |
| 263 if (code == 0) |
| 264 make_regfree_cleanup (pattern); |
| 265 else |
| 266 { |
| 267 char *err = get_regcomp_error (code, pattern); |
| 268 |
| 269 make_cleanup (xfree, err); |
| 270 error (("%s: %s"), message, err); |
| 271 } |
| 272 } |
| 273 |
| 274 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME. |
| 275 If POPS is not NULL, only probes of this certain probe_ops will match. |
| 276 Each argument is a regexp, or NULL, which matches anything. */ |
| 277 |
| 278 static VEC (probe_and_objfile_s) * |
| 279 collect_probes (char *objname, char *provider, char *probe_name, |
| 280 const struct probe_ops *pops) |
| 281 { |
| 282 struct objfile *objfile; |
| 283 VEC (probe_and_objfile_s) *result = NULL; |
| 284 struct cleanup *cleanup, *cleanup_temps; |
| 285 regex_t obj_pat, prov_pat, probe_pat; |
| 286 |
| 287 cleanup = make_cleanup (VEC_cleanup (probe_and_objfile_s), &result); |
| 288 |
| 289 cleanup_temps = make_cleanup (null_cleanup, NULL); |
| 290 compile_rx_or_error (&prov_pat, provider, _("Invalid provider regexp")); |
| 291 compile_rx_or_error (&probe_pat, probe_name, _("Invalid probe regexp")); |
| 292 compile_rx_or_error (&obj_pat, objname, _("Invalid object file regexp")); |
| 293 |
| 294 ALL_OBJFILES (objfile) |
| 295 { |
| 296 VEC (probe_p) *probes; |
| 297 struct probe *probe; |
| 298 int ix; |
| 299 |
| 300 if (! objfile->sf || ! objfile->sf->sym_probe_fns) |
| 301 continue; |
| 302 |
| 303 if (objname) |
| 304 { |
| 305 if (regexec (&obj_pat, objfile->name, 0, NULL, 0) != 0) |
| 306 continue; |
| 307 } |
| 308 |
| 309 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); |
| 310 |
| 311 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) |
| 312 { |
| 313 probe_and_objfile_s entry; |
| 314 |
| 315 if (pops != NULL && probe->pops != pops) |
| 316 continue; |
| 317 |
| 318 if (provider |
| 319 && regexec (&prov_pat, probe->provider, 0, NULL, 0) != 0) |
| 320 continue; |
| 321 |
| 322 if (probe_name |
| 323 && regexec (&probe_pat, probe->name, 0, NULL, 0) != 0) |
| 324 continue; |
| 325 |
| 326 entry.probe = probe; |
| 327 entry.objfile = objfile; |
| 328 VEC_safe_push (probe_and_objfile_s, result, &entry); |
| 329 } |
| 330 } |
| 331 |
| 332 do_cleanups (cleanup_temps); |
| 333 discard_cleanups (cleanup); |
| 334 return result; |
| 335 } |
| 336 |
| 337 /* A qsort comparison function for probe_and_objfile_s objects. */ |
| 338 |
| 339 static int |
| 340 compare_entries (const void *a, const void *b) |
| 341 { |
| 342 const probe_and_objfile_s *ea = a; |
| 343 const probe_and_objfile_s *eb = b; |
| 344 int v; |
| 345 |
| 346 v = strcmp (ea->probe->provider, eb->probe->provider); |
| 347 if (v) |
| 348 return v; |
| 349 |
| 350 v = strcmp (ea->probe->name, eb->probe->name); |
| 351 if (v) |
| 352 return v; |
| 353 |
| 354 if (ea->probe->address < eb->probe->address) |
| 355 return -1; |
| 356 if (ea->probe->address > eb->probe->address) |
| 357 return 1; |
| 358 |
| 359 return strcmp (ea->objfile->name, eb->objfile->name); |
| 360 } |
| 361 |
| 362 /* Helper function that generate entries in the ui_out table being |
| 363 crafted by `info_probes_for_ops'. */ |
| 364 |
| 365 static void |
| 366 gen_ui_out_table_header_info (VEC (probe_and_objfile_s) *probes, |
| 367 const struct probe_ops *p) |
| 368 { |
| 369 /* `headings' refers to the names of the columns when printing `info |
| 370 probes'. */ |
| 371 VEC (info_probe_column_s) *headings = NULL; |
| 372 struct cleanup *c; |
| 373 info_probe_column_s *column; |
| 374 size_t headings_size; |
| 375 int ix; |
| 376 |
| 377 gdb_assert (p != NULL); |
| 378 |
| 379 if (p->gen_info_probes_table_header == NULL |
| 380 && p->gen_info_probes_table_values == NULL) |
| 381 return; |
| 382 |
| 383 gdb_assert (p->gen_info_probes_table_header != NULL |
| 384 && p->gen_info_probes_table_values != NULL); |
| 385 |
| 386 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings); |
| 387 p->gen_info_probes_table_header (&headings); |
| 388 |
| 389 headings_size = VEC_length (info_probe_column_s, headings); |
| 390 |
| 391 for (ix = 0; |
| 392 VEC_iterate (info_probe_column_s, headings, ix, column); |
| 393 ++ix) |
| 394 { |
| 395 probe_and_objfile_s *entry; |
| 396 int jx; |
| 397 size_t size_max = strlen (column->print_name); |
| 398 |
| 399 for (jx = 0; VEC_iterate (probe_and_objfile_s, probes, jx, entry); ++jx) |
| 400 { |
| 401 /* `probe_fields' refers to the values of each new field that this |
| 402 probe will display. */ |
| 403 VEC (const_char_ptr) *probe_fields = NULL; |
| 404 struct cleanup *c2; |
| 405 const char *val; |
| 406 int kx; |
| 407 |
| 408 if (entry->probe->pops != p) |
| 409 continue; |
| 410 |
| 411 c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields); |
| 412 p->gen_info_probes_table_values (entry->probe, entry->objfile, |
| 413 &probe_fields); |
| 414 |
| 415 gdb_assert (VEC_length (const_char_ptr, probe_fields) |
| 416 == headings_size); |
| 417 |
| 418 for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val); |
| 419 ++kx) |
| 420 { |
| 421 /* It is valid to have a NULL value here, which means that the |
| 422 backend does not have something to write and this particular |
| 423 field should be skipped. */ |
| 424 if (val == NULL) |
| 425 continue; |
| 426 |
| 427 size_max = max (strlen (val), size_max); |
| 428 } |
| 429 do_cleanups (c2); |
| 430 } |
| 431 |
| 432 ui_out_table_header (current_uiout, size_max, ui_left, |
| 433 column->field_name, column->print_name); |
| 434 } |
| 435 |
| 436 do_cleanups (c); |
| 437 } |
| 438 |
| 439 /* Helper function to print extra information about a probe and an objfile |
| 440 represented by ENTRY. */ |
| 441 |
| 442 static void |
| 443 print_ui_out_info (probe_and_objfile_s *entry) |
| 444 { |
| 445 int ix; |
| 446 int j = 0; |
| 447 /* `values' refers to the actual values of each new field in the output |
| 448 of `info probe'. `headings' refers to the names of each new field. */ |
| 449 VEC (const_char_ptr) *values = NULL; |
| 450 VEC (info_probe_column_s) *headings = NULL; |
| 451 info_probe_column_s *column; |
| 452 struct cleanup *c; |
| 453 |
| 454 gdb_assert (entry != NULL); |
| 455 gdb_assert (entry->probe != NULL); |
| 456 gdb_assert (entry->probe->pops != NULL); |
| 457 |
| 458 if (entry->probe->pops->gen_info_probes_table_header == NULL |
| 459 && entry->probe->pops->gen_info_probes_table_values == NULL) |
| 460 return; |
| 461 |
| 462 gdb_assert (entry->probe->pops->gen_info_probes_table_header != NULL |
| 463 && entry->probe->pops->gen_info_probes_table_values != NULL); |
| 464 |
| 465 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings); |
| 466 make_cleanup (VEC_cleanup (const_char_ptr), &values); |
| 467 |
| 468 entry->probe->pops->gen_info_probes_table_header (&headings); |
| 469 entry->probe->pops->gen_info_probes_table_values (entry->probe, |
| 470 entry->objfile, &values); |
| 471 |
| 472 gdb_assert (VEC_length (info_probe_column_s, headings) |
| 473 == VEC_length (const_char_ptr, values)); |
| 474 |
| 475 for (ix = 0; |
| 476 VEC_iterate (info_probe_column_s, headings, ix, column); |
| 477 ++ix) |
| 478 { |
| 479 const char *val = VEC_index (const_char_ptr, values, j++); |
| 480 |
| 481 if (val == NULL) |
| 482 ui_out_field_skip (current_uiout, column->field_name); |
| 483 else |
| 484 ui_out_field_string (current_uiout, column->field_name, val); |
| 485 } |
| 486 |
| 487 do_cleanups (c); |
| 488 } |
| 489 |
| 490 /* Helper function that returns the number of extra fields which POPS will |
| 491 need. */ |
| 492 |
| 493 static int |
| 494 get_number_extra_fields (const struct probe_ops *pops) |
| 495 { |
| 496 VEC (info_probe_column_s) *headings = NULL; |
| 497 struct cleanup *c; |
| 498 int n; |
| 499 |
| 500 if (pops->gen_info_probes_table_header == NULL) |
| 501 return 0; |
| 502 |
| 503 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings); |
| 504 pops->gen_info_probes_table_header (&headings); |
| 505 |
| 506 n = VEC_length (info_probe_column_s, headings); |
| 507 |
| 508 do_cleanups (c); |
| 509 |
| 510 return n; |
| 511 } |
| 512 |
| 513 /* See comment in probe.h. */ |
| 514 |
| 515 void |
| 516 info_probes_for_ops (char *arg, int from_tty, const struct probe_ops *pops) |
| 517 { |
| 518 char *provider, *probe = NULL, *objname = NULL; |
| 519 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); |
| 520 VEC (probe_and_objfile_s) *items; |
| 521 int i, any_found; |
| 522 int ui_out_extra_fields = 0; |
| 523 size_t size_addr; |
| 524 size_t size_name = strlen ("Name"); |
| 525 size_t size_objname = strlen ("Object"); |
| 526 size_t size_provider = strlen ("Provider"); |
| 527 probe_and_objfile_s *entry; |
| 528 struct gdbarch *gdbarch = get_current_arch (); |
| 529 |
| 530 /* Do we have a `provider:probe:objfile' style of linespec? */ |
| 531 provider = extract_arg (&arg); |
| 532 if (provider) |
| 533 { |
| 534 make_cleanup (xfree, provider); |
| 535 |
| 536 probe = extract_arg (&arg); |
| 537 if (probe) |
| 538 { |
| 539 make_cleanup (xfree, probe); |
| 540 |
| 541 objname = extract_arg (&arg); |
| 542 if (objname) |
| 543 make_cleanup (xfree, objname); |
| 544 } |
| 545 } |
| 546 |
| 547 if (pops == NULL) |
| 548 { |
| 549 const struct probe_ops *po; |
| 550 int ix; |
| 551 |
| 552 /* If the probe_ops is NULL, it means the user has requested a "simple" |
| 553 `info probes', i.e., she wants to print all information about all |
| 554 probes. For that, we have to identify how many extra fields we will |
| 555 need to add in the ui_out table. |
| 556 |
| 557 To do that, we iterate over all probe_ops, querying each one about |
| 558 its extra fields, and incrementing `ui_out_extra_fields' to reflect |
| 559 that number. */ |
| 560 |
| 561 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix) |
| 562 ui_out_extra_fields += get_number_extra_fields (po); |
| 563 } |
| 564 else |
| 565 ui_out_extra_fields = get_number_extra_fields (pops); |
| 566 |
| 567 items = collect_probes (objname, provider, probe, pops); |
| 568 make_cleanup (VEC_cleanup (probe_and_objfile_s), &items); |
| 569 make_cleanup_ui_out_table_begin_end (current_uiout, |
| 570 4 + ui_out_extra_fields, |
| 571 VEC_length (probe_and_objfile_s, items), |
| 572 "StaticProbes"); |
| 573 |
| 574 if (!VEC_empty (probe_and_objfile_s, items)) |
| 575 qsort (VEC_address (probe_and_objfile_s, items), |
| 576 VEC_length (probe_and_objfile_s, items), |
| 577 sizeof (probe_and_objfile_s), compare_entries); |
| 578 |
| 579 /* What's the size of an address in our architecture? */ |
| 580 size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10; |
| 581 |
| 582 /* Determining the maximum size of each field (`provider', `name' and |
| 583 `objname'). */ |
| 584 for (i = 0; VEC_iterate (probe_and_objfile_s, items, i, entry); ++i) |
| 585 { |
| 586 size_name = max (strlen (entry->probe->name), size_name); |
| 587 size_provider = max (strlen (entry->probe->provider), size_provider); |
| 588 size_objname = max (strlen (entry->objfile->name), size_objname); |
| 589 } |
| 590 |
| 591 ui_out_table_header (current_uiout, size_provider, ui_left, "provider", |
| 592 _("Provider")); |
| 593 ui_out_table_header (current_uiout, size_name, ui_left, "name", _("Name")); |
| 594 ui_out_table_header (current_uiout, size_addr, ui_left, "addr", _("Where")); |
| 595 |
| 596 if (pops == NULL) |
| 597 { |
| 598 const struct probe_ops *po; |
| 599 int ix; |
| 600 |
| 601 /* We have to generate the table header for each new probe type that we |
| 602 will print. */ |
| 603 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix) |
| 604 gen_ui_out_table_header_info (items, po); |
| 605 } |
| 606 else |
| 607 gen_ui_out_table_header_info (items, pops); |
| 608 |
| 609 ui_out_table_header (current_uiout, size_objname, ui_left, "object", |
| 610 _("Object")); |
| 611 ui_out_table_body (current_uiout); |
| 612 |
| 613 for (i = 0; VEC_iterate (probe_and_objfile_s, items, i, entry); ++i) |
| 614 { |
| 615 struct cleanup *inner; |
| 616 |
| 617 inner = make_cleanup_ui_out_tuple_begin_end (current_uiout, "probe"); |
| 618 |
| 619 ui_out_field_string (current_uiout, "provider", entry->probe->provider); |
| 620 ui_out_field_string (current_uiout, "name", entry->probe->name); |
| 621 ui_out_field_core_addr (current_uiout, "addr", |
| 622 get_objfile_arch (entry->objfile), |
| 623 entry->probe->address); |
| 624 |
| 625 if (pops == NULL) |
| 626 { |
| 627 const struct probe_ops *po; |
| 628 int ix; |
| 629 |
| 630 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); |
| 631 ++ix) |
| 632 if (entry->probe->pops == po) |
| 633 print_ui_out_info (entry); |
| 634 } |
| 635 else |
| 636 print_ui_out_info (entry); |
| 637 |
| 638 ui_out_field_string (current_uiout, "object", entry->objfile->name); |
| 639 ui_out_text (current_uiout, "\n"); |
| 640 |
| 641 do_cleanups (inner); |
| 642 } |
| 643 |
| 644 any_found = !VEC_empty (probe_and_objfile_s, items); |
| 645 do_cleanups (cleanup); |
| 646 |
| 647 if (!any_found) |
| 648 ui_out_message (current_uiout, 0, _("No probes matched.\n")); |
| 649 } |
| 650 |
| 651 /* Implementation of the `info probes' command. */ |
| 652 |
| 653 static void |
| 654 info_probes_command (char *arg, int from_tty) |
| 655 { |
| 656 info_probes_for_ops (arg, from_tty, NULL); |
| 657 } |
| 658 |
| 659 /* See comments in probe.h. */ |
| 660 |
| 661 struct value * |
| 662 probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n) |
| 663 { |
| 664 struct probe *probe; |
| 665 struct objfile *objfile; |
| 666 unsigned n_probes; |
| 667 |
| 668 probe = find_probe_by_pc (get_frame_pc (frame), &objfile); |
| 669 if (!probe) |
| 670 return NULL; |
| 671 gdb_assert (objfile->sf && objfile->sf->sym_probe_fns); |
| 672 |
| 673 n_probes |
| 674 = objfile->sf->sym_probe_fns->sym_get_probe_argument_count (objfile, |
| 675 probe); |
| 676 if (n >= n_probes) |
| 677 return NULL; |
| 678 |
| 679 return objfile->sf->sym_probe_fns->sym_evaluate_probe_argument (objfile, |
| 680 probe, |
| 681 n); |
| 682 } |
| 683 |
| 684 /* See comment in probe.h. */ |
| 685 |
| 686 const struct probe_ops * |
| 687 probe_linespec_to_ops (const char **linespecp) |
| 688 { |
| 689 int ix; |
| 690 const struct probe_ops *probe_ops; |
| 691 |
| 692 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); ix++) |
| 693 if (probe_ops->is_linespec (linespecp)) |
| 694 return probe_ops; |
| 695 |
| 696 return NULL; |
| 697 } |
| 698 |
| 699 /* See comment in probe.h. */ |
| 700 |
| 701 int |
| 702 probe_is_linespec_by_keyword (const char **linespecp, const char *const *keyword
s) |
| 703 { |
| 704 const char *s = *linespecp; |
| 705 const char *const *csp; |
| 706 |
| 707 for (csp = keywords; *csp; csp++) |
| 708 { |
| 709 const char *keyword = *csp; |
| 710 size_t len = strlen (keyword); |
| 711 |
| 712 if (strncmp (s, keyword, len) == 0 && isspace (s[len])) |
| 713 { |
| 714 *linespecp += len + 1; |
| 715 return 1; |
| 716 } |
| 717 } |
| 718 |
| 719 return 0; |
| 720 } |
| 721 |
| 722 /* Implementation of `is_linespec' method for `struct probe_ops'. */ |
| 723 |
| 724 static int |
| 725 probe_any_is_linespec (const char **linespecp) |
| 726 { |
| 727 static const char *const keywords[] = { "-p", "-probe", NULL }; |
| 728 |
| 729 return probe_is_linespec_by_keyword (linespecp, keywords); |
| 730 } |
| 731 |
| 732 /* Dummy method used for `probe_ops_any'. */ |
| 733 |
| 734 static void |
| 735 probe_any_get_probes (VEC (probe_p) **probesp, struct objfile *objfile) |
| 736 { |
| 737 /* No probes can be provided by this dummy backend. */ |
| 738 } |
| 739 |
| 740 /* Operations associated with a generic probe. */ |
| 741 |
| 742 const struct probe_ops probe_ops_any = |
| 743 { |
| 744 probe_any_is_linespec, |
| 745 probe_any_get_probes, |
| 746 }; |
| 747 |
| 748 /* See comments in probe.h. */ |
| 749 |
| 750 struct cmd_list_element ** |
| 751 info_probes_cmdlist_get (void) |
| 752 { |
| 753 static struct cmd_list_element *info_probes_cmdlist; |
| 754 |
| 755 if (info_probes_cmdlist == NULL) |
| 756 add_prefix_cmd ("probes", class_info, info_probes_command, |
| 757 _("\ |
| 758 Show available static probes.\n\ |
| 759 Usage: info probes [all|TYPE [ARGS]]\n\ |
| 760 TYPE specifies the type of the probe, and can be one of the following:\n\ |
| 761 - stap\n\ |
| 762 If you specify TYPE, there may be additional arguments needed by the\n\ |
| 763 subcommand.\n\ |
| 764 If you do not specify any argument, or specify `all', then the command\n\ |
| 765 will show information about all types of probes."), |
| 766 &info_probes_cmdlist, "info probes ", |
| 767 0/*allow-unknown*/, &infolist); |
| 768 |
| 769 return &info_probes_cmdlist; |
| 770 } |
| 771 |
| 772 VEC (probe_ops_cp) *all_probe_ops; |
| 773 |
| 774 void _initialize_probe (void); |
| 775 |
| 776 void |
| 777 _initialize_probe (void) |
| 778 { |
| 779 VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any); |
| 780 |
| 781 add_cmd ("all", class_info, info_probes_command, |
| 782 _("\ |
| 783 Show information about all type of probes."), |
| 784 info_probes_cmdlist_get ()); |
| 785 } |
OLD | NEW |