DebugView doesn't capture KdPrint output - windows

I cannot make DbgView.exe work properly on my Windows 10 64-bit v2004 Virtual Machine. The program doesn't capture any kernel message from the driver if using KdPrint, but works fine with DbgPrint. I've already tried "bcdedit /debug on", adding "Debug Print Filter" on the registry editor and rebooting, enabling verbose kernel output.
I've also tried on my host machine, same outcome.
It is a very simple driver, only to be loaded and unloaded, copied from the book Windows Kernel Programming.
This works
DbgPrint("Driver initialized.\n");
This doesn't
KdPrint(("Driver initialized.\n"));
Any help would be greatly appreciated!

Jump to KdPrint and you will see a preprocessing magic:
#if DBG
#define KdPrint(_x_) DbgPrint _x_
#define KdPrintEx(_x_) DbgPrintEx _x_
#define vKdPrintEx(_x_) vDbgPrintEx _x_
#define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
#define KdBreakPoint() DbgBreakPoint()
#define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
#else
#define KdPrint(_x_)
#define KdPrintEx(_x_)
#define vKdPrintEx(_x_)
#define vKdPrintExWithPrefix(_x_)
#define KdBreakPoint()
#define KdBreakPointWithStatus(s)
#endif // DBG wudfwdm
This means that if you are compiling with Release configuration (DBG macro will not be defined), nothing will happen to KdPrint.
So it's not a DbgView problem.

Even with debug compiled drivers, dbgView 4.90 on winPE (dbgview64.exe) does not print KdPrint unless you click both Capture, Capture Kernel, and Capture, Enable Verbose Kernel Output.

Related

How to implement CMake configure_file command in Makefile?

I think everybody knows this excellent CMake command:
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/version.h
)
But I have to implement that in Makefile. Could you please help me? How to do it?
Configuration file (version.h) is very simple:
#ifndef _VERSION_H_
#define _VERSION_H_
#define VERSION_MAJOR #VERSION_MAJOR#
#define VERSION_MINOR #VERSION_MINOR#
#define VERSION_BUILD #VERSION_BUILD#
#define VERSION_REVISION #VERSION_REVISION#
#endif // _VERSION_H_
This won't work. Well it might be, but it will be a hassle. These config.h files are made to communicate the result from a configure tool (configure from Autotools, CMake etc.) to the compiler.
When you use Makefiles, you can simply attach necessary flags or variables to the C(++) compiler call (with -D). There is no need to add the complexity of a config.h.

Concatenate strings in a macro using gfortran

The C preprocessor macro for concatenation (##) does not seem to work on a Mac using gfortran. Using other Fortran compilers on other systems works so I am looking for a workaround for gfortran. I have to use the ## to create many variables so I can't do without them.
Example code:
#define CONCAT(x,y) x##y
program main
integer, parameter:: CONCAT(ID,2) = 3
print*,"Hello", ID_2
end program main
Compilation error with gfortran on MAC
gfortran m.F90 -o m
m.F90:5.23:
integer, parameter:: ID##2 = 3
1
Error: PARAMETER at (1) is missing an initializer
## doesn't work in gfortran (any OS, not just Mac) because it runs CPP in the traditional mode.
According to this thread the gfortran mailing list the correct operator in the traditional mode is x/**/y, so you must distinguish between different compilers:
#ifdef __GFORTRAN__
#define CONCAT(x,y) x/**/y
#else
#define CONCAT(x,y) x ## y
#endif
Others (http://c-faq.com/cpp/oldpaste.html) use this form, which behaves better when a macro passed to the CONCAT (via Concatenating an expanded macro and a word using the Fortran preprocessor):
#ifdef __GFORTRAN__
#define PASTE(a) a
#define CONCAT(a,b) PASTE(a)b
#else
#define PASTE(a) a ## b
#define CONCAT(a,b) PASTE(a,b)
#endif
The indirect formulation helps to expand the passed macro before the strings are concatenated (it is too late after).

Verbose debug printing in arduino?

I'd like to have some sort of verbose debug printing in arduino that can be enabled/disabled by a flag. For example I'd like the ability to do something like
#define VERBOSE
#define VERBOSE_PRINT(text) #ifdef VERBOSE Serial.println(text); #endif
Later in code:
VERBOSE_PRINT("Doing something");
if VERBOSE is defined then I should get stuff out over the serial port and if it's not defined then that code won't be compiled. Unfortunately this isn't working. I get the error: "error: '#' is not followed by a macro parameter". So I'm wondering what's the best way to get an optionally compiled print (or anything for that matter). Of course I could manually write out the #ifdefs, but I'd like it streamlined so that it doesn't take up a ton space and so I don't have to write it out each time I'd like to use it. Is a function w/ the #ifdef inside the function the best way to do this?
#define VERBOSE
#ifdef VERBOSE
#define VERBOSE_PRINT(str) Serial.println(str)
#else
#define VERBOSE_PRINT(str)
#endif
VERBOSE_PRINT("Doing something");

What are those gcc options doing?

In a makefile I work on, gcc is used with the -D XOPEN_SOURCE=500 and -D_BSD_SOURCE options. gcc --help does not tell me what these are; a quick google search didn't help either. I'm quite a newbie with gcc, could someone give me a hint?
According to the GCC documentation ("3.11 Options Controlling the Preprocessor"), the -D switch defines the macros XOPEN_SOURCE and _BSD_SOURCE with the values 500 and 1 respectively. It's as though you have this code at the beginning of all the source files you pass to GCC:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE 1
Build scripts usually take advantage of the compiler's ability to "insert" macros like these to "communicate" to the source code details about the platform being targeted (e.g. operating system version).
The "opposite" command-line switch for -D is -U, which #undefs a macro.
Most (if not all) modern C/C++ compilers include similar switches. For example, Visual C++ compilers accept the /D compiler switch, which essentially serves the same purpose as GCC's -D switch.
For future reference, the GCC option index is great if you need to look up compiler switches for the GCC compiler.
-D is used to set defines. The source code you are compiling most likely is using those defines to include specific header files.
Think of -D as doing the same thing as:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE 1
at the top of the file it is currently compiling.
These do not nothing for gcc. These are definitions like similar you have in your .c, .cpp or .h files:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE
-D is equlivant of a #define
i.e.
#define XOPEN_SOURCE 500
-D sets a define. It's like adding a header file that contains:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE 1
You can then use #ifdef _BSD_SOURCE to enable conditional compilation of certain part of the code.

Eclipse CDT syntax error on __attribute__ keyword

I would like to know if there is a way to get rid of CDT syntax error warnings when using gcc's "__attribute__" keyword.
It goes without saying that I would not like to switch off CDT syntax check.
The "ECLIPSE_THINKS_THIS_IS_SET_BUT_GCC_DOESNT" definition (from ams's answer) really extsts and it called __CDT_PARSER__. For example:
#ifdef __CDT_PARSER__
#define __FILE__ "<file>"
#define __LINE__ (-1)
#define __DATE__ "<date>"
#define __TIME__ "<time>"
#endif // #ifdef __CDT_PARSER__
Hope this will be helpful.
I've not tried it, and I've not used Eclipse for some time, but here's an idea:
In the CDT settings for Eclipse (or maybe just your project) set up a predefined macro (I seem to remember you can tell it what the compiler auto-defines) named __attribute__ that takes one parameter, and expands to nothing.
Maybe I haven't explained that right. Let me try again with an example. Basically, the aim is to define a macro that works like this:
#if ECLIPSE_THINKS_THIS_IS_SET_BUT_GCC_DOESNT
#define __attribute__(X) /* nothing */
#endif
but without putting anything actually in your code.
Project->Properties->C/C++ general->Path and Symbols->Symbols
Add->
Name: __attribute__(X)
Value: (leave blank)
Related links: You can use this technique basically with any offending keyword
ziu's answer is also working for XC8 Microchip compilers
Name: __interrupt
Value: (leave blank)
The function prototype now is clean:
void __interrupt ISRs(void);
And Eclipse won't complain about it.

Resources