OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 8:51 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Bochs Debugging
PostPosted: Mon Mar 23, 2009 4:55 pm 
Offline

Joined: Tue Feb 24, 2009 2:04 pm
Posts: 11
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:
  [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


Top
 Profile  
 
 Post subject: Re: Bochs Debugging
PostPosted: Mon Mar 23, 2009 8:10 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
What I usually do in these cases is:
Code:
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();}


Top
 Profile  
 
 Post subject: Re: Bochs Debugging
PostPosted: Mon Mar 23, 2009 8:29 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 29, 2008 1:07 pm
Posts: 550
Location: Throw a dart at central Texas
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?


Top
 Profile  
 
 Post subject: Re: Bochs Debugging
PostPosted: Mon Mar 23, 2009 9:41 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
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.)


Top
 Profile  
 
 Post subject: Re: Bochs Debugging
PostPosted: Tue Mar 24, 2009 2:55 pm 
Offline

Joined: Tue Feb 24, 2009 2:04 pm
Posts: 11
thanks guy.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], SemrushBot [Bot] and 153 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group