Re: Allocation of dwarf2_frame_state_reg_info

Daniel Jacobowitz
2006-03-21T14:20:48Z

On Tue, Mar 14, 2006 at 04:16:23PM +0000, Christopher Philip SMITH wrote:
> In dwarf2-frame.c:dwarf2_frame_cache(), the two
> dwarf2_frame_state_reg_infos, fs->regs and fs->initial, seem to be
> allocated by calls to dwarf2_frame_state_alloc_regs() in only some cases
> of execute_cfa_program(). In the case of the function above, none of the
> cases exercised while going through the CIE result in an allocation,
> which has the effect back in dwarf2_frame_cache() of leaving fs->initial
> unallocated, and so uninitialised.

Well, it's not entirely uninitialized, is it? At least it was memset
to zeroes.

> Later, when processing the FDE, a
> DW_CFA_restore is encountered which reads from fs->initial and causes
> the error...

dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
if (reg < fs->initial.num_regs)
fs->regs.reg[reg] = fs->initial.reg[reg];
else
fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNSPECIFIED;

Are we looking at the same version of GDB here?

> My question is, what is the reasoning behind only allocating the
> dwarf2_frame_state_reg_infos in execute_cfa_program()? It seems that if
> both fs->regs and fs->initial were allocated with the dwarf2_frame_state
> at the beginning of dwarf2_frame_cache(), then all the registers would
> be set as "undefined" unless explicitly changed when processing the
> DWARF (standard behaviour?) and the uninitialised read could never
> happen? Is it only a case of avoiding unnecessary allocation, or is
> there something more subtle going on here?

The problem is that we have no idea how many columns there are.

--
Daniel Jacobowitz
CodeSourcery