Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: gdb/infcall.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/inf-ttrace.c ('k') | gdb/infcmd.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Perform an inferior function call, for GDB, the GNU debugger. 1 /* Perform an inferior function call, for GDB, the GNU debugger.
2 2
3 Copyright (C) 1986-2012 Free Software Foundation, Inc. 3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
4 4
5 This file is part of GDB. 5 This file is part of GDB.
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or 9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 value); 81 value);
82 } 82 }
83 83
84 /* This boolean tells what gdb should do if a signal is received while 84 /* This boolean tells what gdb should do if a signal is received while
85 in a function called from gdb (call dummy). If set, gdb unwinds 85 in a function called from gdb (call dummy). If set, gdb unwinds
86 the stack and restore the context to what as it was before the 86 the stack and restore the context to what as it was before the
87 call. 87 call.
88 88
89 The default is to stop in the frame where the signal was received. */ 89 The default is to stop in the frame where the signal was received. */
90 90
91 int unwind_on_signal_p = 0; 91 static int unwind_on_signal_p = 0;
92 static void 92 static void
93 show_unwind_on_signal_p (struct ui_file *file, int from_tty, 93 show_unwind_on_signal_p (struct ui_file *file, int from_tty,
94 struct cmd_list_element *c, const char *value) 94 struct cmd_list_element *c, const char *value)
95 { 95 {
96 fprintf_filtered (file, 96 fprintf_filtered (file,
97 _("Unwinding of stack if a signal is " 97 _("Unwinding of stack if a signal is "
98 "received while in a call dummy is %s.\n"), 98 "received while in a call dummy is %s.\n"),
99 value); 99 value);
100 } 100 }
101 101
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 saved by the called function. */ 152 saved by the called function. */
153 arg = value_coerce_to_target (arg); 153 arg = value_coerce_to_target (arg);
154 154
155 switch (TYPE_CODE (type)) 155 switch (TYPE_CODE (type))
156 { 156 {
157 case TYPE_CODE_REF: 157 case TYPE_CODE_REF:
158 { 158 {
159 struct value *new_value; 159 struct value *new_value;
160 160
161 if (TYPE_CODE (arg_type) == TYPE_CODE_REF) 161 if (TYPE_CODE (arg_type) == TYPE_CODE_REF)
162 » return value_cast_pointers (type, arg); 162 » return value_cast_pointers (type, arg, 0);
163 163
164 /* Cast the value to the reference's target type, and then 164 /* Cast the value to the reference's target type, and then
165 convert it back to a reference. This will issue an error 165 convert it back to a reference. This will issue an error
166 if the value was not previously in memory - in some cases 166 if the value was not previously in memory - in some cases
167 we should clearly be allowing this, but how? */ 167 we should clearly be allowing this, but how? */
168 new_value = value_cast (TYPE_TARGET_TYPE (type), arg); 168 new_value = value_cast (TYPE_TARGET_TYPE (type), arg);
169 new_value = value_ref (new_value); 169 new_value = value_ref (new_value);
170 return new_value; 170 return new_value;
171 } 171 }
172 case TYPE_CODE_INT: 172 case TYPE_CODE_INT:
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 392
393 clear_proceed_status (); 393 clear_proceed_status ();
394 394
395 disable_watchpoints_before_interactive_call_start (); 395 disable_watchpoints_before_interactive_call_start ();
396 396
397 /* We want stop_registers, please... */ 397 /* We want stop_registers, please... */
398 call_thread->control.proceed_to_finish = 1; 398 call_thread->control.proceed_to_finish = 1;
399 399
400 TRY_CATCH (e, RETURN_MASK_ALL) 400 TRY_CATCH (e, RETURN_MASK_ALL)
401 { 401 {
402 proceed (real_pc, TARGET_SIGNAL_0, 0); 402 proceed (real_pc, GDB_SIGNAL_0, 0);
403 403
404 /* Inferior function calls are always synchronous, even if the 404 /* Inferior function calls are always synchronous, even if the
405 target supports asynchronous execution. Do here what 405 target supports asynchronous execution. Do here what
406 `proceed' itself does in sync mode. */ 406 `proceed' itself does in sync mode. */
407 if (target_can_async_p () && is_running (inferior_ptid)) 407 if (target_can_async_p () && is_running (inferior_ptid))
408 { 408 {
409 wait_for_inferior (); 409 wait_for_inferior ();
410 normal_stop (); 410 normal_stop ();
411 } 411 }
412 } 412 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 May fail to return, if a breakpoint or signal is hit 457 May fail to return, if a breakpoint or signal is hit
458 during the execution of the function. 458 during the execution of the function.
459 459
460 ARGS is modified to contain coerced values. */ 460 ARGS is modified to contain coerced values. */
461 461
462 struct value * 462 struct value *
463 call_function_by_hand (struct value *function, int nargs, struct value **args) 463 call_function_by_hand (struct value *function, int nargs, struct value **args)
464 { 464 {
465 CORE_ADDR sp; 465 CORE_ADDR sp;
466 struct type *values_type, *target_values_type; 466 struct type *values_type, *target_values_type;
467 unsigned char struct_return = 0, lang_struct_return = 0; 467 unsigned char struct_return = 0, hidden_first_param_p = 0;
468 CORE_ADDR struct_addr = 0; 468 CORE_ADDR struct_addr = 0;
469 struct infcall_control_state *inf_status; 469 struct infcall_control_state *inf_status;
470 struct cleanup *inf_status_cleanup; 470 struct cleanup *inf_status_cleanup;
471 struct infcall_suspend_state *caller_state; 471 struct infcall_suspend_state *caller_state;
472 CORE_ADDR funaddr; 472 CORE_ADDR funaddr;
473 CORE_ADDR real_pc; 473 CORE_ADDR real_pc;
474 struct type *ftype = check_typedef (value_type (function)); 474 struct type *ftype = check_typedef (value_type (function));
475 CORE_ADDR bp_addr; 475 CORE_ADDR bp_addr;
476 struct frame_id dummy_id; 476 struct frame_id dummy_id;
477 struct cleanup *args_cleanup; 477 struct cleanup *args_cleanup;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 hidden argument pointing to storage) or a normal value return? 591 hidden argument pointing to storage) or a normal value return?
592 There are two cases: language-mandated structure return and 592 There are two cases: language-mandated structure return and
593 target ABI structure return. The variable STRUCT_RETURN only 593 target ABI structure return. The variable STRUCT_RETURN only
594 describes the latter. The language version is handled by passing 594 describes the latter. The language version is handled by passing
595 the return location as the first parameter to the function, 595 the return location as the first parameter to the function,
596 even preceding "this". This is different from the target 596 even preceding "this". This is different from the target
597 ABI version, which is target-specific; for instance, on ia64 597 ABI version, which is target-specific; for instance, on ia64
598 the first argument is passed in out0 but the hidden structure 598 the first argument is passed in out0 but the hidden structure
599 return pointer would normally be passed in r8. */ 599 return pointer would normally be passed in r8. */
600 600
601 if (language_pass_by_reference (values_type)) 601 if (gdbarch_return_in_first_hidden_param_p (gdbarch, values_type))
602 { 602 {
603 lang_struct_return = 1; 603 hidden_first_param_p = 1;
604 604
605 /* Tell the target specific argument pushing routine not to 605 /* Tell the target specific argument pushing routine not to
606 expect a value. */ 606 expect a value. */
607 target_values_type = builtin_type (gdbarch)->builtin_void; 607 target_values_type = builtin_type (gdbarch)->builtin_void;
608 } 608 }
609 else 609 else
610 { 610 {
611 struct_return = using_struct_return (gdbarch, 611 struct_return = using_struct_return (gdbarch, function, values_type);
612 » » » » » value_type (function), values_type);
613 target_values_type = values_type; 612 target_values_type = values_type;
614 } 613 }
615 614
616 /* Determine the location of the breakpoint (and possibly other 615 /* Determine the location of the breakpoint (and possibly other
617 stuff) that the called function will return to. The SPARC, for a 616 stuff) that the called function will return to. The SPARC, for a
618 function returning a structure or union, needs to make space for 617 function returning a structure or union, needs to make space for
619 not just the breakpoint but also an extra word containing the 618 not just the breakpoint but also an extra word containing the
620 size (?) of the structure being passed. */ 619 size (?) of the structure being passed. */
621 620
622 /* The actual breakpoint (at BP_ADDR) is inserted separatly so there
623 is no need to write that out. */
624
625 switch (gdbarch_call_dummy_location (gdbarch)) 621 switch (gdbarch_call_dummy_location (gdbarch))
626 { 622 {
627 case ON_STACK: 623 case ON_STACK:
628 sp = push_dummy_code (gdbarch, sp, funaddr, 624 {
629 » » » » args, nargs, target_values_type, 625 » const gdb_byte *bp_bytes;
630 » » » » &real_pc, &bp_addr, get_current_regcache ()); 626 » CORE_ADDR bp_addr_as_address;
627 » int bp_size;
628
629 » /* Be careful BP_ADDR is in inferior PC encoding while
630 » BP_ADDR_AS_ADDRESS is a plain memory address. */
631
632 » sp = push_dummy_code (gdbarch, sp, funaddr, args, nargs,
633 » » » target_values_type, &real_pc, &bp_addr,
634 » » » get_current_regcache ());
635
636 » /* Write a legitimate instruction at the point where the infcall
637 » breakpoint is going to be inserted. While this instruction
638 » is never going to be executed, a user investigating the
639 » memory from GDB would see this instruction instead of random
640 » uninitialized bytes. We chose the breakpoint instruction
641 » as it may look as the most logical one to the user and also
642 » valgrind 3.7.0 needs it for proper vgdb inferior calls.
643
644 » If software breakpoints are unsupported for this target we
645 » leave the user visible memory content uninitialized. */
646
647 » bp_addr_as_address = bp_addr;
648 » bp_bytes = gdbarch_breakpoint_from_pc (gdbarch, &bp_addr_as_address,
649 » » » » » &bp_size);
650 » if (bp_bytes != NULL)
651 » write_memory (bp_addr_as_address, bp_bytes, bp_size);
652 }
631 break; 653 break;
632 case AT_ENTRY_POINT: 654 case AT_ENTRY_POINT:
633 { 655 {
634 CORE_ADDR dummy_addr; 656 CORE_ADDR dummy_addr;
635 657
636 real_pc = funaddr; 658 real_pc = funaddr;
637 dummy_addr = entry_point_address (); 659 dummy_addr = entry_point_address ();
660
638 /* A call dummy always consists of just a single breakpoint, so 661 /* A call dummy always consists of just a single breakpoint, so
639 » its address is the same as the address of the dummy. */ 662 » its address is the same as the address of the dummy.
663
664 » The actual breakpoint is inserted separatly so there is no need to
665 » write that out. */
640 bp_addr = dummy_addr; 666 bp_addr = dummy_addr;
641 break; 667 break;
642 } 668 }
643 case AT_SYMBOL:
644 /* Some executables define a symbol __CALL_DUMMY_ADDRESS whose
645 address is the location where the breakpoint should be
646 placed. Once all targets are using the overhauled frame code
647 this can be deleted - ON_STACK is a better option. */
648 {
649 struct minimal_symbol *sym;
650 CORE_ADDR dummy_addr;
651
652 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
653 real_pc = funaddr;
654 if (sym)
655 {
656 dummy_addr = SYMBOL_VALUE_ADDRESS (sym);
657 /* Make certain that the address points at real code, and not
658 a function descriptor. */
659 dummy_addr = gdbarch_convert_from_func_ptr_addr (gdbarch,
660 dummy_addr,
661 &current_target);
662 }
663 else
664 dummy_addr = entry_point_address ();
665 /* A call dummy always consists of just a single breakpoint,
666 so it's address is the same as the address of the dummy. */
667 bp_addr = dummy_addr;
668 break;
669 }
670 default: 669 default:
671 internal_error (__FILE__, __LINE__, _("bad switch")); 670 internal_error (__FILE__, __LINE__, _("bad switch"));
672 } 671 }
673 672
674 if (nargs < TYPE_NFIELDS (ftype)) 673 if (nargs < TYPE_NFIELDS (ftype))
675 error (_("Too few arguments in function call.")); 674 error (_("Too few arguments in function call."));
676 675
677 { 676 {
678 int i; 677 int i;
679 678
(...skipping 21 matching lines...) Expand all
701 700
702 if (param_type != NULL && language_pass_by_reference (param_type)) 701 if (param_type != NULL && language_pass_by_reference (param_type))
703 args[i] = value_addr (args[i]); 702 args[i] = value_addr (args[i]);
704 } 703 }
705 } 704 }
706 705
707 /* Reserve space for the return structure to be written on the 706 /* Reserve space for the return structure to be written on the
708 stack, if necessary. Make certain that the value is correctly 707 stack, if necessary. Make certain that the value is correctly
709 aligned. */ 708 aligned. */
710 709
711 if (struct_return || lang_struct_return) 710 if (struct_return || hidden_first_param_p)
712 { 711 {
713 int len = TYPE_LENGTH (values_type); 712 int len = TYPE_LENGTH (values_type);
714 713
715 if (gdbarch_inner_than (gdbarch, 1, 2)) 714 if (gdbarch_inner_than (gdbarch, 1, 2))
716 { 715 {
717 /* Stack grows downward. Align STRUCT_ADDR and SP after 716 /* Stack grows downward. Align STRUCT_ADDR and SP after
718 making space for the return value. */ 717 making space for the return value. */
719 sp -= len; 718 sp -= len;
720 if (gdbarch_frame_align_p (gdbarch)) 719 if (gdbarch_frame_align_p (gdbarch))
721 sp = gdbarch_frame_align (gdbarch, sp); 720 sp = gdbarch_frame_align (gdbarch, sp);
722 struct_addr = sp; 721 struct_addr = sp;
723 } 722 }
724 else 723 else
725 { 724 {
726 /* Stack grows upward. Align the frame, allocate space, and 725 /* Stack grows upward. Align the frame, allocate space, and
727 then again, re-align the frame??? */ 726 then again, re-align the frame??? */
728 if (gdbarch_frame_align_p (gdbarch)) 727 if (gdbarch_frame_align_p (gdbarch))
729 sp = gdbarch_frame_align (gdbarch, sp); 728 sp = gdbarch_frame_align (gdbarch, sp);
730 struct_addr = sp; 729 struct_addr = sp;
731 sp += len; 730 sp += len;
732 if (gdbarch_frame_align_p (gdbarch)) 731 if (gdbarch_frame_align_p (gdbarch))
733 sp = gdbarch_frame_align (gdbarch, sp); 732 sp = gdbarch_frame_align (gdbarch, sp);
734 } 733 }
735 } 734 }
736 735
737 if (lang_struct_return) 736 if (hidden_first_param_p)
738 { 737 {
739 struct value **new_args; 738 struct value **new_args;
740 739
741 /* Add the new argument to the front of the argument list. */ 740 /* Add the new argument to the front of the argument list. */
742 new_args = xmalloc (sizeof (struct value *) * (nargs + 1)); 741 new_args = xmalloc (sizeof (struct value *) * (nargs + 1));
743 new_args[0] = value_from_pointer (lookup_pointer_type (values_type), 742 new_args[0] = value_from_pointer (lookup_pointer_type (values_type),
744 struct_addr); 743 struct_addr);
745 memcpy (&new_args[1], &args[0], sizeof (struct value *) * nargs); 744 memcpy (&new_args[1], &args[0], sizeof (struct value *) * nargs);
746 args = new_args; 745 args = new_args;
747 nargs++; 746 nargs++;
(...skipping 17 matching lines...) Expand all
765 dummy breakpoint. */ 764 dummy breakpoint. */
766 /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL, 765 /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL,
767 saved as the dummy-frame TOS, and used by dummy_id to form 766 saved as the dummy-frame TOS, and used by dummy_id to form
768 the frame ID's stack address. */ 767 the frame ID's stack address. */
769 dummy_id = frame_id_build (sp, bp_addr); 768 dummy_id = frame_id_build (sp, bp_addr);
770 769
771 /* Create a momentary breakpoint at the return address of the 770 /* Create a momentary breakpoint at the return address of the
772 inferior. That way it breaks when it returns. */ 771 inferior. That way it breaks when it returns. */
773 772
774 { 773 {
775 struct breakpoint *bpt; 774 struct breakpoint *bpt, *longjmp_b;
776 struct symtab_and_line sal; 775 struct symtab_and_line sal;
777 776
778 init_sal (&sal); /* initialize to zeroes */ 777 init_sal (&sal); /* initialize to zeroes */
779 sal.pspace = current_program_space; 778 sal.pspace = current_program_space;
780 sal.pc = bp_addr; 779 sal.pc = bp_addr;
781 sal.section = find_pc_overlay (sal.pc); 780 sal.section = find_pc_overlay (sal.pc);
782 /* Sanity. The exact same SP value is returned by 781 /* Sanity. The exact same SP value is returned by
783 PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by 782 PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by
784 dummy_id to form the frame ID's stack address. */ 783 dummy_id to form the frame ID's stack address. */
785 bpt = set_momentary_breakpoint (gdbarch, sal, dummy_id, bp_call_dummy); 784 bpt = set_momentary_breakpoint (gdbarch, sal, dummy_id, bp_call_dummy);
785
786 /* set_momentary_breakpoint invalidates FRAME. */
787 frame = NULL;
788
786 bpt->disposition = disp_del; 789 bpt->disposition = disp_del;
790 gdb_assert (bpt->related_breakpoint == bpt);
791
792 longjmp_b = set_longjmp_breakpoint_for_call_dummy ();
793 if (longjmp_b)
794 {
795 /* Link BPT into the chain of LONGJMP_B. */
796 bpt->related_breakpoint = longjmp_b;
797 while (longjmp_b->related_breakpoint != bpt->related_breakpoint)
798 longjmp_b = longjmp_b->related_breakpoint;
799 longjmp_b->related_breakpoint = bpt;
800 }
787 } 801 }
788 802
789 /* Create a breakpoint in std::terminate. 803 /* Create a breakpoint in std::terminate.
790 If a C++ exception is raised in the dummy-frame, and the 804 If a C++ exception is raised in the dummy-frame, and the
791 exception handler is (normally, and expected to be) out-of-frame, 805 exception handler is (normally, and expected to be) out-of-frame,
792 the default C++ handler will (wrongly) be called in an inferior 806 the default C++ handler will (wrongly) be called in an inferior
793 function call. This is wrong, as an exception can be normally 807 function call. This is wrong, as an exception can be normally
794 and legally handled out-of-frame. The confines of the dummy frame 808 and legally handled out-of-frame. The confines of the dummy frame
795 prevent the unwinder from finding the correct handler (or any 809 prevent the unwinder from finding the correct handler (or any
796 handler, unless it is in-frame). The default handler calls 810 handler, unless it is in-frame). The default handler calls
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 1043
1030 regcache_cpy_no_passthrough (retbuf, stop_registers); 1044 regcache_cpy_no_passthrough (retbuf, stop_registers);
1031 1045
1032 /* Inferior call is successful. Restore the inferior status. 1046 /* Inferior call is successful. Restore the inferior status.
1033 At this stage, leave the RETBUF alone. */ 1047 At this stage, leave the RETBUF alone. */
1034 restore_infcall_control_state (inf_status); 1048 restore_infcall_control_state (inf_status);
1035 1049
1036 /* Figure out the value returned by the function. */ 1050 /* Figure out the value returned by the function. */
1037 retval = allocate_value (values_type); 1051 retval = allocate_value (values_type);
1038 1052
1039 if (lang_struct_return) 1053 if (hidden_first_param_p)
1040 read_value_memory (retval, 0, 1, struct_addr, 1054 read_value_memory (retval, 0, 1, struct_addr,
1041 value_contents_raw (retval), 1055 value_contents_raw (retval),
1042 TYPE_LENGTH (values_type)); 1056 TYPE_LENGTH (values_type));
1043 else if (TYPE_CODE (target_values_type) != TYPE_CODE_VOID) 1057 else if (TYPE_CODE (target_values_type) != TYPE_CODE_VOID)
1044 { 1058 {
1045 /* If the function returns void, don't bother fetching the 1059 /* If the function returns void, don't bother fetching the
1046 return value. */ 1060 return value. */
1047 » switch (gdbarch_return_value (gdbarch, value_type (function), 1061 » switch (gdbarch_return_value (gdbarch, function, target_values_type,
1048 » » » » target_values_type, NULL, NULL, NULL)) 1062 » » » » NULL, NULL, NULL))
1049 { 1063 {
1050 case RETURN_VALUE_REGISTER_CONVENTION: 1064 case RETURN_VALUE_REGISTER_CONVENTION:
1051 case RETURN_VALUE_ABI_RETURNS_ADDRESS: 1065 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1052 case RETURN_VALUE_ABI_PRESERVES_ADDRESS: 1066 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1053 » gdbarch_return_value (gdbarch, value_type (function), values_type, 1067 » gdbarch_return_value (gdbarch, function, values_type,
1054 retbuf, value_contents_raw (retval), NULL); 1068 retbuf, value_contents_raw (retval), NULL);
1055 break; 1069 break;
1056 case RETURN_VALUE_STRUCT_CONVENTION: 1070 case RETURN_VALUE_STRUCT_CONVENTION:
1057 read_value_memory (retval, 0, 1, struct_addr, 1071 read_value_memory (retval, 0, 1, struct_addr,
1058 value_contents_raw (retval), 1072 value_contents_raw (retval),
1059 TYPE_LENGTH (values_type)); 1073 TYPE_LENGTH (values_type));
1060 break; 1074 break;
1061 } 1075 }
1062 } 1076 }
1063 1077
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 what gdb should do if a std::terminate() call is made from the\n\ 1126 what gdb should do if a std::terminate() call is made from the\n\
1113 default exception handler. If set, gdb unwinds the stack and restores\n\ 1127 default exception handler. If set, gdb unwinds the stack and restores\n\
1114 the context to what it was before the call. If unset, gdb allows the\n\ 1128 the context to what it was before the call. If unset, gdb allows the\n\
1115 std::terminate call to proceed.\n\ 1129 std::terminate call to proceed.\n\
1116 The default is to unwind the frame."), 1130 The default is to unwind the frame."),
1117 NULL, 1131 NULL,
1118 show_unwind_on_terminating_exception_p, 1132 show_unwind_on_terminating_exception_p,
1119 &setlist, &showlist); 1133 &setlist, &showlist);
1120 1134
1121 } 1135 }
OLDNEW
« no previous file with comments | « gdb/inf-ttrace.c ('k') | gdb/infcmd.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698