Bochs Debugging

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
wererabit
Posts: 11
Joined: Tue Feb 24, 2009 2:04 pm

Bochs Debugging

Post by wererabit »

Hi guys,

I have a question about Bochs Debugging, I tried to do some google but there was no luck. Hope you guys can help

I know how to do basic debugging with Bochs such as putting a break point and jump to a particular address, ….

But sometime, we don’t always know what address it is, like when you want to jump to a label. So how can I jump to a label within an assembly code

For example:

Code: Select all

  [org 0x500]

  xor eax, eax
  ….
  ….

label1:
  ; more codes

We start executing from 0x500, how can I jump to label1 in Bochs Debugger?

Thanks so much for your help
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Bochs Debugging

Post by neon »

What I usually do in these cases is:

Code: Select all

mov eax, label
cli
hlt
You now have its address from the bochs log (the value of eax). So, remove the added code, and set a breakpoint at the address. (if the label is below the added code, you may need to try a few breakpoints as the labels address might be off a few bytes.)

There might be easier ways but its what I do ;)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Bochs Debugging

Post by Firestryke31 »

I have my assembler generate a listing file, which is basically just a copy of the source along with what and where it assembled to. Then I just look up the address for the label in that. The parameter for yasm is "-l name.lst" but you can change the extension of the file to whatever is convenient.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Bochs Debugging

Post by bewing »

Hopefully, this is all one program that you are debugging, and it is all loaded into memory at once.
It is even better if you are using the GUI debugger, because you can examine a very long listing all at once -- or the same thing also works if you are using a graphical desktop under linux with the textmode bochs debugger.
But basically, you start at a known good address that is "below" the label you are interested in. Since your code is already ASM code, you approximately count the number of lines between your "known" address, and the label that you want.

Then you use the "u" command in the bochs textmode debugger, or the "disassemble" command in the GUI debugger, and tell it the number of lines to list.

(It also works to just GUESS at your starting address, rather than using a known good address -- your first handful of listed opcodes will be all wrong because they are misaligned, but they almost always end up getting aligned correctly all by themselves.)

But basically, you match your assembly code to the disassembly dump, line by line, until you get to the label that you want, and bochs will have printed the proper linear address right next to it. (Then you can set a linear breakpoint with the lb command. Or, if you REALLY mean that you want to JUMP to the label and SKIP all the code in between, then you can use the bochs debugger to type in a new value for EIP.)
wererabit
Posts: 11
Joined: Tue Feb 24, 2009 2:04 pm

Re: Bochs Debugging

Post by wererabit »

thanks guy.
Post Reply