Windows NTSD Debugger - debugging

I am doing some debugging of a crash dump file using NTSD. Is it possible to redirect all the output that I am seeing on console now to a txt file? I am getting all the call stacks of all the threads however can't see that information in a debugger window.
Thanks

Look at the .logopen and .logclose commands. You should be able to do .logopen foo.txt, issue your command (which I'm assuming is ~*k), and then when it's done, do .logclose.

Related

golang: optional console on windows

I am writing a service program which is expected to run in background. On Windows it will open a console window when run. I want it to go to background directly without that console window, so I used the -ldconf "-H=windowsgui" option, which worked as expected.
However, there is a catch. The program has a command line option -help, which output command line usage in the console. If I use -H=windowsgui, the help text is NOT printed even I start it in cmd.exe prompt.
It seems that the windowsgui option is not what I want. Is there anyway that the -help still works at commant line, and the console window will not persist if the program runs normally. I do not care if there is a console window pops up, provided that it disappears shortly without user intervention. i.e. I want a way on windows which is similar to the & operator on Linux.
P.S. if provided solution uses any other tools, I want that tool to be a Windows component, not any 3rd-party program. Thanks.

Redirect windows console output from another process to file

I have a DLL which does as plugin into the TS3 client.
The problem is, the plugin provokes a crash that I cannot seem to find in my code directly.
So my idea is to set the Console Output of the console windows in the background (-console option) to a file, because when the program crashes there is no way I can read the console output as the console disappears immediately.
Is there a way to set the output of a crashing console to a file?
Because so far, when using the stdout operator (ts3client_win64 -console > output.txt) it does not write anything to the file. (I assume it cannot close the file handle and loses all its data?) But I want to keep the console output when the crash occurs.
It also has to be said that I can not just run it with a batch file and a pause statement, because when starting the application it opens its own console window (and thats the one of which I want the output).
It is the type of crash one would get from failed (safe) string operations in C like strtok_s or strcpy_s.

ReportLiveObjects getting the logs programmatically

I have my app using IDXGIDebug::ReportLiveObjects to report some memory leaks. But I'd like to pipe these logs through my own log system.
I could not find much info online. Anyone knows how I could access these DXGI logs programmatically besides looking at the visual studio output window.
As far as I can tell, there isn't a way to do this. ReportLiveObjects likely uses OutputDebugString or DbgPrint under the hood, and these go directly to the process's attached debugger. While some tools do have the ability to tap into these streams, all filtering has to be done by the program capturing the data, meaning you get to deal with not just the output of ReportLiveObjects, but the output of Visual Studio, of any drivers that get loaded and check for a debugger, and quite possibly the system itself. In all honesty, it's probably easier to simply dump the log file to VS's output window, then save the contents of the window as a log file.

Output a watched Visual Studio variable to a file

Is there a way in Visual Studio (2008 if it matters) that I can, in debug/break mode, write the contents of a variable to a text/XML file?
The scenario is that I have a long process running in debug and I have realised too late that I haven't logged enough detail about the events that the process has been monitoring, but fortunately a history is still available within a variable in the code.
I could trawl through the tens of thousands of items in this list, but it's not going to persist once I hit stop on the application ... there is no obvious context option for this, but is there any way, a better way than manual? Or is there no hope and I just need to hit stop, re-tool the logging function and run the thing again?
Aside from trying to hit a breakpoint, modify the code and re-write to make a better logger, is there a way of not losing that in-memory data?
One way to do it would be to use the immediate window (menu Debug -> Windows -> Immediate). In the window that appears you can use the "?" to query the value of a variable.
Assuming your history variable is a string you view its contents by typing the following in the immediate window:
?history
You could copy and paste the output from there into a text file or alternatively ask Visual Studio to log all command window output. To do this type:
>log "c:\test.log"
>? history
>log off
Log is an alias for Tools.LogCommandWindowOutput and accepts the following parameters:
Tools.LogCommandWindowOutput [filename] [/on|/off] [/overwrite]
Check out the MSDN article Log Command Window Output Command for more information.
 
I think that my answer is pretty much the same as JamesPickrell's, but from the Immediate Window you could also do something like this:
My.Computer.FileSystem.WriteAllText("c:\temp.txt",history,True)
This would output the content of the "history" variable to a file called c:\temp.txt.
Thanks to Richard's answer, this is working for me.
System.IO.File.WriteAllBytes(#"c:\Temp\temp.txt", myVar);
Make sure that C:\Temp exists.
The reason for writing to a folder and not to the root C:\ is to avoid UnauthorizedAccessException when not running Visual Studio as administrator.
I found useful/demonstrative/shareable to save the variable as a json string to the file. From Immediate Window enter the following:
string jsonedVariable = Newtonsoft.Json.JsonConvert.SerializeObject(VARIABLE);
System.IO.File.WriteAllText(#"C:\FILENAME.json", jsonedVariable);
Not sure from which version it's supported, but you can simply put it in the WATCH window, then right-click copy past wherever you want.

Output window to file (Visual Studio 2005)

In Visual Studio 2005, how can I save what's written to the output window to a file (I can't change the code writing to the output window, and it writes a lot; I just want to save the output window content to a file)?
"File" -> "SaveOutputAs..." let's you save the contents of the output window to a file, but I imagine you want to redirect the output to a file while debugging? I'm still looking for a way to do that myself..
You can just redirect the output stream in the command line arguments in Visual Studio.
Right click on your project → Properties → Configuration properties → Debugging → Command arguments.
After your arguments, just add:
> outputfile.txt
If you mean the output to the debug/trace window, you can capture this at runtime with DebugView without running Visual Studio.
I just answered a very similar question here. I'm using this method myself to capture, filter and log debug output to a file on Windows Vista 32 bit. I use Visual Studio 2005 and work in C++, so this might help you too.
ATLTrace Tool intercepts the ATLTRACE calls. You can save the output of any process into a file.
Are you developing in .NET? And what is the code used to write to the output window?
In case you are using Trace.WriteLine or Debug.WriteLine you could use a TextWriterFileListener class to write all messages to a file automatically.
If the app runs in a command window, you can use the old DOS redirect command ">" to redirect the output to a file.
For example.
c:\>dir > out.txt
...will redirect the output of the dir command to a file called out.txt. You should be able to do the same with your application.
This will stop the output from going to the console, but you can always go the log file to get you the info you want.

Resources