Debian Codegraph @

src/trace.c

raw symbols SCIP
1 /* $Id: trace.c,v 1.6 2005/12/20 15:11:24 rockyb Exp $
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3 Copyright (C) 2008, 2012 R. Bernstein <[email protected]>
4
5 This file is part of GNU Make.
6
7 GNU Make is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Make is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Make; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include <sys/time.h>
23 /* Header for routines related to tracing and debugging support */
24
25 /* AIX likes this: */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "globals.h"
31 #include "trace.h"
32 #include "print.h"
33 #include "debug.h"
34 // debugger include(s)
35 #include "cmd.h"
36 #include "profile.h"
37
38 /** Pointer to top of current target call stack */
39 target_stack_node_t *p_stack_top;
40
41 /** Pointer to top of current target floc stack */
42 floc_stack_node_t *p_stack_floc_top = NULL;
43
44 /*! Push "target" to the call stack. */
45 extern target_stack_node_t *
46 trace_push_target (target_stack_node_t *p, file_t *p_target)
47 {
48 target_stack_node_t *new_node = CALLOC(target_stack_node_t, 1);
49
50 /* We allocate and make a copy of p_target in case we want to
51 modify information, like the file location or target name
52 on the fly as we process file commands or handle dependencies from
53 target patterns.
54 */
55 new_node->p_target = CALLOC (file_t, 1);
56 memcpy(new_node->p_target, p_target, sizeof(file_t));
57 new_node->p_shared_target = p_target;
58
59 new_node->p_parent = p;
60
61 if (p_target && p_target->floc.filenm != NULL) {
62
63 if ( db_level & DB_VERBOSE ) {
64 print_file_target_prefix(p_target);
65 printf("\n");
66 }
67 }
68
69 if (profile_flag) {
70 file_t *prev = NULL;
71
72 if (NULL != new_node->p_parent) {
73 prev = new_node->p_parent->p_target;
74 }
75
76 profile_add_dependency(new_node->p_target, prev);
77 }
78
79 return new_node;
80 };
81
82 /*! Pop the next target from the call stack.. */
83 extern void
84 trace_pop_target (target_stack_node_t *p)
85 {
86
87 if (NULL == p) return;
88
89 if (profile_flag) {
90 profile_update_target(p->p_target);
91 }
92
93 free(p->p_target);
94 free(p);
95 }
96
97 /*! Push "p_floc" to the floc stack. Return the new stack top.
98 */
99 extern void
100 trace_push_floc (gmk_floc *p_floc)
101 {
102 floc_stack_node_t *new_node = CALLOC (floc_stack_node_t, 1);
103
104 /* We DO NOT allocate and make a copy of p_floc so that as we
105 read the Makefile, the line number gets updated automatically.
106 Slick, huh? Also it shortens and simplifies code a bit.
107 */
108 new_node->p_floc = p_floc;
109 new_node->p_parent = p_stack_floc_top;
110 p_stack_floc_top = new_node;
111 };
112
113 /*! Pop the next target from the floc stack. */
114 extern void
115 trace_pop_floc (void)
116 {
117 if (NULL == p_stack_floc_top) return;
118 else {
119 floc_stack_node_t *p_new_top = p_stack_floc_top->p_parent;
120 free(p_stack_floc_top);
121 p_stack_floc_top = p_new_top;
122 }
123 }