How can I debug an ActiveX control (OCX) or make log errors?

I am currently working with a rather old Borland C ++ application that uses the ActiveX component to draw graphics. The application has several windows with ActiveX comp. can be opened at any time - they can display the same graphics (different scaling factors, etc.) or different graphics.

The application is designed for positioning, and ActiveX draws and displays the positions of different units.

About 10 times per second, the Borland application takes a new position and finds out which forms (and their ActiveX) need to know about the updated position in order to draw it. This went well, but I had to make some changes to ActiveX for the new version of the product.

About a year ago, I also had to make some minor changes to the component, and I found that the application might terminate in state, resulting in a "index out of bounds" error in the component. This did not result in an error being shown or terminating the program, but instead, the application began to use a huge amount of memory - and continued to grow very quickly. At some point, he stopped, and the component that had the error simply stopped showing anything (he stopped drawing himself).

Now with the recent changes that I made, I have the same problem when one of the components seems to get an error that does not appear, and instead it does not redraw itself, and the memory usage is sky-high. On some computer, it seems that an access violation has been violated - this indicates that the error occurred in OCX, but on the PC that I am developing, I can not get this Access Violation in any way.

Also, I cannot pinpoint when the error will occur - that is, what causes the error. I can run the same setup 10 times in a row for 15 minutes, sometimes it happens that the memory usage goes up and the component fails, otherwise nothing happens and it works as it should for the entire duration.

Like OCX, it registers with regsvr32 and therefore is not a code-based part of the main application. Therefore, I cannot use breakpoints and debug it this way.

I am sure that some error occurs inside the component that is not transmitted, so I can not see what it is.

So does anyone know how I can debug this? Can I somehow make any errors in the OCX log that might occur, or make it show an error, or what can I do?

Any help would be greatly appreciated - I tried to track down the error for 3 days, without any results.

+4
source share
3 answers

Essentially, you are asking how to debug a DLL. OCX is just a DLL file loaded into a process. This is a somewhat broad topic, but I will try to give a quick start:

DLL / EXE / OCX files are commonly referred to as โ€œmodulesโ€ in the context of Windows programming. All of them are basically the same thing. I will call them DLLs here, though for simplicity.

Debuggers (Visual Studio and Borland are both debuggers and IDEs) โ€œattachโ€ parasites to processes, allowing you to do things like given breakpoints, read process memory, see stack traces, etc. They can see / manipulate all memory and resources for this process, including all DLLs.

DLLs do not contain much information to help debuggers, even in building debugging. They mainly contain binary machine code, and if you enter a DLL call using a debugger, you can only see the assembly code, not the source code. Functions are only addresses in memory, local variables are not even visible; you get only some pointers to the memory stack.

PDB files ("program database") contain all the additional information and metadata for the debugger to do things like map addresses in memory with lines of source code, local variables, data types, function signatures, etc. This information is called "debugging characters" or simply "characters". When Visual Studio creates the DLL, it issues the corresponding PDB file. This is this PDB file, which allows all magic to go through the source code in the debugger, view local variables, properly view data types in the viewer.

When the Visual Studio debugger is connected to the process and sees the loaded DLL, it searches for the corresponding PDB file. He searches for this in several places - the simplest of which is in the same folder as the DLL. Therefore, if you downloaded C:\something\myctl.ocx , it will look for C:\something\myctl.pdb . If he can find it, he will use it, and you can debug the DLL with rich debugger support. If he cannot find it, you will be where you are now - where DLL calls are a black box that you cannot see.

Microsoft even provides PDB files for the Windows DLL, such as ntdll.dll . They should be downloaded as needed. Visual Studio can do this automatically by going to Tools -> Options -> Debugging -> Symbols , and it should be possible to use Microsoft Symbol Servers to automatically retrieve missing symbol files.

A small example to put you in the right direction:

Say you wrote an OCX called myctl.ocx , which crashes when it is added to a Wordpad document. The way to debug is to attach the debugger to wordpad.exe . In Visual Studio, that Debug -> Attach to Process , I find. When it is attached, you can even see in the output window:

 'wordpad.exe': Loaded 'C:\Program Files\Windows NT\Accessories\wordpad.exe', Symbols loaded (source information stripped). 'wordpad.exe': Loaded 'C:\Windows\System32\ntdll.dll', Symbols loaded (source information stripped). 'wordpad.exe': Loaded 'C:\Windows\System32\kernel32.dll', Symbols loaded (source information stripped). 'wordpad.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Symbols loaded (source information stripped). ... 

You can see how Visual Studio loads PDB files (symbol files), which provide a little extra information for them. When you load myctl.ocx , you will see this line. If myctl.pdb is available, it will also download it.

 'wordpad.exe': Loaded 'C:\something\myctl.ocx', Symbols loaded. 

With this, you can debug anything in myctl.ocx with the source code and everything else. When Wordpress crashes inside myctl.ocx , it should show you the source code and everything, again taking it in an accessible place.

+9
source

Add code to OCX that opens the file and prints what happens, possibly with a timestamp. The contents of the log may include a thread of execution, input values, values โ€‹โ€‹of critical variables, an important internal state.

At least that's how I approach him.

+1
source

How to debug OCX / C ++ in IE.10 + WIN8 64bit + VS2008
* .build ocx in vs2008, add the CSID ocx tag to your html.
* .Keep TabProcGrowth with environment (doesn't change!)
* .Create a VS2008 OCX project Debugging using the command C:\Program Files (x86)\Internet Explorer\iexplore.exe,Attach = Yes,Debugger Type=Native Only
*. Open the Explore 10 on the Internet panel in the WIN8 taskbar.
* .key in the ocx htm target file path in the URL of Internet Explorer 10. and press enter to download htm.
*. ocx is loaded and you need to enable IE 10 ActiveX mode.
*. When IE10 was ready to use ActiveX, start the VS2008 OCX project, which will attach IE10 with a breakpoint.
* .Refresh IE.10 html restart ocx again and start debugging ocx source code.

+1
source

Source: https://habr.com/ru/post/1432690/


All Articles