1 /*
2 Copyright (C) 2005, 2008, 2009, 2011 R. Bernstein <rocky@gnu.org>
3 This file is part of GNU Make (remake variant).
4
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 /* debugger command interface. */
21
22 #include "fns.h"
23 #include "msg.h"
24 #include "print.h"
25 #include "stack.h"
26 #include "commands.h"
27
28 int i_stack_pos = 0;
29
30 /** Pointer to current target call stack at the place we are currently
31 focused on.
32 */
33 target_stack_node_t *p_stack = NULL;
34 floc_stack_node_t *p_floc_stack = NULL;
35
36
dbg_stack_size()37 unsigned int dbg_stack_size()
38 {
39 int i=0;
40
41 if (p_stack_top) {
42 for ( p_stack=p_stack_top; p_stack ; p_stack = p_stack->p_parent ) {
43 i++;
44 }
45 return i;
46 } else if (p_stack_floc_top) {
47 /* We have a Makefile stack */
48 for ( p_floc_stack=p_stack_floc_top;
49 p_floc_stack ; p_floc_stack = p_floc_stack->p_parent ) {
50 i++;
51 }
52
53 }
54 return i;
55 }
56
57
58 debug_return_t
dbg_adjust_frame(int i_amount,int b_absolute)59 dbg_adjust_frame(int i_amount, int b_absolute)
60 {
61 int i=0;
62 int i_try_frame_pos;
63
64 if (b_absolute) {
65 if (i_amount < 0)
66 i_try_frame_pos = dbg_stack_size() + i_amount;
67 else
68 i_try_frame_pos = i_amount;
69 } else
70 i_try_frame_pos = i_stack_pos + i_amount;
71
72 if (i_try_frame_pos < 0) {
73 dbg_errmsg(_("Moving target would go beyond bottom-most target position."));
74 return debug_cmd_error;
75 }
76
77 i = i_try_frame_pos + 1;
78
79 if (p_stack_top) {
80 for ( p_stack=p_stack_top; p_stack ; p_stack = p_stack->p_parent ) {
81 i--;
82 if (0 == i)
83 break;
84 }
85
86 if (0 != i) {
87 dbg_errmsg(_("Can't set frame to position %d; "
88 "%d is the highest target position."),
89 i_try_frame_pos, i_try_frame_pos - i);
90 return debug_cmd_error;
91 }
92
93 i_stack_pos = i_try_frame_pos;
94 p_target_loc = &(p_stack->p_target->floc);
95
96 print_target_stack_entry(p_stack->p_target, i_stack_pos, i_stack_pos);
97 print_debugger_location(p_stack->p_target, DEBUG_STACK_CHANGING, NULL);
98 } else if (p_stack_floc_top) {
99 /* We have a Makefile stack */
100 for ( p_floc_stack=p_stack_floc_top;
101 p_floc_stack ; p_floc_stack = p_floc_stack->p_parent ) {
102 i--;
103 if (0 == i)
104 break;
105 }
106
107 if (0 != i) {
108 dbg_errmsg(_("Can't set frame to position %d; "
109 "%d is the highest target position."),
110 i_try_frame_pos, i_try_frame_pos - i);
111 return debug_cmd_error;
112 }
113 i_stack_pos = i_try_frame_pos;
114
115 print_debugger_location(NULL, DEBUG_NOT_GIVEN, p_floc_stack);
116 }
117
118 return debug_readloop;
119 }
120
121