set a breakpoint inside c function using bochs debugger
set a breakpoint inside c function using bochs debugger
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
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
A. use a debuggerfiras981 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
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
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:
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
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" \
)
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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:set a breakpoint inside c function using bochs debugger
Thank you Brendan , I got benefit of your code .
thanks.
thanks.
Re:set a breakpoint inside c function using bochs debugger
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
???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
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
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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:set a breakpoint inside c function using bochs debugger
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.
Code: Select all
cli
hlt
sti
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
Or, if you need to keep the interrupt flag how it is, use:Curufir wrote:Only impact this snippet has on machine state is the interrupt flag, and you should already know what that is.Code: Select all
cli hlt sti
Code: Select all
pushfd
cli
hlt
popfd
Re:set a breakpoint inside c function using bochs debugger
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
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
I don't know the reason , at any rate bochs is now working well with internal debugger
thanks