GNU Binutils with patches for OS216
Revisión | 1c90d9f022469629c255d44664b4452998168359 (tree) |
---|---|
Tiempo | 2017-08-11 17:30:02 |
Autor | Yao Qi <yao.qi@lina...> |
Commiter | Yao Qi |
Class-fy dwarf2_frame_state_reg_info
This patch adds dwarf2_frame_state_reg_info ctor, dtor, copy ctor,
assignment operator, and move assignment. This patch also adds unit test
to execute_cfa_program to cover the changes.
gdb:
2017-08-11 Yao Qi <yao.qi@linaro.org>
* dwarf2-frame.c (dwarf2_frame_state_alloc_regs): Remove.
(dwarf2_frame_state_copy_regs): Remove.
(dwarf2_frame_state_free_regs): Remove.
(dwarf2_frame_state::~dwarf2_frame_state): Remove.
(dwarf2_restore_rule): Call method .alloc_regs instead of
dwarf2_frame_state_alloc_regs.
(execute_cfa_program): Likewise. Call dwarf2_frame_state_reg_info
constructor. Call std::move.
(dwarf2_fetch_cfa_info): Don't call dwarf2_frame_state_copy_regs.
(dwarf2_frame_cache): Likewise.
[GDB_SELF_TEST]: Include selftest.h and
selftest-arch.h.
[GDB_SELF_TEST] (execute_cfa_program_test): New function.
(_initialize_dwarf2_frame) [GDB_SELF_TEST]: Register
execute_cfa_program_test.
* dwarf2-frame.h (dwarf2_frame_state_reg_info): Add ctor, dtor,
copy ctor, assignment operator, move assignment.
<alloc_regs>: New method.
<swap>: New method.
(struct dwarf2_frame_state): Delete dtor.
(dwarf2_frame_state_alloc_regs): Remove declaration.
* sparc-tdep.c (sparc_execute_dwarf_cfa_vendor_op): Don't call
dwarf2_frame_state_alloc_regs, use .alloc_regs instead.
@@ -1,5 +1,33 @@ | ||
1 | 1 | 2017-08-11 Yao Qi <yao.qi@linaro.org> |
2 | 2 | |
3 | + * dwarf2-frame.c (dwarf2_frame_state_alloc_regs): Remove. | |
4 | + (dwarf2_frame_state_copy_regs): Remove. | |
5 | + (dwarf2_frame_state_free_regs): Remove. | |
6 | + (dwarf2_frame_state::~dwarf2_frame_state): Remove. | |
7 | + (dwarf2_restore_rule): Call method .alloc_regs instead of | |
8 | + dwarf2_frame_state_alloc_regs. | |
9 | + (execute_cfa_program): Likewise. Call dwarf2_frame_state_reg_info | |
10 | + constructor. Call std::move. | |
11 | + (dwarf2_fetch_cfa_info): Don't call dwarf2_frame_state_copy_regs. | |
12 | + (dwarf2_frame_cache): Likewise. | |
13 | + | |
14 | + [GDB_SELF_TEST]: Include selftest.h and | |
15 | + selftest-arch.h. | |
16 | + [GDB_SELF_TEST] (execute_cfa_program_test): New function. | |
17 | + (_initialize_dwarf2_frame) [GDB_SELF_TEST]: Register | |
18 | + execute_cfa_program_test. | |
19 | + | |
20 | + * dwarf2-frame.h (dwarf2_frame_state_reg_info): Add ctor, dtor, | |
21 | + copy ctor, assignment operator, move assignment. | |
22 | + <alloc_regs>: New method. | |
23 | + <swap>: New method. | |
24 | + (struct dwarf2_frame_state): Delete dtor. | |
25 | + (dwarf2_frame_state_alloc_regs): Remove declaration. | |
26 | + * sparc-tdep.c (sparc_execute_dwarf_cfa_vendor_op): Don't call | |
27 | + dwarf2_frame_state_alloc_regs, use .alloc_regs instead. | |
28 | + | |
29 | +2017-08-11 Yao Qi <yao.qi@linaro.org> | |
30 | + | |
3 | 31 | * dwarf2-frame.c (dwarf2_frame_state_free): Remove. |
4 | 32 | (dwarf2_frame_state::dwarf2_frame_state): New. |
5 | 33 | (dwarf2_frame_state::~dwarf2_frame_state): New. |
@@ -38,6 +38,10 @@ | ||
38 | 38 | #include "ax.h" |
39 | 39 | #include "dwarf2loc.h" |
40 | 40 | #include "dwarf2-frame-tailcall.h" |
41 | +#if GDB_SELF_TEST | |
42 | +#include "selftest.h" | |
43 | +#include "selftest-arch.h" | |
44 | +#endif | |
41 | 45 | |
42 | 46 | struct comp_unit; |
43 | 47 |
@@ -169,69 +173,12 @@ static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding, | ||
169 | 173 | which is unused in that case. */ |
170 | 174 | #define cfa_exp_len cfa_reg |
171 | 175 | |
172 | -/* Assert that the register set RS is large enough to store gdbarch_num_regs | |
173 | - columns. If necessary, enlarge the register set. */ | |
174 | - | |
175 | -void | |
176 | -dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs, | |
177 | - int num_regs) | |
178 | -{ | |
179 | - size_t size = sizeof (struct dwarf2_frame_state_reg); | |
180 | - | |
181 | - if (num_regs <= rs->num_regs) | |
182 | - return; | |
183 | - | |
184 | - rs->reg = (struct dwarf2_frame_state_reg *) | |
185 | - xrealloc (rs->reg, num_regs * size); | |
186 | - | |
187 | - /* Initialize newly allocated registers. */ | |
188 | - memset (rs->reg + rs->num_regs, 0, (num_regs - rs->num_regs) * size); | |
189 | - rs->num_regs = num_regs; | |
190 | -} | |
191 | - | |
192 | -/* Copy the register columns in register set RS into newly allocated | |
193 | - memory and return a pointer to this newly created copy. */ | |
194 | - | |
195 | -static struct dwarf2_frame_state_reg * | |
196 | -dwarf2_frame_state_copy_regs (struct dwarf2_frame_state_reg_info *rs) | |
197 | -{ | |
198 | - size_t size = rs->num_regs * sizeof (struct dwarf2_frame_state_reg); | |
199 | - struct dwarf2_frame_state_reg *reg; | |
200 | - | |
201 | - reg = (struct dwarf2_frame_state_reg *) xmalloc (size); | |
202 | - memcpy (reg, rs->reg, size); | |
203 | - | |
204 | - return reg; | |
205 | -} | |
206 | - | |
207 | -/* Release the memory allocated to register set RS. */ | |
208 | - | |
209 | -static void | |
210 | -dwarf2_frame_state_free_regs (struct dwarf2_frame_state_reg_info *rs) | |
211 | -{ | |
212 | - if (rs) | |
213 | - { | |
214 | - dwarf2_frame_state_free_regs (rs->prev); | |
215 | - | |
216 | - xfree (rs->reg); | |
217 | - xfree (rs); | |
218 | - } | |
219 | -} | |
220 | - | |
221 | 176 | dwarf2_frame_state::dwarf2_frame_state (CORE_ADDR pc_, struct dwarf2_cie *cie) |
222 | 177 | : pc (pc_), data_align (cie->data_alignment_factor), |
223 | 178 | code_align (cie->code_alignment_factor), |
224 | 179 | retaddr_column (cie->return_address_register) |
225 | 180 | { |
226 | 181 | } |
227 | - | |
228 | -dwarf2_frame_state::~dwarf2_frame_state () | |
229 | -{ | |
230 | - dwarf2_frame_state_free_regs (initial.prev); | |
231 | - dwarf2_frame_state_free_regs (regs.prev); | |
232 | - xfree (initial.reg); | |
233 | - xfree (regs.reg); | |
234 | -} | |
235 | 182 | |
236 | 183 | |
237 | 184 | /* Helper functions for execute_stack_op. */ |
@@ -255,7 +202,7 @@ dwarf2_restore_rule (struct gdbarch *gdbarch, ULONGEST reg_num, | ||
255 | 202 | |
256 | 203 | gdb_assert (fs->initial.reg); |
257 | 204 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg_num, eh_frame_p); |
258 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
205 | + fs->regs.alloc_regs (reg + 1); | |
259 | 206 | |
260 | 207 | /* Check if this register was explicitly initialized in the |
261 | 208 | CIE initial instructions. If not, default the rule to |
@@ -409,7 +356,7 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr, | ||
409 | 356 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
410 | 357 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); |
411 | 358 | offset = utmp * fs->data_align; |
412 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
359 | + fs->regs.alloc_regs (reg + 1); | |
413 | 360 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; |
414 | 361 | fs->regs.reg[reg].loc.offset = offset; |
415 | 362 | } |
@@ -453,7 +400,7 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr, | ||
453 | 400 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
454 | 401 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); |
455 | 402 | offset = utmp * fs->data_align; |
456 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
403 | + fs->regs.alloc_regs (reg + 1); | |
457 | 404 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; |
458 | 405 | fs->regs.reg[reg].loc.offset = offset; |
459 | 406 | break; |
@@ -466,14 +413,14 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr, | ||
466 | 413 | case DW_CFA_undefined: |
467 | 414 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, ®); |
468 | 415 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
469 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
416 | + fs->regs.alloc_regs (reg + 1); | |
470 | 417 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNDEFINED; |
471 | 418 | break; |
472 | 419 | |
473 | 420 | case DW_CFA_same_value: |
474 | 421 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, ®); |
475 | 422 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
476 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
423 | + fs->regs.alloc_regs (reg + 1); | |
477 | 424 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAME_VALUE; |
478 | 425 | break; |
479 | 426 |
@@ -482,7 +429,7 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr, | ||
482 | 429 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
483 | 430 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); |
484 | 431 | utmp = dwarf2_frame_adjust_regnum (gdbarch, utmp, eh_frame_p); |
485 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
432 | + fs->regs.alloc_regs (reg + 1); | |
486 | 433 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG; |
487 | 434 | fs->regs.reg[reg].loc.reg = utmp; |
488 | 435 | break; |
@@ -491,9 +438,7 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr, | ||
491 | 438 | { |
492 | 439 | struct dwarf2_frame_state_reg_info *new_rs; |
493 | 440 | |
494 | - new_rs = XNEW (struct dwarf2_frame_state_reg_info); | |
495 | - *new_rs = fs->regs; | |
496 | - fs->regs.reg = dwarf2_frame_state_copy_regs (&fs->regs); | |
441 | + new_rs = new dwarf2_frame_state_reg_info (fs->regs); | |
497 | 442 | fs->regs.prev = new_rs; |
498 | 443 | } |
499 | 444 | break; |
@@ -509,11 +454,7 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), | ||
509 | 454 | paddress (gdbarch, fs->pc)); |
510 | 455 | } |
511 | 456 | else |
512 | - { | |
513 | - xfree (fs->regs.reg); | |
514 | - fs->regs = *old_rs; | |
515 | - xfree (old_rs); | |
516 | - } | |
457 | + fs->regs = std::move (*old_rs); | |
517 | 458 | } |
518 | 459 | break; |
519 | 460 |
@@ -560,7 +501,7 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), | ||
560 | 501 | case DW_CFA_expression: |
561 | 502 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, ®); |
562 | 503 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
563 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
504 | + fs->regs.alloc_regs (reg + 1); | |
564 | 505 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); |
565 | 506 | fs->regs.reg[reg].loc.exp.start = insn_ptr; |
566 | 507 | fs->regs.reg[reg].loc.exp.len = utmp; |
@@ -573,14 +514,14 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), | ||
573 | 514 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
574 | 515 | insn_ptr = safe_read_sleb128 (insn_ptr, insn_end, &offset); |
575 | 516 | offset *= fs->data_align; |
576 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
517 | + fs->regs.alloc_regs (reg + 1); | |
577 | 518 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; |
578 | 519 | fs->regs.reg[reg].loc.offset = offset; |
579 | 520 | break; |
580 | 521 | |
581 | 522 | case DW_CFA_val_offset: |
582 | 523 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, ®); |
583 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
524 | + fs->regs.alloc_regs (reg + 1); | |
584 | 525 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); |
585 | 526 | offset = utmp * fs->data_align; |
586 | 527 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET; |
@@ -589,7 +530,7 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), | ||
589 | 530 | |
590 | 531 | case DW_CFA_val_offset_sf: |
591 | 532 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, ®); |
592 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
533 | + fs->regs.alloc_regs (reg + 1); | |
593 | 534 | insn_ptr = safe_read_sleb128 (insn_ptr, insn_end, &offset); |
594 | 535 | offset *= fs->data_align; |
595 | 536 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET; |
@@ -598,7 +539,7 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), | ||
598 | 539 | |
599 | 540 | case DW_CFA_val_expression: |
600 | 541 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, ®); |
601 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
542 | + fs->regs.alloc_regs (reg + 1); | |
602 | 543 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); |
603 | 544 | fs->regs.reg[reg].loc.exp.start = insn_ptr; |
604 | 545 | fs->regs.reg[reg].loc.exp.len = utmp; |
@@ -631,7 +572,7 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), | ||
631 | 572 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
632 | 573 | insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp); |
633 | 574 | offset = utmp * fs->data_align; |
634 | - dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
575 | + fs->regs.alloc_regs (reg + 1); | |
635 | 576 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; |
636 | 577 | fs->regs.reg[reg].loc.offset = -offset; |
637 | 578 | break; |
@@ -655,12 +596,73 @@ bad CFI data; mismatched DW_CFA_restore_state at %s"), | ||
655 | 596 | if (fs->initial.reg == NULL) |
656 | 597 | { |
657 | 598 | /* Don't allow remember/restore between CIE and FDE programs. */ |
658 | - dwarf2_frame_state_free_regs (fs->regs.prev); | |
599 | + delete fs->regs.prev; | |
659 | 600 | fs->regs.prev = NULL; |
660 | 601 | } |
661 | 602 | |
662 | 603 | return insn_ptr; |
663 | 604 | } |
605 | + | |
606 | +#if GDB_SELF_TEST | |
607 | + | |
608 | +namespace selftests { | |
609 | + | |
610 | +/* Unit test to function execute_cfa_program. */ | |
611 | + | |
612 | +static void | |
613 | +execute_cfa_program_test (struct gdbarch *gdbarch) | |
614 | +{ | |
615 | + struct dwarf2_fde fde; | |
616 | + struct dwarf2_cie cie; | |
617 | + | |
618 | + memset (&fde, 0, sizeof fde); | |
619 | + memset (&cie, 0, sizeof cie); | |
620 | + | |
621 | + cie.data_alignment_factor = -4; | |
622 | + cie.code_alignment_factor = 2; | |
623 | + fde.cie = &cie; | |
624 | + | |
625 | + dwarf2_frame_state fs (0, fde.cie); | |
626 | + | |
627 | + gdb_byte insns[] = | |
628 | + { | |
629 | + DW_CFA_def_cfa, 1, 4, /* DW_CFA_def_cfa: r1 ofs 4 */ | |
630 | + DW_CFA_offset | 0x2, 1, /* DW_CFA_offset: r2 at cfa-4 */ | |
631 | + DW_CFA_remember_state, | |
632 | + DW_CFA_restore_state, | |
633 | + }; | |
634 | + | |
635 | + const gdb_byte *insn_end = insns + sizeof (insns); | |
636 | + const gdb_byte *out = execute_cfa_program (&fde, insns, insn_end, gdbarch, | |
637 | + 0, &fs); | |
638 | + | |
639 | + SELF_CHECK (out == insn_end); | |
640 | + SELF_CHECK (fs.pc == 0); | |
641 | + | |
642 | + /* The instructions above only use r1 and r2, but the register numbers | |
643 | + used are adjusted by dwarf2_frame_adjust_regnum. */ | |
644 | + auto r1 = dwarf2_frame_adjust_regnum (gdbarch, 1, fde.eh_frame_p); | |
645 | + auto r2 = dwarf2_frame_adjust_regnum (gdbarch, 2, fde.eh_frame_p); | |
646 | + | |
647 | + SELF_CHECK (fs.regs.num_regs == (std::max (r1, r2) + 1)); | |
648 | + | |
649 | + SELF_CHECK (fs.regs.reg[r2].how == DWARF2_FRAME_REG_SAVED_OFFSET); | |
650 | + SELF_CHECK (fs.regs.reg[r2].loc.offset == -4); | |
651 | + | |
652 | + for (auto i = 0; i < fs.regs.num_regs; i++) | |
653 | + if (i != r2) | |
654 | + SELF_CHECK (fs.regs.reg[i].how == DWARF2_FRAME_REG_UNSPECIFIED); | |
655 | + | |
656 | + SELF_CHECK (fs.regs.cfa_reg == 1); | |
657 | + SELF_CHECK (fs.regs.cfa_offset == 4); | |
658 | + SELF_CHECK (fs.regs.cfa_how == CFA_REG_OFFSET); | |
659 | + SELF_CHECK (fs.regs.cfa_exp == NULL); | |
660 | + SELF_CHECK (fs.regs.prev == NULL); | |
661 | +} | |
662 | + | |
663 | +} // namespace selftests | |
664 | +#endif /* GDB_SELF_TEST */ | |
665 | + | |
664 | 666 | |
665 | 667 | |
666 | 668 | /* Architecture-specific operations. */ |
@@ -884,7 +886,6 @@ dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc, | ||
884 | 886 | |
885 | 887 | /* Save the initialized register set. */ |
886 | 888 | fs.initial = fs.regs; |
887 | - fs.initial.reg = dwarf2_frame_state_copy_regs (&fs.regs); | |
888 | 889 | |
889 | 890 | /* Then decode the insns in the FDE up to our target PC. */ |
890 | 891 | execute_cfa_program (fde, fde->instructions, fde->end, gdbarch, pc, &fs); |
@@ -1026,7 +1027,6 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache) | ||
1026 | 1027 | |
1027 | 1028 | /* Save the initialized register set. */ |
1028 | 1029 | fs.initial = fs.regs; |
1029 | - fs.initial.reg = dwarf2_frame_state_copy_regs (&fs.regs); | |
1030 | 1030 | |
1031 | 1031 | if (get_frame_func_if_available (this_frame, &entry_pc)) |
1032 | 1032 | { |
@@ -2418,4 +2418,8 @@ _initialize_dwarf2_frame (void) | ||
2418 | 2418 | { |
2419 | 2419 | dwarf2_frame_data = gdbarch_data_register_pre_init (dwarf2_frame_init); |
2420 | 2420 | dwarf2_frame_objfile_data = register_objfile_data (); |
2421 | + | |
2422 | +#if GDB_SELF_TEST | |
2423 | + register_self_test_foreach_arch (selftests::execute_cfa_program_test); | |
2424 | +#endif | |
2421 | 2425 | } |
@@ -94,16 +94,85 @@ enum cfa_how_kind | ||
94 | 94 | |
95 | 95 | struct dwarf2_frame_state_reg_info |
96 | 96 | { |
97 | - struct dwarf2_frame_state_reg *reg; | |
98 | - int num_regs; | |
97 | + dwarf2_frame_state_reg_info () = default; | |
98 | + ~dwarf2_frame_state_reg_info () | |
99 | + { | |
100 | + delete prev; | |
101 | + xfree (reg); | |
102 | + } | |
103 | + | |
104 | + /* Copy constructor. */ | |
105 | + dwarf2_frame_state_reg_info (const dwarf2_frame_state_reg_info &src) | |
106 | + : num_regs (src.num_regs), cfa_offset (src.cfa_offset), | |
107 | + cfa_reg (src.cfa_reg), cfa_how (src.cfa_how), cfa_exp (src.cfa_exp), | |
108 | + prev (src.prev) | |
109 | + { | |
110 | + size_t size = src.num_regs * sizeof (struct dwarf2_frame_state_reg); | |
111 | + | |
112 | + reg = (struct dwarf2_frame_state_reg *) xmalloc (size); | |
113 | + memcpy (reg, src.reg, size); | |
114 | + } | |
115 | + | |
116 | + /* Assignment operator for both move-assignment and copy-assignment. */ | |
117 | + dwarf2_frame_state_reg_info& | |
118 | + operator= (dwarf2_frame_state_reg_info rhs) | |
119 | + { | |
120 | + swap (*this, rhs); | |
121 | + return *this; | |
122 | + } | |
123 | + | |
124 | + /* Move constructor. */ | |
125 | + dwarf2_frame_state_reg_info (dwarf2_frame_state_reg_info &&rhs) noexcept | |
126 | + : reg (rhs.reg), num_regs (rhs.num_regs), cfa_offset (rhs.cfa_offset), | |
127 | + cfa_reg (rhs.cfa_reg), cfa_how (rhs.cfa_how), cfa_exp (rhs.cfa_exp), | |
128 | + prev (rhs.prev) | |
129 | + { | |
130 | + rhs.prev = nullptr; | |
131 | + rhs.reg = nullptr; | |
132 | + } | |
99 | 133 | |
100 | - LONGEST cfa_offset; | |
101 | - ULONGEST cfa_reg; | |
102 | - enum cfa_how_kind cfa_how; | |
103 | - const gdb_byte *cfa_exp; | |
134 | +/* Assert that the register set RS is large enough to store gdbarch_num_regs | |
135 | + columns. If necessary, enlarge the register set. */ | |
136 | + void alloc_regs (int num_regs_requested) | |
137 | + { | |
138 | + if (num_regs_requested <= num_regs) | |
139 | + return; | |
140 | + | |
141 | + size_t size = sizeof (struct dwarf2_frame_state_reg); | |
142 | + | |
143 | + reg = (struct dwarf2_frame_state_reg *) | |
144 | + xrealloc (reg, num_regs_requested * size); | |
145 | + | |
146 | + /* Initialize newly allocated registers. */ | |
147 | + memset (reg + num_regs, 0, (num_regs_requested - num_regs) * size); | |
148 | + num_regs = num_regs_requested; | |
149 | + } | |
150 | + | |
151 | + struct dwarf2_frame_state_reg *reg = NULL; | |
152 | + int num_regs = 0; | |
153 | + | |
154 | + LONGEST cfa_offset = 0; | |
155 | + ULONGEST cfa_reg = 0; | |
156 | + enum cfa_how_kind cfa_how = CFA_UNSET; | |
157 | + const gdb_byte *cfa_exp = NULL; | |
104 | 158 | |
105 | 159 | /* Used to implement DW_CFA_remember_state. */ |
106 | - struct dwarf2_frame_state_reg_info *prev; | |
160 | + struct dwarf2_frame_state_reg_info *prev = NULL; | |
161 | + | |
162 | +private: | |
163 | + friend void swap (dwarf2_frame_state_reg_info& lhs, | |
164 | + dwarf2_frame_state_reg_info& rhs) | |
165 | + { | |
166 | + using std::swap; | |
167 | + | |
168 | + swap (lhs.reg, rhs.reg); | |
169 | + swap (lhs.num_regs, rhs.num_regs); | |
170 | + swap (lhs.cfa_offset, rhs.cfa_offset); | |
171 | + swap (lhs.cfa_reg, rhs.cfa_reg); | |
172 | + swap (lhs.cfa_how, rhs.cfa_how); | |
173 | + swap (lhs.cfa_exp, rhs.cfa_exp); | |
174 | + swap (lhs.prev, rhs.prev); | |
175 | + } | |
107 | 176 | }; |
108 | 177 | |
109 | 178 | struct dwarf2_cie; |
@@ -113,7 +182,6 @@ struct dwarf2_cie; | ||
113 | 182 | struct dwarf2_frame_state |
114 | 183 | { |
115 | 184 | dwarf2_frame_state (CORE_ADDR pc, struct dwarf2_cie *cie); |
116 | - ~dwarf2_frame_state (); | |
117 | 185 | |
118 | 186 | /* Each register save state can be described in terms of a CFA slot, |
119 | 187 | another register, or a location expression. */ |
@@ -180,12 +248,6 @@ extern const struct frame_base * | ||
180 | 248 | |
181 | 249 | CORE_ADDR dwarf2_frame_cfa (struct frame_info *this_frame); |
182 | 250 | |
183 | -/* Assert that the register set RS is large enough to store gdbarch_num_regs | |
184 | - columns. If necessary, enlarge the register set. */ | |
185 | - | |
186 | -void dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs, | |
187 | - int num_regs); | |
188 | - | |
189 | 251 | /* Find the CFA information for PC. |
190 | 252 | |
191 | 253 | Return 1 if a register is used for the CFA, or 0 if another |
@@ -1588,7 +1588,7 @@ sparc_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op, | ||
1588 | 1588 | uint64_t reg; |
1589 | 1589 | int size = register_size (gdbarch, 0); |
1590 | 1590 | |
1591 | - dwarf2_frame_state_alloc_regs (&fs->regs, 32); | |
1591 | + fs->regs.alloc_regs (32); | |
1592 | 1592 | for (reg = 8; reg < 16; reg++) |
1593 | 1593 | { |
1594 | 1594 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG; |