GNU Binutils with patches for OS216
Revisión | aaa63a31909946c4f68da64a93662147d67630bd (tree) |
---|---|
Tiempo | 2017-09-12 20:37:00 |
Autor | Simon Marchi <simon.marchi@eric...> |
Commiter | Simon Marchi |
Make probe_ops::get_probes fill an std::vector
This patch changes one usage of VEC to std::vector. It is a relatively
straightforward 1:1 change. The implementations of
sym_probe_fns::sym_get_probes return a borrowed reference to their probe
vectors, meaning that the caller should not free it. In the new code, I
made them return a const reference to the vector.
This patch and the following one were tested by the buildbot. I didn't
see any failures that looked related to this one.
gdb/ChangeLog:
* probe.h (struct probe_ops) <get_probes>: Change parameter from
vec to std::vector.
* probe.c (parse_probes_in_pspace): Update.
(find_probes_in_objfile): Update.
(find_probe_by_pc): Update.
(collect_probes): Update.
(probe_any_get_probes): Update.
* symfile.h (struct sym_probe_fns) <sym_get_probes> Change
return type to reference to std::vector.
* dtrace-probe.c (dtrace_process_dof_probe): Change parameter to
std::vector and update.
(dtrace_process_dof): Likewise.
(dtrace_get_probes): Likewise.
* elfread.c (elf_get_probes): Change return type to std::vector,
store an std::vector in bfd_data.
(probe_key_free): Update to std::vector.
* stap-probe.c (handle_stap_probe): Change parameter to
std::vector and update.
(stap_get_probes): Likewise.
* symfile-debug.c (debug_sym_get_probes): Change return type to
std::vector and update.
@@ -1,3 +1,27 @@ | ||
1 | +2017-09-12 Simon Marchi <simon.marchi@ericsson.com> | |
2 | + | |
3 | + * probe.h (struct probe_ops) <get_probes>: Change parameter from | |
4 | + vec to std::vector. | |
5 | + * probe.c (parse_probes_in_pspace): Update. | |
6 | + (find_probes_in_objfile): Update. | |
7 | + (find_probe_by_pc): Update. | |
8 | + (collect_probes): Update. | |
9 | + (probe_any_get_probes): Update. | |
10 | + * symfile.h (struct sym_probe_fns) <sym_get_probes> Change | |
11 | + return type to reference to std::vector. | |
12 | + * dtrace-probe.c (dtrace_process_dof_probe): Change parameter to | |
13 | + std::vector and update. | |
14 | + (dtrace_process_dof): Likewise. | |
15 | + (dtrace_get_probes): Likewise. | |
16 | + * elfread.c (elf_get_probes): Change return type to std::vector, | |
17 | + store an std::vector in bfd_data. | |
18 | + (probe_key_free): Update to std::vector. | |
19 | + * stap-probe.c (handle_stap_probe): Change parameter to | |
20 | + std::vector and update. | |
21 | + (stap_get_probes): Likewise. | |
22 | + * symfile-debug.c (debug_sym_get_probes): Change return type to | |
23 | + std::vector and update. | |
24 | + | |
1 | 25 | 2017-09-11 Tom Tromey <tom@tromey.com> |
2 | 26 | |
3 | 27 | * breakpoint.c (program_breakpoint_here_p): Update. |
@@ -313,7 +313,8 @@ struct dtrace_dof_probe | ||
313 | 313 | |
314 | 314 | static void |
315 | 315 | dtrace_process_dof_probe (struct objfile *objfile, |
316 | - struct gdbarch *gdbarch, VEC (probe_p) **probesp, | |
316 | + struct gdbarch *gdbarch, | |
317 | + std::vector<probe *> *probesp, | |
317 | 318 | struct dtrace_dof_hdr *dof, |
318 | 319 | struct dtrace_dof_probe *probe, |
319 | 320 | struct dtrace_dof_provider *provider, |
@@ -448,7 +449,7 @@ dtrace_process_dof_probe (struct objfile *objfile, | ||
448 | 449 | ret->enablers = VEC_copy (dtrace_probe_enabler_s, enablers); |
449 | 450 | |
450 | 451 | /* Successfully created probe. */ |
451 | - VEC_safe_push (probe_p, *probesp, (struct probe *) ret); | |
452 | + probesp->push_back ((struct probe *) ret); | |
452 | 453 | } |
453 | 454 | |
454 | 455 | do_cleanups (cleanup); |
@@ -461,7 +462,7 @@ dtrace_process_dof_probe (struct objfile *objfile, | ||
461 | 462 | |
462 | 463 | static void |
463 | 464 | dtrace_process_dof (asection *sect, struct objfile *objfile, |
464 | - VEC (probe_p) **probesp, struct dtrace_dof_hdr *dof) | |
465 | + std::vector<probe *> *probesp, struct dtrace_dof_hdr *dof) | |
465 | 466 | { |
466 | 467 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
467 | 468 | struct dtrace_dof_sect *section; |
@@ -620,7 +621,7 @@ dtrace_get_arg (struct dtrace_probe *probe, unsigned n, | ||
620 | 621 | /* Implementation of the get_probes method. */ |
621 | 622 | |
622 | 623 | static void |
623 | -dtrace_get_probes (VEC (probe_p) **probesp, struct objfile *objfile) | |
624 | +dtrace_get_probes (std::vector<probe *> *probesp, struct objfile *objfile) | |
624 | 625 | { |
625 | 626 | bfd *abfd = objfile->obfd; |
626 | 627 | asection *sect = NULL; |
@@ -1309,35 +1309,30 @@ elf_symfile_init (struct objfile *objfile) | ||
1309 | 1309 | |
1310 | 1310 | /* Implementation of `sym_get_probes', as documented in symfile.h. */ |
1311 | 1311 | |
1312 | -static VEC (probe_p) * | |
1312 | +static const std::vector<probe *> & | |
1313 | 1313 | elf_get_probes (struct objfile *objfile) |
1314 | 1314 | { |
1315 | - VEC (probe_p) *probes_per_bfd; | |
1315 | + std::vector<probe *> *probes_per_bfd; | |
1316 | 1316 | |
1317 | 1317 | /* Have we parsed this objfile's probes already? */ |
1318 | - probes_per_bfd = (VEC (probe_p) *) bfd_data (objfile->obfd, probe_key); | |
1318 | + probes_per_bfd = (std::vector<probe *> *) bfd_data (objfile->obfd, probe_key); | |
1319 | 1319 | |
1320 | - if (!probes_per_bfd) | |
1320 | + if (probes_per_bfd == NULL) | |
1321 | 1321 | { |
1322 | 1322 | int ix; |
1323 | 1323 | const struct probe_ops *probe_ops; |
1324 | + probes_per_bfd = new std::vector<probe *>; | |
1324 | 1325 | |
1325 | 1326 | /* Here we try to gather information about all types of probes from the |
1326 | 1327 | objfile. */ |
1327 | 1328 | for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); |
1328 | 1329 | ix++) |
1329 | - probe_ops->get_probes (&probes_per_bfd, objfile); | |
1330 | - | |
1331 | - if (probes_per_bfd == NULL) | |
1332 | - { | |
1333 | - VEC_reserve (probe_p, probes_per_bfd, 1); | |
1334 | - gdb_assert (probes_per_bfd != NULL); | |
1335 | - } | |
1330 | + probe_ops->get_probes (probes_per_bfd, objfile); | |
1336 | 1331 | |
1337 | 1332 | set_bfd_data (objfile->obfd, probe_key, probes_per_bfd); |
1338 | 1333 | } |
1339 | 1334 | |
1340 | - return probes_per_bfd; | |
1335 | + return *probes_per_bfd; | |
1341 | 1336 | } |
1342 | 1337 | |
1343 | 1338 | /* Helper function used to free the space allocated for storing SystemTap |
@@ -1346,14 +1341,12 @@ elf_get_probes (struct objfile *objfile) | ||
1346 | 1341 | static void |
1347 | 1342 | probe_key_free (bfd *abfd, void *d) |
1348 | 1343 | { |
1349 | - int ix; | |
1350 | - VEC (probe_p) *probes = (VEC (probe_p) *) d; | |
1351 | - struct probe *probe; | |
1344 | + std::vector<probe *> *probes = (std::vector<probe *> *) d; | |
1352 | 1345 | |
1353 | - for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
1346 | + for (struct probe *probe : *probes) | |
1354 | 1347 | probe->pops->destroy (probe); |
1355 | 1348 | |
1356 | - VEC_free (probe_p, probes); | |
1349 | + delete probes; | |
1357 | 1350 | } |
1358 | 1351 | |
1359 | 1352 |
@@ -58,10 +58,6 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops, | ||
58 | 58 | |
59 | 59 | ALL_PSPACE_OBJFILES (search_pspace, objfile) |
60 | 60 | { |
61 | - VEC (probe_p) *probes; | |
62 | - struct probe *probe; | |
63 | - int ix; | |
64 | - | |
65 | 61 | if (!objfile->sf || !objfile->sf->sym_probe_fns) |
66 | 62 | continue; |
67 | 63 |
@@ -71,9 +67,10 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops, | ||
71 | 67 | objfile_namestr) != 0) |
72 | 68 | continue; |
73 | 69 | |
74 | - probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
70 | + const std::vector<probe *> &probes | |
71 | + = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
75 | 72 | |
76 | - for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
73 | + for (struct probe *probe : probes) | |
77 | 74 | { |
78 | 75 | if (probe_ops != &probe_ops_any && probe->pops != probe_ops) |
79 | 76 | continue; |
@@ -211,15 +208,14 @@ VEC (probe_p) * | ||
211 | 208 | find_probes_in_objfile (struct objfile *objfile, const char *provider, |
212 | 209 | const char *name) |
213 | 210 | { |
214 | - VEC (probe_p) *probes, *result = NULL; | |
215 | - int ix; | |
216 | - struct probe *probe; | |
211 | + VEC (probe_p) *result = NULL; | |
217 | 212 | |
218 | 213 | if (!objfile->sf || !objfile->sf->sym_probe_fns) |
219 | 214 | return NULL; |
220 | 215 | |
221 | - probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
222 | - for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
216 | + const std::vector<probe *> &probes | |
217 | + = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
218 | + for (struct probe *probe : probes) | |
223 | 219 | { |
224 | 220 | if (strcmp (probe->provider, provider) != 0) |
225 | 221 | continue; |
@@ -246,17 +242,14 @@ find_probe_by_pc (CORE_ADDR pc) | ||
246 | 242 | |
247 | 243 | ALL_OBJFILES (objfile) |
248 | 244 | { |
249 | - VEC (probe_p) *probes; | |
250 | - int ix; | |
251 | - struct probe *probe; | |
252 | - | |
253 | 245 | if (!objfile->sf || !objfile->sf->sym_probe_fns |
254 | 246 | || objfile->sect_index_text == -1) |
255 | 247 | continue; |
256 | 248 | |
257 | 249 | /* If this proves too inefficient, we can replace with a hash. */ |
258 | - probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
259 | - for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
250 | + const std::vector<probe *> &probes | |
251 | + = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
252 | + for (struct probe *probe : probes) | |
260 | 253 | if (get_probe_address (probe, objfile) == pc) |
261 | 254 | { |
262 | 255 | result.objfile = objfile; |
@@ -297,10 +290,6 @@ collect_probes (const std::string &objname, const std::string &provider, | ||
297 | 290 | |
298 | 291 | ALL_OBJFILES (objfile) |
299 | 292 | { |
300 | - VEC (probe_p) *probes; | |
301 | - struct probe *probe; | |
302 | - int ix; | |
303 | - | |
304 | 293 | if (! objfile->sf || ! objfile->sf->sym_probe_fns) |
305 | 294 | continue; |
306 | 295 |
@@ -310,9 +299,10 @@ collect_probes (const std::string &objname, const std::string &provider, | ||
310 | 299 | continue; |
311 | 300 | } |
312 | 301 | |
313 | - probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
302 | + const std::vector<probe *> &probes | |
303 | + = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
314 | 304 | |
315 | - for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
305 | + for (struct probe *probe : probes) | |
316 | 306 | { |
317 | 307 | struct bound_probe bound; |
318 | 308 |
@@ -901,7 +891,7 @@ probe_any_is_linespec (const char **linespecp) | ||
901 | 891 | /* Dummy method used for `probe_ops_any'. */ |
902 | 892 | |
903 | 893 | static void |
904 | -probe_any_get_probes (VEC (probe_p) **probesp, struct objfile *objfile) | |
894 | +probe_any_get_probes (std::vector<probe *> *probesp, struct objfile *objfile) | |
905 | 895 | { |
906 | 896 | /* No probes can be provided by this dummy backend. */ |
907 | 897 | } |
@@ -64,7 +64,7 @@ struct probe_ops | ||
64 | 64 | |
65 | 65 | /* Function that should fill PROBES with known probes from OBJFILE. */ |
66 | 66 | |
67 | - void (*get_probes) (VEC (probe_p) **probes, struct objfile *objfile); | |
67 | + void (*get_probes) (std::vector<probe *> *probes, struct objfile *objfile); | |
68 | 68 | |
69 | 69 | /* Compute the probe's relocated address. OBJFILE is the objfile |
70 | 70 | in which the probe originated. */ |
@@ -1472,7 +1472,7 @@ stap_clear_semaphore (struct probe *probe_generic, struct objfile *objfile, | ||
1472 | 1472 | |
1473 | 1473 | static void |
1474 | 1474 | handle_stap_probe (struct objfile *objfile, struct sdt_note *el, |
1475 | - VEC (probe_p) **probesp, CORE_ADDR base) | |
1475 | + std::vector<probe *> *probesp, CORE_ADDR base) | |
1476 | 1476 | { |
1477 | 1477 | bfd *abfd = objfile->obfd; |
1478 | 1478 | int size = bfd_get_arch_size (abfd) / 8; |
@@ -1543,7 +1543,7 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el, | ||
1543 | 1543 | ret->args_u.text = probe_args; |
1544 | 1544 | |
1545 | 1545 | /* Successfully created probe. */ |
1546 | - VEC_safe_push (probe_p, *probesp, (struct probe *) ret); | |
1546 | + probesp->push_back ((struct probe *) ret); | |
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | /* Helper function which tries to find the base address of the SystemTap |
@@ -1588,7 +1588,7 @@ get_stap_base_address (bfd *obfd, bfd_vma *base) | ||
1588 | 1588 | SystemTap probes from OBJFILE. */ |
1589 | 1589 | |
1590 | 1590 | static void |
1591 | -stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile) | |
1591 | +stap_get_probes (std::vector<probe *> *probesp, struct objfile *objfile) | |
1592 | 1592 | { |
1593 | 1593 | /* If we are here, then this is the first time we are parsing the |
1594 | 1594 | SystemTap probe's information. We basically have to count how many |
@@ -1597,7 +1597,7 @@ stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile) | ||
1597 | 1597 | bfd *obfd = objfile->obfd; |
1598 | 1598 | bfd_vma base; |
1599 | 1599 | struct sdt_note *iter; |
1600 | - unsigned save_probesp_len = VEC_length (probe_p, *probesp); | |
1600 | + unsigned save_probesp_len = probesp->size (); | |
1601 | 1601 | |
1602 | 1602 | if (objfile->separate_debug_objfile_backlink != NULL) |
1603 | 1603 | { |
@@ -1628,7 +1628,7 @@ stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile) | ||
1628 | 1628 | handle_stap_probe (objfile, iter, probesp, base); |
1629 | 1629 | } |
1630 | 1630 | |
1631 | - if (save_probesp_len == VEC_length (probe_p, *probesp)) | |
1631 | + if (save_probesp_len == probesp->size ()) | |
1632 | 1632 | { |
1633 | 1633 | /* If we are here, it means we have failed to parse every known |
1634 | 1634 | probe. */ |
@@ -384,20 +384,20 @@ static const struct quick_symbol_functions debug_sym_quick_functions = | ||
384 | 384 | |
385 | 385 | /* Debugging version of struct sym_probe_fns. */ |
386 | 386 | |
387 | -static VEC (probe_p) * | |
387 | +static const std::vector<probe *> & | |
388 | 388 | debug_sym_get_probes (struct objfile *objfile) |
389 | 389 | { |
390 | 390 | const struct debug_sym_fns_data *debug_data |
391 | 391 | = ((const struct debug_sym_fns_data *) |
392 | 392 | objfile_data (objfile, symfile_debug_objfile_data_key)); |
393 | - VEC (probe_p) *retval; | |
394 | 393 | |
395 | - retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile); | |
394 | + const std::vector<probe *> &retval | |
395 | + = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile); | |
396 | 396 | |
397 | 397 | fprintf_filtered (gdb_stdlog, |
398 | 398 | "probes->sym_get_probes (%s) = %s\n", |
399 | 399 | objfile_debug_name (objfile), |
400 | - host_address_to_string (retval)); | |
400 | + host_address_to_string (retval.data ())); | |
401 | 401 | |
402 | 402 | return retval; |
403 | 403 | } |
@@ -314,11 +314,8 @@ struct quick_symbol_functions | ||
314 | 314 | |
315 | 315 | struct sym_probe_fns |
316 | 316 | { |
317 | - /* If non-NULL, return an array of probe objects. | |
318 | - | |
319 | - The returned value does not have to be freed and it has lifetime of the | |
320 | - OBJFILE. */ | |
321 | - VEC (probe_p) *(*sym_get_probes) (struct objfile *); | |
317 | + /* If non-NULL, return a reference to vector of probe objects. */ | |
318 | + const std::vector<probe *> &(*sym_get_probes) (struct objfile *); | |
322 | 319 | }; |
323 | 320 | |
324 | 321 | /* Structure to keep track of symbol reading functions for various |