Monday, May 18, 2009
Monday, April 20, 2009
How to use jdb on anroid
5. happy debuging :)
Wednesday, April 15, 2009
How to use gdbserver on android
1. get and build cupcake
Any issues, please refer sources.android.com
2. make you library debugable (add -g options in makefile)
modify your Android.mk add below command "LOCAL_CPPFLAGS += -g" for C++ files and "LOCAL_CFLAGS += -G" FOR C files.
rebuild your library and system image
3. redirect debug port
$ telnet localhost 5554
redir add tcp:1234:1234
exit
current release will fail if you redirect in this step, hope final cupcake will fix it.
you can start emulator by below command with debug port redirected.
./emulator @jove -qemu -redir udp:1234::1234
4. push gdbserver to emulator
adb push ./out/target/product/generic/obj/EXECUTABLES/gdbserver_intermediates/gdbserver /data/local
5. run /data/local/gdbserver 10.0.2.2:1234 --attach your-desired-pid
6. run ./prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb ./out/target/product/generic/symbols/system/bin/app_process
set solib-search-path out/target/product/generic/symbols/system/lib
target remote localhost:1234
b xxx.cpp:xx
7. enjoy debuging and life :)
Tuesday, April 14, 2009
SDL init failure
make sdk
android create avd --name jove --target 1
after I execute"./emulator @jove", it reports errors: SDL init failure, reason is: No available video device
I resolve it by
$ export DISPLAY=:0
./emulator @jove
Wednesday, February 11, 2009
How G++ implement virtual function
Introduction
We know that virtual function in C++ is implemented by VPTR. And there is a pointer in the beginning of every instance of the Class point to the VPTR table. That means VPTR table is sole in the process and every instance share the same VPTR.
When the virtual function is called in program, this pointer pass to the virtual function as the first parameter.(all the non-static function of the class use the same call method) The function can know which instance is used.
It's clear and simple. But how the whole mechanism is implemented in machine code or assemble code.
Let's begin our fascinating journey by a little example:
class A{
public:
virtual void test( ){i = 0;};
int i;
};
class B: public A{
public:
virtual void test(){i=1976;};
};
void tv(A* p)
{
p->test();
}
int main()
{
B b;
tv(&b);
}
The example do nothing, only set the class attribute i to 1976.
We can generate assemble code by a option -S, “g++ vptr.cpp -S�.
Let's check the assemble code in two parts:
-
How to instance b?
-
How virtual function is called?
First part, How to instant b?
In the main function, after push esp, init ebp , the program do the following thing.
subl $20, %esp
leal -12(%ebp), %eax
movl %eax, (%esp)
call _ZN1BC1Ev
What's that mean? Let me explain it instruction by instruction.
First instruction subtitude esp by 20, it will reserve 20 bytes for local variable. You may ask rith now, the size of B is only 8 bytes, including VPTR pointer and an int i, why do GCC reserve 20 bytes. Beats me, Except the 8 bytes, there are 12 bytes left. Who need them? The answer is call stack and return value. In next two instructions, it's function will displayed.
“leal� and “movl� instrunciton assign the instance b's memory and make preparation for call the constructor of B. After this two instructions, the stack illustrated as below diagram.
Let's enter the construction of _ZN1BC1Ev:
pushl %ebp
movl %esp, %ebp.
subl $8, %esp
movl 8(%ebp), %eax
movl %eax, (%esp)
call _ZN1AC2Ev
movl $_ZTV1B+8, %edx
movl 8(%ebp), %eax
movl %edx, (%eax)
leave
retB,
We skip A's constructor because they are same as call B's constructor. The first instructor after “call _ZN1AC2Ev� is a movl instructor. The _ ZTV1B is the VPTR table. It is defined in code:
_ZTV1B:
.long 0
.long _ZTI1B
.long _ZN1B4testEv
_ZTV1B+8 is the virtual function test address. This instruction would move the VPTR's address to register edx. The next two instruction will init the class's VPTR pointer, put the VPTR's address into the pointer's value. Then the construction is completed. The later leave instruction will move EBP's value and pop EBP from the stack.
The Second Part: How virtual function is called?
Let's watch the assemble code of function tv:
The two instructions before the tv is called are very clear. They are function tv's parameter.
leal -12(%ebp), %eax
movl %eax, (%esp)
call _Z2tvP1A
Let's enter function tv directly.
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl 8(%ebp), %eax
movl (%eax), %eax
movl (%eax), %edx
movl 8(%ebp), %eax
movl %eax, (%esp)
call *%edx
leave
ret
I'll skip the first three instructions, they are all same in each function. After the instruction,movl 8(%ebp), %eax , register eax's value is the address of variable b. After the instruction, movl (%eax), %eax, register eax value is the address of VPTR. After the instruction,movl (%eax), %edx, register edx value is the virtual function's address. The next three instruction is calling the virtual function.
Then all is done. It's simple, right?
Monday, February 2, 2009
Plan for 2009
1. Develop my English(Oral,Listening, writing).
1.1 read one Grimm’s fairy tale everyday.
1.2 watch Friends.
1.3 recite Family Album USA and New Concept English 3,4
1.4 listen to CRI(FM91.7) everyday.
2. Develop knowledge of Android and linux kernel( or minix kernel)
2.1 Master Binder.
2.2 Master how to write linux driver
2.3 learn SVG engine.
3. Strengthen the ability of communication, to express myself and persuading others.
4. Attend Ielts examination.
5. Travel twice at least.
5.1 go to Ziyuan in the spring.
5.2 go to Tibet in the summer.
6. develop my tennis skills.
6.1 pratice tennis every week.
7. Read China News week and an IT related magzine.
8. Buy an apartment.
9. make new friends and extend my social circle.
10. Exercise every week.
Plan for my Chinese New Year holiday
1. relax from Jan 24 to Jan 26
2. Go to Ditan temple fair and take photos
There are too much people in Ditan, I give up.
3. go to ski twice
3.1 learn wedge turn
3.2 learn Stem Christi turn
4. setup the enviroment of android.
5. learn binder
6. learn how text is draw in svg engine.