fbdbg  3.0
FreeBASIC Debugger
fbdbg2_main.bas
Go to the documentation of this file.
1 
6 
8 '#Include Once "fbdbg2_start.bas"
9 #Include Once "fbdbg2_extract.bas"
10 #Include Once "fbdbg2_handlefiles.bas"
11 '
12 '#include Once "fbdbg2_butmenu.bas"
13 '#include Once "fbdbg2_break.bas"
14 '#include Once "fbdbg2_thread.bas"
15 
16 '#include Once "fbdbg2_var.bas"
17 '#include Once "fbdbg2_watch.bas"
18 
19 'in string STRG all the occurences of SRCH are replaced by REPL
20 Sub str_replace(strg As String,srch As String, repl As String)
21  Dim As Integer p,lgr=Len(repl),lgs=Len(srch)
22  p=InStr(strg,srch)
23  While p
24  strg=Left(strg,p-1)+repl+Mid(strg,p+lgs)
25  p=InStr(p+lgr,strg,srch)
26  Wend
27 End Sub
28 '========================
29 'flaglog=0 --> no output / 1--> only screen / 2-->only file / 3 --> both
30 Sub dbg_prt(t As String)
31  'TODO
32 
33  'Static As HANDLE scrnnumber
34  'Static As Integer filenumber
35  'Dim cpt As Integer,libel As String
36  'Dim As COORD maxcoord
37  'Dim As CONSOLE_SCREEN_BUFFER_INFO csbi
38  'Dim As SMALL_RECT disparea=Type(0,0,0,0)
39  '
40  'If t=" $$$$___CLOSE ALL___$$$$ " Then
41  ' If scrnnumber<>0 And (flaglog And 1)=0 Then FreeConsole():scrnnumber=0
42  ' If filenumber And (flaglog And 2)=0 Then Close filenumber:filenumber=0
43  ' Exit Sub
44  'EndIf
45  '
46  'If scrnnumber=0 And (flaglog And 1) Then
47  ' libel=Chr(13)+Chr(10)+Date+" "+Time+Chr(10)
48  ' AllocConsole()
49  ' scrnnumber=GetStdHandle(STD_OUTPUT_HANDLE)
50  ' setconsoletitle(StrPtr("FBdebugger trace/log"))
51  ' maxcoord=GetLargestConsoleWindowSize(scrnnumber)
52  ' GetConsoleScreenBufferInfo(scrnnumber,@csbi)
53  ' 'change buffer to max sizes
54  ' maxcoord.y=csbi.dwsize.y
55  ' SetConsoleScreenBufferSize(scrnnumber,maxcoord)
56  ' 'change display
57  ' disparea.right=(maxcoord.x-1)*.8
58  ' disparea.bottom=(csbi.dwMaximumWindowSize.y-1)/2
59  ' SetConsoleWindowInfo(scrnnumber,TRUE,@disparea)
60  ' SetConsoleCtrlHandler(Cast(PHANDLER_ROUTINE,@CtrlHandler),TRUE)
61  ' WriteConsole(scrnnumber, StrPtr(libel),Len(libel),@cpt,0)
62  'EndIf
63  '
64  'If filenumber=0 And (flaglog And 2) Then
65  ' filenumber=FreeFile:Open ExePath+"\dbg_log_file.txt" For Append As filenumber
66  ' Print #filenumber,Date,Time
67  'EndIf
68  '
69  'If (flaglog And 1) Then libel=t+Chr(10):WriteConsole(scrnnumber, StrPtr(libel),Len(libel),@cpt,0)
70  'If (flaglog And 2) Then Print # filenumber,t
71 End Sub
72 '=============================================
73 'todo If Command<>"" Then treat_file("") 'case command line exe see treat_file
74 '======== init =========================================
75 Sub re_ini()
76 
77 'Reset all the widgets
78 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(SRC->BuffCur), "", -1) 'clear curent line
79 gtk_label_set_text(GTK_LABEL(GUI.butStopVar),"Break on var") 'reset break on var
80 gtk_window_set_title (GTK_WINDOW(gui.window1),"Debug") 'reset title in main window
81 
82 gtk_list_store_clear(GTK_LIST_STORE(GUI.lstoreMemory)) 'reset memory listview
83 
84 gtk_tree_store_clear(GTK_TREE_STORE(GUI.tstoreProcVar))'reset the treeviews
85 gtk_tree_store_clear(GTK_TREE_STORE(GUI.tstoreProcs))
86 gtk_tree_store_clear(GTK_TREE_STORE(GUI.tstoreThreads))
87 gtk_tree_store_clear(GTK_TREE_STORE(GUI.tstoreWatch))
88 
89 'TODO if dsptyp Then dsp_hide(dsptyp) RESET DISPLAY
90 'TODO dsp_sizecalc
91 'TODO close all bx bx_closing
92 
93 If flagrestart=-1 Then 'add test for restart without loading again all the files
94  SRC->removeAll() 'remove all the source tabs
95 Else
96  'TODO not sure to be needed reset selected line ??? : sel_line(curlig-1,0,1,richedit(curtab),FALSE) 'default color
97 EndIf
98 
99 'reset status bar
100 WITH *ACT
101  gtk_label_set_text(GTK_LABEL(.SbarLab1), "")
102  gtk_label_set_text(GTK_LABEL(.SbarLab2), "")
103  gtk_label_set_text(GTK_LABEL(.SbarLab3), "")
104  gtk_label_set_text(GTK_LABEL(.SbarLab4), "")
105  gtk_label_set_text(GTK_LABEL(.SbarLab5), "")
106 END WITH
107 
108 
109 ' reset watch bar
110 WITH GUI
111  gtk_label_set_text(GTK_LABEL(.watch1), "< empty >")
112  gtk_label_set_text(GTK_LABEL(.watch2), "< empty >")
113  gtk_label_set_text(GTK_LABEL(.watch3), "< empty >")
114  gtk_label_set_text(GTK_LABEL(.watch4), "< empty >")
115 END With
116 
117 '=========
118 prun=FALSE
119 runtype=RTOFF:ACT->setState(runtype)
120 brkv.adr=0 'no on var
121 brknb=0 'no break on line
122 brkol(0).ad=0 'no break on cursor
123 
124 curline=0
125 sourcenb=-1:dllnb=0
126 threadnb=-1
127 vrrnb=0:procnb=0:procrnb=0:linenb=0:cudtnb=0:arrnb=0:procr(1).vr=1:procin=0:procfn=0:procbot=0:proctop=FALSE
128 proc(1).vr=VGBLMAX+1 'for the first stored proc
129 excldnb=0
130 dumpadr=0
131 'TODO flaglog=0:dbg_prt(" $$$$___CLOSE ALL___$$$$ "):flagtrace=0
132 flagmain=TRUE:flagattach=FALSE:flagkill=FALSE
133 udtcpt=0:udtmax=0
134 
135 vrbgbl=0:vrbloc=VGBLMAX:vrbgblprev=0
136 udtbeg=16:cudtbeg=1:locbeg=VGBLMAX+1:vrbbeg=1:prcbeg=1
137 
138 '' code moved to gui/source.bas executed by SRC->removeAll()
139  'Reset bookmarks TODO maybe keep them if rerun (caution with dll or so)
140  'Var box = GTK_COMBO_BOX_TEXT(SRC->CBMarks)
141  'gtk_combo_box_text_remove_all(box) 'remove all
142  'gtk_combo_box_text_insert(box, -1, "0", "No bookmark")
143 
144 'todo remove the 2 lines below no needed as all is handled by the gui part
145 For i As Integer =1 To bmkcpt:bmk(i).ntab=0:bmk(i).nline=0:Next
146 bmkcpt=0
147 gtk_action_set_sensitive(ACT->act_bmknext, FALSE)
148 gtk_action_set_sensitive(ACT->act_bmkprev, FALSE)
149 
150 'TODO grey log button EnableMenuItem(menutools,IDHIDLOG,MF_GRAYED)
151 
152 compinfo="" 'information about compilation
153 threadprv=0
154 threadsel=0
155 ReDim Trans(70000)
156 Trans(1)="1"
157 Trans(2)="2"
158 Trans(3)="1"
159 Trans(4)="8"
160 Trans(5)="8"
161 Trans(6)="9"
162 Trans(7)="10"
163 Trans(8)="5"
164 Trans(9)="6"
165 Trans(10)="2"
166 Trans(11)="3"
167 Trans(12)="11"
168 Trans(13)="12"
169 Trans(18)="7"
170 Trans(19)="2"
171 Trans(20)="3"
172 Trans(21)="5"
173 Trans(22)="6"
174 Trans(23)="1"
175 Trans(24)="8"
176 Trans(25)="9"
177 Trans(26)="10"
178 
179 End Sub
180 Function kill_process(text As String) As Integer
181  If prun=0 Then Return TRUE 'not running.... TODO remove this line
182  Var dia = gtk_message_dialog_new_with_markup(GTK_WINDOW(GUI.window1) _
183  , GTK_DIALOG_MODAL OR GTK_DIALOG_DESTROY_WITH_PARENT _
184  , GTK_MESSAGE_QUESTION _
185  , GTK_BUTTONS_YES_NO _
186  , ( _
187  *__(!"Kill current running Program ?\n\n") _
188  & *__(!"From action : <b>%s</b>\n\n") _
189  & *__(!"USE CARREFULLY SYSTEM CAN BECOME UNSTABLE, LOSS OF DATA, MEMORY LEAK\n") _
190  & *__("Try to close your program first") _
191  ) _
192  , Text _
193  , NULL)
194 
195  If GTK_RESPONSE_YES = gtk_dialog_run(GTK_DIALOG(dia)) THEN
196  flagkill=TRUE
197  #Ifdef __FB_LINUX__
198  'TODO add terminate
199  #Else
200  #Ifdef __FB_WIN32__
201  'TODO dbg_prt ("return code terminate process + lasterror "+Str(terminateprocess(dbghand,999))+" "+Str(GetLastError))
202  'TODO thread_rsm()
203  'TODO While prun:Sleep 500:Wend
204  #Else
205  'other OS Android,...
206  #EndIf
207  #EndIf
208  kill_process=TRUE
209  Else
210  kill_process=FALSE
211  End If
212  gtk_widget_destroy(dia)
213 End Function
214 Sub simple_message(line1 As String,line2 As String =" ")
215  Var dia = gtk_message_dialog_new_with_markup(GTK_WINDOW(GUI.window1) _
216  , GTK_DIALOG_MODAL OR GTK_DIALOG_DESTROY_WITH_PARENT _
217  , GTK_MESSAGE_WARNING _
218  , GTK_BUTTONS_OK _
219  , ( _
220  *__(!"<b>%s</b>\n\n") _
221  & *__("%s") _
222  ) _
223  , line1 _
224  , line2 _
225  , NULL)
226 
227  gtk_dialog_run(GTK_DIALOG(dia))
228  gtk_widget_destroy(dia)
229 End Sub
230 
231 
250 Sub ini_main
251 stoplibel(0)=@""
252 stoplibel(1)=__("cursor")
253 stoplibel(2)=__("tempo break")
254 stoplibel(3)=__("break")
255 stoplibel(4)=__("Break var")
256 stoplibel(5)=__("Break mem")
257 stoplibel(6)=__("Halt by user")
258 stoplibel(7)=__("Access violation")
259 stoplibel(8)=__("New thread")
260 stoplibel(9)=__("Exception")
261 
262 udt(0).nm="Typ Unknown"
263 udt(1).nm="Integer":udt(1).lg=Len(Integer)
264 udt(2).nm="Byte":udt(2).lg=Len(Byte)
265 udt(3).nm="Ubyte":udt(3).lg=Len(UByte)
266 udt(4).nm="Zstring":udt(4).lg=4
267 udt(5).nm="Short":udt(5).lg=Len(Short)
268 udt(6).nm="Ushort":udt(6).lg=Len(UShort)
269 udt(7).nm="Void":udt(7).lg=4 :udt(7).index=7'dwarf
270 udt(8).nm="Uinteger":udt(8).lg=Len(UInteger)
271 udt(9).nm="Longint":udt(9).lg=Len(LongInt)
272 udt(10).nm="Ulongint":udt(10).lg=Len(ULongInt)
273 udt(11).nm="Single":udt(11).lg=Len(Single)
274 udt(12).nm="Double":udt(12).lg=Len(Double)
275 udt(13).nm="String":udt(13).lg=Len(String)
276 udt(14).nm="Fstring":udt(14).lg=4
277 udt(15).nm="fb_Object":udt(15).lg=Len(UInteger)
278 End Sub
279 
280 
281