No, you can’t use pretty much anything io stream related in the kernel, at
least without writing some sort of translation layer, which you don’t want
to do.
Leaving out the io stream related stuff, you will however find a fair amount
of your average CRT’s functions does exist in the kernel, through
‘lcntptr.lib,’ that that’s not really documented particularly well.
The easiest way for you to get started would be to just use
DbgPrint()/KdPrint(). DbgPrint() takes almost the same arguments as
printf(), with the output going to the kernel debugger rather than stdio.
KdPrint() is just a macro that wraps DbgPrint() that is defined as
DbgPrint() in debug builds and undefined in free builds. This prevents
ordinary debug trace statements from getting into free builds.
I realize that it sounds like you wish to actually do some logging, which
DbgPrint()/KdPrint() won’t really do for you, but they are an easy way to
start while you get your feet wet with windows kernel development and the
kernel debugger.
To actually implement logging, you’re two basic options would be to handle
all the io/file stuff from the kernel - which is pretty complicated for a
beginner - or you could create a driver and an application that sends IO
requests to that driver, requesting the information which is to be logged.
This is probably simpler than doing the file stuff in the kernel directly,
but it too is a lot more complicated than just leveraging DbgPrint()
combined with WinDbg or DbgView (both of which would allow you to save the
contents of their consoles to a file, not that that is really what you’re
looking for).
I totally get what you want and why you want it, but the problem is that
implementing it will be a harder way to start than just getting a driver up
and running using the existing facilities.
Good luck,
mm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@siemens.com
Sent: Thursday, February 10, 2011 6:05 PM
To: Kernel Debugging Interest List
Subject: [windbg] C2275 stdio.h for logging
Hi,
I not very experienced with driver developing.
I am writing a lot of other c++ stuff since years, but in this area here I
am new. So sorry for some easy / stupid questions
I got the task to fix some problems in a existing WDM driver.
Now I am able to debug an play around a little bit with the code, that I
got.
From earlier C and C++ projects I have some own simple logging functions.
That I was trying to use in the WDM driver, to bring a little bit light into
the stuff.
The logging functions just contain fopen, fprintf, fscanf and fclose. That’s
all.
In Visual Studio 2010 and other C and C++ projects the logging code complies
well without errors.
When I copied two simple logging functions to the top of a c file of my WDM
driver and when I typed build into the building command shell, I always
received the error C2275 telling me that FILE is unknown. But at the start
of the c file I added “include <stdio.h>”. I have no idea why building the
driver with the two new methods fails with the described error.
I did the necessary include. The c code of those functions worked hundred
times in other regular c / c++ application.
=====
Now my questions:
1. Is it allowed to use fprintf, fscanf etc… in a WDM driver. Does this
work?
2. If yes, how can I solve C2275 for the struc FILE?
Thanks in advance for your help.
—
WINDBG is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer</stdio.h>