GacUI Demo: PDB Viewer (analyze the pdb file and obtain the details of the C ++ class declaration)

Source: Internet
Author: User

To serialize and deserialize the interface to XML, GacUI must have functions similar to reflection. However, C ++ has no reflection. The current method is to take out the compiled pdb file. Because the control is not a template class, data can be directly obtained. The pdb file contains information about all functions and templates and functions after being instantiated. Therefore, you only need to use IDiaDataSource (COM component provided by Visual Studio) to read the pdb class declaration, sort the information and output it to an xml file, then, you can use C # to write a program named linq to xml to analyze and generate a series of peripheral code that supports C ++ reflection. In this way, some of the necessary classes in C ++ will be automatically reflected. The cost is that after each code modification, remember to update the automatically generated code unhuman.

However, to better display the content of pdb, I use the TreeView with Virtual Mode in GacUI to open the pdb filling. There are two views, the first is pdb, and the second is the sorted class view. The GuiTreeView control of pdb shows how to provide a data source to implement the technology of "reading information from the pdb file when expanding. The class view provides a data source to read the xml in a file to the memory and display it. However, this avoids new TreeViewNode objects that do not need to be displayed yet. Code in Vczh Library ++ 3.0 http://vlpp.codeplex.com/(Candidate \ GUI \ GUIDemo. sln ). Now first:



 


 

The key code for parsing PDB is in the DumpPDB. cpp file. You only need to download and read the code. All content can be obtained from the MSDN IDiaDataSource search, but this COM component is required for running. Visual Studio is generally required to be installed. The following is a piece of C ++ code. This is the callback function of the button above. This callback function does the following:
1. Disable both the Button and TagPage
2. Use the thread pool to asynchronously Save the content of PDB to an XML file (one second)
3. After step 3 is completed, send a message back to the GUI thread and the second TagPage is automatically displayed.
4. Read XML to the memory asynchronously. I didn't use the latency reading technology here, So I directly created millions of strings, which took five seconds.
5. After Step 5 is completed, will a message be sent back to the GUI thread and the XML format in the created memory be displayed in the TreeView?

These asynchronous operations are complex, but can be clearly described with C ++ 0x. The implementation of GacUI does not use C ++ 0x, but it can still provide some more optimized interfaces for users who use C ++ 0x. Therefore, these complex steps are written as follows:

ButtonDump-> Clicked. AttachLambda ([=] (GuiGraphicsComposition * sender, GuiEventArgs & arguments)
{
INativeController * controller = GetCurrentController ();
TabControl-> GetPages () [0]-> GetContainer ()-> SetEnabled (false );
ButtonDump-> SetEnabled (false );
ButtonDump-> SetText (L "Dumping ...");
ButtonDump-> GetRelatedControlHost ()-> GetBoundsComposition ()-> SetAssociatedCursor (controller-> GetSystemCursor (INativeCursor: LargeWaiting ));

ThreadPoolLite: queuelamlite ([=] ()
{
Dumppdb: DumpPdbToXml (diaSymbol, L ".. \ Debug \ GuiDemo. xml ");
GetApplication ()-> InvokeLambdaInMainThread ([=] ()
{
TabControl-> GetPages () [0]-> GetContainer ()-> SetEnabled (true );
TabControl-> SetSelectedPage (tabControl-> GetPages () [1]);
ButtonDump-> SetText (L "Loading GuiDemo. xml in the class view ...");

ThreadPoolLite: queuelamlite ([=] ()
{
FileStream fileStream (L ".. \ Debug \ GuiDemo. xml", FileStream: ReadOnly );
CacheStream cacheStream (fileStream, 1048576 );
BomDecoder decoder;
DecoderStream decoderStream (cacheStream, decoder );
StreamReader reader (decoderStream );
Ptr <TreeElement> xml = LoadXmlRawDocument (reader). Cast <TreeElement> ();

GetApplication ()-> InvokeLambdaInMainThreadAndWait ([=] ()
{
ButtonDump-> SetText (L "GuiDemo. xml dumpped .");
ButtonDump-> GetRelatedControlHost ()-> GetBoundsComposition ()-> SetAssociatedCursor (controller-> getdefasystemsystemcursor ());

GuiTreeView * treeControl = new GuiTreeView (new win7: Win7TreeViewProvider, CreateProviderFromXml (xml ));
TreeControl-> GetBoundsComposition ()-> SetAlignmentToParent (Margin (0, 0, 0, 0 ));
TreeControl-> SetVerticalAlwaysVisible (false );
TreeControl-> SetHorizontalAlwaysVisible (false );
TabControl-> GetPages () [1]-> GetContainer ()-> GetContainerComposition ()-> AddChild (treeControl-> GetBoundsComposition ());
});
});
});
});
});


ButtonDump-> Clicked. AttachLambda means to bind a lambda expression that meets the C ++ 0x standard as an event handler to a time. ThreadPoolLite: QueueLambda puts a lambda expression into the memory pool implemented by the Windows Kernel for asynchronous calls. GetApplication ()-> InvokeLambdaInMainThread (AndWait) is to put a lambda expression in another thread and run it in the GUI thread (generally the main thread. If the Wait version is called, the function will not return until the lambda expression is executed in the main thread. If you are concerned about the implementation, you can view it in the Candidate \ GUI \ NativeWindow \ Windows \ WinNativeWindow. cpp file.

As you can imagine, in the old C ++ version that does not support lambda expressions, how many functions will this function be split into to implement this process. In order to pass many complex objects, how many temporary struct files need to be written, and how many new memory fragments can be used to make the asynchronous callback function parameters into the DWORD (_ stdcall *) expected by Windows *) (void *) format. How many private Win32 messages must be implemented in order to put some things back to the GUI thread (we all know that the GUI library is not worth doing a lot of Performance Waste for thread safety, how many things subclass can achieve. All this is simplified in GacUI.

Next, we will study how to use the information in pdb to make GacUI-related objects support reflection details. New Year's Day begins with a rest.
 


From Lambda-calculus (surprised to get to ouye)
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.