• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版1eac6bea98f41ee12ba9e750a9578bd8585011c9 (tree)
时间2017-09-12 20:55:32
作者Simon Marchi <simon.marchi@eric...>
CommiterSimon Marchi

Log Message

Make collect_probes return an std::vector

Change collect_probes so it returns an std::vector<bound_probe> instead
of a VEC(bound_probe_s). This allows removing some cleanups. It also
seems like enable_probes_command and disable_probes_command were not
freeing that vector.

The comparison function compare_probes needs to be updated to return a
bool indicating whether the first parameter is "less than" the second
parameter.

I defined two constructors to bound_probe. The default constructor is
needed, for example, so the instance in struct bp_location can be
constructed without parameters. The constructor with parameters is
useful so we can use emplace_back and pass the values directly.

The s390 builder on the buildbot shows a weird failure that I can't
explain:

../../binutils-gdb/gdb/elfread.c: In function void probe_key_free(bfd*, void*):
../../binutils-gdb/gdb/elfread.c:1346:8: error: types may not be defined in a for-range-declaration [-Werror]

for (struct probe *probe : *probes)
~

I guess it's a bug with that specific version< of the compiler, since no
other gcc gives me that error. It is using:

g++ (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)

Any idea about this problem?

gdb/ChangeLog:

* probe.h (struct bound_probe): Define constructors.
* probe.c (bound_probe_s): Remove typedef.
(DEF_VEC_O (bound_probe_s)): Remove VEC.
(collect_probes): Change return type to std::vector, remove
cleanup.
(compare_probes): Return bool, change parameter type. Change
semantic to "less than".
(gen_ui_out_table_header_info): Change parameter to std::vector
and update.
(exists_probe_with_pops): Likewise.
(info_probes_for_ops): Update to std::vector change.
(enable_probes_command): Likewise.
(disable_probes_command): Likewise.

更改概述

差异

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,21 @@
11 2017-09-12 Simon Marchi <simon.marchi@ericsson.com>
22
3+ * probe.h (struct bound_probe): Define constructors.
4+ * probe.c (bound_probe_s): Remove typedef.
5+ (DEF_VEC_O (bound_probe_s)): Remove VEC.
6+ (collect_probes): Change return type to std::vector, remove
7+ cleanup.
8+ (compare_probes): Return bool, change parameter type. Change
9+ semantic to "less than".
10+ (gen_ui_out_table_header_info): Change parameter to std::vector
11+ and update.
12+ (exists_probe_with_pops): Likewise.
13+ (info_probes_for_ops): Update to std::vector change.
14+ (enable_probes_command): Likewise.
15+ (disable_probes_command): Likewise.
16+
17+2017-09-12 Simon Marchi <simon.marchi@ericsson.com>
18+
319 * probe.h (struct probe_ops) <get_probes>: Change parameter from
420 vec to std::vector.
521 * probe.c (parse_probes_in_pspace): Update.
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -38,11 +38,6 @@
3838 #include <algorithm>
3939 #include "common/gdb_optional.h"
4040
41-typedef struct bound_probe bound_probe_s;
42-DEF_VEC_O (bound_probe_s);
43-
44-
45-
4641 /* A helper for parse_probes that decodes a probe specification in
4742 SEARCH_PSPACE. It appends matching SALs to RESULT. */
4843
@@ -267,17 +262,14 @@ find_probe_by_pc (CORE_ADDR pc)
267262 If POPS is not NULL, only probes of this certain probe_ops will match.
268263 Each argument is a regexp, or NULL, which matches anything. */
269264
270-static VEC (bound_probe_s) *
265+static std::vector<bound_probe>
271266 collect_probes (const std::string &objname, const std::string &provider,
272267 const std::string &probe_name, const struct probe_ops *pops)
273268 {
274269 struct objfile *objfile;
275- VEC (bound_probe_s) *result = NULL;
276- struct cleanup *cleanup;
270+ std::vector<bound_probe> result;
277271 gdb::optional<compiled_regex> obj_pat, prov_pat, probe_pat;
278272
279- cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result);
280-
281273 if (!provider.empty ())
282274 prov_pat.emplace (provider.c_str (), REG_NOSUB,
283275 _("Invalid provider regexp"));
@@ -304,8 +296,6 @@ collect_probes (const std::string &objname, const std::string &provider,
304296
305297 for (struct probe *probe : probes)
306298 {
307- struct bound_probe bound;
308-
309299 if (pops != NULL && probe->pops != pops)
310300 continue;
311301
@@ -317,46 +307,39 @@ collect_probes (const std::string &objname, const std::string &provider,
317307 && probe_pat->exec (probe->name, 0, NULL, 0) != 0)
318308 continue;
319309
320- bound.objfile = objfile;
321- bound.probe = probe;
322- VEC_safe_push (bound_probe_s, result, &bound);
310+ result.emplace_back (probe, objfile);
323311 }
324312 }
325313
326- discard_cleanups (cleanup);
327314 return result;
328315 }
329316
330317 /* A qsort comparison function for bound_probe_s objects. */
331318
332-static int
333-compare_probes (const void *a, const void *b)
319+static bool
320+compare_probes (const bound_probe &a, const bound_probe &b)
334321 {
335- const struct bound_probe *pa = (const struct bound_probe *) a;
336- const struct bound_probe *pb = (const struct bound_probe *) b;
337322 int v;
338323
339- v = strcmp (pa->probe->provider, pb->probe->provider);
340- if (v)
341- return v;
324+ v = strcmp (a.probe->provider, b.probe->provider);
325+ if (v != 0)
326+ return v < 0;
342327
343- v = strcmp (pa->probe->name, pb->probe->name);
344- if (v)
345- return v;
328+ v = strcmp (a.probe->name, b.probe->name);
329+ if (v != 0)
330+ return v < 0;
346331
347- if (pa->probe->address < pb->probe->address)
348- return -1;
349- if (pa->probe->address > pb->probe->address)
350- return 1;
332+ if (a.probe->address != b.probe->address)
333+ return a.probe->address < b.probe->address;
351334
352- return strcmp (objfile_name (pa->objfile), objfile_name (pb->objfile));
335+ return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0;
353336 }
354337
355338 /* Helper function that generate entries in the ui_out table being
356339 crafted by `info_probes_for_ops'. */
357340
358341 static void
359-gen_ui_out_table_header_info (VEC (bound_probe_s) *probes,
342+gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
360343 const struct probe_ops *p)
361344 {
362345 /* `headings' refers to the names of the columns when printing `info
@@ -385,11 +368,9 @@ gen_ui_out_table_header_info (VEC (bound_probe_s) *probes,
385368 VEC_iterate (info_probe_column_s, headings, ix, column);
386369 ++ix)
387370 {
388- struct bound_probe *probe;
389- int jx;
390371 size_t size_max = strlen (column->print_name);
391372
392- for (jx = 0; VEC_iterate (bound_probe_s, probes, jx, probe); ++jx)
373+ for (const bound_probe &probe : probes)
393374 {
394375 /* `probe_fields' refers to the values of each new field that this
395376 probe will display. */
@@ -398,11 +379,11 @@ gen_ui_out_table_header_info (VEC (bound_probe_s) *probes,
398379 const char *val;
399380 int kx;
400381
401- if (probe->probe->pops != p)
382+ if (probe.probe->pops != p)
402383 continue;
403384
404385 c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
405- p->gen_info_probes_table_values (probe->probe, &probe_fields);
386+ p->gen_info_probes_table_values (probe.probe, &probe_fields);
406387
407388 gdb_assert (VEC_length (const_char_ptr, probe_fields)
408389 == headings_size);
@@ -529,14 +510,14 @@ get_number_extra_fields (const struct probe_ops *pops)
529510 featuring the given POPS. It returns 0 otherwise. */
530511
531512 static int
532-exists_probe_with_pops (VEC (bound_probe_s) *probes,
513+exists_probe_with_pops (const std::vector<bound_probe> &probes,
533514 const struct probe_ops *pops)
534515 {
535516 struct bound_probe *probe;
536517 int ix;
537518
538- for (ix = 0; VEC_iterate (bound_probe_s, probes, ix, probe); ++ix)
539- if (probe->probe->pops == pops)
519+ for (const bound_probe &probe : probes)
520+ if (probe.probe->pops == pops)
540521 return 1;
541522
542523 return 0;
@@ -568,21 +549,19 @@ info_probes_for_ops (const char *arg, int from_tty,
568549 {
569550 std::string provider, probe_name, objname;
570551 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
571- VEC (bound_probe_s) *probes;
572- int i, any_found;
552+ int any_found;
573553 int ui_out_extra_fields = 0;
574554 size_t size_addr;
575555 size_t size_name = strlen ("Name");
576556 size_t size_objname = strlen ("Object");
577557 size_t size_provider = strlen ("Provider");
578558 size_t size_type = strlen ("Type");
579- struct bound_probe *probe;
580559 struct gdbarch *gdbarch = get_current_arch ();
581560
582561 parse_probe_linespec (arg, &provider, &probe_name, &objname);
583562
584- probes = collect_probes (objname, provider, probe_name, pops);
585- make_cleanup (VEC_cleanup (probe_p), &probes);
563+ std::vector<bound_probe> probes
564+ = collect_probes (objname, provider, probe_name, pops);
586565
587566 if (pops == NULL)
588567 {
@@ -609,27 +588,23 @@ info_probes_for_ops (const char *arg, int from_tty,
609588 {
610589 ui_out_emit_table table_emitter (current_uiout,
611590 5 + ui_out_extra_fields,
612- VEC_length (bound_probe_s, probes),
613- "StaticProbes");
591+ probes.size (), "StaticProbes");
614592
615- if (!VEC_empty (bound_probe_s, probes))
616- qsort (VEC_address (bound_probe_s, probes),
617- VEC_length (bound_probe_s, probes),
618- sizeof (bound_probe_s), compare_probes);
593+ std::sort (probes.begin (), probes.end (), compare_probes);
619594
620595 /* What's the size of an address in our architecture? */
621596 size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10;
622597
623598 /* Determining the maximum size of each field (`type', `provider',
624599 `name' and `objname'). */
625- for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
600+ for (const bound_probe &probe : probes)
626601 {
627- const char *probe_type = probe->probe->pops->type_name (probe->probe);
602+ const char *probe_type = probe.probe->pops->type_name (probe.probe);
628603
629604 size_type = std::max (strlen (probe_type), size_type);
630- size_name = std::max (strlen (probe->probe->name), size_name);
631- size_provider = std::max (strlen (probe->probe->provider), size_provider);
632- size_objname = std::max (strlen (objfile_name (probe->objfile)),
605+ size_name = std::max (strlen (probe.probe->name), size_name);
606+ size_provider = std::max (strlen (probe.probe->provider), size_provider);
607+ size_objname = std::max (strlen (objfile_name (probe.objfile)),
633608 size_objname);
634609 }
635610
@@ -657,18 +632,18 @@ info_probes_for_ops (const char *arg, int from_tty,
657632 current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
658633 current_uiout->table_body ();
659634
660- for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
635+ for (const bound_probe &probe : probes)
661636 {
662- const char *probe_type = probe->probe->pops->type_name (probe->probe);
637+ const char *probe_type = probe.probe->pops->type_name (probe.probe);
663638
664639 ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
665640
666641 current_uiout->field_string ("type",probe_type);
667- current_uiout->field_string ("provider", probe->probe->provider);
668- current_uiout->field_string ("name", probe->probe->name);
669- current_uiout->field_core_addr (
670- "addr", probe->probe->arch,
671- get_probe_address (probe->probe, probe->objfile));
642+ current_uiout->field_string ("provider", probe.probe->provider);
643+ current_uiout->field_string ("name", probe.probe->name);
644+ current_uiout->field_core_addr ("addr", probe.probe->arch,
645+ get_probe_address (probe.probe,
646+ probe.objfile));
672647
673648 if (pops == NULL)
674649 {
@@ -677,20 +652,20 @@ info_probes_for_ops (const char *arg, int from_tty,
677652
678653 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po);
679654 ++ix)
680- if (probe->probe->pops == po)
681- print_ui_out_info (probe->probe);
655+ if (probe.probe->pops == po)
656+ print_ui_out_info (probe.probe);
682657 else if (exists_probe_with_pops (probes, po))
683658 print_ui_out_not_applicables (po);
684659 }
685660 else
686- print_ui_out_info (probe->probe);
661+ print_ui_out_info (probe.probe);
687662
688663 current_uiout->field_string ("object",
689- objfile_name (probe->objfile));
664+ objfile_name (probe.objfile));
690665 current_uiout->text ("\n");
691666 }
692667
693- any_found = !VEC_empty (bound_probe_s, probes);
668+ any_found = !probes.empty ();
694669 }
695670 do_cleanups (cleanup);
696671
@@ -713,14 +688,12 @@ enable_probes_command (char *arg, int from_tty)
713688 {
714689 std::string provider, probe_name, objname;
715690 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
716- VEC (bound_probe_s) *probes;
717- struct bound_probe *probe;
718- int i;
719691
720692 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
721693
722- probes = collect_probes (objname, provider, probe_name, NULL);
723- if (VEC_empty (bound_probe_s, probes))
694+ std::vector<bound_probe> probes
695+ = collect_probes (objname, provider, probe_name, NULL);
696+ if (probes.empty ())
724697 {
725698 current_uiout->message (_("No probes matched.\n"));
726699 do_cleanups (cleanup);
@@ -729,19 +702,19 @@ enable_probes_command (char *arg, int from_tty)
729702
730703 /* Enable the selected probes, provided their backends support the
731704 notion of enabling a probe. */
732- for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
705+ for (const bound_probe &probe: probes)
733706 {
734- const struct probe_ops *pops = probe->probe->pops;
707+ const struct probe_ops *pops = probe.probe->pops;
735708
736709 if (pops->enable_probe != NULL)
737710 {
738- pops->enable_probe (probe->probe);
711+ pops->enable_probe (probe.probe);
739712 current_uiout->message (_("Probe %s:%s enabled.\n"),
740- probe->probe->provider, probe->probe->name);
713+ probe.probe->provider, probe.probe->name);
741714 }
742715 else
743716 current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
744- probe->probe->provider, probe->probe->name);
717+ probe.probe->provider, probe.probe->name);
745718 }
746719
747720 do_cleanups (cleanup);
@@ -754,14 +727,12 @@ disable_probes_command (char *arg, int from_tty)
754727 {
755728 std::string provider, probe_name, objname;
756729 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
757- VEC (bound_probe_s) *probes;
758- struct bound_probe *probe;
759- int i;
760730
761731 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
762732
763- probes = collect_probes (objname, provider, probe_name, NULL /* pops */);
764- if (VEC_empty (bound_probe_s, probes))
733+ std::vector<bound_probe> probes
734+ = collect_probes (objname, provider, probe_name, NULL /* pops */);
735+ if (probes.empty ())
765736 {
766737 current_uiout->message (_("No probes matched.\n"));
767738 do_cleanups (cleanup);
@@ -770,19 +741,19 @@ disable_probes_command (char *arg, int from_tty)
770741
771742 /* Disable the selected probes, provided their backends support the
772743 notion of enabling a probe. */
773- for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
744+ for (const bound_probe &probe : probes)
774745 {
775- const struct probe_ops *pops = probe->probe->pops;
746+ const struct probe_ops *pops = probe.probe->pops;
776747
777748 if (pops->disable_probe != NULL)
778749 {
779- pops->disable_probe (probe->probe);
750+ pops->disable_probe (probe.probe);
780751 current_uiout->message (_("Probe %s:%s disabled.\n"),
781- probe->probe->provider, probe->probe->name);
752+ probe.probe->provider, probe.probe->name);
782753 }
783754 else
784755 current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
785- probe->probe->provider, probe->probe->name);
756+ probe.probe->provider, probe.probe->name);
786757 }
787758
788759 do_cleanups (cleanup);
--- a/gdb/probe.h
+++ b/gdb/probe.h
@@ -214,15 +214,26 @@ struct probe
214214 their point of use. */
215215
216216 struct bound_probe
217- {
218- /* The probe. */
217+{
218+ /* Create an empty bound_probe object. */
219219
220- struct probe *probe;
220+ bound_probe ()
221+ {}
221222
222- /* The objfile in which the probe originated. */
223+ /* Create and initialize a bound_probe object using PROBE and OBJFILE. */
223224
224- struct objfile *objfile;
225- };
225+ bound_probe (struct probe *probe_, struct objfile *objfile_)
226+ : probe (probe_), objfile (objfile_)
227+ {}
228+
229+ /* The probe. */
230+
231+ struct probe *probe = NULL;
232+
233+ /* The objfile in which the probe originated. */
234+
235+ struct objfile *objfile = NULL;
236+};
226237
227238 /* A helper for linespec that decodes a probe specification. It
228239 returns a std::vector<symtab_and_line> object and updates LOC or