Page 1 of 1
set a breakpoint inside c function using bochs debugger
Posted: Mon Jun 14, 2004 8:04 pm
by firas981
how I can set a breakpoint inside c function ?
I know how to breakpoint at a physical address using bochs debugger , but say that I want to breakpoint at the instruction x inside the c function y
How I can do so ?
thanks
Re:set a breakpoint inside c function using bochs debugger
Posted: Mon Jun 14, 2004 11:02 pm
by Candy
firas981 wrote:
how I can set a breakpoint inside c function ?
I know how to breakpoint at a physical address using bochs debugger , but say that I want to breakpoint at the instruction x inside the c function y
How I can do so ?
thanks
A. use a debugger
B. Disassemble the instruction stream, figure out where your instruction starts & replace it with an interrupting opcode, such as INT3
Re:set a breakpoint inside c function using bochs debugger
Posted: Tue Jun 15, 2004 6:03 am
by Brendan
Hi,
In some cases I find it easiest to stop Bochs with JECXZ, and then use the internal debugger of Bochs (must be enabled when Bochs is compiled).
To make this easier I've got a little C macro:
Code: Select all
#define BOCHSHALT __asm__ __volatile__ ( \
"pushl %ecx\n\t" \
"xor %ecx,%ecx\n" \
"0:\n\t" \
"jecxz 0b\n\t" \
"popl %ecx\n\t" \
)
When BOCHS reaches this macro you press control+c to enter the debugger, then "set $ecx = 1" to stop the loop. Now you can step through the code an instruction at a time using 's' or 'p'...
While it is possible to end up inside an IRQ handler it does save you from trying to figure out the address of the instruction.
Cheers,
Brendan
Re:set a breakpoint inside c function using bochs debugger
Posted: Tue Jun 15, 2004 4:28 pm
by firas981
Thank you Brendan , I got benefit of your code .
thanks.
Re:set a breakpoint inside c function using bochs debugger
Posted: Sun Jun 27, 2004 5:10 pm
by firas981
BOCHSHALT helped me stop execution at any point inside c source
???but I couldn't get into debugger , why ?
???The answer is that i haven't bochs build with internal
???debugger option .
???
???Okay , I have downloaded bochs source : "bochs-2.1.1.src.rpm" to re-build using
???" ./configure --enable-debugger --enable-disasm " , but the simplest form of rebuilding
???"rpm -rebuilddb " gave me the error :
???"error: db4 error(16) from dbenv->remove: Device or resource busy "
???
???Okay , I've tried another way :
???I have the debugger bochsdbg.exe on Windows and I run it using
???WINE bochsdbg , it is working , and the c macro did its task but here as you
???know ctrl+c stops execution at all , and i didn't find any way to return to
???bochsdebugger command prompt to issue commands .
???
???This is the situation , probably you have a suggestion ..
???
???Thanks
Re:set a breakpoint inside c function using bochs debugger
Posted: Sun Jun 27, 2004 11:06 pm
by Brendan
Hi,
I downloaded the Bochs 2.1.1 source as a tar.gz and compiled it on Redhat linux and windows/cygwin without any problems..
./configure --enable-debugger --enable-disasm
make bochs
I don't know what "rpm -rebuilddb" is supposed to do, or how it works...
Cheers,
Brendan
Re:set a breakpoint inside c function using bochs debugger
Posted: Mon Jun 28, 2004 6:06 am
by Curufir
Well it's not going to work in C without inline asm, but my favourite trick for 'setting a breakpoint' in asm for Bochs when playing with the kernel is to just have:
Then let Bochs run until it hits the hlt, break out of the run into the debugger and you'll be at precisely the right location.
Once you tell Bochs to continue it will do so at the next instruction (sti).
Only impact this snippet has on machine state is the interrupt flag, and you should already know what that is.
Re:set a breakpoint inside c function using bochs debugger
Posted: Mon Jun 28, 2004 9:43 pm
by Ytinasni
Curufir wrote:
Only impact this snippet has on machine state is the interrupt flag, and you should already know what that is.
Or, if you
need to keep the interrupt flag how it is, use:
Re:set a breakpoint inside c function using bochs debugger
Posted: Tue Jun 29, 2004 11:14 am
by Curufir
Yup, that's a nicer way of doing it Ytinasni, and leaves the current state of #IF on the stack for you to examine.
Re:set a breakpoint inside c function using bochs debugger
Posted: Wed Jun 30, 2004 2:31 pm
by firas981
tar.gz worked nice , rpm didn't ....
I don't know the reason , at any rate bochs is now working well with internal debugger
thanks