4 # Generate the necessary information for resolving line-number information
5 # to function names in C files that reference a certain symbol (by default
6 # mrp_debug). This is used to convert file:line information to function
7 # names while _listing_ debug sites.
16 echo "warning: $*" 1>&2
24 info "usage: $0 [-s <symbol>] [-q] -o <output> <inputs>"
31 if [ "$1" = "-n" ]; then
37 if [ "$1" = "-e" ]; then
42 echo $_opts "$*" >> $OUTPUT
46 emit "#include <stdlib.h>"
47 emit "#include <murphy/common/debug.h>"
52 emit "#include <murphy/common/debug-auto-register.c>"
55 emit_function_info() {
58 while read func line file; do
59 if [ "$prev" != "$file" ]; then
60 if [ $cnt -gt 0 ]; then
61 emit " { .line = 0, .func = NULL }"
63 emit "static mrp_debug_file_t file_$(($cnt - 1)) = {"
64 emit " .file = \"$prev\","
65 emit " .info = info_$(($cnt - 1))"
70 emit "static mrp_debug_info_t info_$cnt[] = {"
74 emit " { .line = $line, .func = \"$func\" },"
76 if [ $cnt -gt 0 ]; then
77 emit " { .line = 0, .func = NULL }"
79 emit "static mrp_debug_file_t file_$(($cnt - 1)) = {"
80 emit " .file = \"$prev\","
81 emit " .info = info_$(($cnt - 1))"
85 emit "/* table of all files */"
86 emit "static mrp_debug_file_t *debug_files[] = {"
88 while [ $i -lt $cnt ]; do
97 emit_no_function_info() {
98 emit "/* No ctags found, could not generate debug info... */"
99 emit "static mrp_debug_file_t *debug_files[] = {"
106 SYMBOL="mrp_debug\(" # symbol to look for
107 SOURCE="" # default to all file containing $SYMBOL
108 OUTPUT="" # no default output, must be specified
111 while [ -n "${1#-}" ]; do
114 if [ -z "$OUTPUT" ]; then
118 error "Multiple output files requested."
133 error "Unknown option '$1'."
143 # check that we've got everything mandatory
144 if [ -z "$OUTPUT" ]; then
145 error "No output file specified (use the -o option)."
148 if [ -z "$SYMBOL" ]; then
151 if [ -z "$SOURCE" ]; then
152 [ -n "VERBOSE" ] && info "Scanning all C files containing $SYMBOL..."
153 SOURCE="`find . -name \*.c -exec grep -Hn $SYMBOL\( {} \; | \
154 cut -d ':' -f 1 | sort -u`"
157 [ -n "$VERBOSE" ] && info "Generating debug function info file $OUTPUT..."
161 # generate the output
164 which ctags >& /dev/null
165 if [ "$?" = "0" ]; then
166 ctags -x --c-kinds=f $SOURCE | tr -s '\t' ' ' | \
167 cut -d ' ' -f 1,3,4 | sort -k 3,3 -k 2,2n | emit_function_info
169 warning "No ctags found, generating empty debug tables..."
170 emit_no_function_info