RE: [PATCHv3 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h

Metzger, Markus T
2019-09-26T08:47:30Z

Hello Andrew,

I can help you run the gdb.btrace suite. Do you have a user branch with these patches?

> @@ -1068,13 +1069,12 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
>
> while (blk != 0)
> {
> - btrace_block_s *block;
> CORE_ADDR pc;
>
> blk -= 1;
>
> - block = VEC_index (btrace_block_s, btrace->blocks, blk);
> - pc = block->begin;
> + const btrace_block &block = btrace->blocks->at (blk);
> + pc = block.begin;

We could also turn BTRACE->BLOCKS into a const & outside the loop.

> @@ -1581,11 +1580,9 @@ btrace_add_pc (struct thread_info *tp)
> pc = regcache_read_pc (regcache);
>
> btrace.format = BTRACE_FORMAT_BTS;
> - btrace.variant.bts.blocks = NULL;
> + btrace.variant.bts.blocks = new std::vector <btrace_block>;

A stack-allocated vector should do. Looks like we leaked the one-entry
vector before.

> @@ -2052,9 +2048,8 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
> begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
> end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
>
> - block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
> - block->begin = *begin;
> - block->end = *end;
> + gdb_assert (btrace->variant.bts.blocks != nullptr);

We don't check most pointers in GDB. Besides, we just allocated the vector.
The invariant is that if BTRACE->FORMAT == BTRACE_FORMAT_BTS, the vector
is non-null.

> @@ -3095,7 +3090,8 @@ btrace_maint_update_packets (struct btrace_thread_info
> *btinfo,
> case BTRACE_FORMAT_BTS:
> /* Nothing to do - we operate directly on BTINFO->DATA. */
> *begin = 0;
> - *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
> + gdb_assert (btinfo->data.variant.bts.blocks != nullptr);

See above. More below.

Regards,
Markus.

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928