User:Oldman/A layman's guide/How to get a debug log
This guide will show you how to get a debug log, using the Debug mode in real hardware and with a virtual machine using com0com (Windows) or tty0tty (unix), using the built in ReactOS debugger. The difference with the other debug modes is explained in Variations
- 1 Debug ISOs
- 2 Stages of the installation of ReactOS
- 3 Hardware requirements:
- 4 Software
- 5 Setting up Putty.
- 6 The ReactOS debugger
- 7 Getting a backtrace:
- 8 Getting a more detailed backtrace:
- 9 No working keyboard!
- 10 Advice:
- 11 Variations
- 12 Getting a debug log - Screenshots
- 13 Getting a debug log from VirtualBox
reactos-bootcd - 0.4.7 - dev - 581-g9c790df - x86-gcc-lin-dbg.7z
reactos-bootcd = type of ISO (boot for installing, live for running OS without installing).
0.4.7 = The number of the next release. The number changes every time a release branch is created, so when the 0.4.7 was branched for release, the number on the daily/latest ISOs became 0.4.8. And when the 0.4.8 was branched for release, the number on the daily/latest ISOs became 0.4.9. Now the 0.4.9 is branched, the number on the daily/lastest ISOs are numbered 0.4.10.
dev = development
581-g9c790df = identifies the commit and the committer.
x86-gcc-lin-dbg = x86 (32bit OS) - gcc (compiler) - lin (built using Linux) - dbg (debug build)
msvc-win = msvc (compiler) - win (built using Windows)
For normal users, the ISOs built with gcc are the ones to go for. You may need a copy of MSVC to make full use of the msvc-win builds.
Stages of the installation of ReactOS
It may be helpful to understand the stages of the installation of ReactOS.
When the installation CD (bootcd) is run, the bootloader asks you to press any key to install (real hardware)
The OS will first load itself into memory, then you are presented with the Language setup window, then 2 more windows, then Device settings window, then choose Hard drive partition window, then format window, then confirm format window. then choose directory window. then 2 more windows, then bootloader choice window. In the last window you are asked to remove media and press Enter. The computer now reboots.
The bootloader shows the Boot options choice window, then boots, loads device drivers, then shows the setup window, after that there are more configuration windows (when testing you can press Enter at all these windows), before it finally reboots.
It now boots up into desktop and displays the driver install wizard, if it finds any hardware without a driver.
Debug output only starts when the OS is loaded into memory, but just before it loads the drivers.
When installing (First stage), debug output is turned on by default and can only be captured through a null modem serial cable connect to a second computer, but once ReactOS is installed (Second stage and normal usage), you will have a choice of how to record debug output, from the boot menu. See  in Screenshots section below.
- A test computer with a serial port.
- A second computer with a serial port and Putty installed (or similar app).
- A nullmodem cable to connect both computers.
Win32 Putty - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html You will also find the source code for Windows and Unix at this link, but Linux users may be able to get Putty through their Package Manager.
Setting up Putty.
There are some vital settings in Putty, which need to be set, so that Putty can capture a debug log.
In putty go to Category and select Session, then set the following inputs to these values:
Serial line = COM1
Speed = 115200
Connection type = Serial
Back to Category and select Logging, in Session logging: check All session output. Note where Putty saves the log file and change if required; use the Browse button for the destination folder.
See in Screenshots   below for visual information.
Save the above changes in putty, with a name of your choice, in Saved Sessions, then use the Save button. It can then be loaded the next time you use Putty, by using the Load button. Note: logging is started by using the Open button.
The ReactOS debugger
The ReactOS debugger has some commands that can be used from the command line; all of the commands are typed into the ReactOS test computer, but will be viewed in the terminal window (i.e putty) on the second computer. To enter a command, press the hotkey combination of Tab+k, which halts the system and gives you the command prompt which looks like this: kdb:> where you can then enter the command.
Tab+k - this command halts the system so you can enter commands into the debugger.
bt - this command gives a backtrace; use it when ROS enters the debugger (see below).
cont - this is short for continue.
set condition * first always - this command tells ROS to enter the debugger on the first exception.
The following is an example of when ROS enters the debugger (see also in the  screenshot below):
Entered debugger on last-chance exception (Exception Code: 0xc0000001) (Unknown/User defined exception)
Getting a backtrace:
By looking in the Putty window, you will see when ROS enters the debugger, when that happens, you need to enter bt at the command prompt, like so:
kdb:> bt  and press enter on the keyboard.
You may see this
--- Press q to abort, any other key to continue --- 
If you do see it, then just press any key other than q, it may show again, just repeat until you are back at the command prompt of kdb:>
Getting a more detailed backtrace:
When you see debug info streaming into putty [Note], then press the hotkey combination of Tab+k on your keyboard, then type set condition * first always at the command prompt and press enter on the keyboard, then type cont  and press enter on the keyboard. Setting the condition to first always, will make ReactOS enter the debugger on every exception, which it will do many times, and each time you will have to type bt then cont.
No working keyboard!
Currently (Jan 2015) usb support is problematic, so your keyboard may not work! If you have found that your usb keyboard does not work with ReactOS, and ReactOS bsods at or before the first input window in the installation process, but after it is running in memory, you should still be able to get a debug log by using a livecd debug version (example: reactos-livecd-0.4.7-dev-575-g48b2714-x86-gcc-lin-rel.7z). The livecd versions currently default to Debug mode, so when it boots, it will output debug info to the serial port, but you will not be able to get a backtrace!
Do not use Tab+k and bt to get a backtrace, when ReactOS does not automatically enter the debugger! If you think by doing so, you will get some more useful information for the dev's to work with (which I have done in the past), you will not, it is a waste of time, the backtrace is of no value!
Putty names the file putty.log, it would be a good idea to re-name it, because the next time that putty is run, it will over-write the file called "putty.log". I use something descriptive, in this format "app name - ReactOS revision number", for example "gimp-1.0.4 [0.4.7-dev-575-g48b2714]".
TIP: If you find that when you use the test computer's keyboard to enter commands, nothing appears at the Command Prompt on the second (receiving) computer, then type the command on the second computer's keyboard, you then should see what you type appear at the Command Prompt.
RosDbg - This is only useful when ReactOS is compiled with a Microsoft compiler, which adds extra debugging code into ReactOS, which can output extra debug info. In use, the difference from Debug, is in the keyboard input, where you can only use Tab + k on the ReactOS test computer, all other keyboard input is via the logging computer's keyboard.
Screen - In this mode, debug information is written to the screen and you will have to take photos to be able to submit the information in a JIRA Issue. Any keyboard input is done on the ReactOS test computer keyboard. The instructions for Debug mode also apply to Screen mode.
Log file - This writes all debug output to a debug.log at C:\reactos\, on the ReactOS test computer's hard drive. Any keyboard input is done on the ReactOS test computer keyboard. You may, also need to use a Linux livecd to be able to recover the log file from the test computer.
Getting a debug log - Screenshots
Getting a debug log from VirtualBox
This section covers a simple VirtualBox setup using com0com or tty0tty as a virtual null modem cable to connect to Putty; all running on the same computer, no need for a real null modem cable and a second computer.
VirtualBox for Windows, Unix, can be down loaded from https://www.virtualbox.org/ (plus installation help, should you need it), it is also available for Unix through your package manager.
Note that for Unix, you will need to have the development package and the kernel source or header files installed.
Install VirtualBox for your operating system, then start it. You will first need to create a virtual machine to install ReactOS into; this is done by clicking on the blue New button. In the first setup window you will need to give it a name in Name:, then set it to Microsoft Windows in Type: and then set it to, either WindowsXP(32bit) or Windows 2003(32 bit) in Version:, then for a simple setup, you can accept all the defaults in all the other setup windows (I alter just one item, I select VHD (Virtual Hard Disk) in the last setup window). There is no need to install ReactOS into the virtual machine just yet, if you want to log the debug output from the start of an installation.
Note: You may find it helpful if you name the virtual machine with a descriptive name, such as 0.4.7-dev-582-g74cc915 or ReactOS-g74cc915 or ROS-0.4.6, especially if you intend doing some serious debugging and having several virtual machines with different versions of ReactOS installed.
There is another user's wiki here User:Matthiasbasler#Tutorial:_Getting_a_stable_software_stack_with_ReactOS_on_VirtualBox. which covers a more detailed setup for VirtualBox.
Windows - com0com
Get the latest com0com from https://sourceforge.net/projects/com0com/files/com0com/ and install it. Then run setup [8a], click on the Add Pair button, which creates a pair of virtual ports, then click on the Apply button. There is no need to tick any of the tick boxes.
In the setup window you will see CNCA0 and CNCB0 which are the newly created virtual ports  (If you should ever have the need to add more virtual ports, then the next pair will be CNCA1 and CNCB1). The CNCA0 is used in the Path/Address: in VirtualBox virtual machine serial configuration  in this format \\.\CNCA0 and the CNCB0 is used in the Serial line in the Putty serial configuration [11a] just as it is.
The com0com virtual ports process remains until you use the Remove button in the setup app, to remove them.
Unix - tty0tty
You can get tty0tty from https://sourceforge.net/projects/tty0tty/files/ (the latest is currently tty0tty-1.2).
Unpack the package tty0tty-1.2tgz to a folder; my OS was able to unpack it to /tty0tty-1.2/, just by clicking on the package.
It requires compiling, so navigate to the directory /tty0tty-1.2/pts (cd /tty0tty-1.2/pts) and open a terminal window (right click - Window - Terminal here). At the command prompt type make and shortly you should have an executable file in the pts folder. Then still within the pts folder/directory, type ./tty0tty at the command prompt to run [8b]. The output could be
(/dev/pts/1) <=> (/dev/pts/2)
(/dev/pts/2) <=> (/dev/pts/3)
it may vary. But whatever the left side is, such as /dev/pts/2 will be entered into the Path/Address: in the VirtualBox virtual machine's serial configuration  and whatever the right side is, such as /dev/pts/3 will be entered into the Serial line in the Putty Serial configuration, instead of the default com or tty [11b].
I end the tty0tty virtual ports process, by using the Ctrl - c combination, but I would expect it to terminate when the terminal window is closed.
There is another folder in the directory /tty0tty-1.2/module which also requires compiling. This will, when run, create several pairs of virtual ports, which remain until the OS is re-installed or upgraded. I have not used it or included it within this tutorial.
Testing com0com and tty0tty
To test if it works, configure one instance of putty with CNCA0 in Windows or /dev/pts/2 in Unix and another instance of putty with CNCB0 in Windows or /dev/pts/3 in Unix, then run both Windows Puttys or both Unix Puttys and type into each terminal window. If the input from each terminal window is shown in the other terminal window (what is typed into Putty No1 should display in Putty No2, also what is typed into Putty No2 should be displayed in Putty No1), then you have a working virtual null modem cable.
Now you can run your VirtualBox virtual machine and install ReactOS.
Note: When you run your virtual machine with an installed OS, then make sure that there is no bootable media in any of your external drives (floppy, USB or CD/DVD), else the VirtualBox virtual machine will boot it instead of the installed OS.
Now you can refer back to #The_ReactOS_debugger