OpenCoverage

caller.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/caller.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is caller.def, from which is created caller.c. It implements the-
2builtin "caller" in Bash.-
3-
4Copyright (C) 2002-2008 Rocky Bernstein for Free Software Foundation, Inc.-
5Copyright (C) 2008-2013 Free Software Foundation, Inc.-
6-
7This file is part of GNU Bash, the Bourne Again SHell.-
8-
9Bash is free software: you can redistribute it and/or modify-
10it under the terms of the GNU General Public License as published by-
11the Free Software Foundation, either version 3 of the License, or-
12(at your option) any later version.-
13-
14Bash is distributed in the hope that it will be useful,-
15but WITHOUT ANY WARRANTY; without even the implied warranty of-
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
17GNU General Public License for more details.-
18-
19You should have received a copy of the GNU General Public License-
20along with Bash. If not, see <http://www.gnu.org/licenses/>.-
21-
22$PRODUCES caller.c-
23-
24$BUILTIN caller-
25$FUNCTION caller_builtin-
26$DEPENDS_ON DEBUGGER-
27$SHORT_DOC caller [expr]-
28Return the context of the current subroutine call.-
29-
30Without EXPR, returns "$line $filename". With EXPR, returns-
31"$line $subroutine $filename"; this extra information can be used to-
32provide a stack trace.-
33-
34The value of EXPR indicates how many call frames to go back before the-
35current one; the top frame is frame 0.-
36-
37Exit Status:-
38Returns 0 unless the shell is not executing a shell function or EXPR-
39is invalid.-
40$END-
41-
42#include <config.h>-
43#include <stdio.h>-
44#include "chartypes.h"-
45#include "bashtypes.h"-
46-
47#if defined (HAVE_UNISTD_H)-
48# ifdef _MINIX-
49# include <sys/types.h>-
50# endif-
51# include <unistd.h>-
52#endif-
53-
54#include <errno.h>-
55-
56#include "../bashintl.h"-
57-
58#include "../shell.h"-
59#include "common.h"-
60#include "builtext.h"-
61#include "bashgetopt.h"-
62-
63#ifdef LOADABLE_BUILTIN-
64# include "builtins.h"-
65#endif-
66-
67#if !defined (errno)-
68extern int errno;-
69#endif /* !errno */-
70-
71int-
72caller_builtin (list)-
73 WORD_LIST *list;-
74{-
75#if !defined (ARRAY_VARS)-
76 printf ("1 NULL\n");-
77 return (EXECUTION_FAILURE);-
78#else-
79 SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;-
80 ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;-
81 char *funcname_s, *source_s, *lineno_s;-
82 intmax_t num;-
83-
84 CHECK_HELPOPT (list);
never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: return (258);
(list)Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
(list)->wordDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((list)->word... ("--help")[0]Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-13
85-
86 GET_ARRAY_FROM_VAR ("FUNCNAME", funcname_v, funcname_a);-
87 GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);-
88 GET_ARRAY_FROM_VAR ("BASH_LINENO", bash_lineno_v, bash_lineno_a);-
89-
90 if (bash_lineno_a == 0 || array_empty (bash_lineno_a))
bash_lineno_a == 0Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
((bash_lineno_...elements == 0)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
91 return (EXECUTION_FAILURE);
never executed: return (1);
0
92-
93 if (bash_source_a == 0 || array_empty (bash_source_a))
bash_source_a == 0Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
((bash_source_...elements == 0)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
94 return (EXECUTION_FAILURE);
never executed: return (1);
0
95-
96 if (no_options (list))
no_options (list)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
97 return (EX_USAGE);
never executed: return (258);
0
98 list = loptend; /* skip over possible `--' */-
99-
100 /* If there is no argument list, then give short form: line filename. */-
101 if (list == 0)
list == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
4-13
102 {-
103 lineno_s = array_reference (bash_lineno_a, 0);-
104 source_s = array_reference (bash_source_a, 1);-
105 printf("%s %s\n", lineno_s ? lineno_s : "NULL", source_s ? source_s : "NULL");-
106 return (EXECUTION_SUCCESS);
executed 4 times by 1 test: return (0);
Executed by:
  • Self test
4
107 }-
108 -
109 if (funcname_a == 0 || array_empty (funcname_a))
funcname_a == 0Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
((funcname_a)-...elements == 0)Description
TRUEnever evaluated
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
0-13
110 return (EXECUTION_FAILURE);
never executed: return (1);
0
111-
112 if (legal_number (list->word->word, &num))
legal_number (...d->word, &num)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-9
113 {-
114 lineno_s = array_reference (bash_lineno_a, num);-
115 source_s = array_reference (bash_source_a, num+1);-
116 funcname_s = array_reference (funcname_a, num+1);-
117-
118 if (lineno_s == NULL|| source_s == NULL || funcname_s == NULL)
lineno_s == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
source_s == ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
funcname_s == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-9
119 return (EXECUTION_FAILURE);
executed 2 times by 1 test: return (1);
Executed by:
  • Self test
2
120-
121 printf("%s %s %s\n", lineno_s, funcname_s, source_s);-
122 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
123 else-
124 {-
125 sh_invalidnum (list->word->word);-
126 builtin_usage ();-
127 return (EX_USAGE);
executed 4 times by 1 test: return (258);
Executed by:
  • Self test
4
128 }-
129-
130 return (EXECUTION_SUCCESS);
executed 7 times by 1 test: return (0);
Executed by:
  • Self test
7
131#endif-
132}-
133-
134#ifdef LOADABLE_BUILTIN-
135static char *caller_doc[] = {-
136N_("Returns the context of the current subroutine call.\n\-
137 \n\-
138 Without EXPR, returns "$line $filename". With EXPR, returns\n\-
139 "$line $subroutine $filename"; this extra information can be used to\n\-
140 provide a stack trace.\n\-
141 \n\-
142 The value of EXPR indicates how many call frames to go back before the\n\-
143 current one; the top frame is frame 0."),-
144 (char *)NULL-
145};-
146-
147struct builtin caller_struct = {-
148 "caller",-
149 caller_builtin,-
150 BUILTIN_ENABLED,-
151 caller_doc,-
152 "caller [EXPR]",-
153 0-
154};-
155-
156#endif /* LOADABLE_BUILTIN */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2