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 <rocky@gnu.org>
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 /* Header for routines related to tracing and debugging support */
23 
24 /* AIX likes this: */
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 
29 #include "trace.h"
30 #include "print.h"
31 #include "debug.h"
32 #include "debugger/cmd.h"
33 
34 /** Pointer to top of current target call stack */
35 target_stack_node_t *p_stack_top;
36 
37 /** Pointer to top of current target floc stack */
38 floc_stack_node_t *p_stack_floc_top = NULL;
39 
40 /*! Push "target" to the call stack. */
41 extern target_stack_node_t *
trace_push_target(target_stack_node_t * p,file_t * p_target)42 trace_push_target (target_stack_node_t *p, file_t *p_target)
43 {
44   target_stack_node_t *new_node = CALLOC(target_stack_node_t, 1);
45 
46   /* We allocate and make a copy of p_target in case we want to
47      modify information, like the file location or target name
48      on the fly as we process file commands or handle dependencies from
49      target patterns.
50    */
51   new_node->p_target = CALLOC (file_t, 1);
52   memcpy(new_node->p_target, p_target, sizeof(file_t));
53   new_node->p_shared_target = p_target;
54 
55   new_node->p_parent = p;
56 
57   if (p_target && p_target->floc.filenm != NULL) {
58 
59     if ( db_level & DB_VERBOSE ) {
60       print_file_target_prefix(p_target);
61       printf("\n");
62     }
63   }
64 
65   return new_node;
66 };
67 
68 /*! Pop the next target from the call stack.. */
69 extern void
trace_pop_target(target_stack_node_t * p)70 trace_pop_target (target_stack_node_t *p)
71 {
72   if (NULL == p) return;
73   free(p->p_target);
74   free(p);
75 }
76 
77 /*! Push "p_floc" to the floc stack. Return the new stack top.
78 */
79 extern void
trace_push_floc(gmk_floc * p_floc)80 trace_push_floc (gmk_floc *p_floc)
81 {
82   floc_stack_node_t *new_node = CALLOC (floc_stack_node_t, 1);
83 
84   /* We DO NOT allocate and make a copy of p_floc so that as we
85      read the Makefile, the line number gets updated automatically.
86      Slick, huh? Also it shortens and simplifies code a bit.
87    */
88   new_node->p_floc = p_floc;
89   new_node->p_parent = p_stack_floc_top;
90   p_stack_floc_top = new_node;
91 };
92 
93 /*! Pop the next target from the floc stack. */
94 extern void
trace_pop_floc(void)95 trace_pop_floc (void)
96 {
97   if (NULL == p_stack_floc_top) return;
98   else {
99     floc_stack_node_t *p_new_top = p_stack_floc_top->p_parent;
100     free(p_stack_floc_top);
101     p_stack_floc_top = p_new_top;
102   }
103 }
104