7

How can I use gdb to debug qemu? I have been googling but couldn't find anything concrete.

1
  • @ismail Hi..Can anyone help me get started with debugging qemu with gdb? The information provided below is not very clear to me. Configuring the debug flags alone is not meeting my requirements. (May be I am missing something totally) My requirement is to use gdb to debug segfaults happening to my custom qemu. Please note that I do NOT want to debug something else (kernel) with qemu and gdb. Commented Jul 22, 2015 at 12:53

2 Answers 2

10

I got an error with GDB 7.5 -> "Error accessing memory address"

It seems there is a problem with "Position Independet Executables" ...so use

./configure --enable-debug --disable-pie 

and debug should work.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 for --disable-pie. My gdb 6.7.1 sees the same issue if pie is enabled.
--disable-pie is not needed at least as of Ubuntu 18.04 GCC 7.4 QEMU 4.0.0. You will likely want PIE whenever possible to mitigate VM breakouts vulnerabilities: stackoverflow.com/questions/2463150/…
remind maybe this answer is old, use --disable-pie I can't compile qemu master
6

Try the following:

./configure --enable-debug 

By default qemu builds with "CFLAGS = -O2 -g" option which somehow doesn't allow debug symbols to be added. Using --enable-debug option will mean -O2 will not be added.

1 Comment

At least in Ubuntu 18.04 GCC 7.4 4.0.0, the default build does -O2 -g according to make V=1 which does add debug symbols and I can see the source. The problem is that a lot of stuff is optimized out and so you lose visibility and jump around weirdly. Without -O2 we have the default -O0: stackoverflow.com/questions/1778538/… Linux kernel boot slowdown was about 3x.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.