14

I'm doing an OS class that's based on xv6 and I wrote a program that needs to run on it.

I know that I can debug kernel code with make qemu-gdb but I'm not sure how to debug my own user program.

Lets say I want to debug cat, how would I go about doing that?

Thanks

P.S. isn't there an xv6 tag? should this question even go here?

sigjuice
  • 28,661
  • 12
  • 68
  • 93
Nathan Dortman
  • 406
  • 1
  • 7
  • 20
  • `:file cat`, `:break main`, `run` gets something? – shevski May 10 '12 at 20:13
  • Okay, now I feel really stupid because I was sure I tried that. But now I think that it might be that i tried `load` instead. Thanks! I looked for this everywhere online, even emailed some people, no one could tell me this... (Answer and I'll accept.) – Nathan Dortman May 10 '12 at 20:25

2 Answers2

14

From the xv6 top-level dir:

  1. Run the emulator in debug mode (assuming no X11): make qemu-nox-gdb

  2. In other terminal just run the debugger loading the kernel symbols with: gdb kernel This is important, otherwise the debugger will be confused between kernel and and user program symbols, for example main()

  3. From the gdb interface run: (gdb) target remote localhost:26000 where 26000 is the TCP port that the step #1 report at the end (this might change).

  4. Load the user exec with (gdb)file user_program

  5. Place a breakpoint (gdb) break main and continue with (gdb) continue

  6. etc...

vpuente
  • 882
  • 7
  • 15
6

file cat, break main, continue

semi reference running and debugging xv6

Gaurang Tandon
  • 6,504
  • 11
  • 47
  • 84
shevski
  • 1,012
  • 1
  • 10
  • 32
  • 3
    When I tried it I needed to do `file _cat break main continue` This is because _cat is the name of the file on the host By the way this is run in the gdb window (so you've run make qemu-gdb, then in another window you've run gdb kernel). – David Watson Mar 30 '14 at 00:18