Skip to contentSkip to conversation

Trouble with GDB & Some 'Can it be done' Debugging questions

Qemu-devel Steve Ellenoff 4 participants 6 messages Jul 19, 2006 – Jul 27, 2006

lore
Share & tools
lore
#0 lore raw

Hi -

I'm having a bit of trouble getting gdb to do what I was hoping it would with qemu. Following the instructions in the docs:

#1) I launch qemu with -S -s flags ( since I want to trace the bootloader code ) It says: Waiting gdb connection on port 1234 - which is correct, and it opens the monitor window.

#2) I open a second terminal window and type gdb vmlinux
It displays:
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details. is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...vmlinux: No such file or directory.

Notice the last part saying it can't find file or directory vmlinux. What am I doing wrong here?

#3) Anytime I try to dump the instruction at the current IP such as:
(gdb) x /10i $eip

I get this - which means it's not actually reading or displaying the memory properly, since those look to be what you would see if it was all 0 in memory (or maybe it's all 0xff - whichever).l

0xe05f: add    %al,(%eax)
0xe061: add    %al,(%eax)
0xe063: add    %al,(%eax)
0xe065: add    %al,(%eax)
0xe067: add    %al,(%eax)
0xe069: add    %al,(%eax)
0xe06b: add    %al,(%eax)
0xe06d: add    %al,(%eax)
0xe06f: add    %al,(%eax)
0xe071: add    %al,(%eax)

So what is the problem here? If I use the QEMU monitor, the dump is correct and shows real instructions.

This leads to my next question:

#4) Can you use gdb to debug and set breakpoints on binary code you don't have any source code or other file for the binary, except the binary file itself? Everything I've read so far on GDB (and especially any GDB Gui front end) seems to suggest it's not possible. That would really suck.

This is easy as pie to do in Bochs since it has a built in debugger (similar to monitor, but far more capable, such as setting break points and stuff).

After hours of googling I'm beginning to wonder if it can be done in GDB - ESPECIALLY setting breakpoints on the code hitting certain memory addresses, ie, the EIP hitting certain values such as 0xc000 for example. Surely it must be able to do this, and i'm just too unfamiliar with gdb to know how.

PS - I'm still quite new to qemu and also linux, so please keep that in mind. QEMU was actually the first time I really had a good reason to sit down and check out linux. I'm glad I did, I like a lot of things about it so far, though being a novice sucks, when I'm used to being a superguru in Windoze.

I hope someone can shed some light for me on these many questions!

Thank you for any help-
-Steve

#1 lore raw

Hi Steve...

Quoted 5 lines

Hi -

I'm having a bit of trouble getting gdb to do what I was hoping it would with qemu. Following the instructions in the docs:

Quoted 8 lines

#1) I launch qemu with -S -s flags ( since I want to trace the bootloader code )
It says: Waiting gdb connection on port 1234 - which is correct, and it opens the monitor window.

#2) I open a second terminal window and type gdb vmlinux [cut]...
"i386-redhat-linux-gnu"...vmlinux: No such file or directory.

This message obviously said: either you don't actually have "vmlinux" file or you don't give correct path to the vmlinux file. Can you confirm that you had given correct path? Also, it is possible that its name isn't vmlinux (since one is free to rename it)...

Quoted 6 lines

#3) Anytime I try to dump the instruction at the current IP such as:
(gdb) x /10i $eip

I get this - which means it's not actually reading or displaying the memory properly, since those look to be what you would see if it was all 0 in memory (or maybe it's all 0xff - whichever).l

are you sure you had executed this command in gdb?:
target remote localhost:1234

Seems like gdb is dumping a wrong address space...

Quoted 7 lines

This leads to my next question:

#4) Can you use gdb to debug and set breakpoints on binary code you don't have any source code or other file for the binary, except the binary file itself? Everything I've read so far on GDB (and especially any GDB Gui front end) seems to suggest it's not possible. That would really suck.

Well, you can, but of course you can't set the breakpoint at certain source code's line, but instead put the breakpoint explicitly as memory address.

Anyway, i really suggest to read more about gdb by typing:
info gdb
in your shell prompt. It will display the complete gdb manual.

Don't be hesitate to ask (we're all still learning after all)...

regards,

Mulyadi

#2 lore raw

Thanks for your help!! That goes for all the people who responded on the thread! :)
Turns out, I just didn't understand what the vmlinux part meant. Being totally new to linux, I just thought that was the required syntax for using gdb with qemu. I didn't realize it was supposed to be the name of the file containing the debug symbols. The reason it was also a bit confusing was that in my case I don't have source code or debug symbols for the code I'm trying to trace through qemu, so for me I found out the correct syntax is just to call gdb with no parameters. When I did that, it properly displayed all the correct instructions (in assembly of course) at each memory location I wanted to view.
I think the reason the instructions weren't decoding was because I had called GDB with vmlinux, but that of course, didn't exist, and it confused gdb.
Thanks again for all your help.
-Steve

From:  Mulyadi Santosa <[email protected]>
Reply-To:  [email protected]
To:  [email protected], "Steve Ellenoff" <[email protected]> Subject:  Re: [Qemu-devel] Trouble with GDB & Some 'Can it be done' Debugging questions Date:  Thu, 20 Jul 2006 14:11:43 +0700

Quoted 55 lines

Hi Steve...

Quoted 5 lines

Hi -

I'm having a bit of trouble getting gdb to do what I was hoping it would with qemu. Following the instructions in the docs:

Quoted 8 lines

#1) I launch qemu with -S -s flags ( since I want to trace the bootloader code )
It says: Waiting gdb connection on port 1234 - which is correct, and it opens the monitor window.

#2) I open a second terminal window and type gdb vmlinux [cut]...
"i386-redhat-linux-gnu"...vmlinux: No such file or directory.

This message obviously said: either you don't actually have "vmlinux" file or you don't give correct path to the vmlinux file.  Can you confirm that you had given correct path? Also, it is possible that its name isn't vmlinux (since one is free to rename it)...

Quoted 6 lines

#3) Anytime I try to dump the instruction at the current IP such as:
(gdb) x /10i $eip

I get this - which means it's not actually reading or displaying the memory properly, since those look to be what you would see if it was all 0 in memory (or maybe it's all 0xff - whichever).l

are you sure you had executed this command in gdb?:
target remote localhost:1234

Seems like gdb is dumping a wrong address space...

Quoted 7 lines

This leads to my next question:

#4) Can you use gdb to debug and set breakpoints on binary code you don't have any source code or other file for the binary, except the binary file itself? Everything I've read so far on GDB (and especially any GDB Gui front end) seems to suggest it's not possible. That would really suck.

Well, you can, but of course you can't set the breakpoint at certain source code's line, but instead put the breakpoint explicitly as memory address.

Anyway, i really suggest to read more about gdb by typing:
info gdb
in your shell prompt. It will display the complete gdb manual.

Don't be hesitate to ask (we're all still learning after all)...

regards,

Mulyadi

#3 lore raw
In reply to Steve Ellenoff
Quoted 8 lines · Steve Ellenoff

#3) Anytime I try to dump the instruction at the current IP such as:
(gdb) x /10i $eip

I get this - which means it's not actually reading or displaying the memory properly, since those look to be what you would see if it was all 0 in memory (or maybe it's all 0xff - whichever).l

0xe05f: add %al,(%eax)

qemu doesn't report memory errors to GDB. It reports -1 values instead. This is annoying. I think I posted a patch for it once and never followed up when it was ignored.

It might be reading the wrong address; it might be confused due to segmenting; it might be looking at something that would require a TLB fault.

Quoted 4 lines

#4) Can you use gdb to debug and set breakpoints on binary code you don't have any source code or other file for the binary, except the binary file itself? Everything I've read so far on GDB (and especially any GDB Gui front end) seems to suggest it's not possible. That would really suck.

Sure you can. It will just work.

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery
#4 lore raw
Quoted 5 lines · Daniel Jacobowitz
Quoted 3 lines · Steve Ellenoff

#3) Anytime I try to dump the instruction at the current IP such as:
(gdb) x /10i $eip

Quoted 8 lines
Quoted 3 lines

I get this - which means it's not actually reading or displaying the memory properly, since those look to be what you would see if it was all 0 in memory (or maybe it's all 0xff - whichever).l

0xe05f: add %al,(%eax)

qemu doesn't report memory errors to GDB. It reports -1 values instead. This is annoying. I think I posted a patch for it once and never followed up when it was ignored.

This is not correct: an error is correctly reported by the QEMU gdb stub...

Regards,

Fabrice.

#5 lore raw
Quoted 10 lines · Fabrice Bellard
Quoted 9 lines · Daniel Jacobowitz
Quoted 7 lines · Steve Ellenoff

#3) Anytime I try to dump the instruction at the current IP such as:
(gdb) x /10i $eip

I get this - which means it's not actually reading or displaying the memory properly, since those look to be what you would see if it was all 0 in memory (or maybe it's all 0xff - whichever).l

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

0xe05f: add %al,(%eax)

qemu doesn't report memory errors to GDB. It reports -1 values instead. This is annoying. I think I posted a patch for it once and never followed up when it was ignored.

This is not correct: an error is correctly reported by the QEMU gdb stub...

Must've been fixed then! Sorry. In that case, Steve, you're probably reading the wrong address (maybe segmentation-related?).

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery