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

Side by Side Diff: gdb/gdbserver/mem-break.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/gdbserver/mem-break.h ('k') | gdb/gdbserver/nto-low.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 /* Memory breakpoint operations for the remote server for GDB. 1 /* Memory breakpoint operations for the remote server for GDB.
2 Copyright (C) 2002-2003, 2005, 2007-2012 Free Software Foundation, 2 Copyright (C) 2002-2003, 2005, 2007-2012 Free Software Foundation,
3 Inc. 3 Inc.
4 4
5 Contributed by MontaVista Software. 5 Contributed by MontaVista Software.
6 6
7 This file is part of GDB. 7 This file is part of GDB.
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or 11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version. 12 (at your option) any later version.
13 13
14 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18 18
19 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 21
22 #include "server.h" 22 #include "server.h"
23 #include "regcache.h"
24 #include "ax.h"
25 #include <stdint.h>
23 26
24 const unsigned char *breakpoint_data; 27 const unsigned char *breakpoint_data;
25 int breakpoint_len; 28 int breakpoint_len;
26 29
27 #define MAX_BREAKPOINT_LEN 8 30 #define MAX_BREAKPOINT_LEN 8
28 31
29 /* GDB will never try to install multiple breakpoints at the same 32 /* GDB will never try to install multiple breakpoints at the same
30 address. But, we need to keep track of internal breakpoints too, 33 address. But, we need to keep track of internal breakpoints too,
31 and so we do need to be able to install multiple breakpoints at the 34 and so we do need to be able to install multiple breakpoints at the
32 same address transparently. We keep track of two different, and 35 same address transparently. We keep track of two different, and
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 gdb_breakpoint, 81 gdb_breakpoint,
79 82
80 /* A basic-software-single-step breakpoint. */ 83 /* A basic-software-single-step breakpoint. */
81 reinsert_breakpoint, 84 reinsert_breakpoint,
82 85
83 /* Any other breakpoint type that doesn't require specific 86 /* Any other breakpoint type that doesn't require specific
84 treatment goes here. E.g., an event breakpoint. */ 87 treatment goes here. E.g., an event breakpoint. */
85 other_breakpoint, 88 other_breakpoint,
86 }; 89 };
87 90
91 struct point_cond_list
92 {
93 /* Pointer to the agent expression that is the breakpoint's
94 conditional. */
95 struct agent_expr *cond;
96
97 /* Pointer to the next condition. */
98 struct point_cond_list *next;
99 };
100
101 struct point_command_list
102 {
103 /* Pointer to the agent expression that is the breakpoint's
104 commands. */
105 struct agent_expr *cmd;
106
107 /* Flag that is true if this command should run even while GDB is
108 disconnected. */
109 int persistence;
110
111 /* Pointer to the next command. */
112 struct point_command_list *next;
113 };
114
88 /* A high level (in gdbserver's perspective) breakpoint. */ 115 /* A high level (in gdbserver's perspective) breakpoint. */
89 struct breakpoint 116 struct breakpoint
90 { 117 {
91 struct breakpoint *next; 118 struct breakpoint *next;
92 119
93 /* The breakpoint's type. */ 120 /* The breakpoint's type. */
94 enum bkpt_type type; 121 enum bkpt_type type;
95 122
123 /* Pointer to the condition list that should be evaluated on
124 the target or NULL if the breakpoint is unconditional or
125 if GDB doesn't want us to evaluate the conditionals on the
126 target's side. */
127 struct point_cond_list *cond_list;
128
129 /* Point to the list of commands to run when this is hit. */
130 struct point_command_list *command_list;
131
96 /* Link to this breakpoint's raw breakpoint. This is always 132 /* Link to this breakpoint's raw breakpoint. This is always
97 non-NULL. */ 133 non-NULL. */
98 struct raw_breakpoint *raw; 134 struct raw_breakpoint *raw;
99 135
100 /* Function to call when we hit this breakpoint. If it returns 1, 136 /* Function to call when we hit this breakpoint. If it returns 1,
101 the breakpoint shall be deleted; 0 or if this callback is NULL, 137 the breakpoint shall be deleted; 0 or if this callback is NULL,
102 it will be left inserted. */ 138 it will be left inserted. */
103 int (*handler) (CORE_ADDR); 139 int (*handler) (CORE_ADDR);
104 }; 140 };
105 141
142 int
143 any_persistent_commands ()
144 {
145 struct process_info *proc = current_process ();
146 struct breakpoint *bp;
147 struct point_command_list *cl;
148
149 for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
150 {
151 for (cl = bp->command_list; cl != NULL; cl = cl->next)
152 if (cl->persistence)
153 return 1;
154 }
155
156 return 0;
157 }
158
106 static struct raw_breakpoint * 159 static struct raw_breakpoint *
107 find_raw_breakpoint_at (CORE_ADDR where) 160 find_raw_breakpoint_at (CORE_ADDR where)
108 { 161 {
109 struct process_info *proc = current_process (); 162 struct process_info *proc = current_process ();
110 struct raw_breakpoint *bp; 163 struct raw_breakpoint *bp;
111 164
112 for (bp = proc->raw_breakpoints; bp != NULL; bp = bp->next) 165 for (bp = proc->raw_breakpoints; bp != NULL; bp = bp->next)
113 if (bp->pc == where) 166 if (bp->pc == where)
114 return bp; 167 return bp;
115 168
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 return ENOENT; 678 return ENOENT;
626 } 679 }
627 680
628 int 681 int
629 delete_breakpoint (struct breakpoint *todel) 682 delete_breakpoint (struct breakpoint *todel)
630 { 683 {
631 struct process_info *proc = current_process (); 684 struct process_info *proc = current_process ();
632 return delete_breakpoint_1 (proc, todel); 685 return delete_breakpoint_1 (proc, todel);
633 } 686 }
634 687
635 static struct breakpoint * 688 struct breakpoint *
636 find_gdb_breakpoint_at (CORE_ADDR where) 689 find_gdb_breakpoint_at (CORE_ADDR where)
637 { 690 {
638 struct process_info *proc = current_process (); 691 struct process_info *proc = current_process ();
639 struct breakpoint *bp; 692 struct breakpoint *bp;
640 693
641 for (bp = proc->breakpoints; bp != NULL; bp = bp->next) 694 for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
642 if (bp->type == gdb_breakpoint && bp->raw->pc == where) 695 if (bp->type == gdb_breakpoint && bp->raw->pc == where)
643 return bp; 696 return bp;
644 697
645 return NULL; 698 return NULL;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 struct breakpoint *bp; 738 struct breakpoint *bp;
686 int err; 739 int err;
687 740
688 if (breakpoint_data == NULL) 741 if (breakpoint_data == NULL)
689 return 1; 742 return 1;
690 743
691 bp = find_gdb_breakpoint_at (addr); 744 bp = find_gdb_breakpoint_at (addr);
692 if (bp == NULL) 745 if (bp == NULL)
693 return -1; 746 return -1;
694 747
748 /* Before deleting the breakpoint, make sure to free
749 its condition list. */
750 clear_gdb_breakpoint_conditions (addr);
695 err = delete_breakpoint (bp); 751 err = delete_breakpoint (bp);
696 if (err) 752 if (err)
697 return -1; 753 return -1;
698 754
699 return 0; 755 return 0;
700 } 756 }
701 757
758 /* Clear all conditions associated with this breakpoint address. */
759
760 void
761 clear_gdb_breakpoint_conditions (CORE_ADDR addr)
762 {
763 struct breakpoint *bp = find_gdb_breakpoint_at (addr);
764 struct point_cond_list *cond;
765
766 if (bp == NULL || bp->cond_list == NULL)
767 return;
768
769 cond = bp->cond_list;
770
771 while (cond != NULL)
772 {
773 struct point_cond_list *cond_next;
774
775 cond_next = cond->next;
776 free (cond->cond->bytes);
777 free (cond->cond);
778 free (cond);
779 cond = cond_next;
780 }
781
782 bp->cond_list = NULL;
783 }
784
785 /* Add condition CONDITION to GDBserver's breakpoint BP. */
786
787 void
788 add_condition_to_breakpoint (struct breakpoint *bp,
789 struct agent_expr *condition)
790 {
791 struct point_cond_list *new_cond;
792
793 /* Create new condition. */
794 new_cond = xcalloc (1, sizeof (*new_cond));
795 new_cond->cond = condition;
796
797 /* Add condition to the list. */
798 new_cond->next = bp->cond_list;
799 bp->cond_list = new_cond;
800 }
801
802 /* Add a target-side condition CONDITION to the breakpoint at ADDR. */
803
804 int
805 add_breakpoint_condition (CORE_ADDR addr, char **condition)
806 {
807 struct breakpoint *bp = find_gdb_breakpoint_at (addr);
808 char *actparm = *condition;
809 struct agent_expr *cond;
810
811 if (bp == NULL)
812 return 1;
813
814 if (condition == NULL)
815 return 1;
816
817 cond = gdb_parse_agent_expr (&actparm);
818
819 if (cond == NULL)
820 {
821 fprintf (stderr, "Condition evaluation failed. "
822 "Assuming unconditional.\n");
823 return 0;
824 }
825
826 add_condition_to_breakpoint (bp, cond);
827
828 *condition = actparm;
829
830 return 0;
831 }
832
833 /* Evaluate condition (if any) at breakpoint BP. Return 1 if
834 true and 0 otherwise. */
835
836 int
837 gdb_condition_true_at_breakpoint (CORE_ADDR where)
838 {
839 /* Fetch registers for the current inferior. */
840 struct breakpoint *bp = find_gdb_breakpoint_at (where);
841 ULONGEST value = 0;
842 struct point_cond_list *cl;
843 int err = 0;
844
845 struct regcache *regcache = get_thread_regcache (current_inferior, 1);
846
847 if (bp == NULL)
848 return 0;
849
850 /* Check if the breakpoint is unconditional. If it is,
851 the condition always evaluates to TRUE. */
852 if (bp->cond_list == NULL)
853 return 1;
854
855 /* Evaluate each condition in the breakpoint's list of conditions.
856 Return true if any of the conditions evaluates to TRUE.
857
858 If we failed to evaluate the expression, TRUE is returned. This
859 forces GDB to reevaluate the conditions. */
860 for (cl = bp->cond_list;
861 cl && !value && !err; cl = cl->next)
862 {
863 /* Evaluate the condition. */
864 err = gdb_eval_agent_expr (regcache, NULL, cl->cond, &value);
865 }
866
867 if (err)
868 return 1;
869
870 return (value != 0);
871 }
872
873 /* Add commands COMMANDS to GDBserver's breakpoint BP. */
874
875 void
876 add_commands_to_breakpoint (struct breakpoint *bp,
877 struct agent_expr *commands, int persist)
878 {
879 struct point_command_list *new_cmd;
880
881 /* Create new command. */
882 new_cmd = xcalloc (1, sizeof (*new_cmd));
883 new_cmd->cmd = commands;
884 new_cmd->persistence = persist;
885
886 /* Add commands to the list. */
887 new_cmd->next = bp->command_list;
888 bp->command_list = new_cmd;
889 }
890
891 /* Add a target-side command COMMAND to the breakpoint at ADDR. */
892
893 int
894 add_breakpoint_commands (CORE_ADDR addr, char **command, int persist)
895 {
896 struct breakpoint *bp = find_gdb_breakpoint_at (addr);
897 char *actparm = *command;
898 struct agent_expr *cmd;
899
900 if (bp == NULL)
901 return 1;
902
903 if (command == NULL)
904 return 1;
905
906 cmd = gdb_parse_agent_expr (&actparm);
907
908 if (cmd == NULL)
909 {
910 fprintf (stderr, "Command evaluation failed. "
911 "Disabling.\n");
912 return 0;
913 }
914
915 add_commands_to_breakpoint (bp, cmd, persist);
916
917 *command = actparm;
918
919 return 0;
920 }
921
922 /* Return true if there are no commands to run at this location,
923 which likely means we want to report back to GDB. */
924 int
925 gdb_no_commands_at_breakpoint (CORE_ADDR where)
926 {
927 struct breakpoint *bp = find_gdb_breakpoint_at (where);
928
929 if (bp == NULL)
930 return 0;
931
932 if (debug_threads)
933 fprintf (stderr, "at 0x%s, bp command_list is 0x%s\n",
934 paddress (where),
935 phex_nz ((uintptr_t) bp->command_list, 0));
936 return (bp->command_list == NULL);
937 }
938
939 void
940 run_breakpoint_commands (CORE_ADDR where)
941 {
942 /* Fetch registers for the current inferior. */
943 struct breakpoint *bp = find_gdb_breakpoint_at (where);
944 ULONGEST value = 0;
945 struct point_command_list *cl;
946 int err = 0;
947
948 struct regcache *regcache = get_thread_regcache (current_inferior, 1);
949
950 if (bp == NULL)
951 return;
952
953 for (cl = bp->command_list;
954 cl && !value && !err; cl = cl->next)
955 {
956 /* Run the command. */
957 err = gdb_eval_agent_expr (regcache, NULL, cl->cmd, &value);
958
959 /* If one command has a problem, stop digging the hole deeper. */
960 if (err)
961 break;
962 }
963 }
964
965 /* Return 1 if there is a breakpoint inserted in address WHERE
966 and if its condition, if it exists, is true. */
967
702 int 968 int
703 gdb_breakpoint_here (CORE_ADDR where) 969 gdb_breakpoint_here (CORE_ADDR where)
704 { 970 {
705 struct breakpoint *bp = find_gdb_breakpoint_at (where); 971 return (find_gdb_breakpoint_at (where) != NULL);
706 972 }
707 return (bp != NULL); 973
708 } 974 void
709
710 void
711 set_reinsert_breakpoint (CORE_ADDR stop_at) 975 set_reinsert_breakpoint (CORE_ADDR stop_at)
712 { 976 {
713 struct breakpoint *bp; 977 struct breakpoint *bp;
714 978
715 bp = set_breakpoint_at (stop_at, NULL); 979 bp = set_breakpoint_at (stop_at, NULL);
716 bp->type = reinsert_breakpoint; 980 bp->type = reinsert_breakpoint;
717 } 981 }
718 982
719 void 983 void
720 delete_reinsert_breakpoints (void) 984 delete_reinsert_breakpoints (void)
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 { 1431 {
1168 mark_breakpoints_out (proc); 1432 mark_breakpoints_out (proc);
1169 1433
1170 /* Note: use PROC explicitly instead of deferring to 1434 /* Note: use PROC explicitly instead of deferring to
1171 delete_all_breakpoints --- CURRENT_INFERIOR may already have been 1435 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
1172 released when we get here. There should be no call to 1436 released when we get here. There should be no call to
1173 current_process from here on. */ 1437 current_process from here on. */
1174 while (proc->breakpoints) 1438 while (proc->breakpoints)
1175 delete_breakpoint_1 (proc, proc->breakpoints); 1439 delete_breakpoint_1 (proc, proc->breakpoints);
1176 } 1440 }
OLDNEW
« no previous file with comments | « gdb/gdbserver/mem-break.h ('k') | gdb/gdbserver/nto-low.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698