20230322
[shlib.git] / doc / example / stdio-dbgout / dbgout-for-debug
blob9c17e60a43a915667687a0548fce49565854fefc
2 #!/bin/bash
3 ############################################################
4 # source: shlib
5 # author: devenkong(18151155@qq.com)
6 # date: 2022-07-29
7 ############################################################
8 # Copyright (C) 2022- Free Software Foundation, Inc.
9 # This configure script is free software; the Free Software 
10 # Foundation gives unlimited permission to copy, distribute 
11 # and modify it.
12 ############################################################
13 # note:
14 #     use dbgout.shlib for debuging.
15 ############################################################
18 # todoļ¼š
19 # @ 
20 # @ 
23 . shlibinc
26 ##############################
27 # section: shlib include
28 ##############################
30 include gplib.shlib
31 include dbgout.shlib
34 ##############################
35 # section: public comment info
36 ##############################
41 ##############################
42 # section: variable define
43 ##############################
45 longstr="adhdhjdjfjfjdjdjd
46 djjdjfjjffjjfjdk
47 djdjjedjdhvhvur
48 jfjrriekddnhffk
49 fjkdslsosojf
50 djjrekksijfuvugufhr
51 fjdjdjkjfhfhfhddjj
52 fkkforoeoeidjchshhsejj
53 fjrrbdhhducucjdsjje"
56 ##############################
57 # section: private function
58 ##############################
60 stub_debug ()
62         #
63         # here is the example for stub debug
64         # use stub string to seperate application string info,
65         # if some of the code running error, it shows error code where it
66         # is invoked.
67         #
68         
69         dbgout "xxxxxxxxxxxx step1 xxxxxxxxxxxx\n"
70         
71         echo 11111
72         dbgout "xxxxxxxxxxxx step2 xxxxxxxxxxxx\n"
73         
74         echo 22222
75         dbgout "xxxxxxxxxxxx step3 xxxxxxxxxxxx\n"
76         
77         echo 33333
78         dbgout "xxxxxxxxxxxx step4 xxxxxxxxxxxx\n"
79         
80         duehehjs
81         dbgout "xxxxxxxxxxxx step5 xxxxxxxxxxxx\n"
82         
83         echo 55555
84         dbgout "xxxxxxxxxxxx step6 xxxxxxxxxxxx\n"
87 func_for_test ()
89         #
90         # using stub to locate in src code
91         # it can be used for branch structure code.
92         #
93         if [[ 1 == 1 ]]; then
94                 dbgout_file_stub
95                 dbgout_func_stub
96                 
97                 echo application string output.
98                 
99                 #
100                 # display invoke stack to get the code location.
101                 #
102                 dbgout_trace
103         fi
107 ##############################
108 # section: public function
109 ##############################
112 # main <eval-str>
114 main ()
116         local testvar=aaa
117         local cnt=0
118         echo "func-paramter:"
119         
120         init_dbglogout 2 shlibopt 20000
121         
122         info "this example shows how to use debug infomation output function in sub-process of while loop."
123         
124         echo xxxxxxxxxxxxxxxxxxxxxxxxx
125         
126         echo testvar=$testvar
127         
128         #
129         # use dbgoutvar to display long string by var name.
130         #
131         dbgoutvar longstr
132         
133         #
134         # display data as hex string.
135         #
136         echo dbgout_hex | dbgout_hex
137         
138         while read line; do
139             : $(( cnt++ ))
140                 info cnt=$cnt
141                 [[ $cnt == 5 ]] && break
142                 
143                 func_for_test
144                 
145                 #
146                 # output string on debug channel
147                 #
148                 dbgout_cmd ls / -l
149                 
150                 #
151                 # debug pause as a single step
152                 #
153                 dbgstub_pause
154                 
155                 info testvar=$testvar
156                 echo xxx $line
157                 echo "echo string in logfile."
158                 dbgout "output debug string here.\n"
159                 info "output info string on tty console."
160         done < <(cat data.txt) > output.txt 
161         
162         echo at last, cnt=$cnt
163         echo output.txt is:
164         cat output.txt
165         
166         echo xxxxxxxxxxxxxxxxxxxxxxxxx
170 main "$@"
172 ##############################
173 # section: file tail
174 ##############################