Quick Start
BTR debug a project. The general steps are:
1) set bdenug.ini
2) startup BTR
3) build cmd to compile&link a project
4) startup the project
5) the project throw a exception( dead , unlimit-loop , unexpect result ......)
6) input some debug command to locate the error code
7) find out the bug reason
8) modify the code and have another try
9) shutdown to exit BTR when no bug found
The most important command is "build". Where you can use BTR "build" a project, where you can debug the project.
There are projects in BTR/demo directory which has many bugs.You can try to use BTR debug them as exercises.
First , your should open quickstart.sln in visual studio , build all projects successful , then you can use BTR debugger build and debug them.
1)The demo directory is: demo\win\helloworld.
2)Start BTR.
start up bdee.exe( enterprise edition , the BTR server , free version need not this step )
start up bd
3)Build the demo
build d:\BTR\demo\win\helloworld
4) Start helloworld.exe
cd d:\BTR\demo\win\helloworld\debug
helloworld.exe
5) The program crashed.
6) In bd command prompt
flash -s a.txt
7) Use notepad to read d:\BTR\client\a.txt or d:\BTR\a.txt
8) The last code stop at *q++ = *p++;.
9) Analysis the bug reason.
10) Modify the code *q++ = *p++; to *p++ = *q++;
11) Build helloword again
build d:\BTR\demo\win\helloworld
12) Run helloworld.exe again
13) Helloworld.exe crashed again
14) In bd command prompt
flash -s a.txt
15) Read a.txt and analysis the bug reason.
16) Modify code :
char buf[ 5 ]; => char buf[ 20 ];
insert *q = 0; before printf("%s" , buf );
17) Build and run helloworld.exe , no bug find.
build d:\BTR\demo\win\helloworld
18) Exit BTR( exit bd )
shutdown
19) When all BTR client are closed , shutdown BTR server.
To bdee.exe( enterprise edition):
shutdown
1)The demo directory is: demo\win\hellowindow.
2)Build the project and run demo\win\hellowindow\Debug\hellowindow.exe
3)When hellowindow.exe crashed
flash -s a.txt
4)Because hellowindow.exe is multithread process, use filter to see clearly:
flash hellowindowview.cpp -s b.txt
5)Find out the bug reason is wild pointer.
1)The demo directory is: demo\win\tstl and demo\win\tstl\usel. tstl project is library. usel project call the function in tstl.lib.
2)Use BTR build demo\win\tstl project
3)Use BTR build demo\win\tstl\usel
4)Run demo\win\tstl\usel\Debug\usel.exe. The process dummyed.
5)Use flash command to find out that process in unlimited loop.
flash -s a.txt
6)Find out the bug reason that pointer is not shift. Add
p++;
1)The demo directory is: demo\win\tstdll and demo\win\tstdll\usedll. tstdll project is library. usedll project call the function in tstdll.dll.
2)Use BTR build demo\win\tstdll project
3)Use BTR build demo\win\usedll
4)Run demo\win\tstdll\usedll\Debug\usedll.exe. The process crashed.
5)Use flash command to find out that dll is loaded , but function no called.
flash -s a.txt
6)Find out the bug reason that dll function pointer is wrong.Modify:
DEFFUNC pFunc;
pFunc = ( DEFFUNC )( dll_load.GetDllFunction( dll_handle ,"fntstdll") );
x = ( *pFunc )( atoi( str ) );
7) bdebug.ini add:
[PV_FUNCTION]
( DllLoad , DllUnload )
a) bd
b) run usedll.exe , usedll.exe exit.
c) in bd , use F2 to pause. Watch the pv function
pv
Resource:10000000 [usedllDlg.cpp:00186]
dll_handle = dll_load.DllLoad(
"..\\..\\Debug\\tstdll.dll" );
1 unfree pointers | resources.
d) dll_handle is regard as pointer. dll_handle is unreleased in the whole process period. So add the code line:
dll_load.DllUnload( dll_handle );
8) We suggest that tstdll project and usedll project are both build by BTR. BTR can debug multiple peojects in one time.
1) Demo directory: demo/win/android/hello-jni demo/win/android/studioAPP
2) Check SDK, NDK , GRADLE_HOME environment variable ,check SDK\build-tools SDK\platforms gradle\gradle-version\bin in PATH
Check "android sdk\tools" , "android sdk\platform-tools" in PATH variable
3) cd demo\win\android
android.bat update project -n anprj -p ...\demo\win\android
ant debug
4) Build it ok manually,then use BTR build it.
cd d:\BTR
bd
bd >
bd > build d:\BTR\demo\win\android\jni
bd > build d:\BTR\demo\win\android
5) Install
cd d:\BTR\demo\win\android\
adb install bin\anprj-debug.apk
6) Find out "anprj" application in android GUI, double click to run it.
7) see log
bd >
bd >flash -s a.txt
bd >clog -s c.txt
Windows driver
1) demo: demo\win\driver readme: debug_driver_readme.txt
2) build & install
bd
bd >
bd > build d:\Windows_Driver_Kit_(WDK)_8.1_Samples\IOCTL\C++\sys
bd > build
d:\Windows_Driver_Kit_(WDK)_8.1_Samples\IOCTL\C++\exe
bd >
4) debug
bd
>
bd > flash -s a.txt
bd >
...
see a.txt
1) demo directory: demo\win\qt readme: debug_qt_readme.txt
1. Install VS2012
2. Download qt-opensource-windows-x86-msvc2012-5.2.1.exe and install it.
3. Open Qt5.2.1 IDE
4. Use Qt5.2.1 IDE build example
C:\Qt\Qt5.2.1\5.2.1\msvc2012\examples\gui\rasterwindow
5. Path=C:\Windows\system32;C:\Windows;...;C:\Qt\Qt5.2.1\5.2.1\msvc2012\bin
6. Run rasterwindow.exe out of Qt5.2.1 IDE , ( Note : if some dll not find , goto 5 to set Path
).
7. Install BTR debugger for win
for example : installed at d:\BTR
8. BTR build
bd
bd >
bd > build
C:\Qt\Qt5.2.1\5.2.1\msvc2012\examples\gui\rasterwindow
bd >
9. run rasterwindow.exe
10. BTR debugger see run log.
bd >
bd > flash -s a.txt
bd >
1)The demo directory is: demo/linux/helloworld
2)makefile, the simplist makefile demo . Include make clean and make , no bdebug.ini file.
3) build
cd /home/usr/BTR
./bd
build /home/usr/BTR/linux/helloworld
4) run
cd /home/usr/BTR/demo/linux/helloworld/release
./helloworld.exe
the program crashed
5) flash command to see crashed line.
flash -s a.txt
6) The error line is :
[main.cpp : 00016 ] delete( pCMyHost );
7) Please try to correct the error.
1)The demo directory is: demo/linux/echo
2)makefile, like demo/linux/helloworld/makefile.
3)use BTR build the project
cd /home/usr/BTR
./bd
build /home/usr/BTR/linux/echo
4)run echo.exe
cd /home/usr/BTR/demo/linux/echo/release
./echo.exe
Please input send string(Q: quit):
Q
5) use pv comannd to see memory leak
pv
1 unrelease pointers | resources.
[echosrv.cpp : 00083] m_pCTcp = new CTcp();
6) Please try to correct the error.
1)The demo directory is:
demo/linux/mylib
demo/linux/mydll
demo/linux/myexe
Project myexe call mylib and mydll.
2) build 3 projects
./bd
build /home/usr/BTR/linux/mylib
build /home/usr/BTR/linux/mydll
build /home/usr/BTR/linux/myexe
3) Run /home/usr/BTR/linux/myexe/my.exe
./my.exe
Process crashed .
6) Use flash command in bd terminal
flash -s a.txt
Look at a.txt to see that the error is
[mycp.cpp : 00019] while( *q ) *q++ = *p++;
Correct the error and build them again.
7) debug myexe project. In its bdebug.ini add [PV_FUNCTION]
( DllLoad , DllUnload ) , then build myexe project.
build /home/usr/BTR/linux/myexe
8) run my.exe
./my.exe
Input number:3
Library copy result=3
Call dll , segma( 3 ) = 6
9) BTR throw out a error.
Error 20011: [pointer:0 ] wild pointer.
The line is:
[main.cpp:00053] delete ( pCMyCP );
Ignore the error report, use F3 hotkey to continue
The process exit.
10) use pv to see resource management bug.
pv
Resource:09c990f0 [main.cpp:00042] handle = pCDllLoad->DllLoad( "../mydll/segma.so" );
1 unfree pointers | resources.
The error shows that DllUnload() not called.
1) The demo directory is: demo/linux/TheApp1
2) Use linux KDE/c++ IDE to create a project named theapp1
3) After add button and label, add event code. Try run it.
4) Quit KDE , run ./configure , make , make distclean.
cd demo/linux/TheApp1
./configure
make clean
make
5) Confirm that the project run ok.
6) BTR build the KDE project
./bd
build /home/usr/BTR/linux/TheApp1
7) Double click the exe file:
demo/linux/TheApp1/src/theapp1
8) use BTR commands to track the process.
flash -s a.txt
func -s b.txt
lon
...
clog -s c.txt
loff
9) Because KDE project is too large size, so we are sorry that we delete it. You can use BTR try it build and debug them.
1) The demo directory is: demo/linux/android
Check android sdk , android ndk , android gradle , check sdk/build-tools sdk/platforms gradle/gradle-version/bin in $PATH
2) cd demo/linux/android
android update project -n hello-jni -p .../demo/linux/android -t 1
ndk-build clean
ant clean
3) build jni c and java manually
ndk-build
ant debug --> generate hello-jni-debug.apk
4) use BTR build jni-c project and java project
bd >
bd > build /.../demo/linux/android/jni
bd > build /.../demo/linux/android
5) set linux BTR debugger
bd >lon
bd >
6) install hello-jni-debug.apk
adb install /.../demo/linux/android/bin/hello-jni-debug.apk
7) run android phone , find hello-jni application, dobule click it
8) check android BTR
bd >
bd > flash -s a.txt
bd > flash myfunc.c -s b.txt
bd > pid
bd >
9) Read a.txt or b.txt, you will find bugs if hello-jni has bugs.
1) demo :demo/linux/driver
2)cd demo/linux/driver
make clean
make
use BTR debugger generate myhello.ko
cd /home/usr/BTR
./bd
bd >
bd > build /home/usr/BTR/demo/linux/driver
bd >
3) install kernel module
su
insmod myhello.ko
4) check mod1.c
bd >
bd > flash
bd >
1) demo: demo/linux/embed/test demo/linux/embed/embedlinux
config cross compile environment
2)cd demo/linux/embed/test
make clean
make
3)compile by BTR debugger , assign IP, generate embedtest.exe
cd /home/usr/BTR
./bd
bd >
bd > build /home/usr/BTR/demo/linux/embed/test
bd >
4) download embedtest.exe to your embed device , run embedtest.exe
tftp > get embedtest.exe
#chmod 0755 embedtest.exe
./embedtest.exe
5) debug
bd >
bd > flash -s a.txt
6) demo/linux/embed/embedlinux is another sample.
1) demo directory: demo/linux/qt/first
2) build
bd > build /home/user/BTR/demo/linux/qt/first
bd >
3) run first
$> cd /home/user/BTR/demo/linux/qt/first
./first
4) flash
bd >
bd > flash
1) The demo directory is: demo\win\javahello
Use or not use eclipse to generate a empty project. eclipse put src and class in difference path. Here *.java and it's *.class in same path.
2) Build demo\win\javahello
bd >
build demo\win\javahello
3) Run java
cd demo\win\javahello_BTR\top
java -jar f1.jar
4) See java running code log.
flash -s a.txt
5) Add BTR output string API in code. Function bprint() defined at jni\bdg.java.
bdg.bprint( "test x+y" );
bdg.bprint( s );
If not use BTR later, please delete bdg.bprint() lines, otherwise it will cause error.
6) Build demo\win\javahello again , run java again
7) Watch bdg.bprint() send to BTR output string.
1) The demo directory is: demo\win\servlet
2) build
bd >
build demo\win\servlet
3) run demo\win\servlet_BTR\brun.bat
start tomcat , deploy TestServlet.war.
You can start tomcat , websphere or weblogical, or other 3rd product. If TestServlet.war deployed successful , then you can use BTR debug it.
4)use ie brower , input url:
http://127.0.0.1:8080/TestServlet
5) use flash command in BTR , look at the servlet code log.
flash
This sample depend on where your javaweb installed . If C:\apache-tomcat-7.0.23\webapps\examples\WEB-INF\classes\jsp2\examples is a javabean.
1) use BTR build command
bd >
build d:\BTR\demo\win\JavaBean
2) run demo\win\JavaBean_BTR\brun.bat
copy *.class to C:\apache-tomcat-7.0.23\webapps\examples\WEB-INF\classes\jsp2\examples\.
create dir C:\apache-tomcat-7.0.23\webapps\examples\WEB-INF\classes\btr
copy d:\BTR\demo\win\JavaBean\btr\bdg.class C:\apache-tomcat-7.0.23\webapps\examples\WEB-INF\classes\btr\bdg.class
3) start tomcat
4) in IE, input url:
http://127.0.0.1:8080/index --> JSP sample
5) use BTR to see the running java bean.
flash -s a.txt
6) open a.txt to see code log.
1)The demo directory is: demo\win\cs.
2)Build the demo
bd >
build d:\BTR\demo\win\cs
3)Run c sharp project.
Dobule click demo\win\cs\obj\Debug\cs.exe. A form displayed.
4)Use BTR , see the code history:
flash -s a.txt
Bsd unix demo is just like linux , please see linux sample demo for detail information. Only makefile is different from the samples in linux. BTR debugger build and debug bsd unix projects is just like it is in linux.
BTR debugger in bsd unix does not support java , it have no java sample.
Code sequence:
1) if ( b )
Q: Why "[00016][x.cpp]if ( b ) goto LABEL_EXIT;" appears two times?
A: [00016][x.cpp]if ( b ) goto LABEL_EXIT;
[00016][x.cpp]if ( b ) goto LABEL_EXIT;
This is right , because b == true.
2) thread crash
Q: The following code log:
[00016][x.cpp] x = 1;
[00260][x.cpp] x += strlen(
s );
[05012][y.cpp] while( bOk
) {
[05013][y.cpp] Sleep( 300 );
[05013][y.cpp] Sleep( 300 );
...
[05013][y.cpp] Sleep( 300 );
Which line crashed?
A: "[00260][x.cpp] x += strlen( s ); " crashed . Because x.cpp in one thread. y.cpp run in another thread. [00260][x.cpp] don't quit function body but quit its thread. So strlen( s ) must be the crashed line.
3) crashed at int x = 0;
Q: The following code log:
[00906][x.cpp] pCSegma->segma( num ) ;
[01509][segma.cpp] int x = 0;
The process crashed at line [01509][segma.cpp] , why ?
A: Because pCSegma is a wild pointer. Sometimes the address of pCSegma is valid, but no ram assigned to pCSegma. Usr should check if "pCSegma = new ..." line appears.
Value Trace
1) value log
[00055][x.cpp] bwatch(
"NUM" , &num , 4 );
NUM: 00 00 00 00 [int]=0 [uint]=0
[01026][y.cpp] num++;
NUM: 01 00 00 00 [int]=1 [uint]=1
[01026][y.cpp] num++;
NUM: 02 00 00 00 [int]=2 [uint]=2
[03016][x.cpp] num--;
NUM: 01 00 00 00 [int]=1 [uint]=1
[03062][z.cpp] pPersonItem->sex
= MAN;
NUM: 5B 00 00 00 [int]=91 [uint]=91
[03016][x.cpp] num--;
NUM: 5A 00 00 00 [int]=90 [uint]=90
Q: Line [03062][z.cpp] changed num value , why?
A: Because pPersonItem is wild pointer . The address of sex is the same as num , so the value of num changed.
VC demo
1) Can't build
Q: I copy the demo projects into my harddisk , I can't build some VC project, why?
A: Please rebuild the project in visual studio first. Because visual studio environment changed, output path changed.
KDE demo
1) Can't build
Q: I copy the KDE demo project into my harddisk , I can't build it, why?
A: Please create a KDE project again in your linux . Then use ./configure, make clean, make , make distclean , check it . Then try again.
By the way , you can try the others x-window ui IDE tools. Generate Makefile and try to use BTR build them.
2) Can't build
Q:I can't build the KDE form demo sample , why?
A:Please check if your linux has already installed KDE.
BTRweb
1)character disorder
Q:I use BTRweb.exe , sometimes I find that character is disordered , why?
A:Please set UTF charset.
2)c#
Q:I use BTRweb and browser test.cs code file, I find disordered char.
A:Because the first 3 chars (0xEF 0xBB 0xBF) in *.cs is microsoft c# file flag. so the char disordered. IE or firefox can not recognize these characters.
So you can browser the c# file , but must not modify them use BTRweb.exe.
Android
1)run again
Q: I can see debug info at the first time . However , I run my android project again, I see 0 lines when use flash command , what should I do?
A: Sorry , please exit android device first , start android device again , start bd again , then you will see debug code lines when use flash command.